将 Pytorch 的图像格式从 NHWC 更改为 NCHW

shu*_*uvo 7 image permutation deep-learning conv-neural-network pytorch

在 pytorch 中,我们需要NCHW格式的图像,但我的图像是NHWC.

将此图像提供给 CNN 的程序是什么?(我发现这个解决方案建议使用“置换”,但我应该在哪里以及如何使用它?)

ben*_*che 9

使用torch.Tensor.permute()

 x = x.permute(0, 3, 1, 2) # from NHWC to NCHW
Run Code Online (Sandbox Code Playgroud)