当前位置:网站首页>YOLOV5 study notes (7) - training your own data set
YOLOV5 study notes (7) - training your own data set
2022-08-10 00:57:00 【birch without tears】
目录
一、数据集介绍
根据YOLOV5The lightweight small target detection network designed by study note six,本节将用tibnetThe produced dataset is used for training and testing,This dataset is used to detect aerial drones,You can see that the drone is very small.该数据集的labels文件是用labelmemarked by the softwarexml形式.
<annotation>
<folder>0829_5JPEGImages</folder>
<filename>0829_5092.jpg</filename>
<path>C:\Users\lsq\Desktop\图片\0829_5JPEGImages\0829_5092.jpg</path>
<source>
<database>Unknown</database>
</source>
<size>
<width>960</width>
<height>540</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>uav</name>
<pose>Unspecified</pose>
<truncated>0</truncated>
<difficult>0</difficult>
<bndbox>
<xmin>477</xmin>
<ymin>259</ymin>
<xmax>499</xmax>
<ymax>279</ymax>
</bndbox>
</object>
</annotation>
二、Data set transformation
2.1 xml转txt
xmlThe annotation format of the file is a box with four dotsx,y范围,而yolov5The format used is the center point of the box plus the width and height,Therefore, the format conversion is required,将xml文件转化为txt文件,代码如下.
import xml.etree.ElementTree as ET
import pickle
import os
from os import listdir , getcwd
from os.path import join
import glob
classes = ["uav"]
def convert(size, box):
dw = 1.0/size[0]
dh = 1.0/size[1]
x = (box[0]+box[1])/2.0
y = (box[2]+box[3])/2.0
w = box[1] - box[0]
h = box[3] - box[2]
x = x*dw
w = w*dw
y = y*dh
h = h*dh
return (x,y,w,h)
def convert_annotation(image_name):
in_file = open('./Annotations/'+image_name[:-3]+'xml') #xml文件路径
out_file = open('./labels/'+image_name[:-3]+'txt', 'w') #转换后的txt文件存放路径
f = open('./Annotations/'+image_name[:-3]+'xml')
xml_text = f.read()
root = ET.fromstring(xml_text)
f.close()
size = root.find('size')
w = int(size.find('width').text)
h = int(size.find('height').text)
for obj in root.iter('object'):
cls = obj.find('name').text
if cls not in classes:
print(cls)
continue
cls_id = classes.index(cls)
xmlbox = obj.find('bndbox')
b = (float(xmlbox.find('xmin').text), float(xmlbox.find('xmax').text), float(xmlbox.find('ymin').text),
float(xmlbox.find('ymax').text))
bb = convert((w,h), b)
out_file.write(str(cls_id) + " " + " ".join([str(a) for a in bb]) + '\n')
wd = getcwd()
if __name__ == '__main__':
for image_path in glob.glob("./JPEGImages/*.jpg"): #每一张图片都对应一个xml文件这里写xml对应的图片的路径
image_name = image_path.split('/')[-1]
convert_annotation(image_name)
The converted format is as follows,第一个0代表类别,After that are the coordinates of the center point of the box and the width and height
Be sure to check after the conversiontxt中是否有值,不知道什么原因,Sometimes it converts to a null value
0 0.47890625 0.3597222222222222 0.0296875 0.05277777777777778
2.2 制作VOC数据集
Select two-thirds of the data astrain,The remaining third asval,The directory of the dataset is as shown above
三、yaml文件修改
3.1 数据集yaml
# YOLOv5 by Ultralytics, GPL-3.0 license
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford
# Example usage: python train.py --data VOC.yaml
# parent
# ├── yolov5
# └── datasets
# └── VOC ← downloads here
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
train: /home/cxl/ros_yolov5/src/yolov5/data/VOCdevkit/images/train/
val: /home/cxl/ros_yolov5/src/yolov5/data/VOCdevkit/images/val/
# Classes
nc: 1 # number of classes
names: ['uav'] # class names
3.2 模型yaml
Major modification category,Because it's like a drone,所以nc改为1
# Parameters
nc: 1 # number of classes
depth_multiple: 1.0 # model depth multiple
width_multiple: 1.0 # layer channel multiple
anchors:
- [2,2, 6,8, 10,14] #4
- [10,13, 16,30, 33,23] # P3/8
- [30,61, 62,45, 59,119] # P4/16
- [116,90, 156,198, 373,326] # P5/32
四、训练评估
4.1 训练
python train.py --data data/VOC.yaml --cfg models/yolov5s-tiny.yaml --weights weights/yolov5stiny.pt --batch-size 16 --epochs 100
查看训练过程
tensorboard --logdir=./runs
4.2 评估
可以看到效果不错,map0.5达到了0.94,loss接近于0
Save the trained weights as yolov5suav.pt,随后进行测试
测试
python detect.py --source ./data/images/ --weights weights/yolov5suav.pt --conf 0.4
detect: weights=['weights/yolov5suav.pt
边栏推荐
- Jpa 查询view or 无主键的table
- 中国SaaS企业排名,龙头企业Top10梳理
- Digital wallets, red sea ecological rapid introduction of small programs can help capture device entry wisdom
- 南大通用数据库-Gbase-8a-学习-04-部署分布式集群
- CMake使用记录
- Golden Warehouse Database KingbaseGIS User Manual (6.4. Geometry Object Access Function)
- ES6 从入门到精通 # 15:生成器 Generator 的用法
- 【云原生】Kubernetes编排工具精讲
- Eureka自我保护
- SRv6 performance measurement
猜你喜欢
ES6 Beginner to Mastery #15: Generator Usage
【云原生】一文讲透Kubevela addon如何添加腾讯Crane
【集训DAY3】石油储备计划【树形DP】
Travel with Shengteng: See all the AI attractions in Jinling City in one day
金仓数据库 KingbaseGIS 使用手册(6.5. 几何对象编辑函数)
【集训DAY4】异或【字典树】
【集训DAY5】堆箱子【数学】
巴比特 | 元宇宙每日必读:国内首个数字人产业专项支持政策发布,2025年北京数字人产业规模将破500亿元...
阿里云短信服务开通
下班后用微信处理工作时发病身亡,法院判决:工伤!
随机推荐
【集训DAY3】阶乘【数学】
Jpa 查询view or 无主键的table
完全背包理论
【集训DAY3】挖金矿【二分答案】
力扣:518. 零钱兑换 II
金仓数据库 KingbaseGIS 使用手册(6.6. 几何对象校验函数、6.7. 空间参考系函数)
【mysql】查询今天9点
HStreamDB v0.9 发布:分区模型扩展,支持与外部系统集成
Wireshark classic practice and interview 13-point summary
ES6 从入门到精通 # 13:数组的扩展方法二
首席信息官如何将可持续性和技术结合起来
CAD 截断线段
数据库优化 | 干货
上海一科技公司刷单被罚22万,揭露网络刷单灰色产业链
61.【快速排序法详解】
SRv6 performance measurement
Live Preview | ICML 2022 11 first-author scholars share online neural network, graph learning and other cutting-edge research
什么是平面文件数据库? 如何导入多种格式的文件:DSV、JSON、XML?
32 JZOF 】 【 print down on binary tree
【集训DAY5】选数字【数学】