目标检测Datasets格式

Ultralytics YOLO 格式

  1. 每个图对应一个txt文件,与图同名
  2. 在txt中:每行对应一个目标物件
  3. 在行中有:
  • 类别索引,用数字表示的类别(如,0是person,1是car,等)
  • Mask区域的边界点坐标,用归一化的数字表示
    1
    <class-index> <x1> <y1> <x2> <y2> ... <xn> <yn>
    每行的长度不一定相同,如果是作为分割任务,最少要有三个xy坐标点

YAML格式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 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
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

这里的trainval分别指的是训练和验证数据的存储位置
names是类别名称的字典,序号与YOLO格式数据里面的对应

使用方法 python

1
2
3
4
5
6
7
from ultralytics import YOLO

# Load a model
model = YOLO('yolov8n-seg.pt') # load a pretrained model (recommended for training)

# Train the model
results = model.train(data='coco8-seg.yaml', epochs=100, imgsz=640)

使用方法 CLI

1
2
# Start training from a pretrained *.pt model
yolo detect train data=coco8-seg.yaml model=yolov8n-seg.pt epochs=100 imgsz=640

自动标注功能

使用SAM模型自动标注

1
2
3
from ultralytics.data.annotator import auto_annotate

auto_annotate(data="path/to/images", det_model="yolov8x.pt", sam_model='sam_b.pt')

Argument Type Description Default
data 待标注的数据
det_model 预训练的检测模型 Defaults to ‘yolov8x.pt’. ‘yolov8x.pt’
sam_model 预训练的SAM模型 Defaults to ‘sam_b.pt’. ‘sam_b.pt’
device 运行设备. Defaults to an empty string (CPU or GPU, if available). ‘’
output_dir 保存标注结果的路径. Defaults to a ‘labels’ folder in the same directory as ‘data’. None