1、RuntimeError: output with shape [1, 128, 128] doesn‘t match the broadcast shape [3, 128, 128]
报错原因:输入图片需要是RGB空间图片而不能是灰度图,所以导致张量的通道数不匹配。
解决方法:知道了问题的原因之后问题就变得好解决了,我的解决思路是用opencv或者是PIL包下面的图形处理函数,把输入的图片从灰度图转为RGB空间的彩色图。这种方法可以适合数据集中既包含有RGB图片又含有灰度图的情况。解决代码如下:
img = Image.open(img_dir)
img = img.convert('RGB')
2、OSError: image file is truncated (26 bytes not processed)
解决办法:在代码中添加两行
from PIL import ImageFile
ImageFile.LOAD_TRUNCATED_IMAGES = True
3. UserWarning: Possibly corrupt EXIF data.
一般来说是图片的piexif的图片有点问题。简单的操作就是删除掉对应的exif信息。或者直接ignore 警告
解决方案1:下载piexif包: pip install piexif -i https://pypi.tuna.tsinghua.edu.cn/simple/
删除掉图片的exif方式:
img_path: 图片的地址
import piexif
piexif.remove(img_path)
解决方案2:跳过这些图片,无视警告信息。
###ignore warning: python -w ignore train.py 或是