Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't understand shape(output) = (shape(value) - ksize + 1) / strides in TensorFlow docs

In the following excerpt from http://tensorflow.org/api_docs/python/nn.md#pooling

shape(output) = (shape(value) - ksize + 1) / strides

where the rounding direction depends on padding:

  • padding = 'SAME': Round down (only full size windows are considered).

  • padding = 'VALID': Round up (partial windows are included).

I can't understand the formula above. I am familiar with following formula though:

shape(out) = (shape(value) - ksize + 2*pad)/strides+1.

Are the two formulas equivalent?

For example, let's say shape(value) = 9, ksize = 3, strides = 2, and padding = 'SAME'.

In the first formula the shape(output) will be (9-3+1)/2 = 7/2 = 3.5 and rounding down results in 3.

In the second formula the shape(output) will be (9-3+2*1)/2 + 1 = 5

It doesn't seem to be the same formula. Even if I round up the first one, the result will be 4.

In addition to that, the padding definition seems to be inverted. Isn't the 'SAME' padding that includes partial windows?

like image 712
cesarsalgado Avatar asked Mar 16 '26 19:03

cesarsalgado


1 Answers

I think I figured out the problem. The two formulas become equivalent if you assume that the appropriate padding is already included in shape(value). But I still think the definition of the padding types have been swapped in the documentation. I created an issue to report that: https://github.com/tensorflow/tensorflow/issues/196

like image 51
cesarsalgado Avatar answered Mar 19 '26 13:03

cesarsalgado



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!