Reputation: 672
I am unable to understand why tensorflow maxpooling with my parameters.
When performed a maxpool with ksize=2
and strides=2
i get the following output with both padding SAME
and padding VALID
input : (?, 28, 28, 1)
conv2d_out : (?, 28, 28, 32)
maxpool2d_out : (?, 14, 14, 32)
But when I try to perfrom maxpool with ksize=3
and strides=1
, I get the following output:
input : (?, 28, 28, 1)
conv2d_out : (?, 28, 28, 32)
maxpool2d_out : (?, 28, 28, 32) PADDING SAME
maxpool2d_out : (?, 26, 26, 32) PADDING VALID
maxpool with ksize=2
and strides=2
using padding SAME
should have produced the output maxpool2d_out : (?, 28, 28, 32)
Is there something I missed out on how max pooling with padding works?
**CODE**==
python_
Upvotes: 0
Views: 490
Reputation: 6660
I saw in your code you use padding=SAME
. When using the SAME paddding and strides=1
, the input and output size are the same. Why do you think the tensorflow implementation is wrong?
Update: According to tensorflow documentation:
Using SAME padding
out_height = ceil(float(in_height) / float(strides[1]))
out_width = ceil(float(in_width) / float(strides[2]))
Using VALID padding
out_height = ceil(float(in_height - filter_height + 1) / float(strides[1]))
out_width = ceil(float(in_width - filter_width + 1) / float(strides[2]))
It is celing((28-3+1)/1)= 26 when k=3, stride =1
It is ceiling((28-2+1)/2)= 14 when k=2, stride=2
As you can see, because of the ceiling function, your result happens to be the same using different PADDING configuration
Upvotes: 1
Reputation: 27042
You're using padding='SAME'
, this means that your output will be padded with zeros in order to have the same size of the input.
If you change padding
to VALID
then the output is not padded with zeros and the pooling operation will work as you expect.
Upvotes: 1