Reputation: 781
I am using ImageDataGenerator to create validation set ( for an image classification using TF (Keras) from a labeled directory of images. The directories are 0,1,2,3,4 corresponding to class of each image, they contain 488, 185, 130, 131, 91 images respectively.
train_image_generator = ImageDataGenerator(rescale=1./255) # Generator for our training data
# validation_image_generator = ImageDataGenerator(rescale=1./255) # Generator for our validation data
train_data_gen = train_image_generator.flow_from_directory(batch_size=batch_size,
directory=train_dir,
shuffle=True,
target_size=(IMG_HEIGHT, IMG_WIDTH),
class_mode='categorical')
returns
Found 0 images belonging to 5 classes.
and the code below
validation_data_generator = train_image_generator.flow_from_directory(
train_dir, # same directory as training data
target_size=(IMG_HEIGHT, IMG_WIDTH),
batch_size=batch_size,
class_mode='categorical',
subset='validation') # set as validation data
outputs:
Found 0 images belonging to 5 classes.
What is wrong please? I suppose the validation set has at least few images for last class!
Any help would be greatly appreciated.
CS
Upvotes: 0
Views: 452
Reputation: 46
It's hard to say without seeing what your directory string is, but I suspect perhaps the problem could be with characters in your "train_dir" variable. You can try using os.path.exists(train_dir) to see if your code is actually pointing to the right spot, or use os.listdir to see if you're seeing the files that way.
Throwing this line in there before you create your data generators might solve it:
import os
train_dir=os.path.normpath(train_dir)
Usually I find the problem is with the slashes in a path. If you just want to use a string, you usually need to use double backslashes (\) or a single forward slash (/) instead of the single backslashes you usually see in a path. This is especially problematic when your filenames or sub-directories start with a number (as yours do).
Upvotes: 2