3.5.5 安装TensorFlow 1.14.0
将下载好的tensorflow-1.14.0-cp37-none-linux_aarch64.whl 放置目录下,安装并编译。(若使用pip3 install tensorflow 会自动安装最新版本的tensorflow包,依赖的numpy包的版本与RKNN要求冲突,故需手动安装)
基于arm的已编译好的各版本tensorflow whl包也可从此地址下载https://github.com/lhelontra/tensorflow-on-arm/releases。
此步骤在编译grpcio时报错,导致无法成功安装tensorflow,具体报错日志如下:
Building wheel for grpcio (setup.py) ... error
ERROR: Command errored out with exit status 1:
raise CompileError(msg)
distutils.errors.CompileError: command 'aarch64-linux-gnu-gcc' failed with exit status 4
----------------------------------------
ERROR: Command errored out with exit status 1: /home/firefly/venv/bin/python3.7 -u -c 'import sys, setuptools, tokenize; ...
此时从清华源下载的gprcio源码包为grpcio-1.36.1.tar.gz,按以往调试经验安装了下列依赖包,grpcio仍然无法编译成功
(venv) firefly@firefly:~/RKNN1.4$ sudo apt-get install gcc
(venv) firefly@firefly:~/RKNN1.4$ sudo apt-get install Cython
(venv) firefly@firefly:~/RKNN1.4$ sudo apt-get install libhdf5-dev
通过查看官方发布的RKNN docker镜像中安装的包版本,发现grpcio版本为1.34.0,故尝试降低grpcio版本,pip3重新安装编译grpcio,具体日志如下:
(venv) firefly@firefly:~/RKNN1.4$ pip3 install grpcio==1.34.0
Building wheels for collected packages: grpcio
Building wheel for grpcio (setup.py) ... done
Created wheel for grpcio:
uccessfully built grpcio
Installing collected packages: grpcio
Successfully installed grpcio-1.34.0
再执行下列命令,重新安装tensorflow即可。
(venv) firefly@firefly:~/RKNN1.6$ pip3 install tensorflow-1.14.0-cp37-none-linux_aarch64.whl
...
Successfully installed absl-py-0.12.0 astor-0.8.1 gast-0.4.0 google-pasta-0.2.0 keras-applications-1.0.8 keras-preprocessing-1.1.2 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 wrapt-1.12.1
3.5.6 安装matplotlib
在测试官方给出的rknn-toolkitexamplesdarknetyolov3路径下的demo时,报如下错误:
raceback (most recent call last):
File "test.py", line 5, in
from matplotlib import gridspec
ModuleNotFoundError: No module named 'matplotlib'
可知需要安装Matplotlib依赖包,官方的docker镜像中,安装的Matplotlib版本为3.0.3,故指定该版本手动安装,但在编译过程中报错,无法成功安装,具体日志如下:
(venv) firefly@firefly:~/RKNN1.4/examples/darknet/yolov3$ pip3 install matplotlib==3.0.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Command errored out with exit status 1:
command: /home/firefly/venv/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-zyrjt7ya/matplotlib_d32c2949086446449427874a51fff411/setup.py'"'"'; __file__='"'"'/tmp/pip-install-zyrjt7ya/matplotlib_d32c2949086446449427874a51fff411/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-v_dy1bs_
Complete output (43 lines):
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [3.0.3]
python: yes [3.7.10 (default, Feb 20 2021, 21:17:23) [GCC
7.5.0]]
platform: yes [linux]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.16.3]
install_requires: yes [handled by setuptools]
libagg: yes [pkg-config information for 'libagg' could not be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h) could not be found. You may need to install the
development package.]
png: yes [version 1.6.34]
qhull: yes [pkg-config information for 'libqhull' could not be found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: no [skipping due to configuration]
toolkits_tests: no [skipping due to configuration]
OPTIONAL BACKEND EXTENSIONS
agg: yes [installing]
tkagg: yes [installing; run-time loading from Python Tcl /
Tk]
macosx: no [Mac OS-X only]
windowing: no [Microsoft Windows only]
]
OPTIONAL PACKAGE DATA
dlls: no [skipping due to configuration]
============================================================================
* The following required packages can not be built:
* freetype
* Try installing freetype with `apt-get install
* libfreetype6-dev` and pkg-config with `apt-get
* install pkg-config`
----------------------------------------
Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement matplotlib==3.0.3
ERROR: No matching distribution found for matplotlib==3.0.3
由The C/C++ header for freetype2 (ft2build.h) could not be found,You may need to install the development package.报错日志可推测,是在开发环境缺少所依赖的freetype包,执行以下命令进行安装,具体日志如下:
sudo apt-get install pkg-config
sudo apt-get install libfreetype6-dev
pip3 install matplotlib==3.0.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
Building wheel for matplotlib (setup.py) ... done
Created wheel for matplotlib: filename=matplotlib-3.0.3-cp37-cp37m-linux_aarch64.whl
Stored in directory: /home/firefly/.cache/pip/wheels/8a/bb/44/9d6804fb3c73fc4f624e76721ed032411f725ac812b070b5b9
Successfully built matplotlib
Installing collected packages: python-dateutil, pyparsing, kiwisolver, cycler, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-3.0.3 pyparsing-2.4.7 python-dateutil-2.8.1
成功安装了Matplotlib,可继续测试官方的yolo v3 demo。
3.5.7 安装PyTorch
因项目暂时用不上PyTorch,故先不安装,可参考下列链接进行编译安装。
四、测试过程
4.1 在python中测试各模块是否正常
venv) firefly@firefly:~/RKNN1.6$ python3
Python 3.7.10 (default, )
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import h5py
>>> h5py.__version__
'2.8.0'
>>> import cv2
>>> import numpy
>>> from rknn.api import RKNN
>>>import tensorflow as tf
>>>tf.__version__
>>>1.14.0
>>>
4.2 运行官方提供的demo,测试RKNN是否安装成功
(venv) firefly@firefly:~/RKNN1.6/examples/tensorflow/ssd_mobilenet_v1$ python3 test.py
Traceback (most recent call last):
File "test.py", line 61, in
... ...
File "/home/firefly/venv/lib/python3.7/site-
packages/tensorflow/contrib/__init__.py", line 31, in
from tensorflow.contrib import cloud
ImportError: cannot import name 'cloud' from 'tensorflow.contrib'
出现报错,将/home/firefly/venv/lib/python3.7/site-packages/tensorflow/contrib/init.py出错那行注释掉即可,并且,在下一句还需缩进,不然会提示以下错误代码:
File "/home/firefly/venv/lib/python3.7/site-packages/tensorflow/contrib/__init__.py", line 33
from tensorflow.contrib import cluster_resolver
^
IndentationError: expected an indented block
测试examplestensorflowssd_mobilenet_v1路径下的demo,发现报错日志:
...
--> Init runtime environment
...
E restore_signals, start_new_session, preexec_fn)
E OSError: [Errno 12] Cannot allocate memory
Init runtime environment failed
此时新开一个终端窗口,top检测导入模型时的系统资源占用情况,具体如下图:
初步判断是CPU和内存不足,导致RKNN初始化运行环境失败,按照官方文档Rockchip_Trouble_Shooting_RKNN_Toolkit_V1.4.0_CN.pdf的方法,对脚本进行修改,将rknn.build(do_quantization=True, dataset=’./dataset.txt’)行,改为rknn.build(do_quantization=False, dataset=’./dataset.txt’)具体如下:
可以输出处理图片结果,但帧率很低,推测可能是安装的tensorflow 1.14.0版本太高,和RKNN的兼容性不够,导致无法成功运行。
tflite下的demo均可运行成功,如下图所示:
4.3 在测试YOLO 官方demo时遇到的问题及解决方法
在运行yolo 官方的测试脚本时,发现一直停留在Downloading yolov3.weights…命令行,参考网上的文章,并查看测试脚本,yolov3.weights,方可进行下一步测试,而由于未知原因一直无法下载,将此链接放入迅雷中将yolov3.weights文件下载至本地,通过Xftpd软件上传至对应路径即可,在PC端测试的结果如下图:
总结
RKNN1.4.0版本 python3.7环境下安装tensorflow1.14.0版本可能还是存在兼容问题,在进行推理时开发板的系统资源不足导致无法运行,后续打算降到RKNN Toolkit 1.3.0版本,python 3.6环境下安装tensorflow 1.11.0版本,基本上可以运行官方提供的各个demo测试脚本。
部署过程中生成的whl包和下载的yolov3.weights文件如有需要可在下面链接自取,因为每个人的开发环境不同,相应的whl包不保证都能正常使用,对应的whl包仅可在RKNN1.4.0,python3.7环境下安装使用。
3.5.5 安装TensorFlow 1.14.0
将下载好的tensorflow-1.14.0-cp37-none-linux_aarch64.whl 放置目录下,安装并编译。(若使用pip3 install tensorflow 会自动安装最新版本的tensorflow包,依赖的numpy包的版本与RKNN要求冲突,故需手动安装)
基于arm的已编译好的各版本tensorflow whl包也可从此地址下载https://github.com/lhelontra/tensorflow-on-arm/releases。
此步骤在编译grpcio时报错,导致无法成功安装tensorflow,具体报错日志如下:
Building wheel for grpcio (setup.py) ... error
ERROR: Command errored out with exit status 1:
raise CompileError(msg)
distutils.errors.CompileError: command 'aarch64-linux-gnu-gcc' failed with exit status 4
----------------------------------------
ERROR: Command errored out with exit status 1: /home/firefly/venv/bin/python3.7 -u -c 'import sys, setuptools, tokenize; ...
此时从清华源下载的gprcio源码包为grpcio-1.36.1.tar.gz,按以往调试经验安装了下列依赖包,grpcio仍然无法编译成功
(venv) firefly@firefly:~/RKNN1.4$ sudo apt-get install gcc
(venv) firefly@firefly:~/RKNN1.4$ sudo apt-get install Cython
(venv) firefly@firefly:~/RKNN1.4$ sudo apt-get install libhdf5-dev
通过查看官方发布的RKNN docker镜像中安装的包版本,发现grpcio版本为1.34.0,故尝试降低grpcio版本,pip3重新安装编译grpcio,具体日志如下:
(venv) firefly@firefly:~/RKNN1.4$ pip3 install grpcio==1.34.0
Building wheels for collected packages: grpcio
Building wheel for grpcio (setup.py) ... done
Created wheel for grpcio:
uccessfully built grpcio
Installing collected packages: grpcio
Successfully installed grpcio-1.34.0
再执行下列命令,重新安装tensorflow即可。
(venv) firefly@firefly:~/RKNN1.6$ pip3 install tensorflow-1.14.0-cp37-none-linux_aarch64.whl
...
Successfully installed absl-py-0.12.0 astor-0.8.1 gast-0.4.0 google-pasta-0.2.0 keras-applications-1.0.8 keras-preprocessing-1.1.2 tensorboard-1.14.0 tensorflow-1.14.0 tensorflow-estimator-1.14.0 termcolor-1.1.0 wrapt-1.12.1
3.5.6 安装matplotlib
在测试官方给出的rknn-toolkitexamplesdarknetyolov3路径下的demo时,报如下错误:
raceback (most recent call last):
File "test.py", line 5, in
from matplotlib import gridspec
ModuleNotFoundError: No module named 'matplotlib'
可知需要安装Matplotlib依赖包,官方的docker镜像中,安装的Matplotlib版本为3.0.3,故指定该版本手动安装,但在编译过程中报错,无法成功安装,具体日志如下:
(venv) firefly@firefly:~/RKNN1.4/examples/darknet/yolov3$ pip3 install matplotlib==3.0.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
ERROR: Command errored out with exit status 1:
command: /home/firefly/venv/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-zyrjt7ya/matplotlib_d32c2949086446449427874a51fff411/setup.py'"'"'; __file__='"'"'/tmp/pip-install-zyrjt7ya/matplotlib_d32c2949086446449427874a51fff411/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /tmp/pip-pip-egg-info-v_dy1bs_
Complete output (43 lines):
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [3.0.3]
python: yes [3.7.10 (default, Feb 20 2021, 21:17:23) [GCC
7.5.0]]
platform: yes [linux]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.16.3]
install_requires: yes [handled by setuptools]
libagg: yes [pkg-config information for 'libagg' could not be found. Using local copy.]
freetype: no [The C/C++ header for freetype2 (ft2build.h) could not be found. You may need to install the
development package.]
png: yes [version 1.6.34]
qhull: yes [pkg-config information for 'libqhull' could not be found. Using local copy.]
OPTIONAL SUBPACKAGES
sample_data: yes [installing]
toolkits: yes [installing]
tests: no [skipping due to configuration]
toolkits_tests: no [skipping due to configuration]
OPTIONAL BACKEND EXTENSIONS
agg: yes [installing]
tkagg: yes [installing; run-time loading from Python Tcl /
Tk]
macosx: no [Mac OS-X only]
windowing: no [Microsoft Windows only]
]
OPTIONAL PACKAGE DATA
dlls: no [skipping due to configuration]
============================================================================
* The following required packages can not be built:
* freetype
* Try installing freetype with `apt-get install
* libfreetype6-dev` and pkg-config with `apt-get
* install pkg-config`
----------------------------------------
Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
ERROR: Could not find a version that satisfies the requirement matplotlib==3.0.3
ERROR: No matching distribution found for matplotlib==3.0.3
由The C/C++ header for freetype2 (ft2build.h) could not be found,You may need to install the development package.报错日志可推测,是在开发环境缺少所依赖的freetype包,执行以下命令进行安装,具体日志如下:
sudo apt-get install pkg-config
sudo apt-get install libfreetype6-dev
pip3 install matplotlib==3.0.3 -i https://pypi.tuna.tsinghua.edu.cn/simple
Building wheel for matplotlib (setup.py) ... done
Created wheel for matplotlib: filename=matplotlib-3.0.3-cp37-cp37m-linux_aarch64.whl
Stored in directory: /home/firefly/.cache/pip/wheels/8a/bb/44/9d6804fb3c73fc4f624e76721ed032411f725ac812b070b5b9
Successfully built matplotlib
Installing collected packages: python-dateutil, pyparsing, kiwisolver, cycler, matplotlib
Successfully installed cycler-0.10.0 kiwisolver-1.3.1 matplotlib-3.0.3 pyparsing-2.4.7 python-dateutil-2.8.1
成功安装了Matplotlib,可继续测试官方的yolo v3 demo。
3.5.7 安装PyTorch
因项目暂时用不上PyTorch,故先不安装,可参考下列链接进行编译安装。
四、测试过程
4.1 在python中测试各模块是否正常
venv) firefly@firefly:~/RKNN1.6$ python3
Python 3.7.10 (default, )
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import h5py
>>> h5py.__version__
'2.8.0'
>>> import cv2
>>> import numpy
>>> from rknn.api import RKNN
>>>import tensorflow as tf
>>>tf.__version__
>>>1.14.0
>>>
4.2 运行官方提供的demo,测试RKNN是否安装成功
(venv) firefly@firefly:~/RKNN1.6/examples/tensorflow/ssd_mobilenet_v1$ python3 test.py
Traceback (most recent call last):
File "test.py", line 61, in
... ...
File "/home/firefly/venv/lib/python3.7/site-
packages/tensorflow/contrib/__init__.py", line 31, in
from tensorflow.contrib import cloud
ImportError: cannot import name 'cloud' from 'tensorflow.contrib'
出现报错,将/home/firefly/venv/lib/python3.7/site-packages/tensorflow/contrib/init.py出错那行注释掉即可,并且,在下一句还需缩进,不然会提示以下错误代码:
File "/home/firefly/venv/lib/python3.7/site-packages/tensorflow/contrib/__init__.py", line 33
from tensorflow.contrib import cluster_resolver
^
IndentationError: expected an indented block
测试examplestensorflowssd_mobilenet_v1路径下的demo,发现报错日志:
...
--> Init runtime environment
...
E restore_signals, start_new_session, preexec_fn)
E OSError: [Errno 12] Cannot allocate memory
Init runtime environment failed
此时新开一个终端窗口,top检测导入模型时的系统资源占用情况,具体如下图:
初步判断是CPU和内存不足,导致RKNN初始化运行环境失败,按照官方文档Rockchip_Trouble_Shooting_RKNN_Toolkit_V1.4.0_CN.pdf的方法,对脚本进行修改,将rknn.build(do_quantization=True, dataset=’./dataset.txt’)行,改为rknn.build(do_quantization=False, dataset=’./dataset.txt’)具体如下:
可以输出处理图片结果,但帧率很低,推测可能是安装的tensorflow 1.14.0版本太高,和RKNN的兼容性不够,导致无法成功运行。
tflite下的demo均可运行成功,如下图所示:
4.3 在测试YOLO 官方demo时遇到的问题及解决方法
在运行yolo 官方的测试脚本时,发现一直停留在Downloading yolov3.weights…命令行,参考网上的文章,并查看测试脚本,yolov3.weights,方可进行下一步测试,而由于未知原因一直无法下载,将此链接放入迅雷中将yolov3.weights文件下载至本地,通过Xftpd软件上传至对应路径即可,在PC端测试的结果如下图:
总结
RKNN1.4.0版本 python3.7环境下安装tensorflow1.14.0版本可能还是存在兼容问题,在进行推理时开发板的系统资源不足导致无法运行,后续打算降到RKNN Toolkit 1.3.0版本,python 3.6环境下安装tensorflow 1.11.0版本,基本上可以运行官方提供的各个demo测试脚本。
部署过程中生成的whl包和下载的yolov3.weights文件如有需要可在下面链接自取,因为每个人的开发环境不同,相应的whl包不保证都能正常使用,对应的whl包仅可在RKNN1.4.0,python3.7环境下安装使用。
举报