【问题标题】:Add padding in pytorch c++ API在 pytorch c++ API 中添加填充
【发布时间】:2019-07-08 21:53:02
【问题描述】:

我有一个尺寸为(1,3, 375, 1242) 的张量。我想通过在其中添加填充将其重塑为(1, 3, 384, 1248)。我如何在 Pytorch c++ API 中做到这一点。提前谢谢你。

target = torch.zeros(1, 3, 384, 1248)
source = torch.ones(1, 3, 375, 1242)
target[: , : , :375, :1242] = source

【问题讨论】:

    标签: c++ pytorch


    【解决方案1】:

    您可以使用torch::constant_pad_nd

    torch::Tensor source = torch::ones(torch::IntList{1, 3, 375, 1242});
    // add 6 zeros to the last dimension and 9 zeros to the third dimension
    torch::Tensor target = torch::constant_pad_nd(target, IntList{0, 6, 0, 9}, 0);
    

    【讨论】:

      猜你喜欢
      • 2020-05-11
      • 2015-01-31
      • 2013-07-12
      • 1970-01-01
      • 1970-01-01
      • 2017-04-03
      • 2014-03-16
      • 1970-01-01
      • 2018-07-19
      相关资源
      最近更新 更多