PyTorch 报错:TypeError: Cannot handle this data type: (1, 1, 512), |u1 (已解决)

PyTorch 报错:TypeError: Cannot handle this data type: (1, 1, 512), |u1 (已解决)

 

pytorch 代码,保存图片this

语句时,报错spa

TypeError: Cannot handle this data type: (1, 1, 512), |u1blog

 

这是由于,当要保存的图片为 灰度图像 时,灰度图像的 numpy 尺度是 [1, h, w];这就会报错。图片

须要将 [1, h, w] 改变为 [h, w], 因此,在将 tensor 格式转为 numpy 时,要将维度变过来:class

这里,当 image_numpy.shape[0]=1,即 image_numpy 是灰度图像,只要将 image_numpy = image_numpy[0],其格式就从 [1, h, w] 改变为 [h, w] 了。numpy

相关文章
相关标签/搜索