Ultralytics YOLO27: Join the waitlist.
License YOLO
Ultralytics YOLO

Segmentation with pre-trained Ultralytics YOLOv8 models in Python

Learn how to run instance segmentation with pre-trained Ultralytics YOLOv8 models in Python, from live webcam inference to training on segmentation datasets.

Nuvola LadiNuvola Ladi2 min read

Listen to this article

Learn how to run instance segmentation with pre-trained Ultralytics YOLOv8 models in Python, from live webcam inference to training on segmentation datasets.

In this post, we’ll look at object segmentation with the Ultralytics YOLOv8 model and walk through setting up and running segmentation in Python.

Setting the stage for segmentation#

Let's start with Ultralytics YOLOv8. Installing the Ultralytics package takes a single command, after which you can use the model's segmentation capabilities.

Instance segmentation goes one step further than object detection by pinpointing individual objects within an image and separating them from the background.

Its output comprises masks or contours outlining each object, accompanied by class labels and confidence scores. This technique is valuable when precise object shapes are essential, providing not just object location but also detailed information on their form.

With a few simple commands, you can run predictions from the command line.

Live segmentation: Bringing images to life#

Segmentation isn't limited to static images. With a short Python script, you can also run it in real time on a live video feed.

By using the YOLO class together with OpenCV, you can segment webcam frames and display the results as they are processed.

In the video, the model segments everyday objects, from chairs to plants.

Nicolai Nielsen outlining the COCO segmentation pre-trained models

Fig 1. Nicolai Nielsen outlining the COCO segmentation pre-trained models.

At Ultralytics, we also provide support for COCO segmentation pre-trained models, which serve as a good starting point for many use cases. You can then fine-tune these models for your specific needs.

As a whole, we offer support for various datasets, such as carparts instance segmentation, crack segmentation, and industrial package segmentation. Training segmentation models on these datasets is made simple with a single command available in our documentation:

yolo segment train data=carparts-seg.yaml model=yolov8n-seg.pt epochs=100 imgsz=640

Stay tuned#

In upcoming videos, we'll go deeper into Ultralytics YOLOv8, covering custom training and inference on your own datasets.

We're committed to making AI and machine learning simpler to use, one segment at a time.

Watch the full video on YouTube.

Written by

Nuvola Ladi
Nuvola Ladi

Digital Content Manager · Ultralytics

Nuvola Ladi is a Digital Content Manager at Ultralytics, where she creates content covering vision AI and Ultralytics YOLO and represents the company at industry events such as the PyTorch Conference 2025. Based in Spain, she holds a Master's degree in Visual and Digital Media from IE University. Before joining Ultralytics, she held roles at organizations including XVA Gallery & Hotel and Rolex.

Comments

Ask a question, share your results, or help someone else.

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