Meet YOLO26: next-gen vision AI.

Link to this sectionVOC 数据集#

PASCAL VOC (Visual Object Classes) 数据集是一个著名的数据集,用于目标检测、分割和分类任务。它旨在鼓励对各类对象类别的研究,并常用于计算机视觉模型的基准测试。对于从事目标检测、分割和分类任务的研究人员和开发人员来说,这是一个必不可少的数据集。



Watch: How to Train Ultralytics YOLO26 on the Pascal VOC Dataset | Object Detection 🚀

Link to this section主要特性#

  • VOC 数据集包含两个主要挑战:VOC2007 和 VOC2012。
  • 该数据集包含 20 个对象类别,包括汽车、自行车和动物等常见对象,以及船、沙发和餐桌等更具体的类别。
  • 注释包括用于目标检测和分类任务的对象边界框和类标签,以及用于分割任务的分割掩码。
  • VOC 提供了标准化的评估指标,例如用于目标检测和分类的 mean Average Precision (mAP),使其非常适合用于比较模型性能。

Link to this section数据集结构#

VOC 数据集被分为三个子集:

  1. 训练集 (Train):此子集包含用于训练目标检测、分割和分类模型的图像。
  2. 验证集 (Validation):此子集包含在模型训练期间用于验证目的的图像。
  3. 测试集 (Test):此子集由用于测试和基准测试训练模型的图像组成。该子集的真值注释不对公众开放,以往的研究结果通常提交给 PASCAL VOC 评估服务器进行性能评估。

Link to this section应用#

The VOC dataset is widely used for training and evaluating deep learning models in object detection (such as Ultralytics YOLO, Faster R-CNN, and SSD), instance segmentation (such as Mask R-CNN), and image classification. The dataset's diverse set of object categories, large number of annotated images, and standardized evaluation metrics make it an essential resource for computer vision researchers and practitioners.

Link to this section数据集 YAML#

YAML (Yet Another Markup Language) 文件用于定义数据集配置。它包含有关数据集路径、类和其他相关信息。对于 VOC 数据集,VOC.yaml 文件维护在 https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/VOC.yaml

ultralytics/cfg/datasets/VOC.yaml
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford
# Documentation: https://docs.ultralytics.com/datasets/detect/voc
# Example usage: yolo train data=VOC.yaml
# parent
# ├── ultralytics
# └── datasets
#     └── VOC ← downloads here (2.8 GB)

# 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: VOC
train: # train images (relative to 'path') 16551 images
  - images/train2012
  - images/train2007
  - images/val2012
  - images/val2007
val: # val images (relative to 'path') 4952 images
  - images/test2007
test: # test images (optional)
  - images/test2007

# Classes
names:
  0: aeroplane
  1: bicycle
  2: bird
  3: boat
  4: bottle
  5: bus
  6: car
  7: cat
  8: chair
  9: cow
  10: diningtable
  11: dog
  12: horse
  13: motorbike
  14: person
  15: pottedplant
  16: sheep
  17: sofa
  18: train
  19: tvmonitor

# Download script/URL (optional) ---------------------------------------------------------------------------------------
download: |
  import xml.etree.ElementTree as ET
  from pathlib import Path

  from ultralytics.utils.downloads import download
  from ultralytics.utils import ASSETS_URL, TQDM

  def convert_label(path, lb_path, year, image_id):
      """Converts XML annotations from VOC format to YOLO format by extracting bounding boxes and class IDs."""

      def convert_box(size, box):
          dw, dh = 1.0 / size[0], 1.0 / size[1]
          x, y, w, h = (box[0] + box[1]) / 2.0 - 1, (box[2] + box[3]) / 2.0 - 1, box[1] - box[0], box[3] - box[2]
          return x * dw, y * dh, w * dw, h * dh

      with open(path / f"VOC{year}/Annotations/{image_id}.xml") as in_file, open(lb_path, "w", encoding="utf-8") as out_file:
          tree = ET.parse(in_file)
          root = tree.getroot()
          size = root.find("size")
          w = int(size.find("width").text)
          h = int(size.find("height").text)

          names = list(yaml["names"].values())  # names list
          for obj in root.iter("object"):
              cls = obj.find("name").text
              if cls in names and int(obj.find("difficult").text) != 1:
                  xmlbox = obj.find("bndbox")
                  bb = convert_box((w, h), [float(xmlbox.find(x).text) for x in ("xmin", "xmax", "ymin", "ymax")])
                  cls_id = names.index(cls)  # class id
                  out_file.write(" ".join(str(a) for a in (cls_id, *bb)) + "\n")

  # Download
  dir = Path(yaml["path"])  # dataset root dir
  urls = [
      f"{ASSETS_URL}/VOCtrainval_06-Nov-2007.zip",  # 446MB, 5012 images
      f"{ASSETS_URL}/VOCtest_06-Nov-2007.zip",  # 438MB, 4953 images
      f"{ASSETS_URL}/VOCtrainval_11-May-2012.zip",  # 1.95GB, 17126 images
  ]
  download(urls, dir=dir / "images", threads=3, exist_ok=True)  # download and unzip over existing (required)

  # Convert
  path = dir / "images/VOCdevkit"
  for year, image_set in ("2012", "train"), ("2012", "val"), ("2007", "train"), ("2007", "val"), ("2007", "test"):
      imgs_path = dir / "images" / f"{image_set}{year}"
      lbs_path = dir / "labels" / f"{image_set}{year}"
      imgs_path.mkdir(exist_ok=True, parents=True)
      lbs_path.mkdir(exist_ok=True, parents=True)

      with open(path / f"VOC{year}/ImageSets/Main/{image_set}.txt") as f:
          image_ids = f.read().strip().split()
      for id in TQDM(image_ids, desc=f"{image_set}{year}"):
          f = path / f"VOC{year}/JPEGImages/{id}.jpg"  # old img path
          lb_path = (lbs_path / f.name).with_suffix(".txt")  # new label path
          f.rename(imgs_path / f.name)  # move image
          convert_label(path, lb_path, year, id)  # convert labels to YOLO format

Link to this section用法#

若要使用图像大小为 640 的 YOLO26n 模型在 VOC 数据集上训练 100 个 轮次,你可以使用以下代码片段。有关可用参数的完整列表,请参阅模型 训练 页面。

训练示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.pt")  # load a pretrained model (recommended for training)

# Train the model
results = model.train(data="VOC.yaml", epochs=100, imgsz=640)

Link to this section样本图像和标注#

VOC 数据集包含一组多样化的图像,具有各种对象类别和复杂的场景。以下是来自数据集的一些图像示例,以及它们对应的注释:

Pascal VOC 数据集马赛克训练批次

  • 马赛克图像:此图像展示了一个由马赛克数据集图像组成的训练批次。马赛克是一种在训练期间使用的技术,它将多张图像合并为单张图像,以增加每个训练批次中物体和场景的多样性。这有助于提高模型对不同物体尺寸、宽高比和上下文的泛化能力。

该示例展示了 VOC 数据集中图像的多样性和复杂性,以及在训练过程中使用马赛克增强的好处。

Link to this section引用与致谢#

如果你在研究或开发工作中使用了 VOC 数据集,请引用以下论文:

引用
@misc{everingham2010pascal,
      title={The PASCAL Visual Object Classes (VOC) Challenge},
      author={Mark Everingham and Luc Van Gool and Christopher K. I. Williams and John Winn and Andrew Zisserman},
      year={2010},
      eprint={0909.5206},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

我们要感谢 PASCAL VOC 联盟为 计算机视觉 社区创建并维护了这一宝贵资源。有关 VOC 数据集及其创建者的更多信息,请访问 PASCAL VOC 数据集网站

Link to this section常见问题解答#

Link to this section什么是 PASCAL VOC 数据集,它对于计算机视觉任务为何如此重要?#

PASCAL VOC (Visual Object Classes) 数据集是计算机视觉中 目标检测、分割和分类任务的著名基准。它包括 20 个不同对象类别的全面注释,如边界框、类标签和分割掩码。由于其具有均值平均精度 (mAP) 等标准化评估指标,研究人员广泛使用它来评估 Faster R-CNN、YOLO 和 Mask R-CNN 等模型的性能。

Link to this section如何使用 VOC 数据集训练 YOLO26 模型?#

要使用 VOC 数据集训练 YOLO26 模型,你需要 YAML 文件中的数据集配置。以下是一个示例,展示了如何开始训练图像大小为 640 的 YOLO26n 模型 100 个轮次:

训练示例
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n.pt")  # load a pretrained model (recommended for training)

# Train the model
results = model.train(data="VOC.yaml", epochs=100, imgsz=640)

Link to this sectionVOC 数据集中包含哪些主要挑战?#

VOC 数据集包含两个主要挑战:VOC2007 和 VOC2012。这些挑战测试了跨越 20 个不同对象类别的目标检测、分割和分类能力。每张图像都经过精心注释,带有边界框、类标签和分割掩码。这些挑战提供了 mAP 等标准化指标,有助于对不同的计算机视觉模型进行比较和基准测试。

Link to this sectionPASCAL VOC 数据集如何增强模型基准测试和评估?#

PASCAL VOC 数据集通过其详细的注释和诸如均值平均 精度 (mAP) 等标准化指标,增强了模型基准测试和评估。这些指标对于评估目标检测和分类模型的性能至关重要。该数据集多样而复杂的图像确保了模型在各种现实场景下都能得到全面的评估。

Link to this section我该如何在 YOLO 模型中将 VOC 数据集用于 语义分割#

要在 YOLO 模型中将 VOC 数据集用于语义分割任务,你需要在一个 YAML 文件中正确配置数据集。YAML 文件定义了训练分割模型所需的路径和类。有关详细设置,请查看 VOC.yaml 数据集配置文件。对于分割任务,你应使用特定于分割的模型(如 yolo26n-seg.pt)而不是检测模型。

评论