关于blinear中 api里面的align=True和False,其实就是角点是否对齐的选项。
- 在opencv中,blinear默认调用的是align=False
- 在pytorch和tensorflow中, 可以通过api去切换align
先放一张图直观的理解一下:
可以明显的看到align_corners=True的时候,角点是对齐状态。而align_cornels=False的时候,角点并没有对齐。
用代码去描述上述的区别为:
# 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)
参考自:
https://discuss.pytorch.org/t/what-we-should-use-align-corners-false/22663/6
https://zhuanlan.zhihu.com/p/87572724