YOLO数据集格式介绍
YOLO支持多种数据集支持计算机视觉任务,包括检测(detection)、实例分割(instant segmentation)、姿态估计(pose estimation)、物品分类( classification)、多目标跟踪( multi-object tracking)。
数据集种类繁多,格式也比较多,很多人会比较迷惑,这里把Ultralytics官网相关内容整理在一起,以便读者对各种数据集有一个全面认识。
以下对各种数据集格式做简要介绍。
1 检测(Detection)
数据集YAML格式
例如COCO数据集:
# 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, ..]
path: ../datasets/coco8 # dataset root dir (absolute or relative; if relative, it's relative to default datasets_dir)
train: images/train # train images (relative to 'path')
val: images/val # val images (relative to 'path')
test: # test images (optional)
# Classes (80 COCO classes)
names:
0: person
1: bicycle
2: car
# ...
77: teddy bear
78: hair drier
79: toothbrush
标注格式
每幅图像都需要对应一个文本文件保存标注数据(*.txt),文件中每行描述一个对象,格式为:
class x_center y_center width height
所有坐标需要经过归一化处理,使用空格隔开。分类号码从0开始。如果图像文件中没有检测对象,则不需要txt文件。
2 分割(Segmentation)
数据集YAML格式
COCO数据集:
# 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, ..]
path: ../datasets/coco8-seg # dataset root dir (absolute or relative; if relative, it's relative to default datasets_dir)
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)
# Classes (80 COCO classes)
names:
0: person
1: bicycle
2: car
# ...
77: teddy bear
78: hair drier
79: toothbrush
标注格式
实例分割是一项计算机视觉任务,涉及识别和划分图像中的单个对象。
用于训练YOLO 分段模型的数据集标签格式如下:
- 每幅图像一个文本文件:数据集中的每幅图像都有一个相应的文本文件,文件名与图像文件相同,扩展名为".txt"。
- 每个对象一行:文本文件中的每一行对应图像中的一个对象实例。
- 每行对象信息:每行包含对象实例的以下信息
- 对象类别索引:代表对象类别的整数(如 0 代表人,1 代表汽车等)。
- 对象边界坐标:遮罩区域周围的边界坐标,归一化后介于 0 和 1 之间。
分割数据集文件中每行的格式如下:
<class> <x1> <y1> <x2> <y2> ... <xn> <yn>
<class>
是对象的类的索引,而 <x1> <y1> <x2> <y2> ... <xn> <yn>
是对象的分割掩码的边界坐标。坐标之间用空格隔开。
以下是YOLO 分割数据集格式的示例,该数据集表示由 3 个点和 5个 点组成的两个对象的单幅图像。
0 0.681 0.485 0.670 0.487 0.676 0.487
1 0.504 0.000 0.501 0.004 0.498 0.004 0.493 0.010 0.492 0.0104
- 每行的长度不必相等。
- 每个分段标签必须有 至少 3 个 xy 点:
<class> <x1> <y1> <x2> <y2> <x3> <y3>
3 姿态(Pose)
数据集YAML格式
# 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, ..]
path: ../datasets/coco8-pose # dataset root dir (absolute or relative; if relative, it's relative to default datasets_dir)
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)
# Keypoints
kpt_shape: [17, 3] # number of keypoints, number of dims (2 for x,y or 3 for x,y,visible)
flip_idx: [0, 2, 1, 4, 3, 6, 5, 8, 7, 10, 9, 12, 11, 14, 13, 16, 15]
# Classes dictionary
names:
0: person
标注格式
每幅图像都需要对应一个文本文件保存标注数据(*.txt),文件中每行描述一个对象,格式为:
class-index 矩形框(x y w h) Keypoints(N个顶点坐标)
坐标都是经过归一化,x,y是中心点除以图片宽高,w,h是框的宽高除以图片宽高,ptx,pty是关键点坐标除以宽高
Keypoints有两种描述方法:dim=2和dim=3。
格式:Dim = 2
<class-index> <x> <y> <width> <height> <px1> <py1> <px2> <py2> ... <pxn> <pyn>
格式:Dim = 3
<class-index> <x> <y> <width> <height> <px1> <py1> <p1-visibility> <px2> <py2> <p2-visibility> <pxn> <pyn> <pn-visibility>
[visibility: 0不可见,1隐藏,2可见]
4 分类(Classification)
数据集目录格式
以 CIFAR-10数据集为例,目录格式为:
cifar-10-/
|
|-- train/
| |-- airplane/
| | |-- 10008_airplane.png
| | |-- 10009_airplane.png
| | |-- ...
| |
| |-- automobile/
| | |-- 1000_automobile.png
| | |-- 1001_automobile.png
| | |-- ...
| |
| |-- bird/
| | |-- 10014_bird.png
| | |-- 10015_bird.png
| | |-- ...
| |
| |-- ...
|
|-- test/
| |-- airplane/
| | |-- 10_airplane.png
| | |-- 11_airplane.png
| | |-- ...
| |
| |-- automobile/
| | |-- 100_automobile.png
| | |-- 101_automobile.png
| | |-- ...
| |
| |-- bird/
| | |-- 1000_bird.png
| | |-- 1001_bird.png
| | |-- ...
| |
| |-- ...
|
|-- val/ (optional)
| |-- airplane/
| | |-- 105_airplane.png
| | |-- 106_airplane.png
| | |-- ...
| |
| |-- automobile/
| | |-- 102_automobile.png
| | |-- 103_automobile.png
| | |-- ...
| |
| |-- bird/
| | |-- 1045_bird.png
| | |-- 1046_bird.png
| | |-- ...
| |
| |-- ...
CIFA10网站:https://www.cs.toronto.edu/~kriz/cifar.html
下图是该数据集中的类别,每个类包括10个随机图像。
具体使用方式参考网站说明。
5 定向边框(OBB)
数据集YAML格式
dota8.yaml
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# DOTA8 dataset 8 images from split DOTAv1 dataset by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/obb/dota8/
# Example usage: yolo train model=yolov8n-obb.pt data=dota8.yaml
# parent
# ├── ultralytics
# └── datasets
# └── dota8 ← downloads here (1MB)
# 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, ..]
path: ../datasets/dota8 # dataset root dir
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
# Classes for DOTA 1.0
names:
0: plane
1: ship
2: storage tank
3: baseball diamond
4: tennis court
5: basketball court
6: ground track field
7: harbor
8: bridge
9: large vehicle
10: small vehicle
11: helicopter
12: roundabout
13: soccer ball field
14: swimming pool
# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/dota8.zip
标注格式
每幅图像都需要对应一个文本文件保存标注数据(*.txt),文件中每行描述一个对象,格式为:
使用4个角点坐标,标识任意旋转角度的矩形
class_index x1 y1 x2 y2 x3 y3 x4 y4
坐标都要经过归一化。
举例:
0 0.780811 0.743961 0.782371 0.74686 0.777691 0.752174 0.776131 0.749758
YOLO内部处理使用xywhr格式,表示边界框的中心点、宽度、高度和角度。
说明:本文主要是对Ultralytics官网相关内容整理而来,方便读者对YOLO数据集格式进行快速了解。