View source Download .ipynb

Train a YOLO segmentation model with 3LC metrics collection¶

This notebook shows how to train a YOLO segmentation model with 3LC metrics collection on a YOLO-compatible 3LC Table.

image1

Install dependencies¶

[ ]:
%pip install "3lc[pacmap]"
%pip install 3lc-ultralytics

Imports¶

[ ]:
import tlc
from tlc_ultralytics import YOLO, Settings

Project setup¶

[ ]:
PROJECT_NAME = "3LC Tutorials - Cell Segmentation"
DATASET_NAME = "Sartorius Cell Segmentation"

# Modify YOLO training parameters when training on your own data
MODEL_NAME = "yolo11n-seg.pt"
EPOCHS = 10
BATCH_SIZE = 4
DOWNLOAD_PATH = "../../transient_data"
NUM_WORKERS = 8  # Multiple workers in notebook environment is not supported on Windows
[ ]:
train_table = tlc.Table.from_names("train", DATASET_NAME, PROJECT_NAME)
val_table = tlc.Table.from_names("val", DATASET_NAME, PROJECT_NAME)
[ ]:
model = YOLO(MODEL_NAME)

settings = Settings(
    project_name=PROJECT_NAME,
    run_name="Train YOLO Instance Segmentation Model",
    conf_thres=0.2,
    sampling_weights=True,
    exclude_zero_weight_training=True,
    exclude_zero_weight_collection=False,
    image_embeddings_dim=2,
)

results = model.train(
    task="segment",
    tables={
        "train": train_table,
        "val": val_table,
    },
    settings=settings,
    batch=BATCH_SIZE,
    epochs=EPOCHS,
    workers=NUM_WORKERS,
    project=DOWNLOAD_PATH,
)
[ ]:
print(f"Run created at {results.run_url}")