0
$\begingroup$

I get this error ValueError: Negative dimension size caused by subtracting 5 from 3 for '{{node conv2d_77/Conv2D}} = Conv2D[T=DT_FLOAT, data_format="NCHW", dilations=[1, 1, 1, 1], explicit_paddings=[], padding="VALID", strides=[1, 1, 1, 1], use_cudnn_on_gpu=true](conv2d_76/Relu, conv2d_77/Conv2D/ReadVariableOp)' with input shapes: [?,32,8,3], [5,5,32,32].

when I don't have padding = 'same' in my second layer in my model, and I get this error TypeError: add() got an unexpected keyword argument 'padding' when I have it.

Model:


model_cnn.add(Conv2D(filters = 32, kernel_size = (5, 5), activation = 'relu', input_shape = (SIZE, SIZE, 3), padding = 'same'))
model_cnn.add(Conv2D(filters = 32, kernel_size = (5, 5), activation = 'relu'), padding = 'same')
model_cnn.add(MaxPool2D(pool_size = (2, 2)))
model_cnn.add(Dropout(rate = 0.3))

model_cnn.add(Conv2D(filters = 64, kernel_size = (3, 3), activation = 'relu'))
model_cnn.add(Conv2D(filters = 64, kernel_size = (3, 3), activation = 'relu'))
model_cnn.add(MaxPool2D(pool_size = (2, 2)))
model_cnn.add(Dropout(rate = 0.3))

model_cnn.add(Flatten())
model_cnn.add(Dense(256, activation = 'relu'))
model_cnn.add(Dropout(rate = 0.3))
model_cnn.add(Dense(43, activation = 'softmax'))

model_cnn.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
```
$\endgroup$
0
$\begingroup$

The first error you're getting is likely because the input becomes too small for the network to perform a 5 by 5 convolution on. The second error is caused by the fact that you are placing the padding argument in the wrong place. You are currently using it for the model.add call, whereas you should use it with the Conv2D classs:

model_cnn.add(Conv2D(filters = 32, kernel_size = (5, 5), activation = 'relu', padding = 'same'))
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.