Setting up a data generator
We are just missing one key ingredient before we try our framework out on a difficult test task. The previous recipe presented a TabularTransformer
that can effectively turn a pandas DataFrame into numerical arrays that a DNN can process. Yet, the recipe can only deal with all the data at once. The next step is to provide a way to create batches of the data of different sizes. This could be accomplished using tf.data
or a Keras generator and, since previously in the book we have already explored quite a few examples with tf.data
, this time we will prepare the code for a Keras generator that's capable of generating random batches on the fly when our DNN is learning.
Getting ready
Our generator will inherit from the Sequence
class:
from tensorflow.keras.utils import Sequence
The Sequence
class is the base object for fitting a sequence of data and it requires you to implement custom __getitem__
(which will return a complete batch) and...