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()

YOLO系列是基于深度学习的端到端实目标检测方法。 PyTorch版的YOLOv5轻量而高性能,更加灵活和易用,当前非常流行。 本课程将手把手地教大家使用labelImg标注和使用YOLOv5训练自己的数据集。课程实战分为两个项目:单目标检测(足球目标检测)和多目标检测(足球和梅西同检测)。  本课程的YOLOv5使用ultralytics/yolov5,在Windows和Ubuntu系统上分别做项目演示。包括:安装YOLOv5、标注自己的数据集、准备自己的数据集(自动划分训练集和验证集)、修改配置文件、使用wandb训练可视化工具、训练自己的数据集、测试训练出的网络模型和性能统计。 除本课程《YOLOv5实战训练自己的数据集(Windows和Ubuntu演示)》外,本人推出了有关YOLOv5目标检测的系列课程。请持续关注该系列的其它视频课程,包括:《YOLOv5(PyTorch)目标检测:原理与源码解析》课程链接:https://edu.csdn.net/course/detail/31428《YOLOv5目标检测实战:Flask Web部署》课程链接:https://edu.csdn.net/course/detail/31087《YOLOv5(PyTorch)目标检测实战:TensorRT加速部署》课程链接:https://edu.csdn.net/course/detail/32303《YOLOv5目标检测实战:Jetson Nano部署》课程链接:https://edu.csdn.net/course/detail/32451《YOLOv5+DeepSORT多目标跟踪与计数精讲》课程链接:https://edu.csdn.net/course/detail/32669《YOLOv5实战口罩佩戴检测》课程链接:https://edu.csdn.net/course/detail/32744《YOLOv5实战中国交通标志识别》课程链接:https://edu.csdn.net/course/detail/35209 《YOLOv5实战垃圾分类目标检测》课程链接:https://edu.csdn.net/course/detail/35284  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值