COCO12-Formats 数据集

介绍

Ultralytics COCO12-Formats 数据集是一个专业的测试数据集,旨在验证所有 12 种受支持图像格式扩展名的图像加载情况。它包含 12 张图像(6 张用于训练,6 张用于验证),每张图像都以不同的格式保存,以确保对图像加载流水线进行全面测试。

该数据集对于以下用途非常有价值:

  • 测试图像格式支持:验证所有受支持的格式是否能正确加载
  • CI/CD 流水线:格式兼容性的自动化测试
  • 调试:定位训练流水线中特定格式的问题
  • 开发:验证新添加或更改的格式

受支持的格式

该数据集为 ultralytics/data/utils.py 中定义的 12 种受支持格式扩展名中的每一种都包含一张图像:

格式扩展名描述训练/验证
AVIF.avifAV1 图像文件格式(现代)训练
BMP.bmp位图 - 未压缩的光栅格式训练
DNG.dng数字负片 - Adobe RAW 格式训练
HEIC.heic高效图像编码训练
JPEG.jpeg完整扩展名的 JPEG训练
JPG.jpg简写扩展名的 JPEG训练
JP2.jp2JPEG 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

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/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 文件,必须在构建 OpenCV 之前 安装 libavif

brew install libavif
注意

通过 pip 安装的 opencv-python 软件包因为是预先构建的,可能不包含 AVIF 支持。当 OpenCV 缺乏支持时,Ultralytics 会使用带有 pillow-avif-plugin 的 Pillow 作为 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)

特定格式说明

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}
}

常见问题 (FAQ)

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

评论