COCO 데이터셋

COCO 데이터셋(일상 환경의 공통 객체)은 대규모 객체 탐지, 분할 및 캡셔닝 데이터셋입니다. 다양한 객체 카테고리에 대한 연구를 촉진하도록 설계되었으며, 컴퓨터 비전 모델의 벤치마크에 널리 사용됩니다. 객체 탐지, 분할, 포즈 추정 작업을 수행하는 연구자와 개발자에게 필수적인 데이터셋입니다.



시청: Ultralytics COCO 데이터셋 개요

COCO 사전 학습 모델#

모델크기
(픽셀)
mAPval50-95mAP검증50-95
(e2e)
속도
CPU ONNX
(ms)
속도
T4 TensorRT10
(ms)
파라미터
(M)
FLOPs
(B)
YOLO26n64040.940.138.9 ± 0.71.7 ± 0.02.45.5
YOLO26s64048.647.887.2 ± 0.92.5 ± 0.09.520.9
YOLO26m64053.152.5220.0 ± 1.44.7 ± 0.120.468.4
YOLO26l64055.054.4286.2 ± 2.06.2 ± 0.224.886.8
YOLO26x64057.556.9525.8 ± 4.011.8 ± 0.255.7194.4

주요 기능#

  • COCO에는 이미지 330K개가 포함되어 있으며, 이 중 200K개에는 객체 탐지, 분할, 캡셔닝 작업을 위한 어노테이션이 있습니다.
  • 이 데이터셋은 자동차, 자전거, 동물과 같은 일반적인 객체부터 우산, 핸드백, 스포츠 장비와 같은 구체적인 범주까지 80개 객체 범주로 구성됩니다.
  • 어노테이션에는 각 이미지의 객체 바운딩 박스, 분할 마스크, 캡션이 포함됩니다.
  • COCO는 객체 탐지 및 분할을 위한 평균 정밀도(mAP)와 재현율 평균(AR) 등 표준화된 평가 지표를 제공하므로 모델 성능을 비교하는 데 적합합니다.

데이터셋 구조#

COCO 데이터셋은 세 개의 하위 집합으로 나뉩니다:

  1. Train2017: 객체 탐지, 세그멘테이션 및 캡셔닝 모델을 학습하기 위한 이미지 118,287장입니다.
  2. Val2017: 모델 학습 중 검증에 사용되는 이미지 5,000장입니다.
  3. Test2017: 학습된 모델을 벤치마킹하는 데 사용되는 test-dev 이미지 20,288장입니다. 이 하위 집합의 정답 어노테이션은 공개되지 않으며, 성능 평가를 위해 결과를 COCO 평가 서버에 제출합니다.

응용 분야#

COCO 데이터셋은 객체 탐지(Ultralytics YOLO, Faster R-CNN, SSD 등), 인스턴스 세그멘테이션(Mask R-CNN 등), 키포인트 탐지(OpenPose 등) 분야의 딥러닝 모델을 학습하고 평가하는 데 널리 사용됩니다. 다양한 객체 범주, 어노테이션이 있는 방대한 이미지 수, 표준화된 평가 지표 덕분에 COCO 데이터셋은 컴퓨터 비전 연구자와 실무자에게 필수적인 리소스입니다.

레이블링 도구에서 COCO JSON 형식으로 내보낸 어노테이션도 동일한 구조를 따릅니다. 자체 COCO 형식 데이터로 학습하려면 COCO 어노테이션을 YOLO 형식으로 변환을 참조하세요.

데이터셋 YAML#

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

ultralytics/cfg/datasets/coco.yaml
# Ultralytics 🚀 AGPL-3.0 License - https://ultralytics.com/license

# COCO 2017 dataset https://cocodataset.org by Microsoft
# Documentation: https://docs.ultralytics.com/datasets/detect/coco
# Example usage: yolo train data=coco.yaml
# parent
# ├── ultralytics
# └── datasets
#     └── coco ← downloads here (20.3 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: coco # dataset root dir
train: train2017.txt # train images (relative to 'path') 118287 images
val: val2017.txt # val images (relative to 'path') 5000 images
test: test-dev2017.txt # 20288 of 40670 images, submit via https://cocodataset.org/#detection-eval

# 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: |
  from pathlib import Path

  from ultralytics.utils import ASSETS_URL
  from ultralytics.utils.downloads import download

  # Download labels
  segments = True  # segment or box labels
  dir = Path(yaml["path"])  # dataset root dir
  urls = [ASSETS_URL + ("/coco2017labels-segments.zip" if segments else "/coco2017labels.zip")]  # labels
  download(urls, dir=dir.parent)

  # Download data (test2017.zip excluded: ground truth is withheld, only used for the eval-server test-dev split)
  urls = [
      "http://images.cocodataset.org/zips/train2017.zip",  # 19G, 118k images
      "http://images.cocodataset.org/zips/val2017.zip",  # 1G, 5k images
  ]
  download(urls, dir=dir / "images", threads=3)

사용법#

COCO2017 학습 및 검증 데이터(20.3 GB)는 학습을 처음 시작할 때 자동으로 다운로드됩니다. 다음 코드 조각을 사용하면 이미지 크기 640으로 COCO에서 100 에포크 동안 YOLO26n 모델을 학습할 수 있습니다. Ultralytics Platform을 사용해 클라우드에서 COCO 학습을 실행할 수도 있습니다.

학습 예제
from ultralytics import YOLO

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

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

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

COCO 데이터셋에는 다양한 객체 범주와 복잡한 장면이 담긴 이미지가 포함되어 있습니다. 다음은 데이터셋 이미지와 해당 어노테이션의 예입니다:

객체 탐지 학습 배치의 COCO 데이터셋 모자이크

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

이 예시는 COCO 데이터셋 이미지의 다양성과 복잡성, 그리고 학습 과정에서 모자이크를 사용하는 이점을 보여줍니다.

인용 및 감사의 글#

연구 또는 개발 작업에서 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 데이터셋 웹사이트에서 확인하세요.

자주 묻는 질문#

  • COCO 데이터셋(일상 환경의 공통 객체)은 객체 탐지, 분할 및 캡셔닝에 사용되는 대규모 데이터셋입니다. 80개 객체 카테고리에 대한 상세 주석이 포함된 이미지 33만 장으로 구성되어 컴퓨터 비전 모델의 벤치마크와 학습에 필수적입니다. 연구자들은 다양한 카테고리와 평균 정밀도(mAP)와 같은 표준화된 평가 지표 때문에 COCO를 사용합니다.

  • COCO 데이터셋을 사용해 YOLO26 모델을 학습하려면 다음 코드 예제를 사용할 수 있습니다:

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

    사용 가능한 인수에 관한 자세한 내용은 학습 페이지를 참조하세요.

  • COCO 데이터셋에는 다음이 포함됩니다:

    • 객체 탐지, 세그멘테이션 및 캡셔닝용으로 어노테이션이 지정된 이미지 200K장을 포함해 총 이미지 330K장입니다.
    • 자동차와 동물 같은 일반적인 항목부터 핸드백과 스포츠 장비 같은 특정 항목까지 80개 객체 범주가 포함됩니다.
    • 객체 탐지 및 세그멘테이션을 위한 표준화된 평가 지표(mAP 및 평균 재현율)가 제공됩니다.
    • 학습 배치에 모자이크 처리 기법을 적용해 다양한 객체 크기와 맥락에서 모델의 일반화 성능을 높입니다.
  • COCO로 학습된 사전 학습 YOLO26 모델은 Ultralytics Platform에서 사용할 수 있으며 처음 사용할 때 자동으로 다운로드됩니다:

    이 모델들은 크기, mAP 및 추론 속도가 서로 달라 다양한 성능 및 리소스 요구 사항에 맞는 옵션을 제공합니다.

  • COCO 데이터셋은 세 개의 하위 집합으로 나뉩니다:

    1. Train2017: 학습용 이미지 118,287장입니다.
    2. Val2017: 학습 중 검증용 이미지 5,000장입니다.
    3. Test2017: 학습된 모델을 벤치마킹하는 test-dev 이미지 20,288장입니다. 성능 평가를 위해 결과를 COCO 평가 서버에 제출해야 합니다.

    데이터셋 YAML 구성 파일은 경로, 클래스 및 데이터셋 세부 정보를 정의하는 coco.yaml에서 확인할 수 있습니다.

댓글40

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

  1. williamrojas8928-commitsGitHub

    If I want to train a custom model on COCO classes, such as person, car, and truck, do I need to train a new model from scratch? Or can I use a pre-trained model and just ignore the predictions of the other classes, even though this might involve more computational cost?

    1
  2. aasharma90GitHub(수정됨)

    Hello,

    What is the pre-trained model yolov8n.pt trained on? Since if it's already COCO dataset, I wonder why the new training is required.

    1
    1. Glenn JocherUltralytics(수정됨)

      Hello,

      Great question! The pre-trained model yolo26n.pt is indeed trained on the COCO dataset. This means it has already learned to detect the 80 object categories included in COCO, such as people, cars, animals, and more.

      However, there are several reasons why you might want to retrain or fine-tune this model:

      1. Custom Dataset: If you have a custom dataset with different object categories or specific variations of the COCO categories, retraining the model will help it adapt to your specific data.

      2. Improved Performance: Fine-tuning the model on your dataset can improve its performance, especially if your dataset has different characteristics (e.g., different lighting conditions, object sizes, or backgrounds) compared to the original COCO dataset.

      3. Additional Classes: If you need to detect additional classes that are not included in the COCO dataset, you will need to retrain the model with your extended dataset.

      4. Domain Adaptation: If your application involves a specific domain (e.g., medical imaging, industrial inspection), retraining the model on domain-specific data can significantly enhance its accuracy and reliability.

      Here’s a quick example of how you can fine-tune the yolo26n.pt model on your custom dataset using Python:

      from ultralytics import YOLO
      
      # Load the pre-trained model
      model = YOLO("yolo26n.pt")
      
      # Train the model on your custom dataset
      results = model.train(data="path/to/your/custom_dataset.yaml", epochs=100, imgsz=640)

      And using the CLI:

      yolo detect train data=path/to/your/custom_dataset.yaml model=yolo26n.pt epochs=100 imgsz=640

      For more details on the COCO dataset and how to use it, you can refer to our COCO Dataset Documentation.

      If you have any more questions or need further assistance, feel free to ask! 😊

    2. aasharma90GitHub(수정됨)

      Hi @glenn-jocher

      Thanks for your detailed explanation and reply.

      I understand the fine-tuning requirement for a custom dataset, but my question was about the fine-tuning part mentioned for the COCO dataset itself in the Train Example segment above.

      Never mind, I think I have my answers. Thanks so much again :)

    3. Glenn JocherUltralytics

      Hi @aasharma90,

      Thank you for your follow-up! I appreciate your understanding regarding the fine-tuning process.

      To clarify, the Train Example segment for the COCO dataset is primarily included to demonstrate how to train a YOLO model from scratch or fine-tune it, even if it has already been pre-trained on COCO. This can be useful for several reasons:

      1. Hyperparameter Tuning: Fine-tuning allows you to adjust hyperparameters specific to your use case, potentially improving model performance.
      2. Extended Training: Additional training can help the model refine its weights and improve accuracy, especially if you have more computational resources or time.
      3. Custom Augmentations: You might want to apply custom data augmentations that are more suited to your specific application or environment.

      If you have any more questions or need further assistance, feel free to ask! 😊

    4. JackEdoubleSGitHub

      I have the same question. If retraining is for domain adaptation and learning new categories, the knowledge from learned model from COCO dataset will be catastrophic forgetting. This means it is the same between retraining with pretrained network and training from scratch.

    5. Glenn JocherUltralytics

      Thank you for your insights. While catastrophic forgetting is a valid concern, fine-tuning with pre-trained weights often accelerates convergence and improves performance, especially when the new dataset shares similarities with COCO. Training from scratch may be suitable for entirely different domains, but pre-trained models retain valuable feature representations that are not fully overwritten during fine-tuning. Let me know if you'd like more resources or examples to explore this further.

    6. JackEdoubleSGitHub

      So right now I need to run YOLO on real world application, but I only have coco dataset. Is it good if I train on coco and test on my application?

    7. Glenn JocherUltralytics

      Running YOLO on real-world applications after training on the COCO dataset can work well if your application involves detecting objects similar to COCO's 80 categories. However, for domain-specific or unseen objects, fine-tuning on a custom dataset is recommended to improve performance. Let me know if you'd like guidance on fine-tuning.

    8. Glenn JocherUltralytics(수정됨)

      To fine-tune the model for your application, load the pretrained model (e.g., yolo26n.pt) and train it on your dataset using the train mode. Ensure your dataset is formatted correctly (e.g., COCO format or YAML-configured). For example:

      from ultralytics import YOLO
      
      model = YOLO("yolo26n.pt")  # Load the pretrained model
      results = model.train(data="your_dataset.yaml", epochs=50, imgsz=640)

      This process adapts the pretrained weights to your specific use case. For more, refer to the Ultralytics training documentation. Let me know if you need further assistance!

  3. williamrojas8928-commitsGitHub

    If I want to train a custom model on COCO classes, such as person, car, and truck, do I need to train a new model from scratch? Or can I use a pre-trained model and just ignore the predictions of the other classes, even though this might involve more computational cost?

  4. xd775GitHub

    In your code example for how the .yaml should be set up:

    path: ../datasets/my_custom_dataset
    train: images/train
    val: images/val
    test: images/test
    
    # Classes
    names:
      0: class1
      1: class2
      ... 

    How would I specify which of my annotation .jsons to use for the train and val datasets? Also, this thread is confusing me about whether YOLO can read in COCO datasets or if converting to another format is required.

    1. Glenn JocherUltralytics(수정됨)

      @xd775 YOLO does not read COCO JSON annotations directly. The provided coco.yaml downloads COCO already converted to YOLO format (images plus .txt label files), so no JSON paths are needed in the YAML. For your own COCO-format JSON, convert it to YOLO labels first with ultralytics.data.converter.convert_coco, then point your dataset YAML at the resulting images/ and labels/ folders, as shown in the COCO dataset documentation.

  5. mod777GitHub

    Hello,

    I want to add Goat and give class ID 80 into COOC.yaml data. set Would you mind to tell me in which file (s) i have to changes and how can i add that goat into coco.yaml data set with label and annotation etc etc

    I have tried few times but totally unluck detail or step by step would be great full for me to understand. thanks

    1. Glenn JocherUltralytics

      To add a new class like "Goat" to the COCO dataset, you'll need to modify the coco.yaml file by adding the class under the names section with the desired ID. Additionally, ensure your dataset includes the corresponding labels and annotations for this new class. For detailed guidance on dataset preparation, please refer to the Ultralytics documentation.

    2. mod777GitHub

      I have added to goat and deer into coco.yaml file also have added them in annotated files both instances_train2017.json and instances_val2017.json

      {
              "supercategory": "animal",
              "id": 91,
              "name": "goat"
          },
          {
              "supercategory": "animal",
              "id": 92,
              "name": "deer"
          },

      this is a python code to check Classes in Training JSON: ID: 91, Name: goat, Supercategory: animal ID: 92, Name: deer, Supercategory: animal

      Classes in Validation JSON: ID: 91, Name: goat, Supercategory: animal ID: 92, Name: deer, Supercategory: animal

      Classes in COCO YAML: ID: 91, Name: goat ID: 92, Name: deer

      Additional Information for Goat (ID 91): Annotation for ID 91: BBox: [100, 200, 50, 50], Area: 2500 Annotation for ID 91: BBox: [30.5, 65.3, 30.0, 30.0], Area: 2000.3

      Additional Information for Deer (ID 92): Annotation for ID 92: BBox: [150, 250, 60, 60], Area: 3600 Annotation for ID 92: BBox: [45.0, 30.5, 35.5, 40.0], Area: 2500.5

      after all these i cant see goat when i test and check my model. as 91: goat

      can u please help me? if u want i give give files so u can have a llok is possible

    3. Glenn JocherUltralytics(수정됨)

      To add "Goat" to the COCO dataset, ensure you've updated both the coco.yaml file and the YOLO-format .txt label files correctly. If the class isn't appearing during testing, double-check that the model is trained with the updated dataset and verify the annotations are correctly formatted. If issues persist, consider reviewing the dataset preparation steps or consulting the Ultralytics documentation for further guidance.

    4. mod777GitHub

      Hello glenn,

      thanks for your reply.

      I have change the annotation files instances_train2017.json and instances_val2017.json to assign annotation filed for goat 80 to following fileds

      Annotation ID: Image ID: Segmentation: Area: Iscrowd: Category ID:

      also add 80: goat at coco.yaml file

      now what i should do next to recognize its goat by coco.yaml or yolov5? thanks

    5. mod777GitHub

      I have change the annotation files instances_train2017.json and instances_val2017.json to assign annotation filed for goat 80 to following fileds

      Annotation ID: Image ID: Segmentation: Area: Iscrowd: Category ID:

      this assigned is done using pythong code. is it ok

    6. mod777GitHub

      its really too hard to incorporate goat into existing coco.yaml file. i have spend long time to do but no luck. Is there any way to add goat only one object into coco.yaml. coz i have to use defauly cooc.yaml file no custom file. but its really hard. Is there a way out?

    7. mod777GitHub

      from ultralytics import YOLO

      Load a pretrained model

      model = YOLO("yolov5x.pt")

      Train the model with your custom data

      results = model.train(data="coco.yaml", epochs=100, imgsz=640)

      this code is not works for me. i m tired. please help

    8. Glenn JocherUltralytics

      I'm sorry to hear you're having trouble. Please ensure your dataset paths and annotations are correctly set up in the coco.yaml file and that your custom data is formatted correctly. If issues persist, reviewing the Ultralytics documentation or community forums may provide additional insights.

    9. mod777GitHub(수정됨)

      I have seen few google documentation as well as Ultralytics documentation but everywhere is talk about how to set or train your owned object detection. I can't find anywhere how to include my object into coco.yaml data set. can u give me link for that? thx

    10. Glenn JocherUltralytics(수정됨)

      To add a new class like "Goat" to the COCO dataset, ensure you've updated the coco.yaml file and the YOLO-format .txt label files correctly. Unfortunately, there isn't a specific guide for adding classes to COCO, but you can refer to general dataset preparation tutorials. If you encounter issues, consider checking community forums for additional support.

    11. mod777GitHub

      If you encounter issues, consider checking community forums for additional support.

      can u recommend few?

    12. Glenn JocherUltralytics

      For community support, consider exploring forums like Stack Overflow, Reddit's r/computervision, or the Ultralytics YOLO GitHub Discussions page. These platforms can provide valuable insights and assistance from other users and developers.

    1. Glenn JocherUltralytics(수정됨)

      @dordanin to train on only 5 classes from COCO, use the classes training argument with the COCO class ids you want, for example model.train(data="coco.yaml", classes=[0, 1, 2, 3, 5]), or yolo train data=coco.yaml classes=0,1,2,3,5. Editing only the names in coco.yaml would not work because the label files still use the original class ids. For more details, visit COCO Dataset Documentation.

    2. HooztGitHub

      This does not work anymore, the training script labels the images as corrupt and are ignored during training.

  6. TanWeeKangGitHub

    Hi, i used cvat to annotate my images and saved it as coco format. Then i need to convert it to yolov8 format for training. My question is what structure is the dataset format after converting to yolov8 format? From what i see, there will be images, annotations, labels, and yaml file. I dont understand what is that labels file, is it necessary to have in order to train the dataset using yolov8? Can you explain to me what is the labels file?

    1. Paula DerrengerUltralytics(수정됨)

      @TanWeeKang hi there!

      Great to hear that you're working with CVAT and YOLOv8! When converting your COCO annotations to the YOLOv8 format, the dataset structure will indeed include images, annotations, labels, and a YAML file. Here's a brief overview of each component:

      1. Images: This folder contains all the images used for training, validation, and testing.
      2. Annotations: This folder typically holds the original COCO annotations in JSON format.
      3. Labels: This is a crucial component for YOLO training. The labels folder contains text files where each file corresponds to an image and includes the bounding box coordinates and class labels in YOLO format.
      4. YAML File: This file (e.g., coco.yaml) defines the dataset configuration, including paths to the images and labels, and the class names.
      Understanding the Labels File

      The labels file is essential for training YOLO models. Each text file in the labels directory corresponds to an image and contains lines of annotations in the following format:

      class_id x_center y_center width height
      • class_id: The class index of the object.
      • x_center, y_center: The normalized center coordinates of the bounding box (values between 0 and 1).
      • width, height: The normalized width and height of the bounding box (values between 0 and 1).
      Example

      For an image image1.jpg, the corresponding label file image1.txt might look like this:

      0 0.5 0.5 0.2 0.4
      1 0.3 0.7 0.1 0.2

      This indicates two objects: one of class 0 and another of class 1, with their respective bounding box coordinates.

      Conversion Tools

      To convert COCO annotations to YOLO format, you can use various tools and scripts available online. Ultralytics includes one: from ultralytics.data.converter import convert_coco; convert_coco(labels_dir="path/to/coco/annotations/"), which writes YOLO labels for you.

      Training Example

      Once your dataset is structured correctly, you can train your YOLOv8 model using the following command:

      from ultralytics import YOLO
      
      # Load a model
      model = YOLO("yolo26n.pt")  # load a pretrained model (recommended for training)
      
      # Train the model
      results = model.train(data="coco.yaml", epochs=100, imgsz=640)

      For more detailed information, you can refer to the Ultralytics COCO Dataset Documentation.

      If you have any further questions or need additional assistance, feel free to ask. Happy training! 🚀

  7. konstantinos-pGitHub

    It is very unclear from your docs how to finetune your models. In particular, I would expect an example in the quickstart for the case of finetuning on a custom dataset. It is still unclear to me what should be the format of the labels of the finetuning dataset. I've seen some answers in the comments about the labels being "like COCO" but what does that even mean?

    1. konstantinos-pGitHub

      Ok, I've found the relevant page in the docs. I still think that it takes way to long to reach this page. Please consider adding some link in the quickstart.

    2. Paula DerrengerUltralytics(수정됨)

      @konstantinos-p thank you for your feedback! Finetuning a YOLO model on a custom dataset involves a few key steps:

      1. Dataset Preparation: Labels must be in YOLO format: one *.txt file per image, with one row per object in class x_center y_center width height format (normalized 0-1, zero-indexed classes). Images and labels go in sibling images/ and labels/ directories. If your annotations are in COCO JSON format, you can convert them with ultralytics.data.converter.convert_coco. See the dataset format guide.

      2. Dataset YAML Configuration: Create a YAML file that specifies the paths to your training, validation, and test images, as well as the class names:

        path: ../datasets/my_custom_dataset
        train: images/train
        val: images/val
        test: images/test
        
        # Classes
        names:
          0: class1
          1: class2
      3. Training the Model: Use the train command to start training your model on the custom dataset:

        from ultralytics import YOLO
        
        # Load a pretrained model
        model = YOLO("yolo26n.pt")
        
        # Train the model on your custom dataset
        results = model.train(data="path/to/your_custom_dataset.yaml", epochs=100, imgsz=640)
        yolo detect train data=path/to/your_custom_dataset.yaml model=yolo26n.pt epochs=100 imgsz=640

      For more on the COCO dataset itself, refer to our COCO Dataset Documentation. If you have any more questions, feel free to ask. 😊

  8. FRAOTIACGitHub

    Thanks for the detailed instructions. Could you please clarify the exact directory structure for the train, val, and annotations folders? Specifically, where should these be placed within the dataset root directory?

    1. Paula DerrengerUltralytics(수정됨)

      Hello!

      For training, the COCO dataset uses this layout under the dataset root (see coco.yaml):

      coco/
      ├── images/
      │   ├── train2017/        # Training images
      │   ├── val2017/          # Validation images
      │   └── test2017/         # Test images (optional)
      ├── labels/
      │   ├── train2017/        # YOLO-format .txt labels, one per image
      │   └── val2017/
      ├── train2017.txt         # List of training image paths
      ├── val2017.txt           # List of validation image paths
      └── test-dev2017.txt      # List of test image paths (optional)

      The original COCO annotations/*.json files are only needed if you convert the labels yourself with convert_coco. Training with data=coco.yaml downloads and prepares the dataset automatically. If you have any more questions, feel free to ask! 😊

    2. Paula DerrengerUltralytics(수정됨)

      Hi there!

      Great question! The coco.yaml file should be placed in a directory where your training script can easily access it. Typically, you would place it in the root directory of your project or in a dedicated configs or datasets folder within your project structure.

      Here’s an example of how your project directory might look:

      my_yolo_project/
      ├── coco.yaml
      ├── datasets/
      │   ├── coco/
      │   │   ├── annotations/
      │   │   │   ├── instances_train2017.json
      │   │   │   ├── instances_val2017.json
      │   │   │   └── ...
      │   │   ├── train2017/
      │   │   ├── val2017/
      │   │   └── test2017/
      ├── models/
      │   ├── yolo26n.pt
      │   └── ...
      ├── scripts/
      │   ├── train.py
      │   └── ...
      └── ...

      In your training script, you would reference the coco.yaml file like this:

      from ultralytics import YOLO
      
      # Load a model
      model = YOLO("yolo26n.pt")  # load a pretrained model (recommended for training)
      
      # Train the model
      results = model.train(data="coco.yaml", epochs=100, imgsz=640)

      Or via the command line:

      yolo detect train data=coco.yaml model=yolo26n.pt epochs=100 imgsz=640

      This setup ensures that the coco.yaml file is easily accessible and correctly referenced in your training scripts.

      If you have any more questions or need further assistance, feel free to ask! 😊

      1