Pytorch 的坑以及记录
The size of tensor a (4) must match the size of tensor b (3) at non-singleton
- 自己复写了一个dataset,有个奇怪的问题,训练时候报这个(Pytorch RuntimeError: The size of tensor a (4) must match the size of tensor b (3) at non-singleton)错误
解决办法
把img = Image.open(cur_img_path)
改写成
img = Image.open(cur_img_path).convert('RGB')
。
实际上是有的图片是四通道,导致了上面的问题。
OSError: image file is truncated
- 在训练pytorch的时候可能出现这问题,实际上可能是因为有图像有问题,有破损。
- 解决办法
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True