Pytorch RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton

原因:

有图片一般有四个通道,需要转换为RGB格式才能被读取到

把 img = Image.open(cur_img_path) 改写成

img = Image.open(cur_img_path).convert(‘RGB’)。

实际上是有的图片是四通道,导致了上面的问题。

你可能感兴趣的:(血泪史,pytorch,深度学习,人工智能)