Are you sure you want to delete this access key?
This repository provides an example implementation for running Ultralytics YOLOv8 models using the ONNX Runtime. This allows for efficient inference across various hardware platforms supporting the ONNX format.
To get started, you'll need Python installed. Then, install the necessary dependencies.
Clone the repository and install the packages listed in the requirements.txt
file using pip:
git clone https://github.com/ultralytics/ultralytics.git
cd ultralytics/examples/YOLOv8-ONNXRuntime
pip install -r requirements.txt
You need to choose the appropriate ONNX Runtime package based on your hardware.
GPU Acceleration (NVIDIA)
If you have an NVIDIA GPU and want to leverage CUDA for faster inference, install the onnxruntime-gpu
package. Ensure you have the correct NVIDIA drivers and CUDA toolkit installed. Refer to the official ONNX Runtime GPU documentation for compatibility details.
pip install onnxruntime-gpu
CPU Only
If you don't have a compatible NVIDIA GPU or prefer CPU-based inference, install the standard onnxruntime
package. Check the ONNX Runtime installation guide for more options.
pip install onnxruntime
Once the dependencies and the appropriate ONNX Runtime backend are installed, you can perform inference using the provided Python script.
Before running inference, you need a YOLOv8 model in the ONNX format (.onnx
). You can export your trained Ultralytics YOLOv8 models using the Ultralytics CLI or Python SDK. See the Ultralytics export documentation for detailed instructions.
Example export command:
yolo export model=yolov8n.pt format=onnx # Export yolov8n model to ONNX
Execute the main.py
script with the path to your ONNX model and input image. You can also adjust the confidence and Intersection over Union (IoU) thresholds for object detection.
python main.py --model yolov8n.onnx --img image.jpg --conf-thres 0.5 --iou-thres 0.5
--model
: Path to the YOLOv8 ONNX model file (e.g., yolov8n.onnx
).--img
: Path to the input image (e.g., image.jpg
).--conf-thres
: Confidence threshold for filtering detections. Only detections with a score higher than this value will be kept. Learn more about thresholds in the performance metrics guide.--iou-thres
: IoU threshold for Non-Maximum Suppression (NMS). Boxes with IoU greater than this threshold will be suppressed. See the NMS glossary entry for details.The script will process the image, perform object detection, draw bounding boxes on the detected objects, and save the output image as output.jpg
.
Contributions to enhance this example or add new features are welcome! Please refer to the main Ultralytics repository for contribution guidelines. If you encounter issues or have suggestions, feel free to open an issue on the ONNX Runtime GitHub or the Ultralytics repository.
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?