YOLOv5 Instance Segmentation: A Fast and Accurate Approach to Object Detection

Yolov5 Instance Segmentation Overview

YOLOv5 and Instance Segmentation

YOLOv5, initially celebrated for object detection, has expanded its capabilities to instance segmentation. This advanced feature not only detects objects but also delineates their boundaries, providing pixel-wise masks for each instance. Combining speed with precision, YOLOv5 offers real-time segmentation, making detailed scene understanding more accessible and deployable even on edge devices.

YOLOv5 Instance Segmentation architecture

Introduction: YOLOv5 is described as the world's most loved vision AI, representing Ultralytics' open-source research into future vision AI methods. It incorporates best practices and lessons learned from extensive research and development.

Segmentation in YOLOv5: The YOLOv5 release v7.0 introduced instance segmentation models that are touted as the fastest and most accurate in the world, surpassing all current state-of-the-art benchmarks. These models have been designed to be straightforward to train, validate, and deploy. More details can be found in their Release Notes and a dedicated YOLOv5 Segmentation Colab Notebook for quickstart tutorials.

Segmentation Checkpoints: YOLOv5 segmentation models were trained on the COCO dataset for 300 epochs at an image size of 640 using A100 GPUs. The models were exported to ONNX for CPU speed tests and TensorRT for GPU speed tests. Speed tests were conducted on Google Colab Pro notebooks. The repository provides details on the performance of various segmentation models, including YOLOv5n-seg, YOLOv5s-seg, YOLOv5m-seg, YOLOv5l-seg, and YOLOv5x-seg.

Segmentation Usage Examples: The repository provides examples of how to train, validate, and use the segmentation models. This includes commands for training on the COCO128-seg segmentation dataset, validating the mask mAP on the COCO dataset, using pretrained models for predictions, and exporting models to ONNX and TensorRT.

For a deeper dive into the architecture and to access the latest updates, you might want to visit the official YOLOv5 repository by Ultralytics.

Yolov5 Instance Segmentation Diagram

YOLOv5 Instance Segmentation Performance Metrics on COCO

Model Size (pixels) mAP box (50-95) mAP mask Train time (300 epochs, A100) Speed ONNX CPU (ms) Speed TRT A100 Params (M) FLOPs @640 (B)
YOLOv5n-seg 640 27.6 23.4 80:17 hours 62.7 1.2 2.0 7.1
YOLOv5s-seg 640 37.6 31.7 88:16 hours 173.3 1.4 7.6 26.4
YOLOv5m-seg 640 45.0 37.1 108:36 hours 427.0 2.2 22.0 70.8
YOLOv5l-seg 640 49.0 39.9 66:43 (2x) hours 857.4 2.9 47.9 147.7
YOLOv5x-seg 640 50.7 41.4 62:56 (3x) hours 1579.2 4.5 88.8 265.7

YOLOv5 Instance Segmentation Training

For a detailed guide on training YOLOv5 instance segmentation models, refer to the official YOLOv5 GitHub repository.

YOLOv5 Instance Segmentation Guide

1. Clone the YOLOv5 repository and install the requirements:

git clone https://github.com/ultralytics/yolov5
cd yolov5
pip install -r requirements.txt

2. Segmentation Inference:

To use a pretrained YOLOv5 instance segmentation model to predict on an image:

python segment/predict.py --weights yolov5m-seg.pt --source data/images/bus.jpg

3. Training YOLOv5 for Instance Segmentation:

If you want to train YOLOv5 for instance segmentation on the COCO128-seg dataset:

python segment/train.py --data coco128-seg.yaml --weights yolov5s-seg.pt --img 640

4. Validation:

To validate the YOLOv5s-seg mask mAP on the COCO dataset:

python segment/val.py --weights yolov5s-seg.pt --data coco.yaml --img 640

5. Exporting the Model:

To export the YOLOv5s-seg model to ONNX and TensorRT:

python export.py --weights yolov5s-seg.pt --include onnx engine --img 640 --device 0