我正在使用 Tensorflow 1.4.0
Tensorflow tf.image.resize_bilinear() 有一个名为“align_corners”的参数,我对将其设置为 False 时的行为感到困惑。在official document ,它说:
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.
当我在以下程序中使用 tf.image.resize_bilinear() 和 align_corners=True 时:
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)
输出
[[[[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. ]]]]
哪些角正确对齐。
但是当我设置 align_corners=False 时,我得到了以下奇怪的输出
[[[[1. ]
[1.5]
[2. ]
[2. ]]
[[2. ]
[2.5]
[3. ]
[3. ]]
[[3. ]
[3.5]
[4. ]
[4. ]]
[[3. ]
[3.5]
[4. ]
[4. ]]]]
有没有人明白为什么 Tensorflow 会使用这种奇怪的实现方式?我在任何地方都找不到任何解释。
实际上 PyTorch 的双线性上采样也有 align_corner 参数,当你将它设置为 True 时,它工作得很好。但是,如果您将其设置为 False,它会执行与 Tensorflow 不同的行为。我现在对他们的实现完全感到困惑(也许只使用 align_corners=True 就可以了)。
最佳答案
似乎是为了向后兼容。链接
https://hackernoon.com/how-tensorflows-tf-image-resize-stole-60-days-of-my-life-aba5eb093f35
建议我始终使用 align_corners=True
关于python - tf.image.resize_bilinear() - 当 align_corners=False 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51077930/