Keras flow_from_directory shuffle not working properly

Viewed 902

I am loading data using Keras flow_from_directory and i have set shuffle=True, but when I print train_generator.classes, it does not return me shuffle classes. It returns all classes in order in following way

array([0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
       2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
       3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4,
       4, 4, 4, 4, 4, 4, 4, 4, 4], dtype=int32)

SO what is the proper way to shuffle images, after being loaded

1 Answers

train_generator.classes gives the class assigned to each sample based on the sorted order of folder names. They are not shuffled at this point.

The samples are shuffled within the batch generator so that when a batch is requested by the fit_generator or evaluate_generator then the random samples are given.

Hope this helps.

Related