COCO8-Seg 데이터셋

소개#

Ultralytics COCO8-Seg는 COCO train 2017 세트의 첫 8개 이미지로 구성된 소규모 인스턴스 세그멘테이션 데이터셋으로, 학습용 4개와 검증용 4개 이미지로 이루어져 있습니다. 이 데이터셋은 세그멘테이션 모델을 테스트하고 디버깅하거나 새로운 세그멘테이션 접근 방식을 실험하는 데 이상적입니다. 이미지가 8개뿐이라 관리하기 쉽고, 학습 파이프라인의 오류를 테스트하고 대규모 데이터셋 학습 전에 정상 작동 여부를 확인할 만큼 다양성도 갖추고 있습니다.

데이터셋 구조#

  • 이미지: 총 8개(학습 4개 / 검증 4개)입니다.
  • 클래스: COCO 카테고리 80개입니다.
  • 레이블: 각 이미지 파일에 대응하는 YOLO 형식 다각형이 labels/{train,val}에 저장됩니다.
  • 다운로드 크기: ~1 MB입니다.

Ultralytics Platform의 COCO8-Seg를 살펴보고 다각형 마스크가 포함된 모든 이미지를 확인하고, Charts 탭에서 클래스 분포와 어노테이션 히트맵을 살펴보고, 클라우드에서 자체 모델을 학습하도록 데이터셋을 복제하세요.

데이터셋 YAML#

데이터셋 구성을 정의하는 데 YAML 파일을 사용합니다. YAML 파일에는 데이터셋 경로, 클래스 및 기타 관련 정보가 포함됩니다. COCO8-Seg 데이터셋의 경우 coco8-seg.yaml 파일이 https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/coco8-seg.yaml에 유지 관리됩니다.

ultralytics/cfg/datasets/coco8-seg.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

사용법#

다음 코드 조각을 사용하면 이미지 크기 640으로 COCO8-Seg 데이터셋에서 100 에포크 동안 YOLO26n-seg 모델을 학습할 수 있습니다.

학습 예제
from ultralytics import YOLO

# 모델 로드
model = YOLO("yolo26n-seg.pt")  # 사전 학습된 모델을 불러옵니다(학습에 권장).

# 모델 학습
results = model.train(data="coco8-seg.yaml", epochs=100, imgsz=640)

샘플 이미지 및 어노테이션#

다음은 COCO8-Seg 데이터셋의 이미지와 각 이미지에 대응하는 어노테이션의 예입니다:

COCO8-seg instance segmentation dataset mosaic
  • 모자이크 이미지: 이 이미지는 모자이크 처리된 데이터셋 이미지로 구성된 학습 배치를 보여줍니다. 모자이크 처리는 학습 중 여러 이미지를 하나의 이미지로 결합해 각 학습 배치에 포함되는 객체와 장면의 다양성을 높이는 기법입니다. 이 기법은 모델이 다양한 객체 크기, 종횡비 및 맥락에 일반화하는 능력을 향상하는 데 도움이 됩니다.

인용 및 감사의 글#

연구 또는 개발 작업에서 COCO 데이터셋을 사용하는 경우 다음 논문을 인용해 주세요:

인용
@misc{lin2015microsoft,
      title={Microsoft COCO: Common Objects in Context},
      author={Tsung-Yi Lin and Michael Maire and Serge Belongie and Lubomir Bourdev and Ross Girshick and James Hays and Pietro Perona and Deva Ramanan and C. Lawrence Zitnick and Piotr Dollár},
      year={2015},
      eprint={1405.0312},
      archivePrefix={arXiv},
      primaryClass={cs.CV}
}

컴퓨터 비전 커뮤니티를 위한 이 귀중한 리소스를 만들고 유지 관리해 주신 COCO Consortium에 감사드립니다. COCO 데이터셋과 제작자에 대한 자세한 내용은 COCO 데이터셋 웹사이트를 방문하세요.

자주 묻는 질문#

  • COCO8-Seg 데이터셋은 Ultralytics의 소규모 인스턴스 세그멘테이션 데이터셋으로, COCO train 2017 세트의 첫 8개 이미지(학습용 4개, 검증용 4개)로 구성됩니다. 이 데이터셋은 세그멘테이션 모델을 테스트하고 디버깅하거나 새로운 세그멘테이션 방법을 실험하는 데 적합합니다. 대규모 데이터셋으로 확장하기 전에 빠르게 반복 작업을 수행하고 파이프라인 오류를 확인할 수 있어 Ultralytics YOLO26과 함께 사용하기에 특히 유용합니다.

  • COCO8-Seg 데이터셋에서 YOLO26n-seg 모델을 이미지 크기 640으로 100 에폭 동안 학습하려면 Python 또는 CLI 명령을 사용할 수 있습니다. 간단한 예는 다음과 같습니다:

    학습 예제
    from ultralytics import YOLO
    
    # 모델 로드
    model = YOLO("yolo26n-seg.pt")  # 사전 학습된 모델을 불러옵니다(학습에 권장).
    
    # 모델 학습
    results = model.train(data="coco8-seg.yaml", epochs=100, imgsz=640)

    사용 가능한 인수와 구성 옵션에 대한 자세한 설명은 학습 문서에서 확인할 수 있습니다.

  • 전체 COCO보다 다운로드 용량이 작고 학습/검증 루프가 훨씬 짧기 때문에, COCO8-Seg를 사용하면 더 큰 데이터셋에 착수하기 전에 학습 및 검증을 한 차례 실행해 데이터 로더 오류, 잘못 구성된 손실 함수, 잘못된 증강 등의 파이프라인 문제를 발견할 수 있습니다. 지원되는 데이터셋 형식에 관한 자세한 내용은 Ultralytics 세그멘테이션 데이터셋 가이드를 참조하세요.

  • COCO8-Seg 데이터셋의 YAML 구성 파일은 Ultralytics 저장소에서 확인할 수 있습니다. 파일에 직접 액세스하려면 https://github.com/ultralytics/ultralytics/blob/main/ultralytics/cfg/datasets/coco8-seg.yaml를 방문하세요. YAML 파일에는 모델 학습 및 검증에 필요한 데이터셋 경로, 클래스 및 구성 설정에 관한 필수 정보가 포함되어 있습니다.

  • 규모 면에서 COCO8-Seg(이미지 8개)는 COCO128-Seg(이미지 128개)와 전체 COCO-Seg 데이터셋(학습 이미지 118,287개)보다 작습니다:

    • COCO8-Seg: 이미지 8개(학습 4개, 검증 4개) — 가장 빠르게 기본 동작을 점검할 수 있어 CI 및 신속한 디버깅에 적합합니다.
    • COCO128-Seg: 이미지 128개 — 크기와 다양성이 균형을 이루며, 학습과 검증에서 동일한 디렉터리를 공유합니다.
    • 전체 COCO-Seg: 학습 이미지 118,287개 — 포괄적인 데이터셋이지만 리소스가 많이 필요하며, 최초 다운로드 시 ~20 GB가 필요합니다.

    가능한 한 빠르게 파이프라인을 점검하려면 COCO8-Seg를 사용한 다음, 확신이 쌓이면 COCO128-Seg 또는 전체 COCO-Seg 데이터셋으로 확장하세요.

댓글6

질문을 하거나 결과를 공유하거나 다른 사람을 도와주세요.

  1. kh-diabGitHub

    Hello I am struggling because I followed the same coco format in the yaml file but still get this error

    Epoch GPU_mem box_loss seg_loss cls_loss dfl_loss Instances Size

    0%| | 0/2 [00:00<?, ?it/s] Traceback (most recent call last): File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/utils/loss.py", line 289, in call targets = torch.cat((batch_idx, batch["cls"].view(-1, 1), batch["bboxes"]), 1) RuntimeError: Sizes of tensors must match except in dimension 1. Expected size 66 but got size 0 for tensor number 1 in the list.

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last): File "/home/kdiab/Documents/OST/workspace/dataset/coding/Train_Model/train segment model V6.0.py", line 33, in results =model.train( File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/engine/model.py", line 652, in train self.trainer.train() File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/engine/trainer.py", line 204, in train self._do_train(world_size) File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/engine/trainer.py", line 381, in _do_train self.loss, self.loss_items = self.model(batch) File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/nn/tasks.py", line 101, in forward return self.loss(x, *args, **kwargs) File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/nn/tasks.py", line 283, in loss return self.criterion(preds, batch) File "/home/kdiab/.conda/envs/yolov8/lib/python3.10/site-packages/ultralytics/utils/loss.py", line 294, in call raise TypeError( TypeError: ERROR ❌ segment dataset incorrectly formatted or not a segment dataset. This error can occur when incorrectly training a 'segment' model on a 'detect' dataset, i.e. 'yolo train model=yolov8n-seg.pt data=coco8.yaml'. Verify your dataset is a correctly formatted 'segment' dataset using 'data=coco8-seg.yaml' as an example.

    and this is my yaml file

    Ultralytics YOLO , AGPL-3.0 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: /home/kdiab/Documents/OST/workspace/dataset/model_train/Group-C-tiny-Segment # dataset root dir train: /home/kdiab/Documents/OST/workspace/dataset/model_train/Group-C-tiny-Segment/images/train # train images (relative to 'path') 4 images val: /home/kdiab/Documents/OST/workspace/dataset/model_train/Group-C-tiny-Segment/images/val # val images (relative to 'path') 4 images test: # test images (optional)

    Classes

    names: 0: weed 1: rumex

    and I am using model model = YOLO('yolov8x-seg.pt')

    my labeled files is as follows

    0 0.094970703125 0.46401098901098903 0.09033203125 0.160989010989011 0 0.07861328125 0.46153846153846156 0.0556640625 0.03296703296703297 0 0.116943359375 0.43763736263736264 0.02783203125 0.036813186813186814

    can you please advise what is the error

    1. Glenn JocherUltralytics

      @kh-diab it looks like the error you're encountering is due to a mismatch in the dataset format. Ensure that your dataset is correctly formatted for segmentation. Verify that your label files contain segmentation masks and not just bounding boxes. Also, make sure you are using the latest version of the Ultralytics package. If the issue persists, please check the dataset structure against the COCO8-Seg example provided in the documentation: https://docs.ultralytics.com/datasets/segment/coco8-seg/. This should help resolve the formatting issue.

  2. Mauricio566GitHub

    I really love their material. I have a question please help me. If the annotations of an image for a detection problem look like this... 1 0.5302913188934326 0.5031314492225647 0.2403690367937088 0.34829962253570557 So what does the annotation of a segmented image look like? because in the dataset I did not understand the annotation and you could help me understand this process. thank you

    1. Glenn JocherUltralytics

      @Mauricio566 hello! Thanks for your kind words and for reaching out with your question. 🌟

      For instance segmentation, unlike detection annotations which typically include class labels and bounding box coordinates (x_center, y_center, width, height), segmentation annotations are more complex. They include polygonal annotations or masks that precisely outline the object within an image.

      In datasets like COCO, each segmented object in an image will have a corresponding mask defined by a set of polygon points. These points outline the exact shape of the object rather than just a bounding rectangle. This allows for a more accurate and detailed representation, especially useful for applications requiring precise object localization and shape delineation.

      If you're working with the COCO8-Seg dataset, the annotations will include these detailed masks for each object in the images. You can view these annotations in the JSON format provided with the dataset, where each object's mask is represented as a series of coordinates outlining the object.

      I hope this helps clarify the difference! If you have any more questions or need further assistance, feel free to ask. Happy coding! 😊

      1
    2. jotar25GitHub

      this is actually not clear, should i separate masked color to multiple images? what is it the processs to generate labels from multi mask image?

    3. Glenn JocherUltralytics

      Hi @jotar25,

      Thank you for your question! 😊 Let's clarify the process for generating labels from multi-mask images for instance segmentation.

      In instance segmentation, each object in an image is annotated with a mask that precisely outlines its shape. These masks are typically represented as polygons or binary masks. Here's a step-by-step overview of the process:

      1. Separate Masks for Each Object: Each object in the image should have its own mask. If you have a multi-mask image where different objects are represented by different colors, you will need to separate these into individual masks.

      2. Polygon Annotations: For datasets like COCO, the masks are often stored as polygons. Each polygon is a list of coordinates that outline the object. These coordinates are stored in the dataset's annotation file (e.g., a JSON file for COCO).

      3. Binary Masks: Alternatively, masks can be stored as binary images where the pixels belonging to an object are set to 1, and all other pixels are set to 0. Each object will have a separate binary mask.

      4. Annotation Format: In the COCO format, each annotation includes:

        • segmentation: A list of polygons for the object.
        • bbox: The bounding box of the object.
        • category_id: The class of the object.
        • image_id: The ID of the image.

      Here's an example of how a COCO annotation might look:

      {
        "segmentation": [[x1, y1, x2, y2, ..., xn, yn]],
        "bbox": [x, y, width, height],
        "category_id": 1,
        "image_id": 123
      }
      Example Code for Generating Binary Masks

      If you have a multi-mask image and need to generate individual binary masks, you can use the following Python code snippet:

      import cv2
      import numpy as np
      
      # Load the multi-mask image
      multi_mask_image = cv2.imread('multi_mask_image.png')
      
      # Assume each object is represented by a unique color
      unique_colors = np.unique(multi_mask_image.reshape(-1, multi_mask_image.shape[2]), axis=0)
      
      # Create binary masks for each unique color
      binary_masks = []
      for color in unique_colors:
          mask = cv2.inRange(multi_mask_image, color, color)
          binary_masks.append(mask)
      
      # Save or process the binary masks
      for i, mask in enumerate(binary_masks):
          cv2.imwrite(f'binary_mask_{i}.png', mask)

      For more detailed information on the COCO8-Seg dataset and how to work with it, please refer to the COCO8-Seg Dataset Documentation.

      I hope this helps! If you have any more questions or need further assistance, feel free to ask. Happy coding! 🚀