I am using Tensorflow 1.4.0
The Tensorflow tf.image.resize_bilinear() has an argument called 'align_corners' and I am confused with the behavior when we set it to be False. In the official document, it says:
align_corners: An optional bool. Defaults to False. If true, the centers of the 4 corner pixels of the input and output tensors are aligned, preserving the values at the corner pixels. Defaults to false.
When I use tf.image.resize_bilinear() with align_corners=True in the following program:
import tensorflow as tf
sess = tf.Session()
x = tf.Variable(tf.Variable([[[[1],[2]],[[3],[4]]]]))
pooling_output_size = [4, 4]
pool_output = tf.image.resize_bilinear(x, pooling_output_size,align_corners=True)
sess.run(tf.global_variables_initializer())
print pool_output.eval(session=sess)
it outputs
[[[[1. ]
[1.3333334]
[1.6666667]
[2. ]]
[[1.6666667]
[2. ]
[2.3333335]
[2.6666667]]
[[2.3333335]
[2.6666665]
[3. ]
[3.3333335]]
[[3. ]
[3.3333333]
[3.6666667]
[4. ]]]]
which corners are correctly aligned.
However when I set the align_corners=False, I got the following weird outputs
[[[[1. ]
[1.5]
[2. ]
[2. ]]
[[2. ]
[2.5]
[3. ]
[3. ]]
[[3. ]
[3.5]
[4. ]
[4. ]]
[[3. ]
[3.5]
[4. ]
[4. ]]]]
Is there anyone who understand why Tensorflow will use this weird implementation? I didn't find any explanation anywhere.
Actually PyTorch's bilinear upsampling has the align_corner argument too, when you set it to True, it works well. But if you set it to False, it performs a differnet behaviour to Tensorflow's. I am totally confused with their implementations now (maybe just use align_corners=True will be fine).