Instance Segmentation and Tracking using Ultralytics YOLO11 🚀
What is Instance Segmentation?
Instance segmentation is a computer vision task that involves identifying and outlining individual objects in an image at the pixel level. Unlike semantic segmentation which only classifies pixels by category, instance segmentation uniquely labels and precisely delineates each object instance, making it crucial for applications requiring detailed spatial understanding like medical imaging, autonomous driving, and industrial automation.
Ultralytics YOLO11 provides powerful instance segmentation capabilities that enable precise object boundary detection while maintaining the speed and efficiency YOLO models are known for.
There are two types of instance segmentation tracking available in the Ultralytics package:
-
Instance Segmentation with Class Objects: Each class object is assigned a unique color for clear visual separation.
-
Instance Segmentation with Object Tracks: Every track is represented by a distinct color, facilitating easy identification and tracking across video frames.
Watch: Instance Segmentation with Object Tracking using Ultralytics YOLO11
Samples
Instance Segmentation | Instance Segmentation + Object Tracking |
---|---|
![]() |
![]() |
Ultralytics Instance Segmentation 😍 | Ultralytics Instance Segmentation with Object Tracking 🔥 |
Instance segmentation using Ultralytics YOLO
import cv2
from ultralytics import solutions
cap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"
# Video writer
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
video_writer = cv2.VideoWriter("isegment_output.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Initialize instance segmentation object
isegment = solutions.InstanceSegmentation(
show=True, # display the output
model="yolo11n-seg.pt", # model="yolo11n-seg.pt" for object segmentation using YOLO11.
# classes=[0, 2], # segment specific classes i.e, person and car with pretrained model.
)
# Process video
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or video processing has been successfully completed.")
break
results = isegment(im0)
# print(results) # access the output
video_writer.write(results.plot_im) # write the processed frame.
cap.release()
video_writer.release()
cv2.destroyAllWindows() # destroy all opened windows
InstanceSegmentation
Arguments
Here's a table with the InstanceSegmentation
arguments:
Argument | Type | Default | Description |
---|---|---|---|
model |
str |
None |
Path to Ultralytics YOLO Model File. |
region |
list |
[(20, 400), (1260, 400)] |
List of points defining the counting region. |
You can also take advantage of track
arguments within the InstanceSegmentation
solution:
Argument | Type | Default | Description |
---|---|---|---|
tracker |
str |
'botsort.yaml' |
Specifies the tracking algorithm to use, e.g., bytetrack.yaml or botsort.yaml . |
conf |
float |
0.3 |
Sets the confidence threshold for detections; lower values allow more objects to be tracked but may include false positives. |
iou |
float |
0.5 |
Sets the Intersection over Union (IoU) threshold for filtering overlapping detections. |
classes |
list |
None |
Filters results by class index. For example, classes=[0, 2, 3] only tracks the specified classes. |
verbose |
bool |
True |
Controls the display of tracking results, providing a visual output of tracked objects. |
device |
str |
None |
Specifies the device for inference (e.g., cpu , cuda:0 or 0 ). Allows users to select between CPU, a specific GPU, or other compute devices for model execution. |
Moreover, the following visualization arguments are available:
Argument | Type | Default | Description |
---|---|---|---|
show |
bool |
False |
If True , displays the annotated images or videos in a window. Useful for immediate visual feedback during development or testing. |
line_width |
None or int |
None |
Specifies the line width of bounding boxes. If None , the line width is automatically adjusted based on the image size. Provides visual customization for clarity. |
Applications of Instance Segmentation
Instance segmentation with YOLO11 has numerous real-world applications across various industries:
Waste Management and Recycling
YOLO11 can be used in waste management facilities to identify and sort different types of materials. The model can segment plastic waste, cardboard, metal, and other recyclables with high precision, enabling automated sorting systems to process waste more efficiently. This is particularly valuable considering that only about 10% of the 7 billion tonnes of plastic waste generated globally gets recycled.
Autonomous Vehicles
In self-driving cars, instance segmentation helps identify and track pedestrians, vehicles, traffic signs, and other road elements at the pixel level. This precise understanding of the environment is crucial for navigation and safety decisions. YOLO11's real-time performance makes it ideal for these time-sensitive applications.
Medical Imaging
Instance segmentation can identify and outline tumors, organs, or cellular structures in medical scans. YOLO11's ability to precisely delineate object boundaries makes it valuable for medical diagnostics and treatment planning.
Construction Site Monitoring
At construction sites, instance segmentation can track heavy machinery, workers, and materials. This helps ensure safety by monitoring equipment positions and detecting when workers enter hazardous areas, while also optimizing workflow and resource allocation.
Note
For any inquiries, feel free to post your questions in the Ultralytics Issue Section or the discussion section mentioned below.
FAQ
How do I perform instance segmentation using Ultralytics YOLO11?
To perform instance segmentation using Ultralytics YOLO11, initialize the YOLO model with a segmentation version of YOLO11 and process video frames through it. Here's a simplified code example:
import cv2
from ultralytics import solutions
cap = cv2.VideoCapture("path/to/video.mp4")
assert cap.isOpened(), "Error reading video file"
# Video writer
w, h, fps = (int(cap.get(x)) for x in (cv2.CAP_PROP_FRAME_WIDTH, cv2.CAP_PROP_FRAME_HEIGHT, cv2.CAP_PROP_FPS))
video_writer = cv2.VideoWriter("instance-segmentation.avi", cv2.VideoWriter_fourcc(*"mp4v"), fps, (w, h))
# Init InstanceSegmentation
isegment = solutions.InstanceSegmentation(
show=True, # display the output
model="yolo11n-seg.pt", # model="yolo11n-seg.pt" for object segmentation using YOLO11.
)
# Process video
while cap.isOpened():
success, im0 = cap.read()
if not success:
print("Video frame is empty or processing is complete.")
break
results = isegment(im0)
video_writer.write(results.plot_im)
cap.release()
video_writer.release()
cv2.destroyAllWindows()
Learn more about instance segmentation in the Ultralytics YOLO11 guide.
What is the difference between instance segmentation and object tracking in Ultralytics YOLO11?
Instance segmentation identifies and outlines individual objects within an image, giving each object a unique label and mask. Object tracking extends this by assigning consistent IDs to objects across video frames, facilitating continuous tracking of the same objects over time. When combined, as in YOLO11's implementation, you get powerful capabilities for analyzing object movement and behavior in videos while maintaining precise boundary information.
Why should I use Ultralytics YOLO11 for instance segmentation and tracking over other models like Mask R-CNN or Faster R-CNN?
Ultralytics YOLO11 offers real-time performance, superior accuracy, and ease of use compared to other models like Mask R-CNN or Faster R-CNN. YOLO11 processes images in a single pass (one-stage detection), making it significantly faster while maintaining high precision. It also provides seamless integration with Ultralytics HUB, allowing users to manage models, datasets, and training pipelines efficiently. For applications requiring both speed and accuracy, YOLO11 provides an optimal balance.
Are there any datasets provided by Ultralytics suitable for training YOLO11 models for instance segmentation and tracking?
Yes, Ultralytics offers several datasets suitable for training YOLO11 models for instance segmentation, including COCO-Seg, COCO8-Seg (a smaller subset for quick testing), Package-Seg, and Crack-Seg. These datasets come with pixel-level annotations needed for instance segmentation tasks. For more specialized applications, you can also create custom datasets following the Ultralytics format. Complete dataset information and usage instructions can be found in the Ultralytics Datasets documentation.