Context:
I am currently working on time series prediction using Keras with Tensorflow backend and, therefore, studied the tutorial provided here.
Following this tutorial, I came to the point where the generator for the fit_generator() method is described. The Output this generator generates is as follows (left sample, right target):
[[[10. 15.]
[20. 25.]]] => [[30. 35.]]
[[[20. 25.]
[30. 35.]]] => [[40. 45.]]
[[[30. 35.]
[40. 45.]]] => [[50. 55.]]
[[[40. 45.]
[50. 55.]]] => [[60. 65.]]
[[[50. 55.]
[60. 65.]]] => [[70. 75.]]
[[[60. 65.]
[70. 75.]]] => [[80. 85.]]
[[[70. 75.]
[80. 85.]]] => [[90. 95.]]
[[[80. 85.]
[90. 95.]]] => [[100. 105.]]
In the tutorial the TimeSeriesGenerator was used, but for my question it is secondary if a custom generator or this class is used. Regarding the data, we have 8 steps_per_epoch and a sample of shape (8, 1, 2, 2). The generator is fed to a Recurrent Neural Network, implemented by an LSTM.
My questions
fit_generator() only allows a single target per batch, as outputted by the TimeSeriesGenerator. When I first read about the option of batches for fit(), I thought that I could have multiple samples and a corresponding number of targets (which are processed batchwise, meaning row by row). But this is not allowed by fit_generator() and, therefore, obviously false.
Secondly, I thought that, for example, [10, 15] and [20, 25] were used as input for the RNN consecutively for the target [30, 35], meaning that this is analog to inputting [10, 15, 20, 25]. Since the output from the RNN differs using the second approach (I tested it), this also has to be a wrong conclusion.
Hence, my questions are:
- Why is only one target per batch allowed (I know there are some workarounds, but there has to be a reason)?
- How may I understand the calculation of one batch? Meaning, how is some input like
[[[40, 45], [50, 55]]] => [[60, 65]]processed and why is it not analog to[[[40, 45, 50, 55]]] => [[60, 65]]
from Keras fit_generator() - How does batch for time series work?
No comments:
Post a Comment