【发布时间】:2021-04-11 12:34:51
【问题描述】:
这是this question 的后续问题。我想在 pytorch 中做同样的事情。是否有可能做到这一点?如果是,怎么做?
import torch
image = torch.tensor([[246, 50, 101], [116, 1, 113], [187, 110, 64]])
iy = torch.tensor([[1, 0, 2], [1, 0, 2], [2, 2, 2]])
ix = torch.tensor([[0, 2, 1], [1, 2, 0], [0, 1, 2]])
warped_image = torch.zeros(size=image.shape)
我需要像 torch.add.at(warped_image, (iy, ix), image) 这样的东西,输出为
[[ 0. 0. 51.]
[246. 116. 0.]
[300. 211. 64.]]
请注意,(0,1) 和 (1,1) 处的索引指向同一位置 (0,2)。所以,我想要warped_image[0,2] = image[0,1] + image[1,1] = 51。
【问题讨论】: