RuntimeError: stack expects each tensor to be equal size, but got [3, ] at entry 0 and [1,]at entry1

RuntimeError: stack expects each tensor to be equal size, but got [3, 256, 256] at entry 0 and [1, 256, 256] at entry 1

该错误是我在用u-net(pytorch版)跑sar图像(灰度图)时爆出来的。

主要是因为设置的n_channel的值和读入图像img的实际通道数不符合,通过调试,我发现我的训练图像灰度图的通道数不全为1,里面还有3通道

于是就索性将dataset中读入图像的命令后面加上转RGB,这样就让所有灰度图通道数都为3.

img = Image.open(img_file[0]).convert('RGB')

 

你可能感兴趣的:(pytorch,opencv,图像识别,深度学习)