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

Project setup¶

[ ]:
PROJECT_NAME = "3LC Tutorials - Cell Segmentation"
DATASET_NAME = "Sartorius Cell Segmentation"
RUN_NAME = "Train YOLO Instance Segmentation Model"
RUN_DESCRIPTION = "Train a yolo11n-seg model for segmenting cells"

# Modify YOLO training parameters when training on your own data
MODEL_NAME = "yolo11n-seg.pt"
EPOCHS = 10
BATCH_SIZE = 4
NUM_WORKERS = 8  # Multiple workers in notebook environment is not supported on Windows
INSTALL_DEPENDENCIES = True

Install dependencies¶

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

Imports¶

[ ]:
import tlc
from tlc_ultralytics import YOLO, Settings
[ ]:
train_table = tlc.Table.from_names(table_name="train", dataset_name=DATASET_NAME, project_name=PROJECT_NAME)
val_table = tlc.Table.from_names(table_name="val", dataset_name=DATASET_NAME, project_name=PROJECT_NAME)
[ ]:
model = YOLO(MODEL_NAME)

settings = Settings(
    project_name=PROJECT_NAME,
    run_name=RUN_NAME,
    run_description=RUN_DESCRIPTION,
    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,
)
[ ]:
print(f"Run created at {results.run_url}")