问题1:
File "yolov5-6.0\models\yolo.py", line 116, in __init__
m.anchors /= m.stride.view(-1, 1, 1)
RuntimeError: The size of tensor a (3) must match the size of tensor b (0) at non-singleton dimension 0
原因分析:
这可能是因为6.0的工程下载了个5.0的模型,所以不匹配, 但问题不能解决
[https://github.com/ultralytics/yolov5/releases/download/v6.0/yolov5s.pt]
打开yolo.py中的class Detect(nn.Module):屏蔽部分,该屏蔽部分用于模型转换成onnx
问题2:
File "yolov5-6.0\lib\site-packages\torchvision\extension.py", line 48, in _assert_has_ops
raise RuntimeError(
RuntimeError: Couldn't load custom C++ ops. This can happen if your PyTorch and torchvision versions are incompatible, or if you had errors while compiling torchvision from source. For further information on the compatible versions, check https://github.com/pytorch/vision#installation for the compatibility matrix. Please check your PyTorch version with torch.__version__ and your torchvision version with torchvision.__version__ and verify if they are compatible, and if not please reinstall torchvision so that it matches your PyTorch install.
问题3:
D:anaconda3\envs\yolov5-6.0\lib\site-packages\torchvision\io\image.py:13: UserWarning: Failed to load image Python extension: '[WinError 127] 找不到指定的程序。'If you don't plan on using image functionality from `torchvision.io`, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have `libjpeg` or `libpng` installed before building `torchvision` from source?
warn(
原因分析:
torch 和 torchvision匹配问题
pip install --upgrade torch==2.2.0 torchvision -i https://pypi.tuna.tsinghua.edu.cn/simple/
用以上指令更新,问题2和问题3属于同一个问题
问题4:
File "yolov5-6.0\utils\plots.py", line 112, in text
w, h = self.font.getsize(text) # text width, height
AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
原因分析:
问题出在 库 Pillow 中的 getsize 函数,getsize已弃用,将在Pillow 10(2023-07-01)中删除。
解决方法: 那么打开yolo5环境,降低版本即可,例如下方的:
pip uninstall -y Pillow
pip install Pillow==9.5.0 -i https://pypi.tuna.tsinghua.edu.cn/simple/
问题5:
indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))
RuntimeError: result type Float can't be cast to the desired output type __int64
解决方法: 参考博文
YOLOv5训练报错:indices.append((b, a, gj.clamp_(0, gain[3] - 1), gi.clamp_(0, gain[2] - 1)))-CSDN博客
在在loss.py文件里修改第L177行
gain = torch.ones(7, device=targets.device).long()