首页 > 解决方案 > 调整 RGB 张量的大小

问题描述

我想在 pytorch 中调整 3-D RBG 张量的大小。我知道如何调整 4-D 张量的大小,但不幸的是,这种方法不适用于 3-D。

输入是:

#input shape: [3, 100, 200]   ---> desired output shape: [3, 80, 120]

如果我有一个 4-D 矢量它工作正常。

#input shape: [2, 3, 100, 200]
out = torch.nn.functional.interpolate(T,size=(100,80), mode='bilinear')

有什么建议么?提前致谢!

标签: pythonpytorchinterpolationtensor

解决方案


感谢jodag,我找到了答案:

# input shape [3, 200, 120]
T = T.unsqueeze(0)
T = torch.nn.functional.interpolate(T,size=(100,80), mode='bilinear')
T = T.squeeze(0)
# output shape [3, 100, 80]

推荐阅读