What is the difference between 'SAME' and 'VALID' padding in tf.nn.max_pool of tensorflow?
In tf.nn.max_pool of tensorflow what is the difference between 'SAME' and 'VALID'?
I read in here that there's no padding in pool operator means we just have to use 'VALID padding' of tensorflow. Then what does 'SAME' padding of max pool means in tensorflow?
VALID Padding: it means no padding and it assumes that all the dimensions are valid so that the input image gets fully covered by a filter and the stride specified by you.
SAME Padding: it applies padding to the input image so that the input image gets fully covered by the filter and specified stride.It is called SAME because, for stride 1 , the output will be the same as the input.
Let’s see an example:
Here,
a is the input image of shape [2, 3], 1 channel
validPad refers to max pool having 2x2 kernel, stride=2 and VALID padding.
samePad refers to max pool having 2x2 kernel, stride=2 and SAME padding.
a = tf.constant([[1., 2., 3.],
[4., 5., 6.]])
a = tf.reshape(x, [1, 2, 3, 1])
validPad = tf.nn.max_pool(x, [1, 2, 2, 1], [1, 2, 2, 1], padding='VALID')
samePad = tf.nn.max_pool(x, [1, 2, 2, 1], [1, 2, 2, 1], padding='SAME')
validPad.get_shape() == [1, 1, 1, 1]
samePad.get_shape() == [1, 1, 2, 1]
Output shapes are-
validPad : output shape is [1,1]
samePad: output shape is [1,2]