|
| 1 | +--- |
| 2 | +sidebar_position: 8 |
| 3 | +--- |
| 4 | + |
| 5 | + |
| 6 | +# Hailo Toolbox Inference Tutorial |
| 7 | + |
| 8 | +This comprehensive tutorial will guide you through running inference with the Hailo Toolbox framework. The toolbox supports both Hailo (.hef) and ONNX models with various input sources and customizable processing pipelines. |
| 9 | + |
| 10 | +## Table of Contents |
| 11 | + |
| 12 | +- [Installation and Configuration](#installation-and-configuration) |
| 13 | +- [Basic Usage](#basic-usage) |
| 14 | +- [Command Line Arguments](#command-line-arguments) |
| 15 | +- [Inference Command](#inference-command) |
| 16 | +- [Input Source Types](#input-source-types) |
| 17 | +- [Callback Functions](#callback-functions) |
| 18 | +- [Practical Usage Examples](#practical-usage-examples) |
| 19 | + |
| 20 | +## Installation and Configuration |
| 21 | + |
| 22 | +### Installation |
| 23 | + |
| 24 | +Ensure you have installed the Hailo Toolbox: |
| 25 | + |
| 26 | +```bash |
| 27 | +git clone https://github.com/Seeed-Projects/hailo_toolbox |
| 28 | +pip install -e . |
| 29 | +``` |
| 30 | + |
| 31 | +### Verify Installation |
| 32 | + |
| 33 | +Check version information: |
| 34 | + |
| 35 | +```bash |
| 36 | +hailo-toolbox --version |
| 37 | +``` |
| 38 | + |
| 39 | +## Basic Usage |
| 40 | + |
| 41 | +### Command Structure |
| 42 | + |
| 43 | +Hailo Toolbox CLI uses a subcommand structure: |
| 44 | + |
| 45 | +```bash |
| 46 | +hailo-toolbox <subcommand> [arguments] |
| 47 | +``` |
| 48 | + |
| 49 | +Supported subcommands: |
| 50 | +- `infer`: Model inference |
| 51 | +- `convert`: Model conversion |
| 52 | + |
| 53 | +### Simple Inference Example |
| 54 | + |
| 55 | +Run inference on a video file: |
| 56 | + |
| 57 | +```bash |
| 58 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source sources/test.mp4 |
| 59 | +``` |
| 60 | + |
| 61 | +## Command Line Arguments |
| 62 | + |
| 63 | +### Global Arguments |
| 64 | + |
| 65 | +#### Version Information |
| 66 | +- `--version` / `-v` / `-V`: Display version information and exit |
| 67 | + ```bash |
| 68 | + hailo-toolbox --version |
| 69 | + ``` |
| 70 | + |
| 71 | +## Inference Command |
| 72 | + |
| 73 | +### Basic Syntax |
| 74 | + |
| 75 | +```bash |
| 76 | +hailo-toolbox infer <model_path> -c <callback> --source <input_source> [OPTIONS] |
| 77 | +``` |
| 78 | + |
| 79 | +### Required Arguments |
| 80 | + |
| 81 | +#### model (positional argument) |
| 82 | +- **Purpose**: Specify the path to the model file |
| 83 | +- **Type**: String |
| 84 | +- **Supported formats**: .hef and .onnx formats |
| 85 | +- **Examples**: |
| 86 | + ```bash |
| 87 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 |
| 88 | + hailo-toolbox infer models/yolov8n.onnx -c yolov8det --source video.mp4 |
| 89 | + ``` |
| 90 | + |
| 91 | +#### --callback / -c (required) |
| 92 | +- **Purpose**: Specify callback function name for custom processing and visualization |
| 93 | +- **Type**: String |
| 94 | +- **Required**: Yes |
| 95 | +- **Common values**: `yolov8det`, `yolov8seg`, `yolov8pose` |
| 96 | +- **Examples**: |
| 97 | + ```bash |
| 98 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 |
| 99 | + hailo-toolbox infer models/yolov8n_seg.hef -c yolov8seg --source video.mp4 |
| 100 | + ``` |
| 101 | + |
| 102 | +#### --source / -s (required) |
| 103 | +- **Purpose**: Specify input source (video file, image file, folder, or camera) |
| 104 | +- **Type**: String |
| 105 | +- **Required**: Yes |
| 106 | +- **Supported formats**: |
| 107 | + - Video files: `.mp4`, `.avi`, `.mov`, `.mkv`, etc. |
| 108 | + - Image files: `.jpg`, `.png`, `.bmp`, `.tiff`, etc. |
| 109 | + - Image folders: Directory containing image files |
| 110 | + - Cameras: `0`, `1` (device ID) |
| 111 | + - IP cameras: `rtsp://...` |
| 112 | +- **Examples**: |
| 113 | + ```bash |
| 114 | + # Video file |
| 115 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 |
| 116 | + |
| 117 | + # Image file |
| 118 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source image.jpg |
| 119 | + |
| 120 | + # Image folder |
| 121 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source images/ |
| 122 | + |
| 123 | + # Webcam |
| 124 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source 0 |
| 125 | + ``` |
| 126 | + |
| 127 | +### Optional Arguments |
| 128 | + |
| 129 | +#### --save / -sv |
| 130 | +- **Purpose**: Save output video (flag parameter) |
| 131 | +- **Type**: Boolean flag |
| 132 | +- **Default**: False |
| 133 | +- **Example**: |
| 134 | + ```bash |
| 135 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 --save |
| 136 | + ``` |
| 137 | + |
| 138 | +#### --save-path / -sp |
| 139 | +- **Purpose**: Specify path to save output video |
| 140 | +- **Type**: String |
| 141 | +- **Default**: Auto-generated |
| 142 | +- **Example**: |
| 143 | + ```bash |
| 144 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 --save --save-path output/result.mp4 |
| 145 | + ``` |
| 146 | + |
| 147 | +#### --show / -sh |
| 148 | +- **Purpose**: Display output video in real-time (flag parameter) |
| 149 | +- **Type**: Boolean flag |
| 150 | +- **Default**: False |
| 151 | +- **Example**: |
| 152 | + ```bash |
| 153 | + hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 --show |
| 154 | + ``` |
| 155 | + |
| 156 | +## Input Source Types |
| 157 | + |
| 158 | +### Supported Input Sources |
| 159 | + |
| 160 | +1. **Video Files** |
| 161 | + - Formats: MP4, AVI, MOV, MKV, WMV, etc. |
| 162 | + - Example: `--source video.mp4` |
| 163 | + |
| 164 | +2. **Image Files** |
| 165 | + - Formats: JPG, PNG, BMP, TIFF, WEBP, etc. |
| 166 | + - Example: `--source image.jpg` |
| 167 | + |
| 168 | +3. **Image Folders** |
| 169 | + - Format: Directory path containing image files |
| 170 | + - Example: `--source images/` |
| 171 | + - Processes all supported image files in the directory |
| 172 | + |
| 173 | +4. **USB Cameras** |
| 174 | + - Format: Device ID (integer) |
| 175 | + - Example: `--source 0` (default camera) |
| 176 | + |
| 177 | +5. **IP Cameras** |
| 178 | + - Format: RTSP stream address |
| 179 | + - Example: `--source rtsp://username:password@ip:port/stream` |
| 180 | + |
| 181 | +## Callback Functions |
| 182 | + |
| 183 | +### Built-in Callback Functions |
| 184 | + |
| 185 | +- `yolov8det`: YOLOv8 object detection |
| 186 | +- `yolov8seg`: YOLOv8 semantic segmentation |
| 187 | +- `yolov8pose`: YOLOv8 pose estimation |
| 188 | + |
| 189 | +### Callback Function Responsibilities |
| 190 | + |
| 191 | +Callback functions handle: |
| 192 | +- **Preprocessing**: Input data preparation |
| 193 | +- **Postprocessing**: Model output processing |
| 194 | +- **Visualization**: Result rendering and display |
| 195 | + |
| 196 | +## Practical Usage Examples |
| 197 | + |
| 198 | +### 1. Object Detection - Video Processing |
| 199 | + |
| 200 | +```bash |
| 201 | +# Basic detection |
| 202 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 |
| 203 | + |
| 204 | +# Detection with saved results |
| 205 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 --save --save-path output/detection_result.mp4 |
| 206 | + |
| 207 | +# Real-time display of detection results |
| 208 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source video.mp4 --show |
| 209 | +``` |
| 210 | + |
| 211 | +### 2. Object Detection - Image Processing |
| 212 | + |
| 213 | +```bash |
| 214 | +# Process single image |
| 215 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source image.jpg --save |
| 216 | + |
| 217 | +# Process image folder |
| 218 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source images/ --save |
| 219 | + |
| 220 | +# Batch process with custom output path |
| 221 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source images/ --save --save-path output/ |
| 222 | +``` |
| 223 | + |
| 224 | +### 3. Semantic Segmentation |
| 225 | + |
| 226 | +```bash |
| 227 | +# Segmentation task |
| 228 | +hailo-toolbox infer models/yolov8n_seg.hef -c yolov8seg --source video.mp4 --show |
| 229 | + |
| 230 | +# Save segmentation results |
| 231 | +hailo-toolbox infer models/yolov8n_seg.hef -c yolov8seg --source video.mp4 --save --save-path output/segmentation_result.mp4 |
| 232 | + |
| 233 | +# Process image folder for segmentation |
| 234 | +hailo-toolbox infer models/yolov8n_seg.hef -c yolov8seg --source images/ --save |
| 235 | +``` |
| 236 | + |
| 237 | +### 4. Pose Estimation |
| 238 | + |
| 239 | +```bash |
| 240 | +# Pose detection |
| 241 | +hailo-toolbox infer models/yolov8s_pose.hef -c yolov8pose --source video.mp4 --show |
| 242 | + |
| 243 | +# Save pose detection results |
| 244 | +hailo-toolbox infer models/yolov8s_pose.hef -c yolov8pose --source video.mp4 --save --save-path output/pose_result.mp4 |
| 245 | + |
| 246 | +# Process image folder for pose estimation |
| 247 | +hailo-toolbox infer models/yolov8s_pose.hef -c yolov8pose --source images/ --save |
| 248 | +``` |
| 249 | + |
| 250 | +### 5. Real-time Camera Inference |
| 251 | + |
| 252 | +```bash |
| 253 | +# Use default camera for real-time detection |
| 254 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source 0 --show |
| 255 | + |
| 256 | +# Use secondary camera |
| 257 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source 1 --show |
| 258 | +``` |
| 259 | + |
| 260 | +### 6. IP Camera Inference |
| 261 | + |
| 262 | +```bash |
| 263 | +# Process RTSP stream |
| 264 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source rtsp://192.168.1.100:554/stream --show |
| 265 | +``` |
| 266 | + |
| 267 | +### 7. ONNX Model Inference |
| 268 | + |
| 269 | +```bash |
| 270 | +# Use ONNX model |
| 271 | +hailo-toolbox infer models/yolov8n.onnx -c yolov8det --source video.mp4 --save |
| 272 | +``` |
| 273 | + |
| 274 | +### 8. Batch Processing Script |
| 275 | + |
| 276 | +Create a batch processing script for multiple files: |
| 277 | + |
| 278 | +```bash |
| 279 | +#!/bin/bash |
| 280 | +# batch_inference.sh |
| 281 | + |
| 282 | +MODEL="models/yolov8n.hef" |
| 283 | +CALLBACK="yolov8det" |
| 284 | +INPUT_DIR="input_videos" |
| 285 | +OUTPUT_DIR="output_results" |
| 286 | + |
| 287 | +mkdir -p "$OUTPUT_DIR" |
| 288 | + |
| 289 | +for video in "$INPUT_DIR"/*.mp4; do |
| 290 | + filename=$(basename "$video" .mp4) |
| 291 | + echo "Processing $filename..." |
| 292 | + |
| 293 | + hailo-toolbox infer "$MODEL" \ |
| 294 | + -c "$CALLBACK" \ |
| 295 | + --source "$video" \ |
| 296 | + --save \ |
| 297 | + --save-path "$OUTPUT_DIR/${filename}_result.mp4" |
| 298 | +done |
| 299 | + |
| 300 | +echo "Batch processing completed!" |
| 301 | +``` |
| 302 | + |
| 303 | +### 9. Folder Processing Examples |
| 304 | + |
| 305 | +```bash |
| 306 | +# Process all images in a folder |
| 307 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source dataset/images/ --save |
| 308 | + |
| 309 | +# Process folder with custom output directory |
| 310 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source dataset/test/ --save --save-path results/ |
| 311 | + |
| 312 | +# Process folder and display results |
| 313 | +hailo-toolbox infer models/yolov8n.hef -c yolov8det --source dataset/demo/ --show |
| 314 | +``` |
| 315 | + |
| 316 | +## Best Practices |
| 317 | + |
| 318 | +### 1. Model Selection |
| 319 | + |
| 320 | +- Use smaller models (yolov8n) for real-time applications |
| 321 | +- Use larger models (yolov8s, yolov8m) for higher accuracy requirements |
| 322 | +- Choose task-specific models (detection, segmentation, pose) |
| 323 | + |
| 324 | +### 2. Input Optimization |
| 325 | + |
| 326 | +- Adjust input size to match model input dimensions |
| 327 | +- Use appropriate color space (RGB/BGR) |
| 328 | +- Maintain consistent input data normalization |
| 329 | + |
| 330 | +### 3. Output Management |
| 331 | + |
| 332 | +- Regularly clean output directories |
| 333 | +- Use appropriate compression for saved videos |
| 334 | +- Consider storage limitations for long-running processes |
| 335 | + |
| 336 | +### 4. Resource Management |
| 337 | + |
| 338 | +- Monitor system resources during inference |
| 339 | +- Use appropriate batch sizes |
| 340 | +- Properly clean up resources after processing |
| 341 | + |
| 342 | +## Summary |
| 343 | + |
| 344 | +This tutorial covers the comprehensive usage of the Hailo Toolbox inference system with the latest parameter requirements. The framework provides flexible, high-performance inference capabilities for various deep learning tasks. By following these guidelines and examples, you can effectively leverage the toolbox for your specific use cases. |
| 345 | + |
| 346 | +Note that both `--callback` and `--source` parameters are now required for the inference command, ensuring proper configuration for all inference operations. |
0 commit comments