0
votes

I am working with Keras to build my own CNN to identify cats and dogs. I've created a folder called "cats-and-dogs". This folder is in the same directory as is my jupyter notebook ("cats-and-dogs" folder & Keras.ipynb notebook both are in Anaconda3 folder). Now the further tree of folders looks like this:

cats-and-dogs/
|_______________train/
|_______________|_______cats/
|_______________________|_____1.jpg
|_______________________|_____2.jpg
|_______________________|_____...
|_______________|_______dogs/
|_______________________|_____21.jpg
|_______________________|_____22.jpg
|_______________________|_____...
|_______________test/
|_______________|_______cats/
|_______________________|_____41.jpg
|_______________________|_____42.jpg
|_______________________|_____...
|_______________|_______dogs/
|_______________________|_____61.jpg
|_______________________|_____62.jpg
|_______________________|_____...
|_______________Valid/
|_______________|_______cats/
|_______________________|_____81.jpg
|_______________________|_____82.jpg
|_______________________|_____...
|_______________|_______dogs/
|_______________________|_____101.jpg
|_______________________|_____102.jpg
|_______________________|_____...
Keras.ipynb
|____
|____
...

My code that gives out error is:

train_batches = ImageDataGenerator().flow_from_directory('cats-and-dogs/train', target_size=(224,224), classes=['dog','cat'], batch_size=10)

Expected output: Found 80 images belonging to 2 classes.
Actual output: Found 0 images belonging to 2 classes.

1
Why does it show 0 images even if there are 80 images in "train" subfolder ?Vinita Kumari
Try replacing the path with os.path.abspath('cats-and-dogs/train'), I'm pretty sure it needs an absolute path.TheLoneDeranger

1 Answers

2
votes

You are setting the classes parameter to classes=['dog','cat'], this will look for dog and cat folders, but your folders are called dogs and cats, so it makes sense that it finds no images.

Either remove the classes parameter for the generator to auto-detect the class names, or put the right classs names that match your folder names.