Keras generator Function
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 __getitem__() and __len__() methods. The first makes your generator iterable and the second returns its length using the builtin len command on the generator object. Both are required by Keras.