问题描述
在Keras中声明输入层时收到此错误消息.
I got this error message when declaring the input layer in Keras.
我的代码就是这样
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/)期望输入采用"channels-last"格式(样本,行,列,通道).您的数据似乎采用了格式(样本,通道,行,列).声明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/卷积"从1中减去3导致的负尺寸大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!