I am trying to write a batch generator function so that I can train my Keras model using it but I don't know from where to start. Does anyone have some examples or tutorials?
This tutorial explains in a nice and simple way how to create a data generator which you can pass to your Keras model to train using
fit_generator(). Two things to keep in mind about Keras generators, in order to be compatible with Tensorflow 2.x requirements:
- Your generator should inherit from
keras.utils.Sequence, which allows for internal parallelization of training
- Populate the
__len__()methods. The first makes your generator iterable and the second returns its length using the builtin
lencommand on the generator object. Both are required by Keras.