Reputation: 612
I have model, that looks like this :
Model: "sequential_4"
_________________________________________________________________
Layer (type) Output Shape Param #
=================================================================
conv2d_170 (Conv2D) (None, 256, 256, 32) 320
_________________________________________________________________
batch_normalization_169 (Bat (None, 256, 256, 32) 128
_________________________________________________________________
activation_166 (Activation) (None, 256, 256, 32) 0
_________________________________________________________________
conv2d_171 (Conv2D) (None, 256, 256, 32) 9248
_________________________________________________________________
batch_normalization_170 (Bat (None, 256, 256, 32) 128
_________________________________________________________________
activation_167 (Activation) (None, 256, 256, 32) 0
_________________________________________________________________
max_pooling2d_35 (MaxPooling (None, 128, 128, 32) 0
..............
But it gives me :
ValueError: Input 0 of layer sequential_4 is incompatible with the layer: expected axis -1 of input shape to have value 1 but received input with shape [None, 256, 256, 3]
Properties of my images :
print(imm.dtype) # float32
print(imm.ndim) # 3
print(imm.shape) # (256, 256, 3)
This error gets raised at :
history = model.fit(
x = train_x, y = train_y,
#batch_size=32,
#epochs=epochs,
#verbose=1,
#shuffle=True,
#validation_split=0.2
)
Trace :
ValueError Traceback (most recent call last)
<ipython-input-36-bf5138504d79> in <module>()
2
3 history = model.fit(
----> 4 x = train_x, y = train_y,
5 #batch_size=32,
6 #epochs=epochs,
When I remove a single comment from model fit, the error gets one line down.
Upvotes: 2
Views: 11607
Reputation: 151
This model is missing the input layer. Start the model sequence with the input layer.
keras.layers.InputLayer(input_shape=(256, 256, 3))
Upvotes: 1
Reputation: 3205
The image has 3
channels, but the first layer has 32
channels. The first layer should have same channel as input image.
Would you please try by adding a new input layer at the beginning of the model (I mean before conv2d_170
layer).
keras.Input(shape=(256, 256, 3))
Upvotes: 2