Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Configuring HHB Compilation Environment for YOLOv5n on LicheePi 4A

Tech Jun 3 4

Setting Up the Development Environment

WSL2 Configuration

Enable virtualization in Windows settings and install WSL2:

wsl --update
wsl --set-default-version 2
wsl --list --verbose

Ubuntu Installation

Install Ubuntu 20.04 from the Microsoft Store and configure the WSL environment.

Visual Studio Code Setup

Install the WSL extension in VSCode to enable seamless integration with the WSL environment.

YOLOv5n Model Compilation and Quantization with HHB

Docker Environment Setup

Install Docker dependencies and configure the environment:

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common

Pull the HHB Docker image:

docker pull hhb4tools/hhb:2.4.5

Start the Docker container and configure the cross-compilation environment:

docker run -itd --name=hhb_container -p 22 "hhb4tools/hhb:2.4.5"
docker exec -it hhb_container /bin/bash
export PATH=/tools/Xuantie-900-gcc-linux-5.10.4-glibc-x86_64-V2.6.1-light.1/bin/:$PATH

Model Export and Compilation

Clone the YOLOv5 repository and export the model with specific dimensions:

git clone https://github.com/ultralytics/yolov5.git
cd yolov5
pip3 install ultralytics
python3 export.py --weights yolov5n.pt --include onnx --imgsz 384 640

Compile the model using HHB with the correct input dimensions:

cd /home/example/th1520_npu/yolov5n
cp ../../../yolov5/yolov5n.onnx ./
hhb -D --model-file yolov5n.onnx --data-scale-div 255 --board th1520 \
     --input-name "images" --output-name "/model.24/m.0/Conv_output_0;/model.24/m.1/Conv_output_0;/model.24/m.2/Conv_output_0" \
     --input-shape "1 3 384 640" --calibrate-dataset kite.jpg --quantization-scheme "int8_asym"

Common Error Resolution

The compilation error occurs when model input dimensions mismatch between the ONNX export and HHB compilation parameters. Ensure consistent dimensions by:

  1. Exporting the ONNX model with the same dimensions used in HHB compilatoin
  2. Using --imgsz 384 640 during ONNX export to match the --input-shape "1 3 384 640" parameter

Successful compilation output indicates proper dimension matching:

[HHB LOG]: Start import model.
[HHB LOG]: Model import completed!
[HHB LOG]: Start quantization.
[HHB LOG]: Quantization completed!

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.