YOLOv5 Linux Demo Setup

This guide walks through setting up and running the YOLOv5 Linux demo on the LPB3588 platform.

Prerequisites:

  • Hardware: One LPB3588 device.
  • Firmware: Flash the device with LPB3588_ubuntu20.04_v1.0_20241010_1726.img.

Step 1: Source Code Download

mkdir -p ~/npu && cd ~/npu;
git clone https://github.com/airockchip/rknn-toolkit2;

rknn-toolkit2 commit (a8dd54d) and version (v2.3.0).

Step 2: Install Build Environment

Update the system and install required packages:

sudo apt update;
sudo apt install build-essential cmake;

Step 3: Modify GCC Environment Variable

Edit the build script to set the GCC compiler directly:

vi ~/npu/rknn-toolkit2-master/rknpu2/examples/rknn_yolov5_demo/build-linux.sh 

Replace the following lines:

+++ b/rknpu2/examples/rknn_yolov5_demo/build-linux.sh
@@ -35,11 +35,8 @@ if [ -z ${TARGET_SOC} ];then
   exit -1
 fi
 
-if [[ -z ${GCC_COMPILER} ]];then
-  echo "Please set GCC_COMPILER for $TARGET_SOC"
-  echo "such as export GCC_COMPILER=~/opt/gcc-linaro-7.5.0-2019.12-x86_64_aarch64-linux-gnu/bin/aarch64-linux-gnu"
-  exit
-fi
+GCC_COMPILER=aarch64-linux-gnu
+
 echo "$GCC_COMPILER"
 export CC=${GCC_COMPILER}-gcc
 export CXX=${GCC_COMPILER}-g++

Step 4: Update MPP Library Symlinks

Create symlinks for the MPP library:

cd ~/npu/rknn-toolkit2-master/rknpu2/examples/3rdparty/mpp/Linux/aarch64
ln -sf librockchip_mpp.so.0.1 librockchip_mpp.so
ln -sf librockchip_mpp.so.0 librockchip_mpp.so

Step 5: Compile and Build the Demo

execute the build script:

cd ~/npu/rknn-toolkit2-master/rknpu2/examples/rknn_yolov5_demo
chmod +x build-linux.sh
./build-linux.sh -t rk3588 -a aarch64 -b Release

Step 6: Run the Demo

Move to the demo’s output directory and run the program:

cd install/rknn_yolov5_demo_Linux/
./rknn_yolov5_demo ./model/RK3588/yolov5s-640-640.rknn ./model/bus.jpg

Optimizations

  • Ensure your build-linux.sh script uses the appropriate paths for gcc compatible with your RK3588 platform.
  • Confirm symlinks point to the correct version of the MPP library files.
  • Use appropriate RKNN models compatible with your platform.

Execution Result

neardi@LPA3588:~/npu/rknn-toolkit2-master/rknpu2/examples/rknn_yolov5_demo/install/rknn_yolov5_demo_Linux$  ./rknn_yolov5_demo ./model/RK3588/yolov5s-640-640.rknn ./model/bus.jpg 
post process config: box_conf_threshold = 0.25, nms_threshold = 0.45
Loading mode...
sdk version: 2.3.0 (c949ad889d@2024-11-07T11:35:33) driver version: 0.8.8
model input num: 1, output num: 3
  index=0, name=images, n_dims=4, dims=[1, 640, 640, 3], n_elems=1228800, size=1228800, w_stride = 640, size_with_stride=1228800, fmt=NHWC, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
  index=0, name=output0, n_dims=4, dims=[1, 255, 80, 80], n_elems=1632000, size=1632000, w_stride = 0, size_with_stride=1638400, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
  index=1, name=286, n_dims=4, dims=[1, 255, 40, 40], n_elems=408000, size=408000, w_stride = 0, size_with_stride=491520, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
  index=2, name=288, n_dims=4, dims=[1, 255, 20, 20], n_elems=102000, size=102000, w_stride = 0, size_with_stride=163840, fmt=NCHW, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
model is NHWC input fmt
model input height=640, width=640, channel=3
Read ./model/bus.jpg ...
img width = 640, img height = 640
once run use 26.678000 ms
loadLabelName ./model/coco_80_labels_list.txt
person @ (209 243 286 510) 0.879723
person @ (479 238 560 526) 0.870588
person @ (109 238 231 534) 0.839831
bus @ (91 129 555 464) 0.692042
person @ (79 353 121 517) 0.300961
save detect result to ./out.jpg
loop count = 10 , average run  22.433800 ms