Link to this sectionCOCO12-Formats 数据集#
Link to this section简介#
Ultralytics COCO12-Formats 数据集是一个专门的测试数据集,旨在验证 12 种受支持图像格式扩展名的图像加载情况。它包含 12 张图像(6 张用于训练,6 张用于验证),每张图像都以不同的格式保存,以确保对图像加载流程进行全面测试。
此数据集对于以下用途非常有价值:
- 测试图像格式支持:验证常用图像格式是否能正确加载
- CI/CD 流水线:格式兼容性的自动化测试
- 调试:隔离训练流水线中特定格式的问题
- 开发:验证新格式的添加或更改
Link to this section支持的格式#
该数据集为 ultralytics/data/utils.py 中定义的每种 12 种受支持格式扩展名各包含一张图像:
| 格式 | 扩展名 | 描述 | 训练/验证 |
|---|---|---|---|
| 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 | 现代 Web 图像格式 | 验证 |
Link to this section数据集结构#
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 configurationLink to this section数据集 YAML#
The COCO12-Formats dataset is configured using a YAML file that defines dataset paths and class names. You can review the official coco12-formats.yaml file in the Ultralytics GitHub repository.
# 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.zipLink to this section要求#
某些格式需要额外的依赖项:
pip install pillow pillow-heif pillow-avif-pluginLink to this sectionAVIF 系统库(可选)#
为了让 OpenCV 直接读取 AVIF 文件,必须在构建 OpenCV 之前安装 libavif:
brew install libavif通过 pip 安装的 opencv-python 包由于是预构建的,可能不包含 AVIF 支持。当 OpenCV 缺乏支持时,Ultralytics 会使用带有 pillow-avif-plugin 的 Pillow 作为 AVIF 图像的备选方案。
Link to this section用法#
要使用 COCO12-Formats 数据集训练 YOLO 模型,请参考以下示例:
from ultralytics import YOLO
# Load a pretrained YOLO model
model = YOLO("yolo26n.pt")
# Train on COCO12-Formats to test 12 supported image formats
results = model.train(data="coco12-formats.yaml", epochs=1, imgsz=640)Link to this section格式特定说明#
Link to this sectionAVIF (AV1 图像文件格式)#
AVIF 是一种基于 AV1 视频编解码器的现代图像格式,提供出色的压缩效果。需要 pillow-avif-plugin:
pip install pillow-avif-pluginLink to this sectionDNG (数字负片)#
DNG 是 Adobe 基于 TIFF 的开放 RAW 格式。出于测试目的,该数据集使用带有 .dng 扩展名的基于 TIFF 的文件。
Link to this sectionJP2 (JPEG 2000)#
JPEG 2000 是一种基于小波的图像压缩标准,比传统 JPEG 提供更好的压缩效果和质量。通常用于医学影像 (DICOM)、地理空间应用和数字电影。OpenCV 和 Pillow 均原生支持此格式。
Link to this sectionMPO (多图片对象)#
MPO 文件用于立体(3D)图像。该数据集存储带有 .mpo 扩展名的标准 JPEG 数据,用于格式测试。
Link to this sectionHEIC (高效图像编码)#
HEIC 需要 pillow-heif 包才能进行正确编码:
pip install pillow-heifLink to this section用例#
Link to this sectionCI/CD 测试#
from ultralytics import YOLO
def test_image_formats():
"""Test that 12 supported image formats load correctly."""
model = YOLO("yolo26n.pt")
results = model.train(data="coco12-formats.yaml", epochs=1, imgsz=64)
assert results is not NoneLink to this section格式验证#
from pathlib import Path
from ultralytics.data.utils import IMG_FORMATS
# Verify all dataset formats are supported
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"Unsupported formats: {found_formats - IMG_FORMATS}"Link to this section引用与致谢#
如果你在研究中使用 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}
}Link to this section常见问题解答#
Link to this sectionCOCO12-Formats 数据集有什么用途?#
COCO12-Formats 数据集旨在测试 Ultralytics YOLO 训练流水线中的图像格式兼容性。它确保 12 种受支持的图像格式(AVIF、BMP、DNG、HEIC、JP2、JPEG、JPG、MPO、PNG、TIF、TIFF、WebP)都能正确加载和处理。
Link to this section为什么要测试多种图像格式?#
不同的图像格式具有独特的特性(压缩、位深、色彩空间)。测试所有格式可确保:
- 健壮的图像加载代码
- 跨不同数据集的兼容性
- 尽早检测特定格式的错误
Link to this section哪些格式需要特殊依赖项?#
- AVIF:需要
pillow-avif-plugin - HEIC:需要
pillow-heif