Xception input_shape channels

The name of the picture


Xception input_shape channels



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))


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)


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!




1 Answer
1



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.






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Keycloak server returning user_not_found error when user is already imported with LDAP

PHP parse/syntax errors; and how to solve them?

How to scale/resize CVPixelBufferRef in objective C, iOS