はじめる

PASCAL VOCデータセット

PASCAL VOC(Visual Object Classes)データセットは、20種類の日常物体カテゴリを含む、古典的な物体検出ベンチマークです。UltralyticsのVOC.yaml設定では、VOC2007とVOC2012のtrainval分割を統合して画像16,551枚のトレーニングセットを作成し、公開アノテーション付きのVOC2007テスト画像4,952枚で検証します。初回使用時にすべてが自動ダウンロードされます(2.8 GB)。



視聴: Pascal VOC データセットで Ultralytics YOLO をトレーニングする方法 | 物体検出 | コンピュータービジョン 🚀

PASCAL VOCチャレンジは2005年から2012年まで開催され、物体検出モデルの評価方法を形作りました。このベンチマークは画像分類、検出、セグメンテーションのタスクを扱い、検出の標準指標として平均適合率(mAP)を広く普及させました。UltralyticsのVOC.yaml設定では検出アノテーションを使用し、ダウンロード時に元のXML形式のバウンディングボックスをYOLO形式に変換します。

主な機能#

  • 日常物体の20クラス:人;6種類の動物(鳥、猫、牛、犬、馬、羊);7種類の乗り物(飛行機、自転車、ボート、バス、自動車、オートバイ、列車);6種類の屋内物体(ボトル、椅子、ダイニングテーブル、鉢植え、ソファ、テレビモニター)。
  • 2世代のチャレンジを統合:トレーニングセットは、VOC2007 trainval(画像5,011枚)とVOC2012 trainval(画像11,540枚)を統合して作成されます。
  • 標準化された評価:長年にわたって公開されたVOCのベースラインがあるため、検出モデルを比較する際の便利な基準となります。
  • YOLOですぐに利用可能:ダウンロードスクリプトがアーカイブを取得し、アノテーションを自動変換するため、手動で準備する必要はありません。

データセットの構成#

UltralyticsのVOC.yaml設定では、次の分割を定義しています。

分割画像ソース
学習16,551VOC2007 trainval(5,011枚)+ VOC2012 trainval(11,540枚)
検証4,952トレーニング中の評価に使用するVOC2007テスト
テスト4,952同じVOC2007テスト画像です。設定には別のホールドアウト分割はありません。

VOC2007のテストアノテーションは、その年のチャレンジ終了後に公開されたため、この分割をラベル付き検証セットとして使用できます。VOC2012のテストアノテーションは非公開のままであり、公式のPASCAL評価サーバーを通じてのみスコアを取得できるため、この設定には含まれません。

難易度の高い物体は除外

自動変換ツールは、元のVOC XMLアノテーションでdifficultと指定された物体をスキップするため、クラスごとのインスタンス数は公式のVOC統計と若干異なります。

Ultralytics Platform上のVOCを開くと、アノテーションを重ねた画像を閲覧したり、Chartsタブでクラス分布やバウンディングボックスのヒートマップを確認したり、データセットを複製してクラウドで独自のモデルをトレーニングしたりできます。

用途#

より大規模なCOCOデータセットが登場する前、PASCAL VOCは物体検出研究の主要なベンチマークでした。Faster R-CNNやSSDなどの検出器は、当初の結果をこのデータセットで報告し、Ultralytics YOLOモデルも追加設定なしでトレーニングできます。現在も、次の用途で広く利用されています。

  • 長年にわたって公開されたベースラインを基準に、新しい検出アーキテクチャを評価する
  • 迅速な実験やコースワーク。トレーニング画像が16,551枚のため、COCOよりもはるかに速くトレーニングできます。
  • コンパクトでよく理解された日常カテゴリのデータセットを用いた転移学習の研究

データセットYAML#

VOC.yamlファイルでは、データセットのパス、20種類のクラス名、自動ダウンロード・変換スクリプトなど、データセット設定を定義します。このファイルはUltralyticsリポジトリの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 https://www.robots.ox.ac.uk/~vgg/projects/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, 5011 images
      f"{ASSETS_URL}/VOCtest_06-Nov-2007.zip",  # 438MB, 4952 images
      f"{ASSETS_URL}/VOCtrainval_11-May-2012.zip",  # 1.95GB, 17125 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

使用方法#

2.8 GBのダウンロード

VOCは初回のトレーニング時に自動的にダウンロードされます。3つのアーカイブの合計サイズは2.8 GBで、展開と変換には約6 GBの空きディスク容量が必要です。

以下のコードスニペットを使用すると、VOCデータセットで画像サイズ640、100エポックの条件でYOLO26nモデルをトレーニングできます。

トレーニング例
from ultralytics import YOLO

# モデルを読み込む
model = YOLO("yolo26n.pt")  # 事前トレーニング済みモデルを読み込みます(トレーニングにはこちらを推奨します)

# モデルをトレーニングします - データセットは初回実行時に自動ダウンロードされます
results = model.train(data="VOC.yaml", epochs=100, imgsz=640)

サンプル画像とアノテーション#

以下の画像は、VOCデータセットのモザイク化されたトレーニングバッチを示しています。モザイク化では複数の画像を1つのトレーニングサンプルに結合することで、各バッチでモデルが認識する物体、スケール、シーンのコンテキストの多様性を高めます。詳しくは、YOLOデータ拡張ガイドを参照してください。

Pascal VOCデータセットのモザイク化トレーニングバッチ

引用と謝辞#

研究または開発でVOCデータセットを使用する場合は、以下の論文を引用してください。

引用
@article{everingham2010pascal,
  author={Everingham, Mark and Van Gool, Luc and Williams, Christopher K. I. and Winn, John and Zisserman, Andrew},
  journal={International Journal of Computer Vision},
  title={The Pascal Visual Object Classes (VOC) Challenge},
  year={2010},
  volume={88},
  number={2},
  pages={303-338},
  doi={10.1007/s11263-009-0275-4}}

コンピュータビジョンコミュニティにとって貴重なリソースであるVOCデータセットを作成し、維持しているPASCAL VOC Consortiumに感謝します。VOCデータセットとその作成者について詳しくは、PASCAL VOCデータセットのウェブサイトをご覧ください。

よくある質問#

  • PASCAL VOCは、人、車、犬、椅子などの日常的な20クラスで物体検出モデルをトレーニングし、ベンチマークするために使用されます。規模が小さく、すべてにラベルが付与され、長年にわたる公開済みのベースラインがあるため、新しいアーキテクチャの検証、授業での実験、迅速な転移学習の検討によく選ばれます。

  • UltralyticsのVOC設定には21,503枚の画像が含まれています。内訳は、トレーニング用が16,551枚(VOC2007 trainval + VOC2012 trainval)、検証用が4,952枚(VOC2007 testセット)です。すべての分割で同じ20クラスが使用されています。詳しい内訳はデータセットの構成を参照してください。

  • data="VOC.yaml"を使用した初回のトレーニング時にVOCが自動的にダウンロードされるため、手動での作業は必要ありません。スクリプトは、Ultralytics GitHubのリリースアセットから3つのアーカイブ(2.8 GB)を取得し、XML形式のアノテーションをYOLO形式に変換します。

  • VOCでYOLO26nモデルを、エポック数100、画像サイズ640でトレーニングします。

    トレーニング例
    from ultralytics import YOLO
    
    # モデルを読み込む
    model = YOLO("yolo26n.pt")  # 事前トレーニング済みモデルを読み込みます(トレーニングにはこちらを推奨します)
    
    # モデルをトレーニングする
    results = model.train(data="VOC.yaml", epochs=100, imgsz=640)

    詳しい設定については、トレーニングページとモデルのトレーニングのヒントをご覧ください。

  • どちらのチャレンジも同じ20クラスを使用していますが、含まれる画像は異なります。VOC2007には、trainval画像5,011枚と、アノテーションが公開されているテストセット4,952枚が含まれます。VOC2012にはtrainval画像が11,540枚含まれますが、テストアノテーションは非公開で、公式評価サーバーでのみスコアが算出されます。UltralyticsのVOC.yamlは、両方のtrainvalセットを統合してトレーニングに使用し、VOC2007 testで検証します。

  • VOCはCOCOより小規模で単純です。VOCは20クラス、21,503枚の画像であるのに対し、COCOは80クラス、330K枚の画像で構成されています。VOCの結果は従来、0.5のIoUにおけるmAPで報告されますが、COCOではIoUしきい値0.5~0.95のmAPを平均します。VOCはトレーニングがはるかに速く、迅速な実験に適しています。COCOデータセットは、本番規模のベンチマークにおける標準です。

  • いいえ。VOC.yamlは検出専用の設定です。コンバーターはVOC XMLアノテーションからバウンディングボックスを抽出しますが、元のベンチマークに含まれるセグメンテーションマスクは変換されません。インスタンスセグメンテーションモデルをトレーニングするには、YOLO26n-segモデルと、COCO-Segなどのポリゴンラベルを含むデータセットを使用してください。

コメント8

質問したり、結果を共有したり、ほかの人をサポートしたりできます。

  1. mengdxiranGitHub

    raise RuntimeError(emojis(f"Dataset '{clean_url(self.args.data)}' error ❌ {e}")) from e RuntimeError: Dataset 'VOC.yaml' error ❌ [Errno 2] No such file or directory: '/home/diana/Code/test/datasets/VOC/images/VOCdevkit/VOC2007/ImageSets/Main/train.txt'

    1. mengdxiranGitHub

      I've identified the issue—it was due to a problem with the data download, where some of the data failed to download successfully

    2. Glenn JocherUltralytics

      Nice find on the root cause. To clean things up, delete the incomplete datasets/VOC folder and run your yolo ... data=VOC.yaml command again so the download/conversion script can fully re-download and unpack everything; if you still hit a path error after that, please share the full command and complete traceback so we can take a closer look.

    1. Glenn JocherUltralytics(編集済み)

      @YustasDev to train YOLO26 on your Pascal VOC dataset, you need to convert the XML annotations to YOLO format (class, x_center, y_center, width, height in normalized coordinates). Use the conversion script provided in the VOC.yaml file under the "Download script/URL" section. Once converted, define a custom YAML file for your dataset paths and run the training using:

      from ultralytics import YOLO
      
      model = YOLO("yolo26n.pt")
      model.train(data="your_dataset.yaml", epochs=100, imgsz=640)

      Refer to the VOC Dataset Docs for detailed guidance.

  2. YustasDevGitHub

    So, I have a train dataset in Pascal VOC format, i.e. /train/ - 1.jpg - 1.xml - 2.jpg - 2.xml ...... and so on.

    Where the xml file format is as follows:

    1.jpg unknown 640 640 3 0 led Unspecified 0 0 0 359 368 82 94

    Respectively, "xmin/ymin" and "xmax/ymax" are the coordinates of the upper-left and lower-right corners of the object. How can I use this dataset to train the YoloV11 neural network?

    1. Glenn JocherUltralytics(編集済み)

      @YustasDev to use your Pascal VOC dataset for YOLO26 training, you need to convert the XML annotations to YOLO format (class, x_center, y_center, width, height with normalized coordinates). You can adapt the XML-to-YOLO conversion script from the VOC dataset documentation here: https://docs.ultralytics.com/datasets/detect/voc/. Once converted, create a dataset YAML file similar to VOC.yaml, specifying your paths and classes, and then start training using yolo detect train data=your_dataset.yaml model=yolo26n.pt. Let me know if you encounter any issues!