Difference between revisions of "NPU/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
Line 4: Line 4:
 
===OS===
 
===OS===
 
Tested on the following OS:
 
Tested on the following OS:
* rk3588-sd-debian-bullseye-desktop-6.1-arm64-20231116.img.gz
+
====Debian11 (bullseye)====
 +
* rk3588-sd-debian-bullseye-desktop-6.1-arm64-20240116.img.gz
 
* rk3568-sd-debian-bullseye-desktop-6.1-arm64-20231113.img.gz
 
* rk3568-sd-debian-bullseye-desktop-6.1-arm64-20231113.img.gz
 +
====Ubuntu20 (focal)====
 +
* rk3588-sd-ubuntu-focal-desktop-6.1-arm64-20240116.img.gz
 
===install rknpu===
 
===install rknpu===
 
<syntaxhighlight lang="text">
 
<syntaxhighlight lang="text">
Line 15: Line 18:
 
sudo cp ./runtime/RK3588/Linux/rknn_server/aarch64/usr/bin/* /usr/bin/
 
sudo cp ./runtime/RK3588/Linux/rknn_server/aarch64/usr/bin/* /usr/bin/
 
</syntaxhighlight>
 
</syntaxhighlight>
===install rknn_toolkit===
+
 
 +
===check rknn version===
 +
<syntaxhighlight lang="text">
 +
strings /usr/bin/rknn_server |grep 'build@'
 +
strings /usr/lib/librknnrt.so |grep 'librknnrt version:'
 +
</syntaxhighlight>
 +
 
 +
===run C/C++ demo===
 +
<syntaxhighlight lang="text">
 +
sudo apt-get update
 +
sudo apt-get install -y gcc g++ make cmake
 +
cd examples/rknn_yolov5_demo
 +
./build-linux_RK3588.sh
 +
 
 +
cd install/rknn_yolov5_demo_Linux
 +
./rknn_yolov5_demo model/RK3588/yolov5s-640-640.rknn model/bus.jpg
 +
</syntaxhighlight>
 +
 
 +
===install rknn_toolkit on debian11===
 +
====install rknn_toolkit====
 
<syntaxhighlight lang="text">
 
<syntaxhighlight lang="text">
 
sudo apt-get update
 
sudo apt-get update
 
sudo apt-get install -y python3-dev python3-numpy python3-opencv python3-pip
 
sudo apt-get install -y python3-dev python3-numpy python3-opencv python3-pip
 +
cd ~
 
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
 
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
 
(cd rknn-toolkit2 && git checkout tags/v1.5.2 -b v1.5.2)
 
(cd rknn-toolkit2 && git checkout tags/v1.5.2 -b v1.5.2)
Line 24: Line 47:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===run test===
+
===run python demo===
 
<syntaxhighlight lang="text">
 
<syntaxhighlight lang="text">
 
$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite/
 
$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite/
Line 36: Line 59:
 
21T09:35:42)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inference type: static_s
 
21T09:35:42)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inference type: static_s
 
hape
 
hape
 +
done
 +
--> Running model
 +
resnet18
 +
-----TOP 5-----
 +
[812]: 0.9996760487556458
 +
[404]: 0.00024927023332566023
 +
[657]: 1.449744013370946e-05
 +
[466 833]: 9.023910024552606e-06
 +
[466 833]: 9.023910024552606e-06
 +
 +
done
 +
</syntaxhighlight>
 +
 +
===install rknn_toolkit on ubuntu===
 +
====build python3.9 from source====
 +
<syntaxhighlight lang="text">
 +
sudo apt install build-essential libssl-dev libffi-dev software-properties-common libbz2-dev libncurses-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev libgdbm-compat-dev libreadline-dev
 +
 +
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tar.xz
 +
tar -xvf Python-3.9.16.tar.xz
 +
cd Python-3.9.16/
 +
./configure --enable-optimizations
 +
make -j$(nproc)
 +
sudo make install
 +
</syntaxhighlight>
 +
 +
====install rknn_toolkit====
 +
<syntaxhighlight lang="text">
 +
pip install --upgrade pip
 +
pip install opencv-python
 +
cd ~
 +
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
 +
(cd rknn-toolkit2 && git checkout tags/v1.5.2 -b v1.5.2)
 +
/usr/local/bin/python3.9 -m pip install ./rknn-toolkit2/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.5.2-cp39-cp39-linux_aarch64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/
 +
</syntaxhighlight>
 +
 +
===run python demo===
 +
<syntaxhighlight lang="text">
 +
$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite/
 +
$ python3 test.py
 +
--> Load RKNN model
 +
done
 +
--> Init runtime environment
 +
I RKNN: [08:41:08.078] RKNN Runtime Information: librknnrt version: 1.5.2 (c6b7b351a@2023-08-23T15:28:22)
 +
I RKNN: [08:41:08.078] RKNN Driver Information: version: 0.9.2
 +
I RKNN: [08:41:08.080] RKNN Model Information: version: 6, toolkit version: 1.5.2-source_code(compiler version: 1.5.2 (71720f3fc@
 +
2023-08-21T09:35:42)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inferenc
 +
e type: static_shape
 
done
 
done
 
--> Running model
 
--> Running model

Revision as of 08:48, 16 January 2024

English

1 How to test NPU

1.1 OS

Tested on the following OS:

1.1.1 Debian11 (bullseye)

  • rk3588-sd-debian-bullseye-desktop-6.1-arm64-20240116.img.gz
  • rk3568-sd-debian-bullseye-desktop-6.1-arm64-20231113.img.gz

1.1.2 Ubuntu20 (focal)

  • rk3588-sd-ubuntu-focal-desktop-6.1-arm64-20240116.img.gz

1.2 install rknpu

export GIT_SSL_NO_VERIFY=1
git clone https://github.com/rockchip-linux/rknpu2.git
cd rknpu2
git checkout tags/v1.5.2 -b v1.5.2
sudo cp ./runtime/RK3588/Linux/librknn_api/aarch64/* /usr/lib
sudo cp ./runtime/RK3588/Linux/rknn_server/aarch64/usr/bin/* /usr/bin/

1.3 check rknn version

strings /usr/bin/rknn_server |grep 'build@'
strings /usr/lib/librknnrt.so |grep 'librknnrt version:'

1.4 run C/C++ demo

sudo apt-get update
sudo apt-get install -y gcc g++ make cmake
cd examples/rknn_yolov5_demo
./build-linux_RK3588.sh
 
cd install/rknn_yolov5_demo_Linux
./rknn_yolov5_demo model/RK3588/yolov5s-640-640.rknn model/bus.jpg

1.5 install rknn_toolkit on debian11

1.5.1 install rknn_toolkit

sudo apt-get update
sudo apt-get install -y python3-dev python3-numpy python3-opencv python3-pip
cd ~
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
(cd rknn-toolkit2 && git checkout tags/v1.5.2 -b v1.5.2)
pip3 install ./rknn-toolkit2/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.5.2-cp39-cp39-linux_aarch64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/

1.6 run python demo

$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite/
$ python3 test.py
--> Load RKNN model
done
--> Init runtime environment
I RKNN: [08:06:49.416] RKNN Runtime Information: librknnrt version: 1.5.2 (c6b7b351a@2023-08-23T15:28:22)
I RKNN: [08:06:49.416] RKNN Driver Information: version: 0.9.2
I RKNN: [08:06:49.416] RKNN Model Information: version: 6, toolkit version: 1.5.2-source_code(compiler version: 1.5.2 (71720f3fc@2023-08-
21T09:35:42)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inference type: static_s
hape
done
--> Running model
resnet18
-----TOP 5-----
[812]: 0.9996760487556458
[404]: 0.00024927023332566023
[657]: 1.449744013370946e-05
[466 833]: 9.023910024552606e-06
[466 833]: 9.023910024552606e-06
 
done

1.7 install rknn_toolkit on ubuntu

1.7.1 build python3.9 from source

sudo apt install build-essential libssl-dev libffi-dev software-properties-common libbz2-dev libncurses-dev libncursesw5-dev libgdbm-dev liblzma-dev libsqlite3-dev tk-dev libgdbm-compat-dev libreadline-dev
 
wget https://www.python.org/ftp/python/3.9.16/Python-3.9.16.tar.xz
tar -xvf Python-3.9.16.tar.xz
cd Python-3.9.16/
./configure --enable-optimizations
make -j$(nproc)
sudo make install

1.7.2 install rknn_toolkit

pip install --upgrade pip
pip install opencv-python
cd ~
git clone https://github.com/rockchip-linux/rknn-toolkit2.git
(cd rknn-toolkit2 && git checkout tags/v1.5.2 -b v1.5.2)
/usr/local/bin/python3.9 -m pip install ./rknn-toolkit2/rknn_toolkit_lite2/packages/rknn_toolkit_lite2-1.5.2-cp39-cp39-linux_aarch64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple/

1.8 run python demo

$ cd rknn-toolkit2/rknn_toolkit_lite2/examples/inference_with_lite/
$ python3 test.py
--> Load RKNN model
done
--> Init runtime environment
I RKNN: [08:41:08.078] RKNN Runtime Information: librknnrt version: 1.5.2 (c6b7b351a@2023-08-23T15:28:22)
I RKNN: [08:41:08.078] RKNN Driver Information: version: 0.9.2
I RKNN: [08:41:08.080] RKNN Model Information: version: 6, toolkit version: 1.5.2-source_code(compiler version: 1.5.2 (71720f3fc@
2023-08-21T09:35:42)), target: RKNPU v2, target platform: rk3588, framework name: PyTorch, framework layout: NCHW, model inferenc
e type: static_shape
done
--> Running model
resnet18
-----TOP 5-----
[812]: 0.9996760487556458
[404]: 0.00024927023332566023
[657]: 1.449744013370946e-05
[466 833]: 9.023910024552606e-06
[466 833]: 9.023910024552606e-06
 
done