Cats and Dogs i=Image Classifier in Python

Hi, I have an issue in ImageDataGenerator. For test, ImageDataGenerator understand classes number but it can’t found images.

Expected Output:

Found 2000 images belonging to 2 classes.
Found 1000 images belonging to 2 classes.
Found 50 images belonging to 1 classes.

My Code:

train_image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
validation_image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)
test_image_generator = tf.keras.preprocessing.image.ImageDataGenerator(rescale=1./255)

train_data_gen = train_image_generator.flow_from_directory(train_dir, 
                                                           target_size=(IMG_HEIGHT, IMG_WIDTH), 
                                                           batch_size=batch_size, 
                                                           class_mode='binary', 
                                                           color_mode='rgb')
val_data_gen = validation_image_generator.flow_from_directory(validation_dir, 
                                                              target_size=(IMG_HEIGHT, IMG_WIDTH), 
                                                              batch_size=batch_size, 
                                                              class_mode='binary', 
                                                              color_mode='rgb')
test_data_gen = test_image_generator.flow_from_directory(directory=test_dir,
                                                         target_size=(IMG_HEIGHT, IMG_WIDTH),
                                                         batch_size=batch_size,
                                                         class_mode='binary',
                                                         color_mode='rgb',
                                                         classes=['test'],
                                                         shuffle=False)

My Output:

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

If you want to see notebook:
cats_dog_classifier

Thanks for your helps

This tells tf to load images from train_dir, using subdirectories of train_dir as the classes.

This tells tf to load images from test_dir in a subdirectory test for your listed class.

Since the directory structure for the data looks like

train
train/cats
train/dogs
validation
validation/cats
validation/dogs
test

if you’re using test_dir = "tests", there’s no subdirectory from which to load images.

See the documentation.

3 Likes