运行yolov5 train.py报错:AssertionError: Image Not Found ../data/images/xxx.png
运行环境
????一开始在笔记本上用显卡跑训练是可以正常运行的,后来随着数据量越来越大,笔记本显卡显存不够用了,改用学校的浪潮服务器来跑,但出现了报错。
报错详情
????当时报错时忘记截图了,这里就大概描述一下报错发生的位置和内容。报错发生在终端输出接下来这句之后。
Optimizer groups: 62 .bias, 62 conv.weight, 59 other
train: Scanning 'data/train.cache' images and labels... 2590 found, 0 missing, 335 empty, 0 corrupted: 100%|##########| 2590/2590 [00:00<?, ?it/s]
????在走完上面这个进度条之后就会出现如标题所示的报错。我这个项目在本地是可以跑通的,只是如果不减小batch-size会之后因为显存不足报错,可见图片训练集的位置没有问题,不会引起报错。
解决方案
????在国内搜索引擎上似乎没有找到相关解决方案,在谷歌后在yolov5 github的issues里找到了可能的解决方案,链接在本文底部。其中有一位评论
I've opened PR #2042 to fix this issue. This runs an additional check on the actual image format using PIL img.format. For this check to actually run you'd need to delete your existing *.cache files in your dataset directories, which will trigger a new caching.
Verified update works correctly. I added a GIF to COCO128 and renamed it with a .jpg extension. The new check caught the file, removed it from the training images, and then trains correctly.
????考虑到报错的位置本应该是要加载'data/val.cache'的,可能是这位提到的cache的问题,我试着将之前在本机训练生成的.cache文件删除,重新在服务器运行train.py
,顺利运行,开始训练。

????如图,删除train.cache和val.cache后再重新在服务器上运行即可。
参考
https://github.com/ultralytics/yolov5/issues/195