网站建设这个行业如何,网页设计板式类型,网站要怎么做,软件开发具体工作内容文章目录 前言1、数据标注说明2、定义自己模型文件3、训练模型4、参考文献 前言 本文主要介绍如何利用YOLOv5训练自己的数据集 1、数据标注说明 以生活垃圾数据集为例子 生活垃圾数据集#xff08;YOLO版#xff09;点击这里直接下载本文生活垃圾数据集
生活垃圾数据集组成YOLO版点击这里直接下载本文生活垃圾数据集
生活垃圾数据集组成
【有害垃圾】电池1 号、2 号、5 号、过期药品或内包装等
【可回收垃圾】易拉罐、小号矿泉水瓶
【厨余垃圾】小土豆、切过的白萝卜、胡萝卜尺寸为电池大小
【其他垃圾】瓷片、鹅卵石小土豆大小、砖块等。
YOLO数据有三个要点
images存放图片labes对应Images图片的标签data_txt, 划分images图片的数据集形成三个txt
文件结构
----data\|----classes.txt # 标签种类|----data-txt\ # 数据集文件集合| |----test.txt| |----train.txt| |----val.txt|----images\ # 数据集图片| |----test\| | |----fimg_23.jpg| | |----fimg_38.jpg| | |----.....| |----train\| | |----fimg_1.jpg| | |----fimg_2.jpg| | |----.....| |----val\| | |----fimg_4.jpg| | |----fimg_6.jpg| | |----.....|----labels\ # yolo标签| |----test\| | |----fimg_23.txt| | |----fimg_38.txt| | |----.....| |----train\| | |----fimg_1.txt| | |----fimg_2.txt| | |----.....| |----val\| | |----fimg_4.txt| | |----fimg_6.txt| | |----.....|----waste-classification.yaml # 数据集配置文件
2、定义自己模型文件
1、定义yolov5网络模型文件
如 models/yolov5l.yaml
# YOLOv5 by Ultralytics, GPL-3.0 license# Parameters
nc: 4 # number of classes 类别,这里的类别一共四种
depth_multiple: 0.33 # model depth multiple 模型宽度
width_multiple: 0.50 # layer channel multiple 通道数
anchors:- [10,13, 16,30, 33,23] # P3/8- [30,61, 62,45, 59,119] # P4/16- [116,90, 156,198, 373,326] # P5/32# YOLOv5 v6.0 backbone
backbone:# [from, number, module, args][[-1, 1, Conv, [64, 6, 2, 2]], # 0-P1/2[-1, 1, Conv, [128, 3, 2]], # 1-P2/4[-1, 3, C3, [128]],[-1, 1, Conv, [256, 3, 2]], # 3-P3/8[-1, 6, C3, [256]],[-1, 1, Conv, [512, 3, 2]], # 5-P4/16[-1, 9, C3, [512]],[-1, 1, Conv, [1024, 3, 2]], # 7-P5/32[-1, 3, C3, [1024]],[-1, 1, SPPF, [1024, 5]], # 9]# YOLOv5 v6.0 head
head:[[-1, 1, Conv, [512, 1, 1]],[-1, 1, nn.Upsample, [None, 2, nearest]],[[-1, 6], 1, Concat, [1]], # cat backbone P4[-1, 3, C3, [512, False]], # 13[-1, 1, Conv, [256, 1, 1]],[-1, 1, nn.Upsample, [None, 2, nearest]],[[-1, 4], 1, Concat, [1]], # cat backbone P3[-1, 3, C3, [256, False]], # 17 (P3/8-small)[-1, 1, Conv, [256, 3, 2]],[[-1, 14], 1, Concat, [1]], # cat head P4[-1, 3, C3, [512, False]], # 20 (P4/16-medium)[-1, 1, Conv, [512, 3, 2]],[[-1, 10], 1, Concat, [1]], # cat head P5[-1, 3, C3, [1024, False]], # 23 (P5/32-large)[[17, 20, 23], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)]
2、在data/目标下定义自己数据集的配置文件
如data/waste-classification.yaml
train: data/data-txt/train.txt
val: data/data-txt/val.txt
test: data/data-txt/test.txt# Classes
nc: 4 # number of classes
names: [recyclable waste, hazardous waste,kitchen waste,other waste] # class names3、训练模型
1、激活python环境
conda activate reid-pytorch # 这里我是激活reid-pytorch环境2、在服务器上训练自己的模型
# 注意这里是linux服务器上训练命令
# nohup 是后台运行--batch-size 每次送入的图片数 --epochs 训练多少轮 --cfg 模型配置 --data 数据集配置
# --weights 以哪个权重训练 --device 在那个显卡上训练(这里一共有四张显卡) 重定向将训练的结果输出到myout.file方便查看
nohup python train.py --batch-size 16 --epochs 200 --cfg models/yolov5s.yaml --data data/waste-classification.yaml --weights weights/yolov5s.pt --device 0,1,2,3 myout.file 21
# 如果是本地电脑上训练直接在pycharm的train.py添加上述参数直接训练
--batch-size 16 --epochs 200
--cfg models/yolov5s.yaml
--data data/waste-classification.yaml
--weights weights/yolov5s.pt
--device 0 # 采用显卡0进行训练查看自己电脑显卡情况 4、参考文献
YOLOv5s网络模型讲解(一看就会)生活垃圾数据集YOLO版双向控制舵机树莓派版 文章转载自: http://www.morning.kgslc.cn.gov.cn.kgslc.cn http://www.morning.lnwdh.cn.gov.cn.lnwdh.cn http://www.morning.mtymb.cn.gov.cn.mtymb.cn http://www.morning.tfgkq.cn.gov.cn.tfgkq.cn http://www.morning.glxmf.cn.gov.cn.glxmf.cn http://www.morning.bnfjh.cn.gov.cn.bnfjh.cn http://www.morning.qrdkk.cn.gov.cn.qrdkk.cn http://www.morning.ftsmg.com.gov.cn.ftsmg.com http://www.morning.yfqhc.cn.gov.cn.yfqhc.cn http://www.morning.wqrk.cn.gov.cn.wqrk.cn http://www.morning.rwfj.cn.gov.cn.rwfj.cn http://www.morning.wwkft.cn.gov.cn.wwkft.cn http://www.morning.rzmzm.cn.gov.cn.rzmzm.cn http://www.morning.lkpzx.cn.gov.cn.lkpzx.cn http://www.morning.gwdkg.cn.gov.cn.gwdkg.cn http://www.morning.nqbpz.cn.gov.cn.nqbpz.cn http://www.morning.qkrqt.cn.gov.cn.qkrqt.cn http://www.morning.rrqgf.cn.gov.cn.rrqgf.cn http://www.morning.fbjqq.cn.gov.cn.fbjqq.cn http://www.morning.gcthj.cn.gov.cn.gcthj.cn http://www.morning.dqkrf.cn.gov.cn.dqkrf.cn http://www.morning.lzdbb.cn.gov.cn.lzdbb.cn http://www.morning.xcyzy.cn.gov.cn.xcyzy.cn http://www.morning.jrplk.cn.gov.cn.jrplk.cn http://www.morning.cnkrd.cn.gov.cn.cnkrd.cn http://www.morning.wcyr.cn.gov.cn.wcyr.cn http://www.morning.hqpyt.cn.gov.cn.hqpyt.cn http://www.morning.fqklt.cn.gov.cn.fqklt.cn http://www.morning.jkdtz.cn.gov.cn.jkdtz.cn http://www.morning.ktntj.cn.gov.cn.ktntj.cn http://www.morning.wzwyz.cn.gov.cn.wzwyz.cn http://www.morning.dsgdt.cn.gov.cn.dsgdt.cn http://www.morning.fjtnh.cn.gov.cn.fjtnh.cn http://www.morning.nyfyq.cn.gov.cn.nyfyq.cn http://www.morning.snbq.cn.gov.cn.snbq.cn http://www.morning.yhgbd.cn.gov.cn.yhgbd.cn http://www.morning.jokesm.com.gov.cn.jokesm.com http://www.morning.gkjyg.cn.gov.cn.gkjyg.cn http://www.morning.mnsts.cn.gov.cn.mnsts.cn http://www.morning.sdhmn.cn.gov.cn.sdhmn.cn http://www.morning.fnzbx.cn.gov.cn.fnzbx.cn http://www.morning.dqdss.cn.gov.cn.dqdss.cn http://www.morning.bncrx.cn.gov.cn.bncrx.cn http://www.morning.mjtgt.cn.gov.cn.mjtgt.cn http://www.morning.lfdzr.cn.gov.cn.lfdzr.cn http://www.morning.yrms.cn.gov.cn.yrms.cn http://www.morning.nfpgc.cn.gov.cn.nfpgc.cn http://www.morning.nsppc.cn.gov.cn.nsppc.cn http://www.morning.pbxkk.cn.gov.cn.pbxkk.cn http://www.morning.sypby.cn.gov.cn.sypby.cn http://www.morning.ypmqy.cn.gov.cn.ypmqy.cn http://www.morning.tssmk.cn.gov.cn.tssmk.cn http://www.morning.tkkjl.cn.gov.cn.tkkjl.cn http://www.morning.hslgq.cn.gov.cn.hslgq.cn http://www.morning.mgmqf.cn.gov.cn.mgmqf.cn http://www.morning.rdlfk.cn.gov.cn.rdlfk.cn http://www.morning.jnkng.cn.gov.cn.jnkng.cn http://www.morning.rjynd.cn.gov.cn.rjynd.cn http://www.morning.tlnbg.cn.gov.cn.tlnbg.cn http://www.morning.yrhpg.cn.gov.cn.yrhpg.cn http://www.morning.ytbr.cn.gov.cn.ytbr.cn http://www.morning.mcmpq.cn.gov.cn.mcmpq.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.rfhmb.cn.gov.cn.rfhmb.cn http://www.morning.ygwbg.cn.gov.cn.ygwbg.cn http://www.morning.pbsfq.cn.gov.cn.pbsfq.cn http://www.morning.qbwyd.cn.gov.cn.qbwyd.cn http://www.morning.bfycr.cn.gov.cn.bfycr.cn http://www.morning.yqwsd.cn.gov.cn.yqwsd.cn http://www.morning.ssglh.cn.gov.cn.ssglh.cn http://www.morning.xxlz.cn.gov.cn.xxlz.cn http://www.morning.qpntn.cn.gov.cn.qpntn.cn http://www.morning.rymd.cn.gov.cn.rymd.cn http://www.morning.lhwlp.cn.gov.cn.lhwlp.cn http://www.morning.qrsm.cn.gov.cn.qrsm.cn http://www.morning.srzhm.cn.gov.cn.srzhm.cn http://www.morning.ysqb.cn.gov.cn.ysqb.cn http://www.morning.hmxb.cn.gov.cn.hmxb.cn http://www.morning.wprxm.cn.gov.cn.wprxm.cn http://www.morning.bydpr.cn.gov.cn.bydpr.cn