Khadas Docs

Amazing Khadas, always amazes you!

User Tools

Site Tools


Sidebar

products:sbc:edge2:npu:npu-applications

This is an old revision of the document!


NPU Applications

Introduction

This document mainly introduces how to compile and use NPU applications in Edge2.

Get Source Code

Clone the source code form our Github.

$ git clone https://github.com/khadas/edge2-npu

There are two types of application source code in C++ and Python.

Python Applications

Enter Python directory,

$ cd Python

Install dependences,

$ sudo cp ../C++/runtime/librknn_api/aarch64/librknnrt.so /usr/lib
$ sudo apt-get install -y python3-dev python3-pip
$ sudo apt-get install -y python3-opencv python3-numpy
$ pip3 install ./wheel/rknn_toolkit_lite2-1.3.0-cp310-cp310-linux_aarch64.whl

Take yolov5 as an example, other demos are similar.

$ cd resnet18
$ python3 resnet18.py 
--> Load RKNN model
done
--> Init runtime environment
I RKNN: [17:07:10.282] RKNN Runtime Information: librknnrt version: 1.3.0 (c193be371@2022-05-04T20:16:33)
I RKNN: [17:07:10.282] RKNN Driver Information: version: 0.7.2
I RKNN: [17:07:10.282] RKNN Model Information: version: 1, toolkit version: 1.3.0-11912b58(compiler version: 1.3.0 (c193be371@2022-05-04T20:23:58)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW
done
--> Running model
resnet18
-----TOP 5-----
[812]: 0.9996383190155029
[404]: 0.00028062646742910147
[657]: 1.632110434002243e-05
[833 895]: 1.015904672385659e-05
[833 895]: 1.015904672385659e-05
 
done

C++ Applications

Enter C++ directory,take yolov5 as an example, other demos are similar.

$ cd C++

Install dependences,

$ sudo apt install cmake

Compile,

$ cd yolov5
$ ./build.sh

Run.

$ cd install/yolov5
$ ./yolov5 data/model/yolov5s-640-640.rknn data/img/bus.jpg 
post process config: box_conf_threshold = 0.50, nms_threshold = 0.60
Read data/img/bus.jpg ...
img width = 640, img height = 640
Loading mode...
sdk version: 1.3.0 (c193be371@2022-05-04T20:16:33) driver version: 0.7.2
model input num: 1, output num: 3
  index=0, name=images, n_dims=4, dims=[1, 640, 640, 3], n_elems=1228800, size=1228800, fmt=NHWC, type=INT8, qnt_type=AFFINE, zp=-128, scale=0.003922
  index=0, name=output, n_dims=5, dims=[1, 3, 85, 80], n_elems=1632000, size=1632000, fmt=UNDEFINED, type=INT8, qnt_type=AFFINE, zp=77, scale=0.080445
  index=1, name=371, n_dims=5, dims=[1, 3, 85, 40], n_elems=408000, size=408000, fmt=UNDEFINED, type=INT8, qnt_type=AFFINE, zp=56, scale=0.080794
  index=2, name=390, n_dims=5, dims=[1, 3, 85, 20], n_elems=102000, size=102000, fmt=UNDEFINED, type=INT8, qnt_type=AFFINE, zp=69, scale=0.081305
model is NHWC input fmt
model input height=640, width=640, channel=3
once run use 32.872000 ms
loadLabelName ./data/coco_80_labels_list.txt
person @ (474 250 559 523) 0.996784
person @ (112 238 208 521) 0.992214
bus @ (99 141 557 445) 0.976798
person @ (211 242 285 509) 0.976798
loop count = 10 , average run  26.577900 ms
Last modified: 2022/09/19 05:30 by frank