Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deploying Computer Vision on LicheePi 4A

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.


TL;DR results

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.


Demo

Result of detection — YOLOv5n object detection running on the LicheePi 4A NPU

▶ Screencast of the result running on the board: docs/media/demo-screencast.webm (~2 MB, WebM).


Documentation

The article is split into the following sections (under docs/):

  1. Introduction — the LicheePi 4A board, its capabilities, and why NPU optimization matters
  2. Hardware Setup — full board specifications
  3. Software Environment — overview of what to install where
  4. LicheePi Board Configuration — OS, Python venv, NPU runtime, ONNX Runtime, OpenCV/NumPy
  5. Host (x86 Laptop) Actions — model conversion, quantization (HHB), and cross-compilation
  6. Performance Metrics — raw benchmark output (NPU & CPU), and NPU driver troubleshooting
  7. Results — analysis of NPU vs CPU
  8. Conclusion

Source code

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

Pipeline at a glance

                          ┌─────────────────────────────────────────────┐
   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    │
                          └─────────────────────────────────────────────┘

Key facts about the board

  • 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)

Toolchain / dependencies

  • HHB (Heterogeneous Honey Badger) 2.4.5 — model conversion, quantization, codegen (via Docker hhb4tools/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 (th1520 for NPU, c920 for 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.


License

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.

About

Real-time YOLOv5 object detection on the LicheePi 4A (RISC-V TH1520) accelerated by the on-board NPU — full pipeline, benchmarks, and source. NPU hits ~135–175 FPS vs 0.02 FPS on CPU.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages