在PC端的Ubuntu中安装RKNN Toolkit 1.6.0开发环境

文章目录

前言

  • 实验室的项目需要用到Firefly的AIO-3399 ProC开发板,在PC端可安装RKNN Toolkit开发套件,总体思路就是,在本地使用PC电脑框架跑相关模型,通过官网相关模型转换代码,将tensorflow/pytorch/mxnet/keras 模型转换成rknn模型,从而可以直接拷贝到嵌入式设备RK3399 pro板子上直接使用。
    安装过程繁琐,故记录下部署过程及遇到的问题,以供自己和各位参考。

一、开发部署环境

PC系统版本:Ubuntu 18.04LTS
RKNN Toolkit版本:1.4.0&1.6.0
Python版本:Python3.6

二、安装过程

sudo apt-get update #检查可更新文件
sudo apt-get upgrade #安装可更新软件

2.1 安装Python3.6

sudo apt update #检查可更新文件
sudo apt install software-properties-common  #安装可添加源的工具
sudo add-apt-repository ppa:deadsnakes/ppa #添加源,否则会无法找到python3.7-dev软件包
sudo apt install python3.6-dev #安装python3.6
sudo apt install python3-tk

2.2 用virtualenv管理python版本

#创建 virtualenv环境
sudo apt install virtualenv #安装virtualenv软件
virtualenv -p /usr/bin/python3.6 venv  #创建虚拟环境
source venv/bin/activate  #激活venv环境
(venv) firefly@firefly:~$  pip3 -V #查看当前pip3所在Python的路径
pip 21.0.1 from /home/firefly/venv/lib/python3.6/site-packages/pip (python 3.6)

至此Python3.6环境配置完成。

2.3 进入目录,列出已下载的离线whl包

离线whl包均从rockcip官方源下载,链接如下:http://repo.rock-chips.com/pypi/simple/
可按自己需要下载对应版本的whl包

ls
mxnet-1.7.0.post2-py2.py3-none-manylinux2014_x86_64.whl
rknn_toolkit-1.6.0-cp36-cp36m-linux_x86_64.whl
tensorflow-1.14.0-cp36-cp36m-manylinux1_x86_64.whl
tensorflow_gpu-1.14.0-cp36-cp36m-manylinux1_x86_64.whl
torch-1.5.1-cp36-cp36m-manylinux1_x86_64.whl

2.4 安装 TensorFlow、 python-opencv等依赖库

(venv) user@admin-machine:~/RKNN1.6.0PC$ pip3 install tensorflow-1.14.0-cp36-cp36m-manylinux1_x86_64.whl 
pip3 install mxnet==1.5.0
pip3 install gluoncv -i https://pypi.tuna.tsinghua.edu.cn/simple

gluoncv依赖关系暂时没搞好,pip自动安装的pillow和matplotlib包的版本不满足RKNN1.6.0所需的版本,后面再说吧

#出现了一下错误
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for ConfigSpace
Failed to build ConfigSpace
ERROR: Could not build wheels for ConfigSpace which use PEP 517 and cannot be installed directly#

 ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
rknn-toolkit 1.6.0 requires Pillow==5.3.0, but you have pillow 8.1.2 which is incompatible.

2.5 安装相关依赖包和RKNN1.6.0

sudo apt-get install gcc python3-dev
pip3 install rknn_toolkit-1.6.0-cp36-cp36m-linux_x86_64.whl 
Successfully installed Pillow-5.3.0 dill-0.2.8.2 flask-1.0.2 flatbuffers-1.10 h5py-2.8.0 lmdb-0.93 networkx-1.11 onnx-tf-1.2.1 ply-3.11 psutil-5.6.2 rknn-toolkit-1.6.0

#安装完成,测试各模块是否正常
(venv) user@admin-machine:~/RKNN1.6.0PC$ python3
Python 3.6.9 (default, Jan 26 2021, 15:33:00) 
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from rknn.api import RKNN
>>> import cv2
>>> import tensorflow
>>> 

2.6 运行官方提供的demo,测试RKNN是否安装成功

(venv) user@admin-machine:~/RKNN1.6.0PC/examples/tensorflow/ssd_mobilenet_v1$ python3 test.py
--> Config model
done
--> Loading model
W The target_platform is not set in config, using default target platform rk1808.
W:tensorflow:From /home/user/venv/lib/python3.6/site-packages/tensorflow/python/ops/control_flow_ops.py:1814: py_func (from tensorflow.python.ops.script_ops) is deprecated and will be removed in a future version.
Instructions for updating:
tf.py_func is deprecated in TF V2. Instead, there are two
    options available in V2.
    - tf.py_function takes a python function which manipulates tf eager
    tensors instead of numpy arrays. It's easy to convert a tf eager tensor to
    an ndarray (just call tensor.numpy()) but having access to eager tensors
    means `tf.py_function`s can use accelerators such as GPUs as well as
    being differentiable using a gradient tape.
    - tf.numpy_function maintains the semantics of the deprecated tf.py_func
    (it is not differentiable, and manipulates numpy arrays). It drops the
    stateful argument making all functions stateful.
    
done
--> Export RKNN model
done
--> Init runtime environment
done
--> Running model
done
--> Evaluate model performance
W When performing performance evaluation, inputs can be set to None to use fake inputs.
========================================================================
                               Performance                              
========================================================================
Layer ID    Name                                         Time(us)
57          openvx.tensor_transpose_3                    125
117         convolution.relu.pooling.layer2_2            204
115         convolution.relu.pooling.layer2_2            404
112         convolution.relu.pooling.layer2_2            416
110         convolution.relu.pooling.layer2_2            597
107         convolution.relu.pooling.layer2_2            245
105         convolution.relu.pooling.layer2_2            503
...         ...                                          ...
23          fullyconnected.relu.layer_3                  13
29          fullyconnected.relu.layer_3                  8
Total Time(us): 10218
FPS(600MHz): 73.40
FPS(800MHz): 97.87
Note: Time of each layer is converted according to 800MHz!
========================================================================

done

测试效果对比图
在PC端的Ubuntu中安装RKNN Toolkit 1.6.0开发环境在PC端的Ubuntu中安装RKNN Toolkit 1.6.0开发环境
在PC端的Ubuntu中安装RKNN Toolkit 1.6.0开发环境

三、总结

不同平台,RKNN提供的基于不同Python版本的安装包,安装时不同平台对应的依赖关系需要处理好,具体如下:
1.Windows只提供 Python3.6的安装包。
2. MacOS提供 python3.6和 python3.7的安装包。
3. ARM64平台(安装 Debian 9或 10操作系统)提供 Python3.5 Debain 9)和 Python3.7Debian10)的安装包。
4. Linux_x64平台提供基于 python3.5和 python3.6的安装包。

上一篇:python pip 出错解决办法


下一篇:海思开发板——YOLOv3模型转换(1)