Using RKNN
Installing Python 3.9 Environment
Since the default Python version in Ubuntu 20.04 is 3.8, and RKNN requires Python 3.9, install the Virtualenv environment with the following steps:
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
After successfully executing the above commands, a new venv directory will be created, as follows:
neardi@LPA3588:~$ ls
Desktop Documents Downloads Music Pictures Public rknn Templates venv Videos
Activate the venv environment with the following command:
source venv/bin/activate
Upon success, the command line will display the venv identifier, as follows:
neardi@LPA3588:~$ source venv/bin/activate
(venv) neardi@LPA3588:~$
Downloading RKNN and 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
Initializing the RKNN Environment
sudo apt-get install -y python3-numpy
pip3 install opencv-python
Install the RKNN module:
(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
Copy the RKNPU2 LIB library to /usr/lib with the following command:
sudo cp /home/neardi/rknn/rknpu2/runtime/RK3588/Linux/librknn_api/aarch64/* /usr/lib/
Running the 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