Instance Segmentation

Instance Segmentation1. Model Introduction2. Start2.1. Enter docker2.2. Instance segmentation: imageEffect preview2.3, Instance segmentation: videoEffect preview2.4, Instance Segmentation: Real-time DetectionEffect PreviewReferences

Use Python to demonstrate the effect of Ultralytics: Instance Segmentation in image, video, and real-time detection.

1. Model Introduction

Instance segmentation goes a step further than object detection. It involves identifying individual objects in an image and segmenting them from the rest of the image.

The output of the instance segmentation model is a set of masks or outlines that outline each object in the image, as well as the class label and confidence score of each object. Instance segmentation is very useful when you need to know not only the location of objects in the image, but also their specific shapes.

2. Start

2.1. Enter docker

Run YOLOv11's docker script

2.2. Instance segmentation: image

Use yolo11n-seg.pt to predict the pictures that come with the ultralytics project.

Enter the code folder:

Run the code:

Effect preview

Yolo recognizes the output image location: /ultralytics/ultralytics/output/

1. View using jupyter lab

Open another terminal to enter the docker container and use jupyter lab to view the image

image-20250324155841464

image-20250324155023395

Access directly through http://localhost:8080/ in the system browser:

image-20250324181439270

2. Copy the file to the host machine for viewing

Enter the following command in the host terminal

image-20241230155959082

Sample code:

2.3, Instance segmentation: video

Use yolo11n-seg.pt to predict videos under the ultralytics project (not the videos that come with ultralytics).

Enter the code folder:

Run the code:

Effect preview

Video location of yolo recognition output: /ultralytics/ultralytics/output/

The output video will be displayed in real time during the code running process. If you want to view the video later, you can refer to the above [2. Copy the file to the host machine for viewing] tutorial operation.

image-20241230161651694

Sample code:

2.4, Instance Segmentation: Real-time Detection

Use yolo11n-seg.pt to predict the USB camera screen.

Enter the code folder:

Run the code: Click the preview screen, press the q key to terminate the program!

Effect Preview

Yolo recognizes the output video location: /ultralytics/ultralytics/output/

The camera screen will be displayed in real time during the code running. If you want to view the video later, you can refer to the above [2. Copy the file to the host machine for viewing] tutorial operation.

image-20241230162518100

Sample code:

References

https://docs.ultralytics.com/tasks/segment/