Custom Data Generator for Keras LSTM with TimeSeriesGenerator
It could be because the object type is changed from Sequence
which is what a TimeseriesGenerator
is to a generic generator. The fit_generator
function treats these differently. A cleaner solution would be to inherit the class and override the processing bit:
class CustomGen(TimeseriesGenerator):
def __getitem__(self, idx):
x, y = super()[idx]
# do processing here
return x, y
And use this class like before as the rest of internal logic will remain the same.
I personally had a problem with the code by nuric. For some reason I had the error saying super not being subscriptable. Here is my possible fix. Let me known if this could possibly work?
class CustomGen(TimeseriesGenerator):
def __getitem__(self, idx):
x,y = super().__getitem__(idx)
return x, y