首页 > 编程语言 >36、RK3399Pro 环境搭建和Yolov5 c++调用opencv进行RKNN模型部署和使用

36、RK3399Pro 环境搭建和Yolov5 c++调用opencv进行RKNN模型部署和使用

时间:2022-12-09 21:35:08浏览次数:86  
标签:box RKNN Yolov5 rknn int float 36 input model


基本思想:记录rk3399 pro配置环境和c++ npu开发记录,主要想搞一份c++代码和其它图像算法结合一下,好进行部署,淘宝链接见附录

36、RK3399Pro 环境搭建和Yolov5 c++调用opencv进行RKNN模型部署和使用_linux

36、RK3399Pro 环境搭建和Yolov5 c++调用opencv进行RKNN模型部署和使用_linux_02

 需要的python3.7对应的aarch64的whl包:包含opencv-whl 、h5py-whl包:

链接: https://pan.baidu.com/s/1cvCAmHBa_4KgEjrcFIYnig 提取码: 5ui4

链接: https://pan.baidu.com/s/1hrcr8Fc2sboD1_uy8T1Z8Q 提取码: e4wq

第一步:因为系统是python3.8,因为官方没有提供python3.8的rknn的版本,需要安装anconda环境构建python3.6 

ubuntu@ubuntu:~$ ssh [email protected]
[email protected]'s password:
_____ _ __ _
| ___(_)_ __ ___ / _| |_ _
| |_ | | '__/ _ \ |_| | | | |
| _| | | | | __/ _| | |_| |
|_| |_|_| \___|_| |_|\__, |
|___/
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 4.4.194 aarch64)

* Documentation: http://wiki.t-firefly.com
* Management: http://www.t-firefly.com

System information as of Mon Aug 22 09:20:44 UTC 2022

System load: 0.40 0.13 0.05 Up time: 0 min Local users: 2
Memory usage: 7 % of 3777MB IP: 10.10.85.75
10.10.85.232
Usage of /: 14% of 12G

Last login: Mon Aug 22 09:03:35 2022 from 10.10.84.222
firefly@firefly:~$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()

firefly@firefly:~$ sudo apt-get -y install libprotobuf-dev protobuf-compiler gfortran \
libboost-dev cmake libleveldb-dev libsnappy-dev \
libboost-thread-dev libboost-system-dev \
libatlas-base-dev libhdf5-serial-dev libgflags-dev \
libgoogle-glog-dev liblmdb-dev \
libboost-all-dev libgtk2.0-dev pkg-config
sudo apt-get -y remove ffmpeg x264 libx264-dev
sudo apt-get -y install libopencv-dev
sudo apt-get -y install build-essential checkinstall cmake pkg-config yasm
sudo apt-get -y install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev
sudo apt-get -y install python-dev python-numpy libgtk2.0-dev
sudo apt-get -y install libtbb-dev libeigen3-dev
sudo apt-get -y install libqt4-dev libgtk2.0-dev
sudo apt-get install ibgtk2.0-dev pkg-config
sudo apt-get -y install libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev
sudo apt-get -y install x264 v4l-utils ffmpeg
sudo apt-get -y install libgtk2.0-dev

下载anconda包,进行安装成功,然后构建环境

firefly@firefly:~$ wget https://github.com/Archiconda/build-tools/releases/download/0.2.2/Archiconda3-0.2.2-Linux-aarch64.sh
firefly@firefly:~$ sh Archiconda3-0.2.2-Linux-aarch64.sh
firefly@firefly:~$ python3
Python 3.8.10 (default, Jun 22 2022, 20:18:18)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
firefly@firefly:~$ source ~/.bashrc
firefly@firefly:~$ python3
Python 3.7.1 | packaged by conda-forge | (default, Jan 7 2019, 00:11:41)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
firefly@firefly:~$ conda create -n rknnpy37 python=3.7
Executing transaction: done
#
# To activate this environment, use
#
# $ conda activate rknnpy37
#
# To deactivate an active environment, use
#
# $ conda deactivate
firefly@firefly:~$ conda activate rknnpy37
(rknnpy37) firefly@firefly:~$

配置环境安装PC安装rknn-toolkit以来支持模型的转,就没必要在开发板安装RKNN ​​Index of /pypi/simple/​

(rknnpy37) firefly@firefly:~$ git clone https://github.com/rockchip-linux/rknn-toolkit.git
(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/packages$ pip3 install rknn_toolkit_lite-1.7.1-cp37-cp37m-linux_aarch64.whl -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
...
Successfully built numpy psutil ruamel.yaml
Installing collected packages: ruamel.yaml, psutil, numpy, rknn-toolkit-lite
Successfully installed numpy-1.16.3 psutil-5.6.2 rknn-toolkit-lite-1.7.1 ruamel.yaml-0.15.81
(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/packages$ python3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:22:24)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rknnlite.api import RKNNLite
>>>
Processing ./opencv_python-4.5.2.54-cp37-cp37m-manylinux2014_aarch64.whl
Requirement already satisfied: numpy>=1.19.3 in /home/firefly/archiconda3/envs/rknnpy37/lib/python3.7/site-packages (from opencv-python==4.5.2.54) (1.21.6)
Installing collected packages: opencv-python
Successfully installed opencv-python-4.5.2.54

第三步,测试demo发现报错,没有npu信息,需要更新一下驱动,然后测试demo成功

(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite$ python3 test.py 
--> Load RKNN model
done
--> Init runtime environment
E Only support ntb mode on Linux_x64 aarch64. But can not find device with ntb mode.
E Catch exception when init runtime!
E Traceback (most recent call last):
File "/home/firefly/archiconda3/envs/rknnpy37/lib/python3.7/site-packages/rknnlite/api/rknn_lite.py", line 145, in init_runtime
async_mode=async_mode, rknn2precompile=rknn2precompile)
File "rknnlite/api/rknn_runtime.py", line 201, in rknnlite.api.rknn_runtime.RKNNRuntime.__init__
File "rknnlite/api/rknn_runtime.py", line 637, in rknnlite.api.rknn_runtime.RKNNRuntime._connect
Exception: Init runtime environment failed!

Init runtime environment failed

(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite$ python3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:22:24)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rknnlite.api import RKNNLite
>>> rknn=RKNNLite()
>>> rknn.list_devices()
/home/firefly/archiconda3/envs/rknnpy37/lib/python3.7/site-packages/rknnlite/3rdparty/platform-tools/ntp/linux-aarch64/npu_transfer_proxy devices
*************************
None devices connected.
*************************
([], [])
>>> exit()
(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite$ sudo apt install firefly-3399pronpu-driver

需要重启一下设备

firefly@firefly:~$ conda activate rknnpy37
(rknnpy37) firefly@firefly:~$ python3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:22:24)
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rknnlite.api import RKNNLite
>>> rknn=RKNNLite()
>>> rknn.list_devices()
/home/firefly/archiconda3/envs/rknnpy37/lib/python3.7/site-packages/rknnlite/3rdparty/platform-tools/ntp/linux-aarch64/npu_transfer_proxy devices
*************************
all device(s) with ntb mode:
0123456789ABCDEF
*************************
([], ['0123456789ABCDEF'])
>>>
(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite$ python3 test.py
--> Load RKNN model
done
--> Init runtime environment
I NPUTransfer: Starting NPU Transfer Client, Transfer version 2.1.0 (b5861e7@2020-11-23T11:50:51)
D RKNNAPI: ==============================================
D RKNNAPI: RKNN VERSION:
D RKNNAPI: API: 1.7.1 (566a9b6 build: 2021-10-28 14:56:17)
D RKNNAPI: DRV: 1.7.1 (0cfd4a1 build: 2021-12-10 09:43:11)
D RKNNAPI: ==============================================
done
--> Running model
D RKNNAPI: __can_use_fixed_point: pix = 3, diff = {0, 1, 0} != 0, disable fixed pointer convert.

D RKNNAPI: __can_use_fixed_point: use_fixed_point = 0.

resnet18
-----TOP 5-----
[812]: 0.999442994594574
[404]: 0.0004096269840374589
[657]: 3.2845448004081845e-05
[833]: 2.6112385967280716e-05
[895]: 1.8509887013351545e-05

done
(rknnpy37) firefly@firefly:~/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite$

第四步:在pc机上操作:下载yolov5.0  v5.0的源码和模型,将model.py的export.py移动到主目录下,同时修改yolo.py参考上一篇博客 ​​Releases · ultralytics/yolov5 · GitHub​

ubuntu@ubuntu:~/Wallpapers/yolov5-5.0$ python3 export.py --weights yolov5s.pt  --img 640 --batch 1
Namespace(batch_size=1, device='cpu', dynamic=False, grid=False, img_size=[640, 640], weights='yolov5s.pt')
YOLOv5

标签:box,RKNN,Yolov5,rknn,int,float,36,input,model
From: https://blog.51cto.com/u_12504263/5926589

相关文章