问题描述
我在 Keras 中声明输入层时收到此错误消息.
I got this error message when declaring the input layer in Keras.
ValueError: 负维度大小由 1 减去 3 引起'conv2d_2/convolution'(操作:'Conv2D')输入形状:[?,1,28,28],[3,3,28,32].
我的代码是这样的
model.add(Convolution2D(32, 3, 3, activation='relu', input_shape=(1,28,28)))
示例应用程序:https://github.com/IntellijSys/tensorflow/blob/master/Keras.ipynb
推荐答案
默认情况下,Convolution2D (https://keras.io/layers/convolutional/) 期望输入的格式为(样本、行、列、通道),即通道最后".您的数据似乎采用格式(样本、通道、行、列).在声明 Convolution2D 层时,您应该能够使用可选关键字 data_format = 'channels_first'
解决此问题.
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'))
这篇关于'conv2d_2/convolution' 由 1 减 3 引起的负尺寸大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!