Kerras : Found 39 images belonging to 3 classes. Found 49 images belonging to 3 classes

Viewed 2108
from keras.preprocessing.image import ImageDataGenerator

WIDTH = 299
HEIGHT = 299
BATCH_SIZE = 32

# data prep
train_datagen = ImageDataGenerator(
    preprocessing_function=preprocess_input,
    rotation_range=40,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    fill_mode='nearest')

validation_datagen = ImageDataGenerator(
    preprocessing_function=preprocess_input,
    rotation_range=40,
    width_shift_range=0.2,
    height_shift_range=0.2,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True,
    fill_mode='nearest')

train_generator = train_datagen.flow_from_directory(
    TRAIN_DIR,
    target_size=(HEIGHT, WIDTH),
        batch_size=BATCH_SIZE,
        class_mode='categorical')

validation_generator = validation_datagen.flow_from_directory(
    TEST_DIR,
    target_size=(HEIGHT, WIDTH),
    batch_size=BATCH_SIZE,
    class_mode='categorical')

For this part of the code my output is supposed to be"Found 39 images belonging to 2 classes.

Found 49 images belonging to 2 classes". But am getting 3 classes.

Please do help me.Thanks in advance.Also could anyone tell on what basis it divides into classes

for full code please do check out this link https://colab.research.google.com/drive/18AN2AUM5sEsTMGUzFUL0FLSULtXF4Ps0

4 Answers

Check the directories present in your folder using this code, this displays the names of all directories in that folder. This code displays all directories even though it is hidden.

          import os
          dir = os.listdir('path_to_your_main_directory')
          print(dir)

Now, after you know the name of the unwanted subdirectory, delete it by using the below code

         file_path = ('path_to_your_main_directory/subdirectory_name')
         os.rmdir(file_path)

Colab automatically creates a folder named '.ipynb_checkpoints' on the working directory in gdrive. Make sure to delete it before you start generating your data.

As you have binary classification problem, Can you try to change class_mode to 'binary` as shown below

train_generator = train_datagen.flow_from_directory(
    TRAIN_DIR,
    target_size=(HEIGHT, WIDTH),
        batch_size=BATCH_SIZE,
        class_mode='binary')

validation_generator = validation_datagen.flow_from_directory(
    TEST_DIR,
    target_size=(HEIGHT, WIDTH),
    batch_size=BATCH_SIZE,
    class_mode='binary')

Edit: I think it will add an extra file in the folder as shown in the screenshot below

enter image description here

Check for a new folder. It might be created by colab.

Related