创建rknn虚拟环境 conda create --name=rknn python=3.6.8
激活rknn环境
conda activate rknn
在rknn虚拟环境下,安装深度学习框架,如Tensorflow,Pytorch等
pip install tensorflow==1.14.0 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install torch==1.6.0+cpu torchvision==0.7.0+cpu -f https://download.pytorch.org/whl/torch_stable.html -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install mxnet==1.5.0 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
pip install opencv-python==4.3.0.38 -i https://pypi.douban.com/simple/ pip install
pip install gluoncv -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
点下面链接
Releases · rockchip-linux/rknn-toolkit · GitHub
下载rknn-toolkit-v1.7.3-packages.zip 包
进入刚刚下载的包
cd 下载/rknn-toolkit-v1.7.3-packages/packages
安装rknn_toolkit-1.6.0-cp36-cp36m-win_amd64.whl
pip install rknn_toolkit-1.6.0-cp36-cp36m-win_amd64.whl -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
然后验证是否安装成功:没有报错就ok
python
from rknn.api import RKNN
下载下面2个项目
如下链接下载交叉编译工具:GCC
https://developer.arm.com/-/media/Files/downloads/gnu-a/8.3-2019.03/binrel/gcc-arm-8.3-2019.03-
x86_64-arm-linux-gnueabihf.tar.xz?revision=e09a1c45-0ed3-4a8e-b06b-db3978fd8d56&rev=e09a1c450
ed34a8eb06bdb3978fd8d56&hash=9C4F2E8255CB4D87EABF5769A2E65733
等待下载完成后,手动提取到当前文件夹
进入到rknpu-1.7.3/rknn/rknn_api/examples/rknn_yolov5_demo文件夹下
cd /home/liqian/下载/rknn/rknpu-1.7.3/rknn/rknn_api/examples/rknn_yolov5_demo
编辑build.sh
vi build.sh
把build.sh下的内容全部删除在粘贴下方内容
#!/bin/bash
set -e
# for rk1808 aarch64
#GCC_COMPILER=${RK1808_TOOL_CHAIN}/bin/aarch64-linux-gnu
GCC_COMPILER=/home/liqian/下载/rknn/gcc-arm-8.3-2019.03-x86_64-arm-linux-gnueabihf/bin/arm-linux-gnueabihf
# for rk1806 armhf
# GCC_COMPILER=~/opts/gcc-linaro-6.3.1-2017.05-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf
# for rv1109/rv1126 armhf
# GCC_COMPILER=${RV1109_TOOL_CHAIN}/bin/arm-linux-gnueabihf
ROOT_PWD=$( cd "$( dirname $0 )" && cd -P "$( dirname "$SOURCE" )" && pwd )
# build rockx
BUILD_DIR=${ROOT_PWD}/build
if [[ ! -d "${BUILD_DIR}" ]]; then
mkdir -p ${BUILD_DIR}
fi
cd ${BUILD_DIR}
cmake .. \
-DCMAKE_C_COMPILER=${GCC_COMPILER}-gcc \
-DCMAKE_CXX_COMPILER=${GCC_COMPILER}-g++
make -j4
make install
cd -
cp run_rk180x.sh install/rknn_yolov5_demo/
cp run_rv1109_rv1126.sh install/rknn_yolov5_demo/
运行build.sh脚本
./build.sh
执行成功,会在当前目录生成一个install目录。
一定要用adb线连接板子
把install目录通过adb放到板卡的/userdata下,并修改执行权限chmod 777 -R 文件夹
adb push ./install/ /userdata/
进入板子
adb shell
进入刚刚放进去的文件夹下
cd /userdata/install/rknn_yolov5_demo
在运行下面代码
./rknn_yolov5_demo model/rv1109_rv1126/yolov5s_relu_rv1109_rv1126_out_opt.rknn model/test1.bmp