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

相關文章
相關標籤/搜索