Hailo Application Code Examples

repository·main·Indexed 42 days ago

https://github.com/hailo-ai/hailo-application-code-examples

A collection of application examples for running inference on Hailo-8, Hailo-8L, Hailo-10, and Hailo-15 devices using C++, Python, and VPU architectures. Includes runtime examples for object detection, segmentation, and pose estimation, as well as compilation tools like the Hailo Optimization diagnostic tool (tested on Dataflow Compiler v3.25.0) and PointPillars offloading. Note: This repository is deprecated and replaced by Hailo-Apps.

Tokens
27.4K
Snippets
85
Records
120
Agent score
52%

What's inside Hailo Application Code Examples

  1. Explore Python application examples

    main

    The runtime/python directory contains several pre-built application examples for running AI models on Hailo hardware using Python. These examples cover various computer vision and audio tasks.

    ### Available Python Applications
    
    | APP | Description |
    |:---|:---|
    | `object_detection` | Object detection and tracking with YOLO, SSD, and CenterNet |
    | `instance_segmentation` | Instance segmentation with yolov5_seg and yolov8_seg |
    | `lane_detection` | Lane detection using UFLDv2 |
    | `pose_estimation` | Pose estimation with yolov8 |
    | `speech_recognition` | Automatic speech recognition with the Whisper model |
    | `super_resolution` | Super-resolution with espcnx4 and SRGAN |
    | `oriented_object_detection` | Oriented object detection using YOLO11 OBB |
  2. Explore C++ AI application examples

    main

    The runtime/cpp directory contains a collection of C++ implementation examples for various computer vision and machine learning tasks optimized for Hailo hardware. These examples demonstrate how to implement specific AI workloads including classification, segmentation, detection, and pose estimation.

    | APP | Description |
    |:---|:---|
    | `classification` | Image classification with models trained on ImageNet |
    | `depth_estimation` | Depth estimation using scdepthv3 and stereonet |
    | `instance_segmentation` | Instance segmentation with yolov5_seg and yolov8_seg |
    | `object_detection` | Generic and asynchronous object detection |
    | `onnxruntime` | Inference with Hailo device and postprocessing via ONNXRuntime |
    | `pose_estimation` | Pose estimation with yolov8 |
    | `semantic_segmentation` | Semantic segmentation with Resnet18_fcn (Cityscapes dataset) |
    | `zero_shot_classification` | Zero-shot classification with clip_vit_l14 |
    | `oriented_object_detection` | Oriented object detection using YOLO11 OBB |
  3. Configure camera input and resolution

    main

    When using camera as the input source (-i camera), you can configure the following:

    • Camera Index: Set via the CAMERA_INDEX environment variable (defaults to 0).
    • Input Resolution (--camera-resolution): Choose from sd (640x480), hd (1280x720), or fhd (1920x1080).
    • Framerate (-f, --framerate): Override the camera input framerate.
    • Output Resolution (--output-resolution): Set the output size using sd|hd|fhd or custom dimensions (e.g., --output-resolution 1920 1080).
    CAMERA_INDEX=1 ./super_resolution.py -n model.hef -i camera
    
    ./super_resolution.py -n ./real_esrgan_x2.hef -i camera -f 20
  4. How to run multiple models on the same device

    main

    To run multiple models on the same virtual device (vdevice) efficiently, use the AsyncModelInfer constructor with a shared group_id. Assigning the same group_id to models from different HEF files allows the runtime to treat them as part of the same group, enabling resource sharing and improved efficiency.

    Implementation Pattern:

    std::string group_id = "<group_id>";
    AsyncModelInfer model1("<hef1_path>", group_id);
    AsyncModelInfer model2("<hef2_path>", group_id);
    std::string group_id = "my_shared_group";
    AsyncModelInfer model1("model1.hef", group_id);
    AsyncModelInfer model2("model2.hef", group_id);
  5. Understand PointPillars Hailo-Assisted Offloading

    main

    This proof-of-concept demonstrates how a Hailo device (such as H8, H15, etc.) can offload the computationally intensive 2D-convolutional components of a 3D object detection network operating on point clouds.

    In the PointPillars (PP) architecture, the 2D backbone and detection head are mapped to the Hailo device. This represents the majority of the required TOPS, as the 3D components are relatively minimal. While 3D parts can also be mapped to Hailo, doing so requires significant task-specific effort to maintain efficiency.

    In this implementation:

    • Hailo: Handles the 2D backbone and detection head.
    • PyTorch/CPU: Handles pre- and post-computation using native OpenPCDet code.
    • CUDA: Required for the 3D-NMS (Non-Maximum Suppression) operation.
  6. How the ONNXRT Hailo Pipeline works

    main

    This pipeline is designed for models where post-processing (like decoding detections or generating masks) is not supported by HailoRT. It requires HEFs without HailoRT-Postprocess.

    Pipeline Workflow

    1. Hailo inference: Produces raw tensor outputs from the HEF.
    2. ONNX Runtime postprocessing: Takes raw tensors and runs a "decode-only" ONNX model to decode detections and generate masks.
    3. Final processing: Performs NMS (Non-Maximum Suppression), mask composition, and visualization.

    Requirements for Custom Models

    If adapting this for a different model architecture:

    • The ONNX model must be a "decode-only" model compatible with the HEF outputs (matching tensor shapes and data types).
    • You may need to modify onnx_decode.cpp (e.g., parse_onnx_output()) to match your model's output format.
    • You may need to modify instance_seg_postprocess.cpp to handle different types of masks, boxes, or keypoints.
  7. Understand diagnostic tool output (Warnings vs Errors)

    main

    The tool outputs information, warnings, and errors during the inspection process:

    • [info]: Indicates the current inspector module being executed.
    • [warning]: Indicates non-standard behavior that may not necessarily be an issue (e.g., data being normalized outside the Hailo pipeline). You may want to add a normalization layer if the behavior is unintended.
    • [error]: Indicates problematic behavior that likely requires correction (e.g., unexpected data distribution or missing normalization when expected).
    [info] Running inspector module: NormInspector
    [warning] Input layer resnet_v1_18/input_layer1 doesn't have normalization. Was the data normalized manually?
    [error] Unexpected data distribution at resnet_v1_18/input_layer1. (expected normalized data) mean: [120.55961  114.191986  94.09033 ], std: [59.070805 56.93998  57.789307]
    [error] Mean or std are above threshold. Data might not be noramlized
  8. How the Hailo DSP image preprocessing pipeline works

    main

    The DSP example demonstrates a multi-stage image preprocessing pipeline using the Hailo DSP. The pipeline chains three distinct operations to transform a raw RGB input into a processed NV12 output:

    1. Crop and Resize with Letterbox: Takes a raw RGB input, crops the top-left quarter (from (0,0) to (input_width/2, input_height/2)), and resizes it to the target dimensions (e.g., 640×640) using letterboxing to preserve the aspect ratio.
    2. Format Conversion: Converts the resulting RGB image into NV12 format.
    3. Affine Rotation: Applies a 30-degree rotation to the NV12 image.

    This sequence illustrates how to compose multiple DSP operations into a single processing flow.