Skip to main content

A Python package to run YOLO models using ONNX Runtime

Project description

YOLO Minimal Inference Library

License Python Version Build Status

YOLO Minimal Inference Library is a lightweight Python package designed for efficient and minimal YOLO object detection using ONNX Runtime. This library extracts the essential components for YOLO inference from the Ultralytics library, offering a streamlined alternative for those who need a simple, no-frills solution for YOLO inference.


Features

  • Lightweight: Focused on essential YOLO inference, reducing overhead.
  • Free Usage: Open to the community under the MIT license.
  • Fast Inference: Powered by ONNX Runtime for optimal performance.
  • Flexible Execution: Supports both CPU and GPU execution providers.
  • Easy Integration: Simplified API for seamless integration into projects.

Installation

Install the package via pip:

pip install yolo_minimal_inference

Quick Start

1. Download a Pretrained ONNX YOLO Model

Download YOLO models in ONNX format from:

2. Example Usage

from imageio import imread
from yolo_minimal_inference import YOLO

# Path to the ONNX model
model_path = "path/to/yolov5.onnx"

# Initialize YOLO model
yolo = YOLO(model_path, conf_thres=0.5, iou_thres=0.4,is_bgr=False)

# Load an image
image = imread("path/to/image.jpg")

# Perform inference
results = yolo(image)

# Display results
for box, conf, cls in zip(results.xyxy, results.conf, results.cls):
    print(f"Box: {box}, Confidence: {conf:.2f}, Class: {cls}")

TODOs and Progress

This package is under active development. Below is a summary of the work done and the planned next steps:

Completed

  • Basic implementation of YOLO inference pipeline:
    • Model initialization with ONNX Runtime.
    • Preprocessing input images (resizing, normalization).
    • Running inference on CPU and GPU (if available).
    • Postprocessing results (Non-Maximum Suppression, confidence filtering).
  • Integration with Pytest for unit tests.
  • Initial CI/CD setup with GitHub Actions.
  • Documentation for installation and usage.

Next Steps

  • Add support for batch inference.
  • Implement error handling for corrupted or unsupported model files.
  • Add a benchmarking utility to measure inference speed on different devices.
  • Improve compatibility with more YOLO model variations (e.g., YOLOv8).
  • Enhance postprocessing for customizable outputs (e.g., drawing bounding boxes).
  • Add visualization utilities to display detections on images/videos.
  • Expand test coverage for edge cases:
    • Corrupted images or unsupported formats.
    • Invalid model paths.
    • Custom confidence and IoU thresholds.
  • Publish an example notebook showcasing library usage.

If you have suggestions or feature requests, feel free to open an issue in the repository.


API Reference

YOLO Class

Initialization

YOLO(model_path: str, conf_thres: float = 0.5, iou_thres: float = 0.4)
  • model_path: Path to the ONNX model file.
  • conf_thres: Confidence threshold for filtering detections.
  • iou_thres: IoU threshold for Non-Maximum Suppression (NMS).

Methods

  1. detect_objects(image: np.ndarray) -> Boxes

    • Takes an input image, processes it, and returns bounding boxes, confidence scores, and class IDs.
  2. prepare_input(image: np.ndarray) -> np.ndarray

    • Prepares an input image for inference.
  3. process_output(output: list) -> Boxes

    • Post-processes the model output into human-readable results.

Supported Use Cases

  • Lightweight Inference: Minimal dependencies for object detection.
  • Real-Time Applications: Efficient enough for live video feeds.
  • Batch Processing: Analyze multiple images at once (future implementation).

Contributing

Contributions are welcome! Here's how you can get involved:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Submit a pull request with a detailed description of your changes.

Tests

To run tests, clone the repository and execute:

pytest

Ensure you have the required static files (model and test images) in the tests/static/ directory.


Continuous Integration

This package uses GitHub Actions for CI/CD:

  • Testing: Runs tests on every push or pull request.
  • Building: Verifies that the package can be built.
  • Publishing: Automatically publishes to PyPI on release.

License

This project is licensed under the MIT License.


Contact

For support or inquiries:


Acknowledgments

Special thanks to the following resources:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

yolo_minimal_inference-0.1.5.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

yolo_minimal_inference-0.1.5-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file yolo_minimal_inference-0.1.5.tar.gz.

File metadata

  • Download URL: yolo_minimal_inference-0.1.5.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.1 CPython/3.11.11 Linux/6.8.0-1017-azure

File hashes

Hashes for yolo_minimal_inference-0.1.5.tar.gz
Algorithm Hash digest
SHA256 d0fcab17eb8d1c01c815fa33624fd34aff3dfd30bda17f4e79f206f6e5d6511e
MD5 63c5aab408affe2ee94312c6c46e34df
BLAKE2b-256 cff50e7a99e96a0b8d94bba959e2e3064e96c5575bdf1a97246fcb35b5191c76

See more details on using hashes here.

File details

Details for the file yolo_minimal_inference-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for yolo_minimal_inference-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 33f019ad0eeba5157834c9e2c5a2eab941ddc6c1a10102087720f97f63f2985e
MD5 6b3fdb48fecfb43fb0ba43c69e14841b
BLAKE2b-256 ad9b3e4459cd9dbabf780f7d1a5bd41dea3bf3486021568d70c6cbddd3fb9654

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page