TransWikia.com

Test data gives "Found 0 images in 0 classes" using flow_from_directory

Stack Overflow Asked by Umair Nasir on December 27, 2021

This is my flow_from_directory code

train_image_generator = ImageDataGenerator(rescale=1./255)
validation_image_generator = ImageDataGenerator(rescale=1./255)
test_image_generator = ImageDataGenerator(rescale=1./255)

train_data_gen = train_image_generator.flow_from_directory(
        train_dir,
        target_size=(150, 150),
        batch_size=batch_size,
        class_mode='binary')
val_data_gen =validation_image_generator.flow_from_directory(
        validation_dir,
        target_size=(150, 150),
        batch_size=batch_size,
        class_mode='binary')
test_data_gen = test_image_generator.flow_from_directory(
        test_dir,
        target_size=(150, 150),
        batch_size=batch_size,
        class_mode='binary',
        shuffle = False,)

And it prints:

Found 2000 images belonging to 2 classes.
Found 1000 images belonging to 2 classes.
Found 0 images belonging to 0 classes.

Even though the data exists as I used:

!ls /root/.keras/datasets/cats_and_dogs/test

Which gives the output:

10.jpg  15.jpg  1.jpg   24.jpg  29.jpg  33.jpg  38.jpg  42.jpg  47.jpg  5.jpg
11.jpg  16.jpg  20.jpg  25.jpg  2.jpg   34.jpg  39.jpg  43.jpg  48.jpg  6.jpg
12.jpg  17.jpg  21.jpg  26.jpg  30.jpg  35.jpg  3.jpg   44.jpg  49.jpg  7.jpg
13.jpg  18.jpg  22.jpg  27.jpg  31.jpg  36.jpg  40.jpg  45.jpg  4.jpg   8.jpg
14.jpg  19.jpg  23.jpg  28.jpg  32.jpg  37.jpg  41.jpg  46.jpg  50.jpg  9.jpg

what am I doing wrong or what must be Done?

One Answer

flow_from_directory expects a directory with a subdirectory by class. The problem with your test folder at the moment is that all images are in it, without any subdir by class. You need to create one subdir for each class, and put the images in the appropriate subdir.

Answered by Raphael Meudec on December 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP