跟着炮哥运行yolov5

(4条消息) 目标检测---教你利用yolov5训练自己的目标检测模型_炮哥带你学的博客-CSDN博客_model.yaml path

下载了yolov5.5的数据集

复制粘贴修改data中voc.yaml,_命名为hat.yaml

 复制粘贴修改models中yolov5s.yaml,命名为yolov5s-hat.yaml

utils路径下找到datasets.py这个文件,将里面的第81行里面的参数nw改完0

 

train中改数据weights、cfg、data、epoch.

epochs别搞太多了,两天运算了40轮。

(解决方法:下载cuda加速器,去安装gpu版pytorch)

11月12日19:14——11月15日10:14

问题的解决

出现的问题1:

OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.

原因:site-packages目录下,有两个以上的libiomp5md.dll文件

解决方式:添加两行代码:

import os
os.environ["KMP_DUPLICATE_LIB_OK"]="TRUE"

注:这两行代码一定要放在import torch之前

(4条消息) 报错:“Initializing libiomp5md.dll, but found libiomp5md.dll already initialized“_非知之难的博客-CSDN博客_libiomp5md.dll

出现的问题2:

general.py中出现Unresolved reference 'utils'

fitness下面划红线

原因:找不到目录

解决方式:设置里面改:file–>setting–>project:server–>project structure,之后再改回来(4条消息) Pycharm中无法导入包问题:Unresolved reference 解决方法_Charles_yy的博客-CSDN博客_@unresolvedimport

出现的问题3:

AssertionError: Image Not Found D:\PycharmProjects\yolov5-hat\VOCdevkit\images\train\000000.jpg

原因:找不到文件

解决方式:新建了一个文件包(4条消息) 深度机器学习:报错AssertionError: Image Not Found D:\PycharmProjects\yolov5-hat\VOCdevkit\images\train\000000_学习中.....臭丫头的博客-CSDN博客

出现的问题4:

RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 2.00 GiB total capacity; 1.10 GiB already allocated; 0 bytes free; 1.11 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

原因:显存不足

解决方式:我的电脑通过修改batchsize=4解决了(4条消息) 解决:RuntimeError: CUDA out of memory. Tried to allocate 2.00 MiB_无尽的沉默的博客-CSDN博客

出现的问题5:

NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'torchvision::nms' is only available for these backends: [CPU, QuantizedCPU, BackendSelect, Python, Named, Conjugate, Negative, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradXLA, AutogradLazy, AutogradXPU, AutogradMLC, Tracer, UNKNOWN_TENSOR_TYPE_ID, Autocast, Batched, VmapMode].

原因:电脑上有GPU,但是安装的torch和torchvision没有加cu113

解决方式:下载torch-cuda版和torchvision-cuda版

至此运行成功.

 启用tensorbord查看参数

输入:tensorboard --logdir=runs/train(复制网址查看)

训练过程查看:tensorboard --logdir=runs
 

  启用tensorbord查看参数

输入:tensorboard --logdir=runs/train(复制网址查看)

训练过程查看:tensorboard --logdir=runs

出现错误:tensorboard : The term 'tensorboard' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

打开detect.py文件修改参数:

得到结果:

 

 

 台式电脑没有装摄像头的我就没试了。

用自己数据集运算

出现错误1:AttributeError: Can't get attribute 'SPPF' on <module 'models.common' from 'F:\\1-test\\yolov5-5.0-LC\\models\\common.py'>

解决方法:在models/commen.py中加个SPPF类

(5条消息) AttributeError: Can‘t get attribute ‘SPPF‘ on <module ‘models.common‘ from ‘H:\\yolov5-5.0\\models\\_啥也不是的py人的博客-CSDN博客

import warnings
class SPPF(nn.Module):
    # Spatial Pyramid Pooling - Fast (SPPF) layer for YOLOv5 by Glenn Jocher
    def __init__(self, c1, c2, k=5):  # equivalent to SPP(k=(5, 9, 13))
        super().__init__()
        c_ = c1 // 2  # hidden channels
        self.cv1 = Conv(c1, c_, 1, 1)
        self.cv2 = Conv(c_ * 4, c2, 1, 1)
        self.m = nn.MaxPool2d(kernel_size=k, stride=1, padding=k // 2)
 
    def forward(self, x):
        x = self.cv1(x)
        with warnings.catch_warnings():
            warnings.simplefilter('ignore')  # suppress torch 1.9.0 max_pool2d() warning
            y1 = self.m(x)
            y2 = self.m(y1)
            return self.cv2(torch.cat([x, y1, y2, self.m(y2)], 1))

出现错误2 :Hint: This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/

解决方法:在train.py开头加入以下代码

Hint: This means that multiple copies of the OpenMP runtime have been linked into the program._hint this means that multple_LiBiGo的博客-CSDN博客

import os
 
os.environ['KMP_DUPLICATE_LIB_OK']='True'

一些增加小知识

改标签框的大小和置信度:

yolov5检测图片时由于检测框太粗而导致目标被遮挡,尤其是当目标较小并且很密集时,目标很容易就被框挡住,不容易观察检测效果如何:

解决方法:在detect.py文件中找到:

 修改line_thickness

yolov5改变bbox检测框的粗细大小_Lpan2020的博客-CSDN博客

删除置信度

 删掉{conf:.2f}

  • 3
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
好的,那我们开始吧! 首先,YOLO(You Only Look Once)是一种基于深度学习的物体检测算法,它通过卷积神经网络直接在图像上完成物体检测和定位,具有速度快、精度高等优点,因此在实际应用中得到了广泛的应用。 YOLOv5是YOLO系列最新的版本,相对于之前的版本,它在网络结构、数据增强、学习策略等方面进行了优化,提高了检测的精度和速度。下面我们来学习一下YOLOv5的使用。 1. 安装YOLOv5 YOLOv5可以通过GitHub上的开源项目进行下载和安装,具体步骤如下: 1)克隆YOLOv5项目到本地 ``` git clone https://github.com/ultralytics/yolov5.git ``` 2)安装相关依赖 ``` pip install -r requirements.txt ``` 2. 训练自己的数据集 训练一个物体检测模型需要准备好标注好的数据集,然后通过训练模型来学习如何检测这些物体。YOLOv5支持各种不同的数据格式,包括COCO、Pascal VOC等。 在准备好数据集之后,可以通过以下命令来训练模型: ``` python train.py --img 640 --batch 16 --epochs 50 --data coco.yaml --cfg models/yolov5s.yaml --weights '' --name yolov5s_results ``` 其中,--img指定输入图像大小,--batch指定批量大小,--epochs指定训练轮数,--data指定数据集的配置文件,--cfg指定模型的配置文件,--weights指定预训练模型的权重,--name指定训练结果保存的文件夹名称。 3. 测试模型 训练完成之后,可以使用训练好的模型对新的图像进行检测。可以使用以下命令来进行测试: ``` python detect.py --source 0 --weights yolov5s_results/weights/best.pt --conf 0.25 ``` 其中,--source指定输入图像或视频的路径,0表示使用摄像头输入,--weights指定训练好的模型权重,--conf指定置信度的阈值,低于这个阈值的检测结果将被忽略。 4. 导出模型 最后,可以将训练好的模型导出到ONNX格式或TorchScript格式,以便在其他平台上使用。可以使用以下命令来导出模型: ``` python models/export.py --weights yolov5s_results/weights/best.pt --img-size 640 --batch-size 1 ``` 其中,--weights指定训练好的模型权重,--img-size指定输入图像大小,--batch-size指定批量大小。 这就是使用YOLOv5进行物体检测的基本流程。当然,在实际应用中,还需要根据具体情况进行参数调整和优化。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值