Skip to content

Commit 32f3555

Browse files
committed
update
1 parent fdf1218 commit 32f3555

1 file changed

Lines changed: 341 additions & 0 deletions

File tree

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

0 commit comments

Comments
 (0)