Keras gets irregular output

For the next 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, a summary of the models gives the following conclusion.

____________________________________________________________________________________________________
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 form?

+2
source share
1 answer

This is a problem caused by the installation input_shape. In the current setting, you want to enter 256x256 with 3 channels. However, Keras thinks you are giving 3x256 images with 256 channels. There are several ways to fix this.

  • Option 1: reorder to input_shape

  • Option 2: specify image_dim_orderingin your layers

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

+5
source

Source: https://habr.com/ru/post/1667080/


All Articles