Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

May I use this with sequential(keras.utils.Sequence) data? #33

Open
asapsmc opened this issue Oct 22, 2022 · 0 comments
Open

May I use this with sequential(keras.utils.Sequence) data? #33

asapsmc opened this issue Oct 22, 2022 · 0 comments

Comments

@asapsmc
Copy link

asapsmc commented Oct 22, 2022

I'm using 3rd party working code that fits a TCN-based model with

model.fit(train_seq, steps_per_epoch=len(train_seq), epochs=20)

where train_seq is a keras.utils.Sequence implemented by the following code:

def cnn_pad(data, pad_frames):
    """Pad the data by repeating the first and last frame N times."""
    pad_start = np.repeat(data[:1], pad_frames, axis=0)
    pad_stop = np.repeat(data[-1:], pad_frames, axis=0)
    return np.concatenate((pad_start, data, pad_stop))
    
class DataSequence(Sequence):
    def __init__(self, x, y, fps=FPS, pad_frames=None):
        self.x = x
        y_proc = np.zeros(np.shape(x)[1])
        np.add.at(y_proc, y[0]*FPS, 1)
        self.y = [y_proc]
        self.pad_frames = pad_frames

    def __len__(self):
        return len(self.x)

    def __getitem__(self, idx):
        x = np.array(cnn_pad(self.x[idx], self.pad_frames))[np.newaxis, ..., np.newaxis]
        y = self.y[idx][np.newaxis, ..., np.newaxis]
        return x, y

x = [np.random.randn(1949, 81)]  # to emulate audio
y = [np.asarray([1, 2, 3, 4, 5])]  # to emulate annotations
train_seq = DataSequence(x[:1], y[:1], pad_frames=2)

How may I use LRFinder for this type of data? Ie, is it possible to "retrieve" valid x and y from the Sequence?
To reproduce this issue (almost in entirety, with the exception of the keras h5 model), here is some dummy code:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant