When I try to use the following snippet of code to try to predict on a batch of images, I get a message saying that no image were found.

test_datagen = ImageDataGenerator()

test_generator = test_datagen.flow_from_directory(
        target_size=(300, 300),
        shuffle = False,

filenames = test_generator.filenames

My directory structure is as follows. I first have a main directory named dogs_vs_cats in which I have two sub directories train and test containing the respective images and also the notebook which contains this code.

  • $\begingroup$ Could you post the exact ErrorMessage? $\endgroup$ – Danny May 9 '19 at 14:40
  • $\begingroup$ I actually solved the issue just now. I forgot to create 2 subdirectories inside the respective train and test folders and put the images in them. Thanks anyway $\endgroup$ – Jitesh Malipeddi May 9 '19 at 14:45
  • $\begingroup$ The output actually was 'Found 0 images belonging to 0 classes' $\endgroup$ – Jitesh Malipeddi May 9 '19 at 14:47

Keras generator alway looks for subfolders (representing the classes). Images insight the subfolders are associated with a class.

So whan you work on C:\images\ and you have two classes, say C1, C2, you need to create subfolders C:\images\C1\ and C:\images\C2\. The directory insight the generator function should point to C:\images\.

See this post for the case of image prediction: https://stackoverflow.com/a/55991598/9524424

  • 1
    $\begingroup$ Thanks a lot. This worked for me $\endgroup$ – Jitesh Malipeddi May 12 '19 at 12:07

There could be two situations when you run ImageDataGenerator on test set of images.

Case #1: Test folder has subfolders representing the classes. Peter has answered this part.

Case #2: There are no labelled test images. In this case, you will have a single test folder which contains all the images that you want to classify.

Kyle Banks has written a tip to handle this in his blog: https://kylewbanks.com/blog/loading-unlabeled-images-with-imagedatagenerator-flowfromdirectory-keras


There is another option with which you don't have to copy the test file into another test file:

datagen = ImageDataGenerator()

test_data = datagen.flow_from_directory('.', classes=['test'])

This solved my problem. For more info, see



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.