Reputation: 93
I have a tensor with dimensions (1,3, 375, 1242)
. I want to reshape it to (1, 3, 384, 1248)
by adding padding into it. How do i do that in Pytorch c++ API. Thank you in advance.
target = torch.zeros(1, 3, 384, 1248)
source = torch.ones(1, 3, 375, 1242)
target[: , : , :375, :1242] = source
Upvotes: 1
Views: 1262
Reputation: 34
You can use 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);
Upvotes: 1