RKNN 使用
安装python3.9环境
由于Ubuntu20.04默认的python版本是3.8,而RKNN需要python3.9的版本,因此安装Virtualenv环境,步骤如下:
sudo apt-get install python3-distutils
su; apt list --installed | grep -v oldstable | cut -d/ -f1 | xargs apt-mark unhold
sudo apt install virtualenv
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get install python3.9 python3.9-dev python3-pip
sudo apt-get install libxslt1-dev zlib1g zlib1g-dev libglib2.0-0 libsm6 libgl1-mesa-glx libprotobuf-dev gcc
virtualenv -p /usr/bin/python3.9 venv
成功执行上面命令后,则会新创建有venv目录,如下:
neardi@LPA3588:~$ ls
Desktop Documents Downloads Music Pictures Public rknn Templates venv Videos
启动venv环境,如下命令:
source venv/bin/activate
成功后,命令行会有venv标识,如下:
neardi@LPA3588:~$ source venv/bin/activate
(venv) neardi@LPA3588:~$
下载 RKNN及RKNPU2
mkdir /home/neardi/rknn
cd /home/neardi/rknn
git clone https://github.com/rockchip-linux/rknn-toolkit2
git clone https://github.com/rockchip-linux/rknpu2
初始化RKNN环境
sudo apt-get install -y python3-numpy
pip3 install opencv-python
安装RKNN模块
(venv) neardi@LPA3588:~$ cd /home/neardi/rknn/rknn-toolkit2/rknn_toolkit_lite2/packages/
(venv) neardi@LPA3588:~/rknn/rknn-toolkit2/rknn_toolkit_lite2/packages$ ll
total 1308
drwxr-xr-x 2 neardi neardi 4096 Dec 21 03:03 ./
drwxr-xr-x 5 neardi neardi 4096 Dec 21 03:03 ../
-rw-r--r-- 1 neardi neardi 669664 Dec 21 03:03 rknn_toolkit_lite2-1.4.0-cp37-cp37m-linux_aarch64.whl
-rw-r--r-- 1 neardi neardi 655128 Dec 21 03:03 rknn_toolkit_lite2-1.4.0-cp39-cp39-linux_aarch64.whl
-rw-r--r-- 1 neardi neardi 175 Dec 21 03:03 rknn_toolkit_lite2_1.4.0_packages.md5sum
(venv) neardi@LPA3588:~/rknn/rknn-toolkit2/rknn_toolkit_lite2/packages$ pip3 install rknn_toolkit_lite2-1.4.0-cp39-cp39-linux_aarch64.whl
拷贝 RKNPU2 LIB库至/usr/lib,如下命令:
sudo cp /home/neardi/rknn/rknpu2/runtime/RK3588/Linux/librknn_api/aarch64/* /usr/lib/
运行RKNN Demo
cd /home/neardi/rknn/rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite
(venv) neardi@LPA3588:~/rknn/rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite$ python3 test.py
--> Load RKNN model
done
--> Init runtime environment
I RKNN: [06:18:52.741] RKNN Runtime Information: librknnrt version: 1.4.0 (a10f100eb@2022-09-09T09:07:14)
I RKNN: [06:18:52.741] RKNN Driver Information: version: 0.8.2
I RKNN: [06:18:52.741] RKNN Model Information: version: 1, toolkit version: 1.4.0-c15f5e0b(compiler version: 1.4.0 (c73777b51@2022-09-05T12:06:01)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW
done
--> Running model
resnet18
-----TOP 5-----
[812]: 0.9996696710586548
[404]: 0.0002492684288881719
[657]: 1.632158637221437e-05
[833]: 1.0159346857108176e-05
[466 895]: 9.02384545042878e-06
done