Configuring HHB Compilation Environment for YOLOv5n on LicheePi 4A
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:
- Exporting the ONNX model with the same dimensions used in HHB compilatoin
- Using
--imgsz 384 640during 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!