【问题标题】:Resize RGB Tensor pytorch调整 RGB 张量的大小
【发布时间】:2020-01-18 17:22:42
【问题描述】:

我想在 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')

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

【问题讨论】:

  • 只需 .unsqueeze(0) 输入和 .squeeze(0) 输出。所有的 torch.nn 函数都假定 dim 0 是批次维度。为 dim 0 添加单一维度只会使函数在批量大小 1 上运行。
  • 谢谢,这正是我想要的!

标签: python pytorch interpolation tensor


【解决方案1】:

感谢 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]

【讨论】:

    猜你喜欢
    • 2015-06-08
    • 2018-11-16
    • 2019-04-21
    • 2020-02-28
    • 2021-05-08
    • 1970-01-01
    • 2020-10-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多