# YOLOv5_Python **Repository Path**: xdltek/YOLOv5_Python ## Basic Information - **Project Name**: YOLOv5_Python - **Description**: Python sample for running YOLOv5 object detection from an ONNX model through the RPP Python runtime. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-07-10 - **Last Updated**: 2026-07-10 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # YOLOv5 Python Demo Python sample for running YOLOv5 object detection from an ONNX model through the RPP Python runtime. The demo loads one image, executes inference with `pyrt`, applies YOLOv5-style post-processing, and saves the rendered detection result to `output.jpg`. **Table of Contents** - [Quick Start](#quick-start) - [Repository Layout](#repository-layout) - [Runtime Environment](#runtime-environment) - [How to Run](#how-to-run) - [Program Arguments](#program-arguments) - [Expected Output](#expected-output) - [Key Source Files](#key-source-files) - [Execution Workflow](#execution-workflow) - [Reusable Reference Points](#reusable-reference-points) - [Adapting the Demo](#adapting-the-demo) - [Notes and Limitations](#notes-and-limitations) ## Quick Start The repository already includes: - a sample input image at `image/test_1.png` - embedded COCO class names inside `yolov5.py` Create and activate the recommended virtual environment: ```bash conda create -n xdl_env python=3.11 -y conda activate xdl_env pip install -r requirements.txt ``` If `conda` is not available on the system, install Anaconda or Miniconda first from the official download page: https://www.anaconda.com/download Note: You can use this repository (https://github.com/xdltek/onnx_model_tool) to quickly export YOLOv5s ONNX models. The example commands below assume the generated or prepared model file is available at `onnx/yolov5s.onnx`. Run the OpenRT path from the repository root: ```bash python yolov5.py --onnx onnx/yolov5s.onnx ``` ## Repository Layout ```text YOLOV5_PYTHON/ |-- image/ | `-- test_1.png |-- requirements.txt |-- yolov5.py `-- README.md ``` ## Runtime Environment This sample expects a Conda environment named `xdl_env` with Python 3.11 and the open Python dependencies installed from `requirements.txt`. Recommended setup: ```bash conda create -n xdl_env python=3.11 -y conda activate xdl_env pip install -r requirements.txt ``` If `conda` is not installed yet, download Anaconda or Miniconda from the official site before creating the environment: https://www.anaconda.com/download `pyrt` is not documented here as a public PyPI dependency. The script imports it from `/usr/local/rpp/lib`, so it is expected to come from an SDK or runtime installation that provides the RPP Python bindings. If the RPP Python bindings are installed in a different location, update the runtime environment or the script import path accordingly. `requirements.txt` is the source of truth for the open Python package versions used by this sample. Install dependencies through that file rather than by listing packages directly in the README. ## How to Run The ONNX model path is required. The image path is optional and defaults to `image/test_1.png`. The command examples below assume the ONNX model file has already been placed under `onnx/`. Default image with OpenRT: ```bash python yolov5.py --onnx onnx/yolov5s.onnx ``` Custom image: ```bash python yolov5.py --onnx onnx/yolov5s.onnx --image /path/to/input.jpg ``` Verbose runtime logging: ```bash python yolov5.py --onnx onnx/yolov5s.onnx --verbose ``` ## Program Arguments | Argument | Required | Description | |---|---|---| | `-o`, `--onnx` | Yes | Path to the ONNX detection model. | | `-i`, `--image` | No | Path to the input image. Default: `image/test_1.png`. | | `-v`, `--verbose` | No | Enable verbose logging in the RPP runtime. | ## Expected Output The script prints: - the ONNX model path in use - the input image path - the detected class names and bounding box coordinates - a frames-per-second estimate for the OpenRT path - the output image save path when detections are rendered Example output: ```text python yolov5.py -o=onnx/yolov5s.onnx onnx model path: onnx/yolov5s.onnx image path: image/test_1.png Frames per second: 172 Object detection result: - Class name: person, left: 72, top: 256, width: 96, height: 243 - Class name: person, left: 156, top: 282, width: 76, height: 238 - Class name: person, left: 230, top: 261, width: 70, height: 187 - Class name: person, left: 548, top: 267, width: 73, height: 219 - Class name: person, left: 755, top: 249, width: 109, height: 288 - Class name: person, left: 612, top: 252, width: 108, height: 276 - Class name: person, left: 346, top: 264, width: 111, height: 124 - Class name: person, left: 0, top: 288, width: 67, height: 187 - Class name: person, left: 469, top: 270, width: 63, height: 150 - Class name: person, left: 912, top: 260, width: 46, height: 259 - Class name: handbag, left: 475, top: 310, width: 44, height: 59 - Class name: person, left: 835, top: 248, width: 93, height: 271 - Class name: person, left: 314, top: 363, width: 223, height: 174 saved output image to: output.jpg ``` ## Key Source Files - `yolov5.py`: Demo entry point, preprocessing, inference execution, post-processing, and output rendering. - `image/test_1.png`: Bundled input image for a quick validation run. - `requirements.txt`: Open Python dependency list for the demo environment. ## Execution Workflow ```text +----------------------+ | __main__ | | parse argv | +----------------------+ | v +----------------------+ | main() | | validate inputs | +----------------------+ | v +----------------------+ | detect() | | preprocess image | +----------------------+ | v +----------------------+ | detect_with_rpp() | | execute inference | +----------------------+ | v +----------------------+ | post-process | | decode + NMS | +----------------------+ | v +----------------------+ | draw and save | | output.jpg | +----------------------+ ``` ## Reusable Reference Points The following parts are directly reusable in other detection samples: - image preprocessing flow in `format_yolov5()` and `blob_to_openrt_input()` - ONNX parsing and engine creation in `detect_with_rpp()` - YOLOv5-style confidence filtering and NMS logic in `detect()` - embedded COCO class-name mapping through `COCO80_CLASS_LABELS` ## Adapting the Demo To adapt this sample to another ONNX detection model: - replace the `--onnx` argument with the target model path - update the preprocessing flow if the model expects a different input size or normalization rule - replace `COCO80_CLASS_LABELS` if the output classes do not follow COCO ordering - update the post-processing logic if the output tensor layout differs from the current YOLOv5-style format - adjust the confidence and NMS thresholds if different filtering behavior is required - update command examples in this README if the default assets or argument behavior change ## Notes and Limitations - The script assumes a YOLOv5-style output layout. - The candidate loop size is fixed at `25200`. - The OpenRT path imports `pyrt` from `/usr/local/rpp/lib`. - The OpenRT path depends on `pyrt`, which is separate from the packages listed in `requirements.txt`. - The post-processing thresholds are hard-coded in the script. - `output.jpg` is a generated runtime artifact and is not tracked as a source file.