YOLOv5在建筑工地中安全帽佩戴检测的应用(已开源+数据集)

论坛 期权论坛     
选择匿名的用户   2021-5-23 01:18   17   0
<h2><strong>前言</strong></h2>
<p>Amusi 发现一个很棒的开源项目,利用YOLOv5进行目标检测的&#34;落地化&#34;应用:<strong>安全帽佩戴检测</strong>。</p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-fac1271db050f91c37d36a727c7a5ffa.png" width="845"></p>
<p>该项目使用了YOLOv5s、YOLOv5m、YOLOv5l来训练安全帽佩戴检测数据集,代码和权重均已开源!安全帽佩戴检测数据集也是开源的(共含7581 张图像)!</p>
<p>项目教程也相当详细,推荐入门练手学习!而且有意思的是,该项目和数据集的两位作者均是中国人,点赞!</p>
<p>项目链接(文末附下载):<a href="https://github.com/xiaobingchan/Smart_Construction">https://github.com/xiaobingchan/Smart_Construction</a></p>
<p>数据集链接(文末附下载):<a href="https://github.com/xiaobingchan/Safety-Helmet-Wearing-Dataset">https://github.com/xiaobingchan/Safety-Helmet-Wearing-Dataset</a></p>
<h2><strong>Smart_Construction</strong></h2>
<p>该项目是使用 YOLOv5 来训练在智能工地安全领域中头盔目标检测的应用</p>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-e72579c45a238172d2e1a92f4a873d52.png" width="1199"></p>
<h2><strong>指标</strong></h2>
<h3><strong>yolov5s 为基础训练,<code>epoch &#61; 50</code></strong></h3>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-64254fd21465e1247a87e0cbe74d8d17.png" width="818"></p>
<p>对应的<strong>权重文件</strong>:<strong><a href="https://link.zhihu.com/?target&#61;https%3A//pan.baidu.com/s/1ELPhtW-Q4G8UqEr4YrV_5A">百度云</a></strong>,提取码: <code>b981</code></p>
<h3><strong>yolov5m 为基础训练,<code>epoch &#61; 100</code></strong></h3>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-7d131a98845d558d9573705299ecf0f8.png" width="825"></p>
<p>对应的<strong>权重文件</strong>:<strong><a href="https://link.zhihu.com/?target&#61;https%3A//pan.baidu.com/s/10hlKrgpxVsw4d_vHnPHwEA">百度云</a></strong>,提取码: <code>psst</code></p>
<h3><strong>yolov5l 为基础训练,<code>epoch &#61; 100</code></strong></h3>
<p><img alt="" src="https://beijingoptbbs.oss-cn-beijing.aliyuncs.com/cs/5606289-b04c7a40054c8551cbd7c1eeb08f4143.png" width="812"></p>
<p>对应的<strong>权重文件</strong>:<strong><a href="https://link.zhihu.com/?target&#61;https%3A//pan.baidu.com/s/1iMZkRNXY1fowpQCcapFDqw">百度云</a></strong>,提取码: <code>a66e</code></p>
<h2><strong>1.YOLO v5训练自己数据集教程</strong></h2>
<p>使用的数据集:<strong><a href="https://link.zhihu.com/?target&#61;https%3A//github.com/njvisionpower/Safety-Helmet-Wearing-Dataset">Safety-Helmet-Wearing-Dataset</a></strong> ,感谢这位大神的开源数据集!</p>
<blockquote>
本文结合
<strong><a href="https://link.zhihu.com/?target&#61;https%3A//github.com/ultralytics/yolov5/wiki/Train-Custom-Data">YOLOv5官方教程</a></strong> 来写
</blockquote>
<h2><strong>环境准备</strong></h2>
<p>首先确保自己的环境:</p>
<pre class="blockcode"><code>Python &gt;&#61; 3.7
Pytorch &#61;&#61; 1.5.x</code></pre>
<h2><strong>训练自己的数据</strong></h2>
<h3><strong>提示:</strong></h3>
<p>关于增加数据集分类的方法,请看【5. 增加数据集的分类】</p>
<h3><strong>1.1 创建自己的数据集配置文件</strong></h3>
<p>因为我这里只是判断 【人没有带安全帽】、【人有带安全帽】、【人体】 3个类别 ,基于 <code>data/coco128.yaml</code> 文件,创建自己的数据集配置文件 <code>custom_data.yaml</code></p>
<pre class="blockcode"><code># 训练集和验证集的 labels 和 image 文件的位置
train: ./score/images/train
val: ./score/images/val

# number of classes
nc: 3

# class names
names: [&#39;person&#39;, &#39;head&#39;, &#39;helmet&#39;]
</code></pre>
<h3><strong>1.2 创建每个图片对应的标签文件</strong></h3>
<p>使用标注工具类似于 <strong><a href="https://link.zhihu.com/?target&#61;https%3A//labelbox.com/">Labelbox</a></strong> 、<strong><a href="https://link.zhihu.com/?target&#61;https%3A//github.com/opencv/cvat">CVAT</a></strong> 、<strong><a href="https://link.zhihu.com/?target&#61;http%3A//www.jinglingbiaozhu.com/">精灵标注助手</a></strong> 标注之后,需要生成每个图片对应的 <code>.txt</code> 文件,其规范如下:</p>
<ul><li>每一行都是一个目标</li><li>类别序号是零索引开始的(从0开始)</li><li>每一行的坐标 <code>class x_center y_center width height</code> 格式</li><li>框坐标必须采用<strong>归一化的 xywh</strong>格式(从0到1)。如果您的框以像素为单位,则将<code>x_center</code>和<code>width</code>除以图像宽度,将<code>y_center</code>和<code>height</code>除以图像高度。代码如下:</li></ul>
<pre class="blockcode"><code>import numpy as np
def convert(size, box):
    &#34;&#34;&#34;
    将标注的 xml 文件生成的【左上角x,左上角y,右
分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP