我正在使用 Tensorflow 1.4.0
Tensorflow tf.image.resize_bilinear() 有一个名为“align_corners”的参数,当我们将其设置为 False 时,我对行为感到困惑。在官方文档中,它说:
align_corners:一个可选的布尔值。默认为假。如果为 true,则输入和输出张量的 4 个角像素的中心对齐,保留角像素处的值。默认为假。
当我在以下程序中使用 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)
Run Code Online (Sandbox Code Playgroud)
它输出
[[[[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. ]]]]
Run Code Online (Sandbox Code Playgroud)
哪些角正确对齐。
但是,当我设置 align_corners=False 时,我得到了以下奇怪的输出
[[[[1. ]
[1.5]
[2. ]
[2. ]]
[[2. ]
[2.5]
[3. ]
[3. …Run Code Online (Sandbox Code Playgroud)