这是后续问题这个问题 https://stackoverflow.com/q/65584330/3337089。我尝试使用index_put_
如建议的答案 https://stackoverflow.com/a/65584479/3337089,但是我收到以下错误
RuntimeError: the derivative for 'indices' is not implemented
我想通过索引反向传播误差梯度,因此我不能detach()
它。有什么办法可以实现这一目标吗?
Example:
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)
warped_image.index_put_((iy, ix), image, accumulate=True)