0
$\begingroup$

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?

$\endgroup$
0
$\begingroup$

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:

  1. Your generator should inherit from keras.utils.Sequence, which allows for internal parallelization of training
  2. 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.
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.