Semantic Segmentation

Semantic segmentation examples

Semantic segmentation assigns a class label to every pixel in an image, producing a dense class map that covers the entire scene. Unlike instance segmentation, which separates individual objects, semantic segmentation groups all pixels of the same class together regardless of how many distinct objects are present.

The output of a semantic segmentation model is a single height-by-width class map where each pixel value corresponds to a predicted class ID. This makes semantic segmentation ideal for scene parsing tasks such as autonomous driving, medical imaging, and land-cover mapping.

Tip

Use task=semantic or the yolo semantic CLI task for semantic segmentation. YOLO26 semantic segmentation model files use the -sem suffix, such as yolo26n-sem.pt.

Models

YOLO26 semantic segmentation models pretrained on the Cityscapes dataset are shown below.

Models download automatically from the latest Ultralytics release on first use.

Modelsize
(pixels)
mIoUvalSpeed
RTX3090 PyTorch
(ms)
params
(M)
FLOPs
(B)
YOLO26n-sem1024 × 204878.34.4 ± 0.01.622.7
YOLO26s-sem1024 × 204880.88.4 ± 0.06.588.8
YOLO26m-sem1024 × 204882.019.9 ± 0.114.3304.5
YOLO26l-sem1024 × 204882.926.5 ± 0.117.9384.7
YOLO26x-sem1024 × 204883.648.9 ± 0.240.2861.7
  • mIoUval values are for single-model single-scale on the Cityscapes validation set.
    Reproduce with yolo semantic val data=cityscapes.yaml device=0 imgsz=2048
  • Speed metrics are averaged over Cityscapes validation images using an Amazon EC2 P4d instance.
    Reproduce with yolo semantic val data=cityscapes.yaml batch=1 device=0|cpu imgsz=2048
  • Params and FLOPs values are for the fused model after model.fuse(), which merges Conv and BatchNorm layers. Pretrained checkpoints retain the full training architecture and may show higher counts.

Train

Train YOLO26n-sem on the Cityscapes8 dataset for 100 epochs at image size 1024. For a full list of available arguments see the Configuration page.

Example
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n-sem.yaml")  # build a new model from YAML
model = YOLO("yolo26n-sem.pt")  # load a pretrained model (recommended for training)
model = YOLO("yolo26n-sem.yaml").load("yolo26n-sem.pt")  # build from YAML and transfer weights

# Train the model
results = model.train(data="cityscapes8.yaml", epochs=100, imgsz=1024)

See full train mode details in the Train page.

Dataset format

Semantic segmentation datasets use single-channel mask images, typically PNG, where each pixel value represents a class ID. Pixels with value 255 are treated as "ignore" and excluded from loss computation. The dataset YAML should specify paths to images and their corresponding mask directories. See the Semantic Segmentation Dataset Guide for format details. Supported datasets include Cityscapes and ADE20K.

Val

Validate trained YOLO26n-sem model accuracy on a semantic segmentation dataset. Pass data explicitly so validation uses the intended dataset YAML.

Example
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n-sem.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom model

# Validate the model
metrics = model.val(data="cityscapes.yaml")
metrics.miou  # mean Intersection over Union
metrics.pixel_accuracy  # overall pixel accuracy

Predict

Use a trained YOLO26n-sem model to run predictions on images.

Example
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n-sem.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom model

# Predict with the model
results = model("https://ultralytics.com/images/bus.jpg")  # predict on an image

# Access the results
for result in results:
    semantic_mask = result.semantic_mask.data  # height x width class map (torch.Tensor)

See full predict mode details in the Predict page.

Export

Export a YOLO26n-sem model to a different format like ONNX, CoreML, etc.

Example
from ultralytics import YOLO

# Load a model
model = YOLO("yolo26n-sem.pt")  # load an official model
model = YOLO("path/to/best.pt")  # load a custom model

# Export the model
model.export(format="onnx")

Available YOLO26 semantic segmentation export formats are in the table below. You can export to any format using the format argument, i.e., format='onnx' or format='engine'. You can predict or validate directly on exported models, i.e., yolo predict model=yolo26n-sem.onnx. Usage examples are shown for your model after export completes.

Formatformat ArgumentModelMetadataArguments
PyTorch-yolo26n-sem.pt-
TorchScripttorchscriptyolo26n-sem.torchscriptimgsz, half, dynamic, optimize, nms, batch, device
ONNXonnxyolo26n-sem.onnximgsz, half, dynamic, simplify, opset, nms, batch, device
OpenVINOopenvinoyolo26n-sem_openvino_model/imgsz, half, dynamic, int8, nms, batch, data, fraction, device
TensorRTengineyolo26n-sem.engineimgsz, half, dynamic, simplify, workspace, int8, nms, batch, data, fraction, device
CoreMLcoremlyolo26n-sem.mlpackageimgsz, dynamic, half, int8, nms, batch, device
TF SavedModelsaved_modelyolo26n-sem_saved_model/imgsz, keras, int8, nms, batch, data, fraction, device
TF GraphDefpbyolo26n-sem.pbimgsz, batch, device
TF Litetfliteyolo26n-sem.tfliteimgsz, half, int8, nms, batch, data, fraction, device
TF Edge TPUedgetpuyolo26n-sem_edgetpu.tfliteimgsz, int8, data, fraction, device
TF.jstfjsyolo26n-sem_web_model/imgsz, half, int8, nms, batch, data, fraction, device
PaddlePaddlepaddleyolo26n-sem_paddle_model/imgsz, batch, device
MNNmnnyolo26n-sem.mnnimgsz, batch, int8, half, device
NCNNncnnyolo26n-sem_ncnn_model/imgsz, half, batch, device
IMX500imxyolo26n-sem_imx_model/imgsz, int8, data, fraction, nms, device
RKNNrknnyolo26n-sem_rknn_model/imgsz, batch, name, device
ExecuTorchexecutorchyolo26n-sem_executorch_model/imgsz, batch, device
Axeleraaxelerayolo26n-sem_axelera_model/imgsz, batch, int8, data, fraction, device
DeepXdeepxyolo26n-sem_deepx_model/imgsz, int8, data, optimize, device

See full export details in the Export page.

FAQ

How do I train a YOLO26 semantic segmentation model on a custom dataset?

To train a YOLO26 semantic segmentation model on a custom dataset, you need to prepare PNG mask images where each pixel value represents a class ID (0, 1, 2, ...) and pixels with value 255 are ignored during training. Create a dataset YAML file pointing to your images and masks directories, then train the model:

Example
from ultralytics import YOLO

# Load a pretrained YOLO26 semantic segmentation model
model = YOLO("yolo26n-sem.pt")

# Train the model
results = model.train(data="path/to/your_dataset.yaml", epochs=100, imgsz=512)

Check the Configuration page for more available arguments.

What is the difference between instance segmentation and semantic segmentation?

Instance segmentation and semantic segmentation are both pixel-level tasks but differ in a key way:

  • Semantic segmentation assigns a class label to every pixel but does not distinguish between individual objects of the same class. For example, all cars in a scene share the same class label.
  • Instance segmentation identifies each individual object separately, producing distinct masks for each object even if they belong to the same class.

Semantic segmentation is best suited for scene understanding tasks like autonomous driving and land-cover mapping, while instance segmentation is preferred when counting or tracking individual objects matters.

Can I use instance segmentation data to train semantic segmentation?

Yes. If your dataset uses Ultralytics YOLO polygon labels (one .txt per image), omit masks_dir from the dataset YAML and the loader will convert polygons to per-image semantic masks on the fly. For multi-class datasets (N > 1) an extra background class is appended to names automatically. For single-class datasets (N == 1) training stays at 1 class — your declared class becomes 1 in the mask and uncovered pixels become 0. See the Semantic Segmentation Dataset Guide for details.

What datasets are supported for semantic segmentation?

Ultralytics YOLO26 provides built-in configurations for several semantic segmentation datasets:

  • Cityscapes: Urban street scenes with 19 classes, widely used for autonomous driving research.
  • ADE20K: A large-scale scene parsing dataset with 150 classes.

You can also use any custom dataset that provides PNG mask annotations where pixel values correspond to class IDs.

How do I validate a pretrained YOLO26 semantic segmentation model?

Validate a pretrained YOLO26 semantic segmentation model with the dataset YAML used for evaluation:

Example
from ultralytics import YOLO

# Load a pretrained model
model = YOLO("yolo26n-sem.pt")

# Validate the model
metrics = model.val(data="cityscapes.yaml")
print("Mean IoU:", metrics.miou)
print("Pixel Accuracy:", metrics.pixel_accuracy)

These steps will provide you with validation metrics like mean Intersection over Union (mIoU) and pixel accuracy, which are standard measures for assessing semantic segmentation performance.

How can I export a YOLO26 semantic segmentation model to ONNX format?

Export a YOLO26 semantic segmentation model to ONNX format with Python or CLI commands:

Example
from ultralytics import YOLO

# Load a pretrained model
model = YOLO("yolo26n-sem.pt")

# Export the model to ONNX format
model.export(format="onnx")

For more details on exporting to various formats, refer to the Export page.

Comments