RoboMaster 目标检测训练(官方数据集)附完整Demo代码

本指南介绍如何使用PyTorch和zisan包在个人电脑上轻松训练YoloV3模型,即使设备配置较低也能高效运行。文章详细展示了从数据准备到模型训练的全过程,包括代码示例和参数调整建议。

参考: Yolov3 训练自己的数据集 Pytorch 最简单 最少代码 最易调参

名言:大部分人都是死在了调参和配置的路上。。。。。然后归咎于设备不行。好了,现在你不需要再担心这些问题了,因为下面这个教程一般来说都不会怎么报错。
首先声明,以下训练是在我的笔记本上完成的,我的是那种很菜鸡的轻薄本,市面上任何一款游戏本都可以吊打它,显卡型号:MX150 2048MB。读者完全可以迁移到更高级设备上进行训练,请留意本文关于迁移到其他设备的说明。

下载数据集

Robomaster2019 数据集上官网就有的下载,文件名称:DJCOCO.zip
数据集官网下载地址:https://terra-1-g.djicdn.com/b2a076471c6c4b72b574a977334d3e05/resources/DJI%20ROCO.zip
数据集百度云下载地址:链接:https://pan.baidu.com/s/1Ezh1ip8ZOLJeVzhBD9JuOQ 提取码:ytls

安装第三方快速训练包:芷山

使用这个zisan包之前确保你已经配置好PyTorch+CUDA+CUDNN环境,如果你还没配置环境,移步到这里:Pytorch+CUDA+CUDNN配置教程
然后安装如下包:

pip install numpy pillow matplotlib opencv-python

然后安装zisan:

pip install zisan

一般来说不会有任何报错,如果报错那就是之前的环境配置出现问题,请仔细检查。因为我们使用的深度学习框架是Pytorch,不像tensorflow会有那么多api接口版本迭代问题,pytorch非常简洁优美。
这里提供 ‘zisan芷山’ 的官网:http://jintupersonal.com/zisan/
相关文档资料:http://jintupersonal.com/zisan/doc/1.html
这个第三方包是开源的,可以到Github自取(求点一个star):https://github.com/JintuZheng/zisan
目前迭代版本1.0.11,更新频率比较快,我也来不及写文档,有的接口用法请读者自行浏览源码理解使用。

训练示例

(1)数据集和本次训练目标

dataset
数据集非常大,一共9.8GB,作为本次演示我不会训练完所有数据集,设备也不允许嘛,作为演示,我先实现识别annotations标签里面的car识别,就是把车子抠出来。
如下图,只把黄色car标签训练识别出来。
在这里插入图片描述
另外说一句,zisan里面底层使用的是Yolov3的Pytorch版本复现代码,是优化过的版本。

(2)打造一个训练目录

首先,我们下载预训练权重文件和zisan的目标检测配置文件,下载地址:
百度云:https://pan.baidu.com/s/1qj-Lpe4OKV0L-w9uKO8EFw
提取码:x9wl
它有图像语义分割权重和目标检测权重,我们只需要完成训练数据集的目标检测任务,只需要Yolov3的权重,找到 runBox.zip (475 MB)下载:
runBox.zip
把runBox解压到一个没有中文路径的地方,里面的文件如下:
runbox inside
此时,cfgs和weights文件夹是有权重和网络配置文件的,我们不要也不需要取改动它。
然后,我们跑回到我们之前下载的那个Robomaster2019数据集里面,任意选一个比赛的文件夹,在image文件选246张图片
注意,我这里为了演示才选那么少,不过迭代30次已经有一定效果了,很明显的,设备好一点的可以选择1000-2000张左右一次训练,下次训练我们使用冷却的权重再训练其他更多的图片。
我们把image的图片选246张复制到刚才runBox/data/images/文件夹下面,然后把相应的246个xml标签文件复制到runBox/data/Annotations/文件夹下面,睁大你的卡斯兰大眼睛!!别复制错了,只是两个文件夹,其余的文件夹不要管也千万不要删除。
在这里插入图片描述
至此,我们的训练目录打造完成,接下来我们只需要很少量的代码就能完成训练。

(3)编写train.py

我们在runBox文件夹新建一个py文件
newtrain
train.py:

from zisan.ObjDetect.Interface import ObjDetect_train, ObjDetect_Preprocess
import os

if __name__ == "__main__":  

    pr=ObjDetect_Preprocess(classnames=['car'],currentpath='D:/xxx/runBox') # cuurentpath is needed, it is your runBox path, car是我们需要训练的类别名称
    #pr.clear_data() #clear all data  
    trainModel=ObjDetect_train(currentpath='D:/xxx/runBox')
    trainModel.Run(cfg='yolov3-tiny.cfg',epochs=35,img_size=(1920/3,1080/3)) # 开始训练,训练好的权重文件保存在 weights文件夹里面

解释:
(1)classnames=[‘class1’,‘class2’],这里是描述你annotation里面xml文件标签的类别名字,我这里只训练一类,就识别所有的车,所以classnames=['car'],必须和xml文件里面的类名字保持一致。

(2)Yolov3版本选择:
zisan一共提供三种版本:Yolov3-tiny,Yolov3-spp,Yolov3,其中要求最低配置的就是tiny了。我也说过了我这个破机器就只能跑tiny了。如果你有更好的机器,你可以把cfg参数cfg='yolov3-tiny.cfg'换成:

  • ‘yolov3-spp.cfg’
  • ‘yolov3.cfg’

(小心引号别漏了)

(4)其他参数说明:
如果你不熟悉调参,请不要随意调参数。使用默认参数即可(我已经调过了)

epochs: The times you loop training.
batch_size: The sum of once you
put into training. cfg: You can choose ‘yolov3-tiny.cfg’,
‘yolov3-spp.cfg’ and ‘yolov3.cfg’, you must sure the weights folder
has the corresponding weight.
img_size: You can set as (height,width),
also like above 416 means (416,416)
resume: Due to the limitation of device resources, you may not be able to train too much data at a time. At this time, you can use resume to continue training for the weight of last cooling
num_workers: Multithreading, you must use main to use this nosave: if save each epoch weight

(5)关于图片放缩参数问题:

img_size=(1920/3,1080/3)
RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具 RoboMaster智能数据集标注工具
评论 58
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值