对于以下CNN
model = Sequential()
model.add(Convolution2D(64, 3, 3, border_mode='same', input_shape=(3, 256, 256)))
# now model.output_shape == (None, 64, 256, 256)
# add a 3x3 convolution on top, with 32 output filters:
model.add(Convolution2D(32, 3, 3, border_mode='same'))
# now model.output_shape == (None, 32, 256, 256)
print(model.summary())
然而,模型摘要给出了以下输出
____________________________________________________________________________________________________
Layer (type) Output Shape Param # Connected to
====================================================================================================
convolution2d_44 (Convolution2D) (None, 3, 256, 64) 147520 convolution2d_input_24[0][0]
____________________________________________________________________________________________________
convolution2d_45 (Convolution2D) (None, 3, 256, 32) 18464 convolution2d_44[0][0]
====================================================================================================
Total params: 165984
为什么我得到给定的输出形状?
这是input_shape
的设置导致的问题。在当前设置中,您想要输入3通道的256x256。但是,Keras认为您提供的是带有256通道的3x256图像。有几种方法可以纠正它。
-
选项1:更改
input_shape
中的顺序 选项2:在图层中指定
image_dim_ordering
选项3:通过将~/.keras/keras.json
中的'tf'更改为'th'来修改keras配置文件