Reputation: 143
I'm new with Keras.
I'm working on the Keras Xception model (version 2.2.0) witch I have successfully trained with RGB images.
My resources are limited and therefore have converted the images into grey scale to reduce the data size (I am not sure if this is correct just an intuition). My current dataset consists of grayscale image and as mush as I studies keras pretrained models expect 3 channel input. I've tried the code below to generate image data:
train_generator = train_datagen.flow_from_directory(
train_folder,
target_size=(img_width, img_height),
color_mode='grayscale',
batch_size=batch_size,
shuffle=True,
seed=seed)
and then built the model as follow:
model = xception.Xception(include_top=False, input_shape=(img_width, img_height, 1))
but I get the error:
ValueError: The input must have 3 channels; got
input_shape=(257, 321, 1)
I've already check color_mode in data generator function and I've not found any solution. If anyone can help out sort the problem, it'd be much appreciated!
Upvotes: 0
Views: 1913
Reputation: 7129
As specified in the Keras documentation:
input_shape: optional shape tuple, only to be specified if include_top is False (otherwise the input shape has to be (299, 299, 3). It should have exactly 3 inputs channels, and width and height should be no smaller than 71. E.g. (150, 150, 3) would be one valid value.
You won't be able to feed grayscale images to this model. If memory is an issue, you can try reducing the width and height of your images, or using smaller batch sizes for training and for inference.
Upvotes: 1