Are you sure you want to delete this access key?
This repository provides a Python demo for performing instance segmentation with Ultralytics YOLOv8 using ONNX Runtime. It highlights the interoperability of YOLOv8 models, allowing inference without requiring the full PyTorch stack. This approach is ideal for deployment scenarios where minimal dependencies are preferred. Learn more about the segmentation task on our documentation.
Install the required packages using pip. You will need ultralytics
for exporting the YOLOv8-seg ONNX model and using some utility functions, onnxruntime-gpu
for GPU-accelerated inference, and opencv-python
for image processing.
pip install ultralytics
pip install onnxruntime-gpu # For GPU support
# pip install onnxruntime # For CPU-only support
pip install numpy opencv-python
First, export your Ultralytics YOLOv8 segmentation model to the ONNX format using the ultralytics
package. This step converts the PyTorch model into a standardized format suitable for ONNX Runtime. Check our Export documentation for more details on export options and our ONNX integration guide.
yolo export model=yolov8s-seg.pt imgsz=640 format=onnx opset=12 simplify
Perform inference with the exported ONNX model on your images or video sources. Specify the path to your ONNX model and the image source using the command-line arguments.
python main.py --model yolov8s-seg.onnx --source path/to/image.jpg
After running the command, the script will process the image, perform segmentation, and display the results with bounding boxes and masks overlaid.
For more advanced usage scenarios, such as processing video streams or adjusting inference parameters, please refer to the command-line arguments available in the main.py
script. You can explore options like confidence thresholds and input image sizes.
We welcome contributions to improve this demo! If you encounter bugs, have feature requests, or want to submit enhancements (like a new algorithm or improved processing steps), please open an issue or pull request on the main Ultralytics repository. See our Contributing Guide for more details on how to get involved.
This project is licensed under the AGPL-3.0 License. For detailed information, please see the LICENSE file or read the full AGPL-3.0 license text.
We hope you find this demo useful! Feel free to contribute and help make it even better.
Press p or to see the previous file or, n or to see the next file
Browsing data directories saved to S3 is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with AWS S3!
Are you sure you want to delete this access key?
Browsing data directories saved to Google Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with Google Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to Azure Cloud Storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with Azure Cloud Storage!
Are you sure you want to delete this access key?
Browsing data directories saved to S3 compatible storage is possible with DAGsHub. Let's configure your repository to easily display your data in the context of any commit!
ultralytics is now integrated with your S3 compatible storage!
Are you sure you want to delete this access key?