0
$\begingroup$

I'm working on a deep learning (CNN) problem. I have structured my images into folders correctly (I think), like this:

train_dir:
   - class 1
   - class 2
validation_dir:
   - class 1
   - class 2
test_dir:
   - class 1
   - class 2

The images are PNG in a (196,256,3) format but will I'd like to convert them to (196,256,1) because they are grayscale. I do this with the flow_from_directory argument color_mode='grayscale'

As such the code I have so far to get on with this is:

train_datagen = ImageDataGenerator(rescale=1./255) # re-scale pixel values between [0,1]
test_datagen = ImageDataGenerator(rescale=1./255)

train_generator = train_datagen.flow_from_directory(
        train_dir,
        target_size = (196,256),
        color_mode='grayscale',
        batch_size=20,
        class_mode='binary')

validation_generator = test_datagen.flow_from_directory(
        validation_dir,
        target_size = (196,256),
        color_mode='grayscale',
        batch_size=20,
        class_mode='binary')

With train_dir and validation_dir being strings with the equivalent path of the correct folders I mentioned earlier above.

However I get this error when running this section of the code:

Found 0 images belonging to 2 classes

After trying for sometime I can't figure out what's wrong. Does anyone have a clue?

$\endgroup$
1
  • $\begingroup$ maybe the images are stored in subdirectories inside your two directories? $\endgroup$
    – Djib2011
    Oct 17, 2018 at 17:44

2 Answers 2

1
$\begingroup$

SOLVED!

Always be sure you have '.png' or whatever other file extension you are using at the end of your filename

$\endgroup$
0
$\begingroup$

Please add class name under classes=(' ', ' ')

train_generator = train_datagen.flow_from_directory( train_dir, target_size = (196,256), color_mode='grayscale', batch_size=20,classes=('class 1','class 2') class_mode='binary')

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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