开发环境 | 软件版本 |
---|---|
PC系统版本 | Ubuntu 18.04LTS |
RKNN Toolkit版本 | 1.4.0 or 1.6.0 |
Python版本 | Python3.6 |
sudo apt-get update #检查可更新文件
sudo apt-get upgrade #安装可更新软件
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
#创建 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)
修改python默认为python3.6:
为了因为C++调用python时,默认是调用python2.7,这导致很多python3.6的语法报错。所以需要更改python默认软连接
#查看路径python,python3.6路径
which python python3.6
/usr/bin/python
/usr/bin/python3.6
sudo rm /usr/bin/python
sudo rm /usr/bin/python3
#创建python3.6软连接到python&Python3
sudo ln -s /usr/bin/python3.6 /usr/bin/python
sudo ln -s /usr/bin/python3.6 /usr/bin/python3
至此Python3.6环境配置完成。
离线whl包均从rockcip官方源下载,链接如下:http://repo.rock-chips.com/pypi/simple/
可按自己需要下载对应版本的whl包,scipy依赖包若自行在开发板上编译,大概需30分钟左右完成编译,耐心等待即可。
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](https://files.pythonhosted.org/packages/76/04/43153bfdfcf6c9a4c38ecdb971ca9a75b9a791bb69a764d652c359aca504/tensorflow_gpu-1.14.0-cp36-cp36m-manylinux1_x86_64.whl)
[tensorflow_gpu-1.14.0-cp36-cp36m-manylinux1_x86_64.whl](https://files.pythonhosted.org/packages/76/04/43153bfdfcf6c9a4c38ecdb971ca9a75b9a791bb69a764d652c359aca504/tensorflow_gpu-1.14.0-cp36-cp36m-manylinux1_x86_64.whl)
torch-1.5.1-cp36-cp36m-manylinux1_x86_64.whl
(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.
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
>>>
(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
不同平台,RKNN提供的基于不同Python版本的安装包,安装时不同平台对应的依赖关系需要处理好,具体如下:
1.Windows只提供 Python3.6的安装包。
2. MacOS提供 python3.6和 python3.7的安装包。
3. ARM64平台(安装 Debian 9或 10操作系统)提供 Python3.5 (Debain 9)和 Python3.7(Debian10)的安装包。
4. Linux_x64平台提供基于 python3.5和 python3.6的安装包。