Search code examples
kerasclassificationgenerator

value of steps per epoch passed to keras fit generator function


What is the need for setting steps_per_epoch value when calling the function fit_generator() when ideally it should be number of total samples/ batch size?


Solution

  • Keras' generators are infinite.

    Because of this, Keras cannot know by itself how many batches the generators should yield to complete one epoch.

    When you have a static number of samples, it makes perfect sense to use samples//batch_size for one epoch. But you may want to use a generator that performs random data augmentation for instance. And because of the random process, you will never have two identical training epochs. There isn't then a clear limit.

    So, these parameters in fit_generator allow you to control the yields per epoch as you wish, although in standard cases you'll probably keep to the most obvious option: samples//batch_size.