Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
559 views
in Technique[技术] by (71.8m points)

python - Keras getting wrong output shape

For the following 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())

However model summary gives the following output

____________________________________________________________________________________________________
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

Why am i getting the given output shape ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is a problem caused by the setting of input_shape. In your current setting, you want to input 256x256 with 3 channels. However, Keras thinks you are giving 3x256 image with 256 channels. There several ways to correct it.

  • Option 1: Change the order in input_shape

  • Option 2: Specify image_dim_ordering in your layers

  • Option 3: Modify the keras configuration file by changing 'tf' to 'th' in your ~/.keras/keras.json


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...