1. Overview
I executed Ultralytics Segmentation on Ubuntu 22.04 using WSL2 on Windows 11. Unlike Object Detection, Segmentation detects not only the rectangular area around the object, but also the boundaries along the shape of the object.
This time, I just ran Segmentation using the trained network and did not try training.
The program was run on a desktop computer ESPRIMO WD2/H2 with NVIDIA GeForce GTX 1650 (GPGPU). The specification of the desktop computer used is listed in the table at the end of this page.
2. Preparation
Install Ultralytics on Ubuntu 22.04 using WSL2 on Windows 11 with the procedure described on this page.
3. Execute Segmentation
3.1. When Segmentation of YOLOv8 is executed
I executed segmentations of YOLOv8 using the example CLI commands on the Segmentation page of Ultralytics.
I placed the 16 target images in the folder C:\dev\data\custom_data, which can be referenced from the Windows 11 side, and executed the following command to perform Segmentation. The folder C:\dev\data\custom_data on Windows 11 can be referenced as /mnt/c/dev/data/custom_data from Ubuntu on WSL2.
fukagai@ESPRIMOWD2H2:~$ yolo segment predict model=yolov8n-seg source= /mnt/c/dev/data/custom_data/ Ultralytics YOLOv8.2.48 🚀 Python-3.10.12 torch-2.3.0+cu121 CUDA:0 (NVIDIA GeForce GTX 1650, 4096MiB) YOLOv8n-seg summary (fused): 195 layers, 3404320 parameters, 0 gradients, 12.6 GFLOPs image 1/16 /mnt/c/dev/data/custom_data/Birds-Tobagawa-2023-02-19.JPG: 448x640 1 person, 9 birds, 46.4ms image 2/16 /mnt/c/dev/data/custom_data/GreyHeron-DSC00089-min.JPG: 448x640 1 bird, 8.7ms ... image 16/16 /mnt/c/dev/data/custom_data/TwoTurtleDoves-DSC00208-min.JPG: 448x640 2 birds, 69.2ms Speed: 2.9ms preprocess, 30.0ms inference, 8.4ms postprocess per image at shape (1, 3, 448, 640) Results saved to runs/segment/predict2 💡 Learn more at https://docs.ultralytics.com/modes/predict
Below are 16 images used as input.
The images below are the results of Segmentation obtained with the above command.
The images below show the results of Segmentation obtained by the following command. Unlike the previous command example, yolov8x-seg, which has a larger size than yolov8n-seg, is specified as the model for the trained network. The segmentation results of yolov8x-seg has fewer false positives and false negatives than the results of yolov8n-seg.
fukagai@ESPRIMOWD2H2:~$ yolo segment predict model=yolov8x-seg source= /mnt/c/dev/data/custom_data/ ...
To remove labels and rectangular areas from the output images, add show_labels=False show_boxes=False as in the example command below.
fukagai@ESPRIMOWD2H2:~$ yolo segment predict model=yolov8x-seg source= /mnt/c/dev/data/custom_data/ show_labels=False show_boxes=False ...
The image below shows the output image obtained with the above command. Only the first image is shown.
3.2. Segmentation by Segment Anything Model
Segmentation was performed by specifying the trained network described on the Segment Anything Model page in Ultralytics. Unlike the segmentation described in 3.1. above, all objects and backgrounds in the image are the targets of segmentation.
Only the first image in the example in 3.1. above is used as the input.
When mobile_sam.pt is specified as the learned network, as in the example command below, the image below is generated.
fukagai@ESPRIMOWD2H2:~$ yolo predict model=mobile_sam.pt source=/mnt/c/dev/data/custom_data/Birds-Tobagawa-2023-02-19.JPG show_labels=False show_boxes=False
When sam_b.pt, which is larger than mobile_sam.pt, is specified as the learned network, the image below is generated.
fukagai@ESPRIMOWD2H2:~$ yolo predict model=sam_b.pt source=/mnt/c/dev/data/custom_data/Birds-Tobagawa-2023-02-19.JPG show_labels=False show_boxes=False
Compared to when mobile_sam.pt was used, even the reflection of the waterfowl on the surface of the water was subject to segmentation, but one of the waterfowl that mobile_sam.pt was able to detect was not detected.
When sam_l.pt, which is larger than sam_b.pt, is specified as the learned network, the image below is generated.
fukagai@ESPRIMOWD2H2:~$ yolo predict model=sam_l.pt source=/mnt/c/dev/data/custom_data/Birds-Tobagawa-2023-02-19.JPG show_labels=False show_boxes=False
Compared to using mobile_sam.pt and sam_b.pt, more elements, including water surfaces, are subject to Segmentation.