Link to this section인스턴스 분할 데이터셋 개요#
인스턴스 분할은 이미지 내의 개별 객체를 식별하고 경계를 지정하는 컴퓨터 비전 작업입니다. 이 가이드에서는 인스턴스 분할 작업을 위해 Ultralytics YOLO에서 지원하는 데이터셋 형식에 대한 개요와 이러한 데이터셋을 모델 학습에 준비, 변환 및 사용하는 방법에 대한 지침을 제공합니다.
Link to this section지원되는 데이터셋 형식#
Link to this sectionUltralytics YOLO 형식#
YOLO 분할 모델 학습에 사용되는 데이터셋 라벨 형식은 다음과 같습니다:
- 이미지당 하나의 텍스트 파일: 데이터셋의 각 이미지에는 이미지 파일과 동일한 이름 및 ".txt" 확장자를 가진 대응하는 텍스트 파일이 있습니다.
- 객체당 한 행: 텍스트 파일의 각 행은 이미지 내의 하나의 객체 인스턴스에 해당합니다.
- 행별 객체 정보: 각 행에는 해당 객체 인스턴스에 대한 다음 정보가 포함됩니다:
- 객체 클래스 인덱스: 객체의 클래스를 나타내는 정수(예: 사람은 0, 자동차는 1 등).
- 객체 경계 좌표: 마스크 영역 주변의 경계 좌표로, 0에서 1 사이로 정규화됩니다.
분할 데이터셋 파일의 단일 행 형식은 다음과 같습니다:
<class-index> <x1> <y1> <x2> <y2> ... <xn> <yn>
이 형식에서 <class-index>는 객체의 클래스 인덱스이며, <x1> <y1> <x2> <y2> ... <xn> <yn>은 객체 분할 마스크의 정규화된 다각형 좌표입니다(값은 이미지 너비와 높이에 상대적인 [0, 1] 범위입니다). 좌표는 공백으로 구분됩니다.
다음은 3점 세그먼트와 5점 세그먼트로 구성된 두 개의 객체가 있는 단일 이미지에 대한 YOLO 데이터셋 형식의 예시입니다.
0 0.681 0.485 0.670 0.487 0.676 0.487
1 0.504 0.000 0.501 0.004 0.498 0.004 0.493 0.010 0.492 0.0104- 각 행의 길이는 동일할 필요가 없습니다.
- 각 분할 라벨은 최소 3개의
(x, y)포인트를 가져야 합니다:<class-index> <x1> <y1> <x2> <y2> <x3> <y3>
Link to this section데이터셋 YAML 형식#
Ultralytics 프레임워크는 분할 모델 학습을 위한 데이터셋 및 모델 구성을 정의하기 위해 YAML 파일 형식을 사용합니다. 다음은 분할 데이터셋을 정의하는 데 사용되는 YAML 형식의 예시입니다:
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# COCO8-seg dataset (first 8 images from COCO train2017) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/segment/coco8-seg
# Example usage: yolo train data=coco8-seg.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco8-seg ← downloads here (1 MB)
# 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: coco8-seg # dataset root dir
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)
# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush
# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-seg.ziptrain 및 val 필드는 각각 학습 및 검증 이미지가 포함된 디렉토리 경로를 지정합니다.
names는 클래스 이름의 딕셔너리입니다. 이름의 순서는 YOLO 데이터셋 파일의 객체 클래스 인덱스 순서와 일치해야 합니다.
Link to this section사용법#
from ultralytics import YOLO
# Load a model
model = YOLO("yolo26n-seg.pt") # load a pretrained model (recommended for training)
# Train the model
results = model.train(data="coco8-seg.yaml", epochs=100, imgsz=640)Link to this section지원되는 데이터셋#
Ultralytics YOLO는 인스턴스 분할 작업을 위한 다양한 데이터셋을 지원합니다. 가장 일반적으로 사용되는 데이터셋 목록은 다음과 같습니다:
- Carparts-seg: 자동차 부품 분할에 중점을 둔 특화 데이터셋으로, 자동차 애플리케이션에 이상적입니다. 개별 자동차 구성 요소에 대한 상세한 주석이 포함된 다양한 차량을 포함합니다.
- COCO: 객체 탐지, 분할 및 캡션 생성을 위한 포괄적인 데이터셋으로, 광범위한 카테고리에 걸쳐 20만 개 이상의 라벨링된 이미지를 제공합니다.
- COCO8-seg:
ultralytics저장소의 CI 검사 및 워크플로 검증을 위해 분할 모델 학습을 빠르게 테스트하도록 설계된 8개 이미지로 구성된 소규모 COCO 서브셋입니다. - COCO128-seg: 인스턴스 분할 작업을 위한 소규모 데이터셋으로, 분할 주석이 포함된 128개의 COCO 이미지 서브셋을 포함합니다.
- Crack-seg: 다양한 표면의 균열 분할을 위해 맞춤화된 데이터셋입니다. 인프라 유지 관리 및 품질 관리에 필수적이며, 구조적 취약점을 식별하기 위한 모델 학습용 상세 이미지를 제공합니다.
- Package-seg: 다양한 유형의 포장재 및 모양을 분할하기 위한 데이터셋입니다. 물류 및 창고 자동화에 특히 유용하며, 포장물 취급 및 분류 시스템 개발을 지원합니다.
Link to this section자신만의 데이터셋 추가하기#
자체 데이터셋을 보유하고 있으며 이를 Ultralytics YOLO 형식으로 분할 모델 학습에 사용하려는 경우, 위에서 명시된 "Ultralytics YOLO 형식"을 따르는지 확인하십시오. 주석을 필수 형식으로 변환하고 YAML 구성 파일에 경로, 클래스 수 및 클래스 이름을 지정하십시오. images/와 labels/를 동일한 수준의 별도 폴더로 유지하고 하위 폴더 구조를 일치시키십시오. 이미지 폴더에 라벨 .txt 파일을 배치하면 모델이 라벨을 인식하지 못할 수 있습니다.
Link to this section라벨 형식 포팅 또는 변환#
Link to this sectionCOCO 데이터셋 형식을 YOLO 형식으로#
다음 코드 스니펫을 사용하여 널리 사용되는 COCO 데이터셋 형식에서 YOLO 형식으로 라벨을 쉽게 변환할 수 있습니다:
from ultralytics.data.converter import convert_coco
convert_coco(labels_dir="path/to/coco/annotations/", use_segments=True)이 변환 도구는 COCO 데이터셋 또는 COCO 형식의 모든 데이터셋을 Ultralytics YOLO 형식으로 변환하는 데 사용할 수 있습니다.
사용하려는 데이터셋이 모델과 호환되며 필요한 형식 규칙을 따르는지 다시 확인하십시오. 올바르게 형식화된 데이터셋은 성공적인 분할 모델 학습에 필수적입니다.
Link to this section자동 주석(Auto-Annotation)#
자동 주석은 사전 학습된 탐지 모델을 사용하여 분할 데이터셋을 생성할 수 있게 해주는 필수 기능입니다. 수동 라벨링 없이 다수의 이미지를 빠르고 정확하게 주석 처리할 수 있어 시간과 노력을 절약할 수 있습니다.
Link to this section탐지 모델을 사용한 분할 데이터셋 생성#
Ultralytics 프레임워크를 사용하여 데이터셋에 자동 주석을 달려면 아래와 같이 auto_annotate 함수를 사용할 수 있습니다:
from ultralytics.data.annotator import auto_annotate
auto_annotate(data="path/to/images", det_model="yolo26x.pt", sam_model="sam_b.pt")| 인수 | 유형 | 기본값 | 설명 |
|---|---|---|---|
data | str | 필수 | 주석 또는 세그멘테이션을 위한 대상 이미지가 포함된 디렉토리 경로. |
det_model | str | 'yolo26x.pt' | 초기 객체 탐지를 위한 YOLO 탐지 모델 경로입니다. |
sam_model | str | 'sam_b.pt' | 세그멘테이션을 위한 SAM 모델 경로입니다 (SAM, SAM 2, MobileSAM 및 SAM 3 가중치 지원). |
device | str | '' | 연산 장치입니다 (예: 'cuda:0', 'cpu', 또는 자동 장치 탐지를 위한 ''). |
conf | float | 0.25 | 약한 탐지를 필터링하기 위한 YOLO 탐지 신뢰도 임계값입니다. |
iou | float | 0.45 | 겹치는 박스를 필터링하기 위한 NMS(Non-Maximum Suppression) IoU 임계값입니다. |
imgsz | int | 640 | 이미지 크기 조정을 위한 입력 크기입니다(32의 배수여야 합니다). |
max_det | int | 300 | 메모리 효율을 위해 이미지당 허용되는 최대 탐지 수입니다. |
classes | list[int] | None | 탐지할 클래스 인덱스 목록입니다(예: 사람 및 자전거의 경우 [0, 1]). |
output_dir | str | None | 주석 저장 디렉토리입니다(기본값: <data>_auto_annotate_labels와 동일한 위치). |
auto_annotate 함수는 이미지 경로와 함께, YOLO26, YOLO11 또는 기타 모델과 같은 사전 학습된 탐지 모델, 그리고 SAM, SAM 2, MobileSAM 또는 SAM 3과 같은 분할 모델, 모델을 실행할 장치, 주석 처리된 결과를 저장할 출력 디렉토리를 지정하는 선택적 인수를 받습니다.
사전 학습된 모델의 성능을 활용함으로써, 자동 주석은 고품질 분할 데이터셋을 생성하는 데 필요한 시간과 노력을 크게 줄일 수 있습니다. 이 기능은 대규모 이미지 컬렉션을 다루는 연구원 및 개발자에게 특히 유용하며, 수동 주석 대신 모델 개발 및 평가에 집중할 수 있도록 해줍니다.
Link to this section데이터셋 어노테이션 시각화#
모델을 학습하기 전에 데이터셋 주석을 시각화하여 올바른지 확인하는 것이 도움이 됩니다. Ultralytics는 이를 위해 유틸리티 함수를 제공합니다:
from ultralytics.data.utils import visualize_image_annotations
label_map = { # Define the label map with all annotated class labels.
0: "person",
1: "car",
}
# Visualize
visualize_image_annotations(
"path/to/image.jpg", # Input image path.
"path/to/annotations.txt", # Annotation file path for the image.
label_map,
)이 함수는 경계 상자를 그리고, 클래스 이름으로 객체에 라벨을 붙이며, 가독성을 높이기 위해 텍스트 색상을 조정하여 학습 전 주석 오류를 식별하고 수정할 수 있도록 도와줍니다.
Link to this section분할 마스크를 YOLO 형식으로 변환#
이진 형식의 분할 마스크를 가지고 있다면, 다음을 사용하여 YOLO 분할 형식으로 변환할 수 있습니다:
from ultralytics.data.converter import convert_segment_masks_to_yolo_seg
# For datasets like COCO with 80 classes
convert_segment_masks_to_yolo_seg(masks_dir="path/to/masks_dir", output_dir="path/to/output_dir", classes=80)이 유틸리티는 이진 마스크 이미지를 YOLO 분할 형식으로 변환하고 지정된 출력 디렉토리에 저장합니다.
Link to this sectionFAQ#
Link to this sectionUltralytics YOLO는 인스턴스 분할을 위해 어떤 데이터셋 형식을 지원합니까?#
Ultralytics YOLO는 인스턴스 분할을 위해 여러 데이터셋 형식을 지원하며, 기본 형식은 고유의 Ultralytics YOLO 형식입니다. 데이터셋의 각 이미지는 객체 정보가 여러 행(객체당 1행)으로 분할된 해당 텍스트 파일이 필요하며, 클래스 인덱스와 정규화된 경계 좌표를 나열합니다. YOLO 데이터셋 형식에 대한 더 자세한 지침은 인스턴스 분할 데이터셋 개요를 방문하십시오.
Link to this sectionCOCO 데이터셋 주석을 YOLO 형식으로 어떻게 변환할 수 있습니까?#
Converting COCO format annotations to YOLO format is straightforward using Ultralytics tools. You can use the convert_coco function from the ultralytics.data.converter module:
from ultralytics.data.converter import convert_coco
convert_coco(labels_dir="path/to/coco/annotations/", use_segments=True)이 스크립트는 COCO 데이터셋 주석을 필수 YOLO 형식으로 변환하여 YOLO 모델 학습에 적합하게 만듭니다. 더 자세한 내용은 라벨 형식 포팅 또는 변환을 참조하십시오.
Link to this sectionUltralytics YOLO 모델 학습을 위한 YAML 파일은 어떻게 준비합니까?#
Ultralytics로 YOLO 모델 학습을 위한 YAML 파일을 준비하려면 데이터셋 경로와 클래스 이름을 정의해야 합니다. 다음은 YAML 구성 예시입니다:
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license
# COCO8-seg dataset (first 8 images from COCO train2017) by Ultralytics
# Documentation: https://docs.ultralytics.com/datasets/segment/coco8-seg
# Example usage: yolo train data=coco8-seg.yaml
# parent
# ├── ultralytics
# └── datasets
# └── coco8-seg ← downloads here (1 MB)
# 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: coco8-seg # dataset root dir
train: images/train # train images (relative to 'path') 4 images
val: images/val # val images (relative to 'path') 4 images
test: # test images (optional)
# Classes
names:
0: person
1: bicycle
2: car
3: motorcycle
4: airplane
5: bus
6: train
7: truck
8: boat
9: traffic light
10: fire hydrant
11: stop sign
12: parking meter
13: bench
14: bird
15: cat
16: dog
17: horse
18: sheep
19: cow
20: elephant
21: bear
22: zebra
23: giraffe
24: backpack
25: umbrella
26: handbag
27: tie
28: suitcase
29: frisbee
30: skis
31: snowboard
32: sports ball
33: kite
34: baseball bat
35: baseball glove
36: skateboard
37: surfboard
38: tennis racket
39: bottle
40: wine glass
41: cup
42: fork
43: knife
44: spoon
45: bowl
46: banana
47: apple
48: sandwich
49: orange
50: broccoli
51: carrot
52: hot dog
53: pizza
54: donut
55: cake
56: chair
57: couch
58: potted plant
59: bed
60: dining table
61: toilet
62: tv
63: laptop
64: mouse
65: remote
66: keyboard
67: cell phone
68: microwave
69: oven
70: toaster
71: sink
72: refrigerator
73: book
74: clock
75: vase
76: scissors
77: teddy bear
78: hair drier
79: toothbrush
# Download script/URL (optional)
download: https://github.com/ultralytics/assets/releases/download/v0.0.0/coco8-seg.zip데이터셋에 따라 경로와 클래스 이름을 업데이트하십시오. 자세한 정보는 데이터셋 YAML 형식 섹션을 확인하십시오.
Link to this sectionUltralytics YOLO의 자동 주석 기능이란 무엇입니까?#
Ultralytics YOLO의 자동 주석 기능을 사용하면 사전 학습된 탐지 모델을 사용하여 데이터셋에 대한 분할 주석을 생성할 수 있습니다. 이는 수동 라벨링의 필요성을 크게 줄여줍니다. 다음과 같이 auto_annotate 함수를 사용할 수 있습니다:
from ultralytics.data.annotator import auto_annotate
auto_annotate(data="path/to/images", det_model="yolo26x.pt", sam_model="sam_b.pt") # or sam_model="mobile_sam.pt"이 함수는 어노테이션 프로세스를 자동화하여 더 빠르고 효율적으로 만들어 줍니다. 자세한 내용은 Auto-Annotate Reference를 확인하십시오.