COCO12-Formats 数据集
简介
The Ultralytics COCO12-Formats 数据集是一个专门的测试数据集,旨在验证所有 12 种支持的图像格式扩展的图像加载功能。它包含 12 张图像(6 张用于训练,6 张用于验证),每张都以不同的格式保存,以确保对图像加载管道进行全面测试。
此数据集对于以下方面非常宝贵:
- 测试图像格式支持:验证所有支持的格式是否正确加载
- CI/CD 管道:格式兼容性的自动化测试
- 调试:隔离训练管道中特定于格式的问题
- 开发:验证新格式的添加或更改
支持的格式
该数据集包含为每个在以下位置定义的 12 种支持的格式扩展提供的一张图像 ultralytics/data/utils.py:
| 格式 | 扩展名 | 描述 | 训练/验证 |
|---|---|---|---|
| AVIF | .avif | AV1 图像文件格式(现代) | 训练 |
| BMP | .bmp | 位图 - 未压缩的栅格格式 | 训练 |
| DNG | .dng | 数字负片 - Adobe RAW 格式 | 训练 |
| HEIC | .heic | 高效图像编码 | 训练 |
| JPEG | .jpeg | 带有完整扩展名的 JPEG | 训练 |
| JPG | .jpg | 带有短扩展名的 JPEG | 训练 |
| JP2 | .jp2 | JPEG 2000 - 医疗/地理空间 | 验证 |
| MPO | .mpo | 多图片对象(立体图像) | 验证 |
| PNG | .png | 便携式网络图形 | 验证 |
| TIF | .tif | 带有短扩展名的 TIFF | 验证 |
| TIFF | .tiff | 标签图像文件格式 | 验证 |
| WebP | .webp | 现代网络图像格式 | 验证 |
数据集结构
coco12-formats/
├── images/
│ ├── train/ # 6 images (avif, bmp, dng, heic, jpeg, jpg)
│ └── val/ # 6 images (jp2, mpo, png, tif, tiff, webp)
├── labels/
│ ├── train/ # Corresponding YOLO format labels
│ └── val/
└── coco12-formats.yaml # Dataset configuration
数据集 YAML
COCO12-Formats 数据集使用一个 yaml 文件进行配置,该文件定义了数据集路径和类名。您可以查看官方 coco12-formats.yaml 文件在 Ultralytics GitHub 仓库.
ultralytics/cfg/datasets/coco12-formats.yaml
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# COCO12-Formats dataset (12 images testing all supported image formats) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/detect/coco12-formats/
# Example usage: yolo train data=coco12-formats.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco12-formats ← downloads here (1 MB)
# 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: coco12-formats # dataset root dir
train: images/train # train images (relative to 'path') 6 images
val: images/val # val images (relative to 'path') 6 images
test: # test images (optional)
# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush
# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco12-formats.zip
要求
某些格式需要额外的依赖项:
pip install pillow pillow-heif pillow-avif-plugin
AVIF 系统库(可选)
为了让OpenCV直接读取AVIF文件, libavif 必须安装 之前 构建OpenCV时:
brew install libavif
sudo apt install libavif-dev libavif-bin
git clone -b v1.2.1 https://github.com/AOMediaCodec/libavif.git
cd libavif
cmake -B build -DAVIF_CODEC_AOM=SYSTEM -DAVIF_BUILD_APPS=ON
cmake --build build --config Release --parallel
sudo cmake --install build
注意
通过pip安装的 opencv-python 包可能不包含AVIF支持,因为它已预构建。Ultralytics使用Pillow并结合 pillow-avif-plugin 作为OpenCV缺乏支持时AVIF图像的备用方案。
用法
要在COCO12-Formats数据集上训练YOLO模型,请使用以下示例:
训练示例
from ultralytics import YOLO
# Load a pretrained YOLO model
model = YOLO("yolo26n.pt")
# Train on COCO12-Formats to test all image formats
results = model.train(data="coco12-formats.yaml", epochs=1, imgsz=640)
# Train YOLO on COCO12-Formats
yolo detect train data=coco12-formats.yaml model=yolo26n.pt epochs=1 imgsz=640
格式特定说明
AVIF (AV1 图像文件格式)
AVIF是一种基于AV1视频编解码器的现代图像格式,提供出色的压缩。需要 pillow-avif-plugin:
pip install pillow-avif-plugin
DNG (数字负片)
DNG是Adobe基于TIFF的开放RAW格式。出于测试目的,该数据集使用带有 .dng 扩展名的TIFF文件。
JP2 (JPEG 2000)
JPEG 2000是一种基于小波的图像压缩标准,提供比传统JPEG更好的压缩和质量。常用于医学成像(DICOM)、地理空间应用和数字电影。OpenCV和Pillow都原生支持。
MPO (多图片对象)
MPO文件用于立体(3D)图像。该数据集存储带有 .mpo 扩展名的标准JPEG数据,用于格式测试。
HEIC (高效图像编码)
HEIC需要 pillow-heif 包才能正确编码:
pip install pillow-heif
应用案例
CI/CD 测试
from ultralytics import YOLO
def test_all_image_formats():
"""Test that all image formats load correctly."""
model = YOLO("yolo26n.pt")
results = model.train(data="coco12-formats.yaml", epochs=1, imgsz=64)
assert results is not None
格式验证
from pathlib import Path
from ultralytics.data.utils import IMG_FORMATS
# Verify all formats are represented
dataset_dir = Path("datasets/coco12-formats/images")
found_formats = {f.suffix[1:].lower() for f in dataset_dir.rglob("*.*")}
assert found_formats == IMG_FORMATS, f"Missing formats: {IMG_FORMATS - found_formats}"
引用和致谢
如果您在研究中使用COCO数据集,请引用:
@misc{lin2015microsoft,
title={Microsoft COCO: Common Objects in Context},
author={Tsung-Yi Lin and Michael Maire and Serge Belongie and Lubomir Bourdev and Ross Girshick and James Hays and Pietro Perona and Deva Ramanan and C. Lawrence Zitnick and Piotr Doll{\'a}r},
year={2015},
eprint={1405.0312},
archivePrefix={arXiv},
primaryClass={cs.CV}
}
常见问题
COCO12-Formats 数据集有何用途?
COCO12-Formats 数据集旨在测试 Ultralytics YOLO 训练管道中的图像格式兼容性。它确保所有12种支持的图像格式(AVIF、BMP、DNG、HEIC、JP2、JPEG、JPG、MPO、PNG、TIF、TIFF、WebP)都能正确加载和处理。
为何测试多种图像格式?
不同的图像格式具有独特的特性(压缩、位深度、色彩空间)。测试所有格式可确保:
- 鲁棒的图像加载代码
- 跨多样化数据集的兼容性
- 早期检测特定格式的错误
哪些格式需要特殊依赖项?
- AVIF:需要
pillow-avif-plugin - HEIC:需要
pillow-heif