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应用场景#

VOC 数据集被广泛用于训练和评估 deep learning 模型,涵盖目标检测(如 Ultralytics YOLOFaster R-CNNSSD)、instance segmentation(如 Mask R-CNN)以及 image classification。该数据集多样化的对象类别、大量的标注图像和标准化的评估指标,使其成为 computer vision 研究人员和从业者的重要资源。

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 的 VOC 数据集训练 YOLO26n 模型 100 个 epochs,你可以使用以下代码片段。有关可用参数的详细列表,请参阅模型 Training 页面。

训练示例
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 dataset mosaic training batch

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

该示例展示了 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 联盟为 computer vision 社区创建并维护了这一宝贵资源。有关 VOC 数据集及其创建者的更多信息,请访问 PASCAL VOC dataset website

Link to this section常见问题 (FAQ)#

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

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

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

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

训练示例
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 数据集通过其详细的标注和标准化的指标(如 mean Average Precision (mAP))增强了模型基准测试和评估。这些指标对于评估目标检测和分类模型的性能至关重要。该数据集多样且复杂的图像确保了对各种现实场景下的模型进行全面评估。

Link to this section如何将 VOC 数据集用于 YOLO 模型中的 semantic segmentation#

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

评论