Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?

What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?

In my opinion, 'VALID' means there will be no zero padding outside the edges when we do max pool.

According to A guide to convolution arithmetic for deep learning, it says that there will be no padding in pool operator, i.e. just use 'VALID' of tensorflow. But what is 'SAME' padding of max pool in tensorflow?

like image 581
karl_TUM Avatar asked Jun 07 '16 08:06

karl_TUM


People also ask

What is the difference between same and valid padding in Tensorflow?

To sum up, 'valid' padding means no padding. The output size of the convolutional layer shrinks depending on the input size & kernel size. On the contrary, 'same' padding means using padding.

What does padding =' Same mean?

The padding type is called SAME because the output size is the same as the input size(when stride=1). Using 'SAME' ensures that the filter is applied to all the elements of the input. Normally, padding is set to "SAME" while training the model.

What's the difference between valid convolution and same convolution in a CNN?

A valid convolution is a type of convolution operation that does not use any padding on the input. where s is the stride length of the convolution. This is in contrast to a same convolution, which pads the n×n n × n input matrix such that the output matrix is also n×n n × n .

What does padding same do in keras?

"same" results in padding with zeros evenly to the left/right or up/down of the input. When padding="same" and strides=1 , the output has the same size as the input.


1 Answers

If you like ascii art:

  • "VALID" = without padding:

       inputs:         1  2  3  4  5  6  7  8  9  10 11 (12 13)                   |________________|                dropped                                  |_________________| 
  • "SAME" = with zero padding:

                   pad|                                      |pad    inputs:      0 |1  2  3  4  5  6  7  8  9  10 11 12 13|0  0                |________________|                               |_________________|                                              |________________| 

In this example:

  • Input width = 13
  • Filter width = 6
  • Stride = 5

Notes:

  • "VALID" only ever drops the right-most columns (or bottom-most rows).
  • "SAME" tries to pad evenly left and right, but if the amount of columns to be added is odd, it will add the extra column to the right, as is the case in this example (the same logic applies vertically: there may be an extra row of zeros at the bottom).

Edit:

About the name:

  • With "SAME" padding, if you use a stride of 1, the layer's outputs will have the same spatial dimensions as its inputs.
  • With "VALID" padding, there's no "made-up" padding inputs. The layer only uses valid input data.
like image 181
MiniQuark Avatar answered Oct 12 '22 22:10

MiniQuark