pytorchF.grid_sample用法

torch.nn.functional.grid_sample(input, grid, mode=’bilinear’, padding_mode=’zeros’, align_corners=None)

pytorchF.grid_sample用法
举个例子,input的shape为[1, 128, 124, 186],
可以知道N = 1 , C = 128 , H i n = 124 , W i n = 186 N=1, C=128, H_{in}=124,W_{in}=186 N =1 ,C =1 2 8 ,H i n ​=1 2 4 ,W i n ​=1 8 6

现在想从input中采些值出来,形成一个2285×1的一维特征向量,
H o u t = 2285 , W o u t = 1 H_{out}=2285, W_{out}=1 H o u t ​=2 2 8 5 ,W o u t ​=1

所以grid的shape为[1, 2285, 1, 2]
最后一个维度2是(x, y)坐标,注意是(x, y)而不是(h, w),它们是行列互换的关系。
而且(x, y)坐标是归一化到[-1, 1]内的:[-1, -1]对应input的左上角,[1, 1]对应input的右下角,(x, y)可以不是整数。
看官网关于维度的解释

For each output location output[n, :, h, w], the size-2 vector grid[n,
h, w] specifies input pixel locations x and y,

把grid中(x, y)坐标对应的每个C中input的值,填入到对应C的output中。因为grid的(x, y)坐标可以不是整数,所以要用到插值,
插值方法通过mode选定,比如双线性插值’bilinear’。

前面说(x, y)坐标要归一化到[-1, 1],如果超出了这个范围,要用到padding。

pytorchF.grid_sample用法

Original: https://blog.csdn.net/level_code/article/details/123817583
Author: 蓝羽飞鸟
Title: pytorchF.grid_sample用法

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/712044/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球