For tf.layers.conv2d
, I noticed that padding="VALID"
sometimes does padding lengths with negative values.
This page in the docs says that with "VALID"
padding, the padding length is calculated as follows:
out_height = math.ceil(float(in_height - filter_height + 1) / float(strides[1]))
pad_along_height = ((out_height - 1) * strides[1] +
filter_height - in_height)
If you use these values, for example:
in_height = 150
filter_height = 7
strides = (1, 4, 4, 1)
Then you get pad_along_height == -3
. Why would tensorflow sometimes choose negative padding by default? This seems weird to me. You lose information about the previous layer. Shouldn't "VALID"
padding be the minimum amount of padding to retain all the information from the previous layer? Rather than losing 3 rows, (and getting an output height of 36), I think I would've preferred padding with 1 row and getting an output height of 37.
Why did Google implement it this way? It's not really "padding" is it? More like "truncating". It just doesn't make sense to me.
EDIT: Note - In this case "SAME"
will produce pad_along_height == 5
for an output height of 38.