c++ - 在 pytorch c++ API 中添加填充

标签 c++ pytorch

我有一个尺寸为 (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/

相关文章:

c++ - qobject_cast 没有 Q_OBJECT 宏错误

c++ - 大缓冲区播放,小尺寸不播放

pytorch - net.zero_grad() 与 optim.zero_grad() pytorch

python - 意外的导入行为 : non-existing module imported

graph - 如何知道节点/功能贡献?

docker - 带有URL路径的Docker满

c++ - 为什么线程过程应该是静态的或成员函数

c++ - 如何在 C++ 中管理位/二进制文件?

c++ - 如何以程序员愉快的方式使用 CUDA 常量内存?

python - Pytorch的卷积损失从一开始就是0.0