Pascal VOC(Visual Object Classes)은 객체 인식(Object Detection)과 분할(Segmentation) 연구를 위해 제안된 표준 데이터 형식입니다. 이미지를 입력(input)으로, XML 기반의 어노테이션(annotation)을 정답(ground truth)으로 사용하여 객체의 위치(바운딩 박스)와 클래스 정보를 기술합니다. 이 형식은 많은 라벨링 툴에서 지원되며, CVAT, VoTT, RectLabel 등에서 내보내기(export) 및 가져오기(import)가 가능합니다[1][2].
폴더 계층 구조
데이터셋을 압축 해제하면 다음과 같은 디렉터리 구조를 가집니다[2][3]:
VOCdevkit/VOC20XX/
├── Annotations/ # XML 어노테이션 파일(.xml)
├── JPEGImages/ # 원본 이미지(.jpg)
├── ImageSets/ # 훈련/검증/테스트 분할 정보(.txt)
│ └── Main/
│ ├── train.txt
│ ├── val.txt
│ └── test.txt
├── SegmentationClass/ # 픽셀 단위 시맨틱 세그멘테이션 마스크
└── SegmentationObject/ # 인스턴스 세그멘테이션 마스크
- Annotations: 각 이미지별 XML 파일(어노테이션)
- JPEGImages:
.jpg
확장자의 원본 이미지 - ImageSets/Main: 클래스별 또는 split별 이미지 목록(txt)
- SegmentationClass / SegmentationObject: 세그멘테이션 태스크용 레이블
XML 어노테이션 구조
각 XML 파일의 기본 구조는 다음과 같습니다[1][3]:
<annotation>
<folder>VOC2007</folder>
<filename>000001.jpg</filename>
<path>VOC2007/JPEGImages/000001.jpg</path>
<source>
<database>The VOC2007 Database</database>
<annotation>PASCAL VOC2007</annotation>
<image>flickr</image>
<flickrid>341012865</flickrid>
</source>
<owner>
<flickrid>Fried Camels</flickrid>
<name>Jinky the Fruit Bat</name>
</owner>
<size>
<width>353</width>
<height>500</height>
<depth>3</depth>
</size>
<segmented>0</segmented>
<object>
<name>dog</name>
<pose>Left</pose>
<truncated>1</truncated>
<difficult>0</difficult>
<occluded>0</occluded>
<bndbox>
<xmin>48</xmin>
<ymin>240</ymin>
<xmax>195</xmax>
<ymax>371</ymax>
</bndbox>
</object>
<object>
<name>person</name>
<pose>Left</pose>
<truncated>1</truncated>
<difficult>0</difficult>
<occluded>0</occluded>
<bndbox>
<xmin>8</xmin>
<ymin>12</ymin>
<xmax>352</xmax>
<ymax>498</ymax>
</bndbox>
</object>
</annotation>
주요 태그 설명
태그 경로 | 설명 |
---|---|
<folder> | 데이터셋 디렉터리명 (e.g., VOC2007) |
<filename> | 이미지 파일 이름 (e.g., 000001.jpg) |
<path> | 이미지 절대 또는 상대 경로 |
<source>/<database> | 데이터베이스 이름 (예: The VOC2007 Database) |
<owner>/<name> | 이미지 소유자 정보 |
<size>/<width> | 이미지 가로 픽셀 수 |
<size>/<height> | 이미지 세로 픽셀 수 |
<size>/<depth> | 채널 수 (RGB:3) |
<segmented> | 세그멘테이션 여부 (0: 없음, 1: 있음) |
<object>/<name> | 객체 클래스명 (e.g., dog, person) |
<object>/<pose> | 객체 포즈 정보 (주로 Unspecified) |
<object>/<truncated> | 이미지 경계 바깥으로 잘린 객체 여부 (0/1) |
<object>/<difficult> | 인식이 어려운 객체 여부 (0/1) |
<object>/<occluded> | 다른 객체에 가려진 정도 (0/1) |
<object>/<bndbox> | 바운딩 박스 좌표 그룹 |
└─ <xmin>, <ymin> | 바운딩 박스 왼쪽 상단 좌표 |
└─ <xmax>, <ymax> | 바운딩 박스 오른쪽 하단 좌표 |
파이썬 예제: XML 파싱
import xml.etree.ElementTree as ET
tree = ET.parse('Annotations/000001.xml')
root = tree.getroot()
# 이미지 크기 정보
size = root.find('size')
width = int(size.find('width').text)
height = int(size.find('height').text)
depth = int(size.find('depth').text)
# 객체 정보 리스트
for obj in root.findall('object'):
cls = obj.find('name').text
truncated = int(obj.find('truncated').text)
difficult = int(obj.find('difficult').text)
xmin = int(obj.find('bndbox/xmin').text)
ymin = int(obj.find('bndbox/ymin').text)
xmax = int(obj.find('bndbox/xmax').text)
ymax = int(obj.find('bndbox/ymax').text)
print(f'{cls}: [{xmin},{ymin}]–[{xmax},{ymax}], truncated={truncated}, difficult={difficult}')
이 코드는 xml.etree.ElementTree
로 XML을 읽어, 이미지 크기와 각 객체의 바운딩 박스 및 속성 정보를 추출합니다[3].
Pascal VOC 형식은 단순하면서도 범용성이 높아, 객체 검출 모델 학습용 데이터셋 구성 시 널리 사용됩니다. XML 기반의 명료한 구조로 원하는 태그를 손쉽게 파싱할 수 있어, Custom 데이터셋 구축에도 적합합니다.
출처
[1] What is the Pascal VOC XML Annotation Format? – Roboflow https://roboflow.com/formats/pascal-voc-xml
[2] Pascal VOC – Documentation | CVAT https://docs.cvat.ai/docs/manual/advanced/formats/format-voc/
[3] 01). PASCAL VOC · GitBook https://deepbaksuvision.github.io/Modu_ObjectDetection/posts/02_01_PASCAL_VOC.html
[4] PASCAL VOC Dataset – Papers With Code https://paperswithcode.com/dataset/pascal-voc
[5] [Python] XML 파싱하기(with Pascal VOC) – fe Lab – 티스토리 https://firsteast.tistory.com/139
[6] Expected dir structure for the Pascal VOC train and test #749 – GitHub https://github.com/facebookresearch/detectron2/issues/749
[7] Reading PASCAL VOC annotations in python – xml – Stack Overflow https://stackoverflow.com/questions/53317592/reading-pascal-voc-annotations-in-python
[8] PASCAL VOC detection 데이터 및 라벨 구조(간단히 정리) – 티스토리 https://better-tomorrow.tistory.com/entry/PASCAL-VOC-detection-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EB%B0%8F-%EB%9D%BC%EB%B2%A8-%EA%B5%AC%EC%A1%B0%EA%B0%84%EB%8B%A8%ED%9E%88-%EC%A0%95%EB%A6%AC
[9] Pascal VOC XML – Supervision https://roboflow.github.io/supervision/0.5.2/annotation/voc/
[10] VOC 포맷 데이터 정리하기 (1) – velog https://velog.io/@bigjoon/VOC-%ED%8F%AC%EB%A7%B7-%EB%8D%B0%EC%9D%B4%ED%84%B0-%EC%A0%95%EB%A6%AC%ED%95%98%EA%B8%B0-1
답글 남기기