align_corner=True/False 的解释

参考链接 what-we-should-use-align-corners-false
查阅资料的时候发现一张图,如下:

align_corner=True/False 的解释_第1张图片

代码角度的差别

# align_corners = False
# x_ori is the coordinate in original image
# x_up is the coordinate in the upsampled image
x_ori = (x_up + 0.5) / factor - 0.5
# align_corners = True
# h_ori is the height in original image
# h_up is the height in the upsampled image
stride = (h_ori - 1) / (h_up - 1)
x_ori_list = []
# append the first coordinate
x_ori_list.append(0)
for i in range(1, h_up - 1):
    x_ori_list.append(0 + i * stride)
# append the last coordinate
x_ori_list.append(h_ori - 1)

举例

假如要将 [0,1] 上采样2倍,
mode=‘bilinear’ and align_corners=False, 结果是 [-0.25, 0.25, 0.75, 0.75];
mode=‘bilinear’ and align_corners=True, 结果是 [0, 1/3, 2/3, 1].
align_corner=True/False 的解释_第2张图片

你可能感兴趣的:(计算机视觉)