If I don't shuffle my files, I can get the file names with generator.filenames
. But when the generator shuffles the images, filenames isn't shuffled, so I don't know how to get the file names back.
Internally, the DirectoryIterator
will iterate over an index_arrray
which is shuffled when you ask it to.
You just need to index the filename array using the current indexes of the batch:
it = ImageDataGenerator().flow_from_directory(shuffle=True,...)
for img in it:
idx = (it.batch_index - 1) * it.batch_size
fnames = [it.filenames[it.index_array[i]] for i in range(idx, idx + it.batch_size)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With