Ultralytics YOLO27: Join the waitlist.
License YOLO
Back to Ultralytics Glossary

Semantic Segmentation

Semantic segmentation assigns a class to every pixel and returns one dense class map. How models work, how it differs from instance segmentation, and code.

Semantic segmentation is a computer vision task that assigns a class label to every pixel in an image. The output is a dense class map with the same height and width as the input, where each value is a class ID such as road, sidewalk, building, sky, or person. Where image classification gives one label per image and object detection draws a box per object, semantic segmentation describes the whole scene region by region, including amorphous background areas like grass and sky that have no countable instances.

How Semantic Segmentation Works#

A semantic segmentation model is a per-pixel classifier. A convolutional neural network (CNN) or vision transformer outputs one score map per class, usually at reduced resolution; the maps are upsampled to the image size and each pixel takes the class with the highest score. Training compares every pixel's prediction with a labeled mask using cross-entropy, and pixels marked with an ignore value, often 255, are left out of the loss.

The core difficulty is that recognizing what a region is requires a large receptive field and heavy downsampling, while drawing accurate boundaries requires fine spatial detail. Fully convolutional networks (FCN) first turned classification networks into dense predictors in 2014. Encoder-decoder designs such as U-Net then recovered boundaries by passing high-resolution encoder features to the decoder through skip connections, and DeepLab used dilated (atrous) convolutions to widen context without shrinking the feature map. Real-time models fuse coarse context with fine detail like this:

Ultralytics YOLO26 semantic segmentation models, marked by the -sem suffix, follow this pattern: they classify pixels from 1/8-scale neck features that already carry fused context, then upsample the logits 8× to the input size. They come pretrained on the 19 Cityscapes classes or the 150 ADE20K classes and train on mask images or on YOLO polygon labels converted to masks on the fly.

from ultralytics import YOLO

# Load a YOLO26 semantic segmentation model trained on the 19 Cityscapes classes
model = YOLO("yolo26n-sem.pt")

# Predict one class ID for every pixel of a street image
results = model("https://ultralytics.com/images/bus.jpg")
class_map = results[0].semantic_mask.data

# Measure how much of the image each class covers
ids, counts = class_map.unique(return_counts=True)
for class_id, count in zip(ids.tolist(), counts.tolist()):
    print(f"{results[0].names[class_id]}: {count / class_map.numel():.1%}")

The printout lists each class present and its share of the image. All the people in the photo fall into a single person share, because the class map stores a class per pixel and nothing about which object a pixel belongs to.

Semantic vs. Instance and Panoptic Segmentation#

Semantic segmentation is one of three image segmentation tasks:

  • Instance segmentation: Gives each countable object its own mask and ID, so three cars become car 1, car 2, and car 3, and leaves background pixels unlabeled.
  • Panoptic segmentation: Labels every pixel with a class, as semantic segmentation does, and adds an instance ID to pixels of countable objects.

Semantic segmentation suits scenes where regions matter more than object counts, such as drivable road area or land cover.

For help choosing between semantic and instance segmentation, see the semantic vs. instance segmentation guide, and the Ultralytics Academy lesson Semantic Segmentation: Label Every Pixel walks through labeling data and training a model for the task.

Real-World Applications#

  • Autonomous vehicles: Driving stacks segment camera frames into road, sidewalk, lane markings, vehicles, and pedestrians to find drivable space and obstacles.
  • Medical imaging: Models outline organs, tumors, and lesions in CT and MRI scans so clinicians can measure volumes and plan treatment; U-Net was originally designed for biomedical images.
  • Satellite image analysis: Land-cover maps label every pixel as water, forest, cropland, or built-up area to track deforestation and urban growth.
  • Agriculture: Field robots and drones classify pixels as crop, weed, or soil so sprayers treat only the weeds.

Benchmarks and Metrics#

Models are evaluated with mean Intersection over Union (IoU), or mIoU: the overlap between predicted and true pixels is computed for each class and then averaged, so rare classes such as poles and traffic signs weigh as much as road and sky. ADE20K covers 150 indoor and outdoor classes for general scene parsing, and Cityscapes, the best-known driving benchmark, contains 5,000 street images from 50 cities with fine pixel-level labels, ranked by mIoU over 19 evaluation classes.

Explore solutions

Computer vision in sports

Computer vision in sports

Discover how Ultralytics YOLO powers sports vision with player and ball tracking, performance analytics, coaching insights, and athlete rehabilitation.
Learn more
Computer vision for aerial imagery

Computer vision for aerial imagery

Turn drone and aerial imagery into real-time insights for agriculture, aquaculture, conservation, and geospatial analysis with Ultralytics YOLO.
Learn more
Computer vision in aerospace

Computer vision in aerospace

Apply computer vision in aerospace with Ultralytics YOLO for aircraft inspection, runway FOD detection, airport ground operations, and composite defect detection.
Learn more
Computer vision in security

Computer vision in security

Protect every site with Ultralytics YOLO models. Vision AI powers perimeter monitoring, threat detection, license-plate recognition, and workplace safety.
Learn more
Computer vision in robotics

Computer vision in robotics

Power smarter machines with Ultralytics YOLO models. Vision AI in robotics drives autonomous navigation, perception, object tracking, and real-time control.
Learn more
Computer vision in logistics

Computer vision in logistics

Streamline logistics with Ultralytics YOLO models. Vision AI enables package inspection, sorting, vehicle tracking, and real-time warehouse safety monitoring.
Learn more
Computer vision in retail

Computer vision in retail

Reimagine retail with Ultralytics YOLO models. Vision AI powers inventory tracking, shelf monitoring, queue management, and smarter customer insights.
Learn more
Computer vision in healthcare

Computer vision in healthcare

Build healthcare solutions with Ultralytics YOLO models. Vision AI in healthcare powers faster medical imaging, smarter diagnostics, and patient monitoring.
Learn more
Computer vision in manufacturing

Computer vision in manufacturing

Optimize manufacturing with Ultralytics YOLO models. Vision AI drives quality control, defect detection, PPE compliance, and assembly line automation.
Learn more
Computer vision in automotive

Computer vision in automotive

Apply computer vision in automotive with Ultralytics YOLO models. Vision AI elevates road safety, driver assistance, and vehicle automation for smarter roads.
Learn more
Computer vision in agriculture

Computer vision in agriculture

Bring vision AI to smart agriculture with Ultralytics YOLO models. Power crop monitoring, livestock tracking, and precision farming for higher, smarter yields.
Learn more

Let's build the future of AI together!

Begin your journey with the future of machine learning