What is batches.N in mnist notebook?

In mnist notebook, inside

lm.fit_generator(batches, batches.N, nb_epoch=1,
validation_data=test_batches, nb_val_samples=test_batches.N)

what is batches.N represents and why it is necessary?

Take a look at the documentation to understand what each argument does.


steps_per_epoch: Total number of steps (batches of samples) to yield from generator before declaring one epoch finished and starting the next epoch. It should typically be equal to the number of unique samples of your dataset divided by the batch size.


Already did that. That’s what I was thinking too. steps_per_epoch. Such a silly one. Thank you Vishnu.

It actually depends on the Keras version you are using.
For recent versions (starting with 2.0) steps_per_epoch interpretation is indeed correct.
On older versions (up to 1.2.2) the parameter had a slightly different name and interpretation

Keras 1.2.2 docs : https://faroit.github.io/keras-docs/1.2.2/models/sequential/

samples_per_epoch: integer, number of samples to process before going to the next epoch.


Noted. thanks

Is the ‘batches.N’ equals to ‘batches.nb_sample’ in the code? I ask this because when I use ‘batches.N’, it will throw “AttributeError: ‘DirectoryIterator’ object has no attribute ‘N’”. However, when I use “batches.nb_sample”, the result looks the same as Jeremy’s.

It may something have to do with keras version. nb_sample was before keras 2 I think.

Hi @VishnuSubramanian,
How can we find the attributes of the batches generator.
For example : batches.N

What are the other attributes does the batches object has? I tried looking at the
keras documentation used in the Part 1 course https://faroit.github.io/keras-docs/1.1.1/ couldn’t find the details I was looking for?
It details the various methods of fit_generator etc…

I do not entirely rely on the tab operator of Jupyter notebook to find the list of attributes the object supports… if possible any pointers on the documentation would greatly help…