Negative dimension size caused by subtracting 3 from 1 for 'conv2d_2/convolution'

后端 未结 6 1712
情书的邮戳
情书的邮戳 2020-12-14 02:33

I got this error message when declaring the input layer in Keras.

ValueError: Negative dimension size caused by subtracting 3 from 1 for \'conv2d_2/

6条回答
  •  半阙折子戏
    2020-12-14 03:32

    By default, Convolution2D (https://keras.io/layers/convolutional/) expects the input to be in the format (samples, rows, cols, channels), which is "channels-last". Your data seems to be in the format (samples, channels, rows, cols). You should be able to fix this using the optional keyword data_format = 'channels_first' when declaring the Convolution2D layer.

    model.add(Convolution2D(32, (3, 3), activation='relu', input_shape=(1,28,28), data_format='channels_first'))
    

提交回复
热议问题