1

I am learning Keras with Tensorflow and I build as very simple model which takes input image of size224x224x3 and applies MaxPooling, flatten it into 1D vector and this 1D vector is the output.

Please note that, this model is just purely for tutorial purpose. However, when I see the summary of the model i.e., model.summary() the output of the pooling layer is of same size as the input.

Code:

    in_shape = (224, 224, 3)
    in_feats = Input(shape=in_shape)
    pool = MaxPooling2D(pool_size=4, strides=1, padding='same')(in_feats)
    flat = Flatten(name='flat')(pool)
    model = Model(inputs=in_feats, outputs=flat)
    # print summary
    print (model.summary())

The summary is as follows:

Layer (type)                 Output Shape              Param #   
=================================================================
input_1 (InputLayer)         (None, 224, 224, 3)       0         
_________________________________________________________________
pool (MaxPooling2D)          (None, 224, 224, 3)       0         
_________________________________________________________________
flat (Flatten)               (None, 150528)            0         
=================================================================
Total params: 0
Trainable params: 0
Non-trainable params: 0
_________________________________________________________________

As you will notice the output from the pooling layer is same size as the input. What may be causing this?

kcc__
  • 1,638
  • 4
  • 30
  • 59

1 Answers1

1

It was a silly mistake. It result depends on the padding type used with the pooling layer. The following gives the correct result.

pool = MaxPooling2D(pool_size=4, strides=1, padding='valid')(in_feats)

You can read more about the padding here

kcc__
  • 1,638
  • 4
  • 30
  • 59