yolov5-6.0运行train.py时遇到的问题集锦

问题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'

原因分析:

参考博文 ‘FreeTypeFont‘ object has no attribute ‘getsize‘报错解决_freetypefont' object has no attribute 'getsize-CSDN博客

问题出在 库 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()

  • 23
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值