This repository provides an end-to-end implementation of YOLOv8 for segmentation. Unlike most implementations available online, this version incorporates all post-processing directly inside the ONNX model, from Non-Maximum Suppression (NMS) to mask calculations, making it a true one-stop solution for real-time object detection and segmentation using ONNX.
- End-to-End ONNX Model: The ONNX model handles all post-processing, including NMS and mask calculation, within the model.
- Multiple Outputs:
- Bounding Boxes: Coordinates of the detected objects.
- Final Mask: A mask containing 1 value for every object mask detected in the image.
- Individual Masks: Separate binary masks for each object detected, which can be applied to the image for visualization.
There are no complete end-to-end implementations of YOLOv8 segmentation models available online. Most solutions require external post-processing code for tasks such as Non-Maximum Suppression (NMS) and mask generation. This repository addresses that gap by embedding all post-processing steps nto the ONNX model, making it easier to integrate the model into any pipeline.
git clone https://github.com/namas191297/yolov8-segmentation-end2end-onnxruntime.git
cd yolov8-segmentation-end2end-onnxruntime
It is recommended to create a virtual environment to manage dependencies.
# Using conda (preferred)
conda create --name yolov8-segmentation python=3.9
conda activate yolov8-segmentation
pip install -r requirements.txt
You can run the following script to download the required YOLOv8 model, convert it to ONNX format and stitch post-processing to the model via ONNX runtime extensions.
python add_postprocessing_yolov8.py \
--yolo-version 8 \
--model-size 512 \
--model yolov8n-seg.onnx \
--final-model yolov8n-seg-final.onnx \
--download-model \
--run-inference \
--input-width 512 \
--input-height 512
You can run the model using your webcam feed for real-time segmentation.
python run_webcam.py --model models/yolov8n-640x640-end2end.onnx --input-width 640 --input-height 640
You can also run it on a single image:
python run_image.py --model models/yolov8n-640x640-end2end.onnx --image assets/pexels-car.jpg --input-width 640 --input-height 640
--input-width
: The input width for the model (default is 640)--input-height
: The input height for the model (default is 640)
- Bounding Boxes: The coordinates of each detected object.
- Final Mask: A single binary mask containing a value of 1 for all masks detected.
- Individual Masks: Binary masks for each individual object detected.
The model provides the following outputs:
- Bounding Boxes: The coordinates (xmin, ymin, xmax, ymax) that enclose each detected object along with class and confidence.
- Final Mask: A single mask representing all detected objects, with one mask per object.
- Individual Masks: Separate masks for each object, making it easy to apply and visualize each object's segmentation.
This repository uses the YOLOv8 model provided by Ultralytics. Please note that YOLOv8 is licensed under the AGPL-3.0 License. If you distribute or modify this repository, ensure compliance with the terms of the AGPL-3.0 license.
For more details, you can review the license here: Ultralytics YOLOv8 License.
This repository is a modified version of Ultralytics YOLOv8 licensed under the AGPL-3.0 License. Modifications include:
- Integrated all post-processing directly into the ONNX model.
- Enhanced real-time object detection and segmentation capabilities.
- Optimized model performance for specific use cases.
Date of Modifications: October 2024
Contributions are welcome! Feel free to submit issues, fork the repository, and open pull requests.