I am using to classify the handwritten characters and following my CNN model. I have converted the images to gray scale and binarized. How can I solve this problem?
model = models.Sequential()
model.add(layers.Conv2D(filters=10,kernel_size=(3,3),padding = 'same', input_shape=(100, 100, 3),activation = 'relu'))
model.add(layers.Conv2D(30,(5,5),activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Dropout(0.5))
model.add(layers.Conv2D(40,(3,3),activation='relu'))
model.add(layers.Conv2D(60,(3,3),activation='relu'))
model.add(layers.MaxPooling2D(pool_size=(2,2)))
model.add(layers.Flatten())
model.add(layers.Dense(180,activation='relu'))
model.add(layers.Dropout(0.5))
model.add(layers.Dense(100,activation='relu'))
model.add(layers.Dense(12,activation='softmax'))
Error
ValueError: Input 0 of layer sequential_41 is incompatible with the layer: expected ndim=4, found ndim=3. Full shape received: [None, 100, 100]
In your model you've stated the input shape to be (100,100,3)
. The model is expecting a 3 channel image but you've said your input data is grayscale, meaning that it only has one channel. This means that your input data is of the shape (100,100,1)
, which then is just (100,100)
. With the addition of the batch_size
dimension it becomes [None,100,100]
which is the error you are getting.
Changing the input shape to (100,100,1)
should do the trick.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.