Running real-time object detection (YOLOv5) on the Sipeed LicheePi 4A RISC-V single-board computer, accelerated by the on-board NPU (T-Head TH1520, 4 TOPS @ INT8).
This repository documents the full pipeline — from flashing the board and setting up the software environment, through converting/quantizing the model on an x86 host, to benchmarking inference on the device. It compares NPU vs. CPU performance and shows that the NPU delivers a ~135–175 FPS vs. 0.02 FPS on the CPU for the same model.
Source: This content was originally published as an internal technical article ("Deploying Computer Vision on LisheePi4A", TechContent space) and has been reorganized here into a runnable repository. Author: Mykhailo Koiev.
| Target | Frames per second | Time per image | One-time init |
|---|---|---|---|
| NPU (TH1520) | 135–175 FPS | 5–8 ms | ~35 s (model load, runs once) |
| CPU (C920) | 0.02 FPS | ~53,400 ms | ~5 ms |
The NPU is roughly 3 orders of magnitude faster than the CPU for this YOLOv5n workload, making the LicheePi 4A viable for real-time computer vision at the edge.
▶ Screencast of the result running on the board: docs/media/demo-screencast.webm (~2 MB, WebM).
The article is split into the following sections (under docs/):
- Introduction — the LicheePi 4A board, its capabilities, and why NPU optimization matters
- Hardware Setup — full board specifications
- Software Environment — overview of what to install where
- LicheePi Board Configuration — OS, Python venv, NPU runtime, ONNX Runtime, OpenCV/NumPy
- Host (x86 Laptop) Actions — model conversion, quantization (HHB), and cross-compilation
- Performance Metrics — raw benchmark output (NPU & CPU), and NPU driver troubleshooting
- Results — analysis of NPU vs CPU
- Conclusion
Under src/:
| File | Description |
|---|---|
inference.py |
Original Python script: preprocess image → run the compiled YOLOv5n NPU binary → draw bounding boxes |
yolov5_HW.py |
Updated benchmark script with switches for CPU/NPU and C++/Python preprocessing, repeated runs, and timing markers |
yolov5n.c |
C source (HHB auto-generated, modified) that loads the quantized model and runs inference + YOLOv5 post-processing |
coco.names |
COCO 80-class label file used by the drawing code |
┌─────────────────────────────────────────────┐
HOST (x86 laptop) │ Docker: hhb4tools/hhb:2.4.5 │
│ 1. yolov5n.pt ──export.py──▶ yolov5n.onnx │
│ 2. hhb quantize ─▶ int8 model (th1520/c920) │
│ 3. cross-compile yolov5n.c ─▶ yolov5n_example│
└───────────────────────┬─────────────────────┘
│ scp the yolov5n/ folder
▼
┌─────────────────────────────────────────────┐
TARGET (LicheePi 4A) │ Debian 12 + Python venv + shl-python │
│ + hhb-onnxruntime + OpenCV/NumPy │
│ python3 yolov5_HW.py ──▶ NPU inference │
└─────────────────────────────────────────────┘
- SoC: T-Head RISC-V TH1520 (12 nm)
- CPU: 4× XuanTie C910 @ up to 1.85–2.0 GHz (RISC-V)
- GPU: OpenGL ES 3.x, OpenCL 1.1/1.2/2.0, Vulkan 1.1/1.2
- NPU: 4 TOPS @ INT8 (up to 1 GHz) — supports TensorFlow, ONNX, Caffe
- Memory: up to 16 GB LPDDR4X · Storage: up to 128 GB eMMC
- OS used in tests: Debian 12 (bookworm)
- HHB (Heterogeneous Honey Badger)
2.4.5— model conversion, quantization, codegen (via Dockerhhb4tools/hhb:2.4.5) - Xuantie-900 GCC toolchain —
riscv64-unknown-linux-gnu-gcc - shl-python — NPU runtime libraries (SHL backend)
- hhb-onnxruntime — ONNX Runtime port using the SHL execution providers (
th1520for NPU,c920for CPU) - YOLOv5 (ultralytics, tag v6.2), exported at input size 384×640
- OpenCV + NumPy (prebuilt RISC-V wheels)
See docs/04 and docs/05 for exact commands.
The C source (src/yolov5n.c) is auto-generated by HHB and carries an
Apache License 2.0 header (it builds on Apache TVM / CSI-NN2 code). This repository is
released under Apache-2.0 accordingly. Documentation text is reproduced from the
original internal article for reference/educational purposes.
