我有一个尺寸为 (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
最佳答案
您可以使用 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);
关于c++ - 在 pytorch c++ API 中添加填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56490480/