我有以下两个Tensor:
*img是形状(224,224,3)的RGB图像
*uvs是具有相同空间大小的Tensor,例如(224,224,2),其Map到坐标(x,y)。换句话说,其为输入图像的每个像素提供(x,y)坐标。
现在我想创建一个新的输出图像Tensor,它包含索引(x,y)上的输入图像的值,所以输出应该也是一个像素根据MapTensor重新排列的图像。
小玩具举例:
img = [[c1,c2], [c3, c4]] where c is a RGB color [r, g, b]
uvs = [[[0,0], [1,1]],[[0,1], [1,0]]]
out = [[c1, c3], [c4, c2]]
如何在pytorch中以快速矢量化的方式实现这样的事情呢?
3条答案
按热度按时间7jmck4yq1#
尝试使用:
3gtaxfhh2#
我能够解决它(在Quang Hoang的帮助下回答)
ajsxfq5m3#
您需要的是torch.nn.functional.grid_sample()。您可以这样做: