VOCデータセット
PASCAL VOC(VisualObject Classes)データセットは、有名な物体検出、セグメンテーション、分類のデータセットである。このデータセットは、様々なオブジェクトカテゴリに関する研究を奨励するために設計されており、コンピュータビジョンモデルのベンチマークによく使用されます。オブジェクトの検出、セグメンテーション、分類タスクに取り組む研究者や開発者にとって不可欠なデータセットです。
主な特徴
- VOCデータセットには2つの主要課題がある:VOC2007とVOC2012である。
- このデータセットは、車、自転車、動物などの一般的なものから、ボート、ソファ、ダイニングテーブルなどの特殊なものまで、20のオブジェクト・カテゴリーで構成されている。
- 注釈には、オブジェクト検出と分類タスクのためのオブジェクトのバウンディングボックスとクラスラベル、セグメンテーションタスクのためのセグメンテーションマスクが含まれる。
- VOCは、物体検出と分類の平均平均精度(mAP)のような標準化された評価指標を提供し、モデルの性能を比較するのに適しています。
データセット構造
VOCデータセットは3つのサブセットに分割される:
- Train:このサブセットには、オブジェクト検出、セグメンテーション、分類モデルをトレーニングするための画像が含まれます。
- 検証:このサブセットは、モデルのトレーニング中に検証目的で使用される画像である。
- テスト:このサブセットは、学習済みモデルのテストとベンチマークに使用される画像で構成される。このサブセットのグランドトゥルースアノテーションは公開されておらず、結果は性能評価のためにPASCAL VOC評価サーバに提出される。
アプリケーション
VOCデータセットは、物体検出(YOLO 、Faster R-CNN、SSDなど)、インスタンスセグメンテーション(Mask R-CNNなど)、画像分類のディープラーニングモデルのトレーニングや評価に広く使用されています。このデータセットの多様なオブジェクトカテゴリ、多数の注釈付き画像、標準化された評価指標は、コンピュータビジョンの研究者や実務家にとって不可欠なリソースとなっています。
データセット 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 YOLO 🚀, AGPL-3.0 license
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC by University of Oxford
# Documentation: # 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: ../datasets/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 tqdm import tqdm
from ultralytics.utils.downloads import download
from pathlib import Path
def convert_label(path, lb_path, year, image_id):
def convert_box(size, box):
dw, dh = 1. / size[0], 1. / 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
in_file = open(path / f'VOC{year}/Annotations/{image_id}.xml')
out_file = open(lb_path, 'w')
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
url = 'https://github.com/ultralytics/yolov5/releases/download/v1.0/'
urls = [f'{url}VOCtrainval_06-Nov-2007.zip', # 446MB, 5012 images
f'{url}VOCtest_06-Nov-2007.zip', # 438MB, 4953 images
f'{url}VOCtrainval_11-May-2012.zip'] # 1.95GB, 17126 images
download(urls, dir=dir / 'images', curl=True, threads=3, exist_ok=True) # download and unzip over existing paths (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
使用方法
画像サイズ640のVOCデータセットでYOLOv8n モデルを100エポック訓練するには、以下のコード・スニペットを使用できます。利用可能な引数の包括的なリストについては、モデルのトレーニングページを参照してください。
列車の例
サンプル画像と注釈
VOCデータセットには、様々なオブジェクトのカテゴリと複雑なシーンを持つ画像の多様なセットが含まれています。このデータセットに含まれる画像の例を、対応するアノテーションとともに紹介する:
- モザイク画像:この画像は、モザイク処理されたデータセット画像で構成されたトレーニングバッチを示す。モザイク処理とは、複数の画像を1つの画像に合成し、各トレーニングバッチ内のオブジェクトやシーンの種類を増やすトレーニング時に使用される手法です。これにより、異なるオブジェクトサイズ、アスペクト比、コンテクストに対するモデルの汎化能力を向上させることができます。
この例では、VOCデータセットに含まれる画像の多様性と複雑さ、および学習プロセスでモザイク処理を使用する利点を示している。
引用と謝辞
研究開発でVOCデータセットを使用する場合は、以下の論文を引用してください:
PASCAL VOC コンソーシアムが、コンピュータビジョンコミュニティのためにこの貴重なリソースを作成し、維持してくださっていることに感謝いたします。VOCデータセットとその作成者についての詳細は、PASCAL VOCデータセットのウェブサイトをご覧ください。