keras-team / keras-preprocessing

Utilities for working with image data, text data, and sequence data.
Other
1.02k stars 444 forks source link

TimeseriesGenerator - how to add third dimension for predict_generator() function to work? #259

Closed HoyaTrader closed 4 years ago

HoyaTrader commented 4 years ago

Hello - I am trying to use TimeseriesGenerator to take univariate data (as numpy arrays of shape (samples, 1)), to train an LSTM, but I can't seem to get the third dimension to appear in the TimeseriesGenerator object. I am trying a number of things, like making data and target different objects with the same data, playing around with different timesteps, etc., but nothing seems to add a third dimension as needed to train a model or make predictions.

Any help would be much appreciated.

HoyaTrader commented 4 years ago

Is it possible to add a third dimension onto a TimeseriesGenerator object directly? The example below produces a three dimensional TImeseriesGenerator object, whereas my code above only makes a 2D object. Without the 3d input, the predict_generator function also does not work.

My code above also aims to feed in a univariate vector of data in, but I am not sure where I went wrong to get a 2D output.

from keras.preprocessing.sequence import TimeseriesGenerator import numpy as np data = np.array([[i] for i in range(50)]) targets = np.array([[i] for i in range(50)])

data_gen = TimeseriesGenerator(data, targets, length=10, sampling_rate=2, batch_size=2) (from Keras' website)