How to get classes from generator in case of Shuffle=True
See original GitHub issueI’ve 10100 images split into 101 folders(classes) that I want to store as single dataset using keras datagen.flow_from_directory.
Here is the code
datagen = ImageDataGenerator(rescale=1./255)
generator = datagen.flow_from_directory(
train_data_dir,
target_size=(150, 150),
batch_size=12,
class_mode='sparse',
shuffle=True)
However I want to shuffle the data while doing so,hence ideally generator.classes output should have been something like this [0, 4, 5, 3, 2 . . …<some random number between 0-100>] …and 101 such column each with 100 elements vertically one under other.However the actual class out put isn’t showing any random fashion and rather showing the value like this 0, 0, . 100 such 0’s followed by 100 such 1’s …upto 100 such 100.hence no random fashion is seen. Any idea whether this is a bug or there is a work around for this.
Please make sure that the boxes below are checked before you submit your issue. Thank you!
- Check that you are up-to-date with the master branch of Keras. You can update with: pip install git+git://github.com/fchollet/keras.git --upgrade --no-deps
- If running on Theano, check that you are up-to-date with the master branch of Theano. You can update with: pip install git+git://github.com/Theano/Theano.git --upgrade --no-deps
- Provide a link to a GitHub Gist of a Python script that can reproduce your issue (or just copy the script here if it is short).
Issue Analytics
- State:
- Created 7 years ago
- Comments:10
This works for both
shuffle=False
andshuffle=True
:Hope this helps.
generator.classes gives the class assigned to each sample based on the sorted order of folder names, you can check it here, It is just a list of length nb_samples (in your case 10100) with each field having sample’s class index, they are not shuffled at this point.
The samples are shuffled with in the batch generator(here) so that when a batch is requested by the fit_generator or evaluate_generator random samples are given.
Hope this helps.