Skip to content

Integrate with Ultralytics YOLOv8

Ultralytics YOLOv8 is a cutting-edge, state-of-the-art (SOTA) model that builds upon the success of previous YOLO versions and introduces new features and improvements to further boost performance and flexibility. YOLOv8 is designed to be fast, accurate, and easy to use, making it an excellent choice for a wide range of object detection and tracking, instance segmentation, image classification and pose estimation tasks.

Connect Comet to your YOLOv8 runs to automatically log parameters, metrics, image predictions, and models.

Open In Colab

Start Logging

Install Dependencies

pip install ultralytics comet_ml torch torchvision

Set Comet Credentials

After you have installed Comet, grab your Comet API key and configure your credentials.

export COMET_API_KEY=<Your API Key>

Run the Example

If you can't wait, check out the results of this example YOLOv8 project for a preview of what's to come.

from ultralytics import YOLO

# Load a model
model = YOLO("yolov8n.pt")  # load a pretrained model (recommended for training)

# train the model
results = model.train(
    data="coco128.yaml",
    project="comet-example-yolov8-coco128",
    batch=32,
    save_period=1,
    save_json=True,
    epochs=3
)

Log automatically

Comet automatically logs the following data, with no additional configuration

  • Metrics (such as mAP and loss)
  • Hyperparameters
  • Model Checkpoints
  • Interactive Confusion Matrix
  • Image Bounding Box Predictions

Configure Comet for YOLOv8

You can further configure Comet's logging behaviour with YOLOv8 through Comet specific environment variables.

Changing the number of logged Image Predictions

By default Comet will log 100 image predictions from the validation set. You can change this by setting the COMET_MAX_IMAGE_PREDICTIONS environment variable

import os
from ultralytics import YOLO

os.environ["COMET_MAX_IMAGE_PREDICTIONS"] = "200"

# Load a model
model = YOLO("yolov8s.pt")

# train the model
results = model.train(
    data="coco128.yaml",
    project="comet-example-yolov8-coco128",
    batch=32,
    save_period=1,
    save_json=True,
    epochs=1,
)

Changing the frequency of Image Prediction logging

You may want to change how often batches of image predictions are logged to Comet.

Set the COMET_EVAL_BATCH_LOGGING_INTERVAL environment variable to control this frequency. By default it is set to 1, which corresponds to logging predictions from every validation batch. e.g. Setting it to 4 will log every fourth batch

Note: YOLOv8 will use a batch size that is double your training batch size when running evaluation.

import os
from ultralytics import YOLO

os.environ['COMET_EVAL_BATCH_LOGGING_INTERVAL'] = "4"

# Load a model
model = YOLO("yolov8s.pt")  # load a pretrained model (recommended for training)

# train the model
results = model.train(
    data="coco128.yaml",
    project="comet-example-yolov8-coco128",
    batch=16,
    save_period=1,
    save_json=True,
    epochs=2,
)

Disabling logging the Confusion Matrix after every Epoch

In case you do not want to log the confusion matrix from your validation set after every epoch, disable it by setting COMET_EVAL_LOG_CONFUSION_MATRIX to false

The Confusion Matrix will only be logged once, after training is completed.

import os
from ultralytics import YOLO

os.environ["COMET_EVAL_LOG_CONFUSION_MATRIX"] = "false"

# Load a model
model = YOLO("yolov8s.pt")

# train the model
results = model.train(
    data="coco128.yaml",
    project="comet-example-yolov8-coco128",
    batch=32,
    save_period=1,
    save_json=True,
    epochs=2,
)

Logging to an Offline Experiment

In case you are in a situation where you are using a machine without public internet access you can still enable Comet logging by using an OfflineExperiment.

Your run will be saved locally in a directory that you can upload to Comet.

Set COMET_MODE to offline to enable this.

import os
from ultralytics import YOLO

os.environ["COMET_MODE"] = "offline"

# Load a model
model = YOLO("yolov8s.pt")

# train the model
results = model.train(
    data="coco128.yaml",
    project="comet-example-yolov8-coco128",
    batch=32,
    save_period=1,
    save_json=True,
    epochs=1,
)

Try it out!

Here's an example for using Comet with YOLOv8.

Open In Colab

Apr. 23, 2024