keras_lr_finder
keras_lr_finder copied to clipboard
May I use this with sequential(keras.utils.Sequence) data?
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: