Keras 得到错误的输出形状

Keras getting wrong output shape

对于以下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设置的问题。在您当前的设置中,您想要输入 256x256 和 3 个通道。但是,Keras 认为您提供的是具有 256 个通道的 3x256 图像。有几种方法可以纠正它。

  • 选项 1:更改 input_shape

  • 中的顺序
  • 选项 2:在图层中指定 image_dim_ordering

  • 方案三:修改keras配置文件,将你的~/.keras/keras.json[=13中的'tf'改为'th' =]