Firefly开源社区

标题: RV1126 安装 RKNN Toolkit Lite 的方法 [打印本页]

作者: 799959745    时间: 2021-6-24 15:57
标题: RV1126 安装 RKNN Toolkit Lite 的方法
本帖最后由 板蓝根 于 2021-6-25 10:31 编辑

RKNN Toolkit Lite 的文件目录在 SDK/external/rknn-toolkit/rknn-toolkit-lite/rknn-toolkit-lite-v1.7.0.dev_0cfb22
或者直接使用 git 拉取代码:git clone https://gitlab.com/firefly-linux/external/rknn-toolkit.git -b rv1126_rv1109/firefly

测试环境使用 RV1126 主机。文件系统是 Firefly Debian10。以下操作均 RV112 上执行。

Firefly Debian10 固件 RKNN Toolkit Lite 安装步骤:

一、 安装依赖 numpy / psutils / ruamel.yaml
# 如果没有装 pip3 ,请先用 sudo apt-get update && sudo apt-get install python3-pip 装下
pip3 install numpy==1.16.3
pip3 install psutil==5.6.2
pip3 install ruamel.yaml==0.15.81

二、 安装 opencv-python 。用 pip3 安装会一直失败,所以直接在网上下载包。
# 先装以下依赖, wget 用到的两个 deb 包已经放在 rknn-toolkit-lite-v1.7.0.dev_0cfb22/requires/ 目录下
sudo apt-get install multiarch-support
wget http://security.debian.org/debian-security/pool/updates/main/j/jasper/libjasper1_1.900.1-debian1-2.4+deb8u6_armhf.deb
sudo dpkg -i libjasper1_1.900.1-debian1-2.4+deb8u6_armhf.deb
wget http://security.debian.org/debian-security/pool/updates/main/j/jasper/libjasper-dev_1.900.1-debian1-2.4+deb8u6_armhf.deb
sudo dpkg -i libjasper-dev_1.900.1-debian1-2.4+deb8u6_armhf.deb
sudo apt-get install libhdf5-dev
sudo apt-get install libatlas-base-dev
sudo apt-get install libqtgui4
sudo apt-get install libqt4-test
pip3 install rknn-toolkit-lite-v1.7.0.dev_0cfb22/requires/opencv_python-4.0.1.24-cp37-cp37m-linux_armv7l.whl

三、安装 RKNN Toolkit Lite
# 使用以下命令安装RKNN Toolkit Lite
pip3 install rknn-toolkit-lite-v1.7.0.dev_0cfb22/packages/rknn_toolkit_lite-1.7.0.dev_0cfb22-cp37-cp37m-linux_armv7l.whl

四、跑 example
cd rknn-toolkit-lite-v1.7.0.dev_0cfb22/examples-lite/inference_with_lite
python3 test.py


结果输出如下:
# 结果输出如下:
root@firefly:/home/firefly/rknn-toolkit-lite-v1.7.0.dev_0cfb22/examples-lite/inference_with_lite# python3 test.py
--> list devices:
*************************
None devices connected.
*************************
done
--> query support target platform
**************************************************
Target platforms filled in RKNN model:         ['RV1109']
Target platforms supported by this RKNN model: ['RK1109', 'RK1126', 'RV1109', 'RV1126']
**************************************************
done
--> Load RKNN model
done
--> Init runtime environment
done
--> get sdk version:
==============================================
RKNN VERSION:
  API: librknn_runtime version 1.6.0 (6523e57 build: 2021-01-15 15:56:31 base: 1126)
  DRV: 6.4.3.5.293908
==============================================

done
--> Running model
resnet18
-----TOP 5-----
[812]: 0.9993900656700134
[404]: 0.0004593880439642817
[657 833]: 2.9284517950145528e-05
[657 833]: 2.9284517950145528e-05
[895]: 1.850890475907363e-05

done



作者: 板蓝根    时间: 2021-6-25 10:32
点赞!
作者: 3d_yl    时间: 2021-7-6 10:21
为啥我的RV1126板子 只能通过172.16网段与主机连接,不能直接上网,安装python环境很麻烦啊
作者: 板蓝根    时间: 2021-7-10 14:11
3d_yl 发表于 2021-7-6 10:21
为啥我的RV1126板子 只能通过172.16网段与主机连接,不能直接上网,安装python环境很麻烦啊

你确定你刷的是 debian10 固件?
作者: 799959745    时间: 2021-7-15 10:48
板蓝根 发表于 2021-6-25 10:32
点赞!

你买的板子是型号是 CORE-1126-JD4 吗?
作者: 板蓝根    时间: 2021-7-15 10:59
799959745 发表于 2021-7-15 10:48
你买的板子是型号是 CORE-1126-JD4 吗?

Debian10 适配的是 CORE-1126-JD4 / CORE-1109-JD4
作者: liu12111    时间: 2021-11-16 21:32
本帖最后由 liu12111 于 2021-11-16 22:46 编辑

板子为core-1126-jd4。镜像为官方2021年4月19号的build镜像搭配debian10的三个文件。
按照上面方法装的环境,跑example。报错如下:firefly@firefly:/opt/rknn-toolkit-lite/rknn-toolkit-lite-v1.7.0.dev_0cfb22/examp
les-lite/inference_with_lite$ python3 test.py
--> list devices:
*************************
None devices connected.
*************************
done
--> query support target platform
**************************************************
Target platforms filled in RKNN model:         ['RV1109']
Target platforms supported by this RKNN model: ['RK1109', 'RK1126', 'RV1109', 'RV1126']
**************************************************
done
--> Load RKNN model
done
--> Init runtime environment
[     1] Failed to open device: No such file or directory, Try again...
[     2] Failed to open device: No such file or directory, Try again...
[     3] Failed to open device: No such file or directory, Try again...
[     4] Failed to open device: No such file or directory, Try again...

[     5] _OpenDevice(1086): FATAL: Failed to open device, errno=No such file or directory.


作者: 799959745    时间: 2021-11-17 10:59
跑 rknn 必须使用 sudo 管理员权限
作者: 东逝之水    时间: 2022-4-10 21:27
请问,rv1126 对yolov3进行模型预测,能实现视频实时效果吗?最高能到多少帧。
作者: 799959745    时间: 2022-4-11 10:45
东逝之水 发表于 2022-4-10 21:27
请问,rv1126 对yolov3进行模型预测,能实现视频实时效果吗?最高能到多少帧。

没有试过
作者: 东逝之水    时间: 2022-4-11 10:49
799959745 发表于 2022-4-11 10:45
没有试过

那用什么算法能达到视频实时效果,有试过吗?
作者: 799959745    时间: 2022-4-12 16:40
东逝之水 发表于 2022-4-11 10:49
那用什么算法能达到视频实时效果,有试过吗?

没有试过,需要自行尝试研发
作者: music1913    时间: 2022-5-21 14:03
liu12111 发表于 2021-11-16 21:32
板子为core-1126-jd4。镜像为官方2021年4月19号的build镜像搭配debian10的三个文件。
按照上面方法装的环 ...

请问你刷的是这个镜像吗?从官方百度云盘下载后的路径是:AIO-RV1126(1109)-JD4\Debian10\debian10_2021_0429_1902\debian10\
里面就3个文件:



但我看到刷固件工具中需要指定以下这么多个文件,这个怎么选择与上述3个文件对应呢?




作者: flamebox    时间: 2022-6-21 12:27
liu12111 发表于 2021-11-16 21:32
板子为core-1126-jd4。镜像为官方2021年4月19号的build镜像搭配debian10的三个文件。
按照上面方法装的环 ...

我一样遇到这个问题。原因是跑这个rknn真只能在root用户下跑。所以所有的pip3安装必须先切换到root用户下进行。。。然后就没有问题了。

这家的文档的水平真不敢恭维,惜字如金。他们的目标对象应该只是做底层的资深嵌入式工程师。想拿来玩和只想快速在上面做应用的小白就不要折腾它了。。。
作者: liuyu220803    时间: 2022-8-25 17:36
这家的文档的水平真不敢恭维,惜字如金。他们的目标对象应该只是做底层的资深嵌入式工程师。

说的太对了
作者: jieke@yiqisoft    时间: 2023-2-3 12:43
  1. --> Load RKNN model
  2. done
  3. --> Init runtime environment
  4. E Catch exception when init runtime!
  5. E Traceback (most recent call last):
  6.   File "/usr/local/lib/python3.7/dist-packages/rknnlite/api/rknn_lite.py", line 144, in init_runtime
  7.     async_mode=async_mode, rknn2precompile=rknn2precompile)
  8.   File "rknnlite/api/rknn_runtime.py", line 292, in rknnlite.api.rknn_runtime.RKNNRuntime.__init__
  9.   File "rknnlite/api/rknn_runtime.py", line 491, in rknnlite.api.rknn_runtime.RKNNRuntime._load_library
  10.   File "rknnlite/api/rknn_runtime.py", line 486, in rknnlite.api.rknn_runtime.RKNNRuntime._get_rknn_api_lib_path
  11. Exception: Unsupported run platform: Linux armv7l

  12. Init runtime environment failed
复制代码


我这里提示 不支持 armv7l ,怎么回事?
作者: jieke@yiqisoft    时间: 2023-2-3 18:14
  1. root@439f7c3e208f:/opt/devel/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite# python3 test.py
  2. --> Load RKNN model
  3. done
  4. --> Init runtime environment
  5. librknn_runtime version 1.7.1 (97198ce build: 2021-11-24 09:32:17 base: 1131)
  6. done
  7. --> Running model
  8. resnet18
  9. -----TOP 5-----
  10. [812]: 0.9993900656700134
  11. [404]: 0.0004593880439642817
  12. [657 833]: 2.9284517950145528e-05
  13. [657 833]: 2.9284517950145528e-05
  14. [895]: 1.850890475907363e-05

  15. done
复制代码


终于,在docker下,成功跑通,不过,这个运行速度好像很慢很慢。
作者: jieke@yiqisoft    时间: 2023-2-3 18:58
1. Dockerfile:

  1. FROM debian:buster

  2. RUN apt update
  3. RUN apt install python3-opencv git python3-pip -y

  4. RUN /usr/bin/python3 -m pip install --upgrade pip

  5. COPY ./rknn_toolkit_lite-1.7.1-cp37-cp37m-linux_armv7l.whl /tmp

  6. RUN pip3 install /tmp/rknn_toolkit_lite-1.7.1-cp37-cp37m-linux_armv7l.whl

  7. RUN rm -rf /tmp/rknn_toolkit_lite-1.7.1-cp37-cp37m-linux_armv7l.whl

  8. RUN apt install libdrm-dev -y

  9. COPY ./lib/* /usr/lib
复制代码


2. copy rknpu driver files to build directory:

  1. cp rknpu/drivers/linux-armhf-puma/usr/lib .
  2. cp rknn-toolkit/rknn-toolkit-lite/packages/rknn_toolkit_lite-1.7.1-cp37-cp37m-linux_armv7l.whl .
复制代码


3. docker build and run command:

  1. docker build . -t debian10-python3-opencv:latest
  2. docker run -it --rm --name rv1126 --privileged -v /dev/dri/card0:/dev/dri/card0 -v /opt/devel/:/opt/devel debian10-python3-opencv /bin/bash
复制代码


作者: jieke@yiqisoft    时间: 2023-2-4 21:00
这是运行的效果:耗时25秒左右。
real        0m24.747s
user       0m24.492s
sys         0m0.705s
  1. root@743eeb4de2f7:/opt/devel/rknn-toolkit/rknn-toolkit-lite/examples/inference_with_lite# time python3 test.py
  2. --> list devices:
  3. *************************
  4. None devices connected.
  5. *************************
  6. done
  7. --> query support target platform
  8. **************************************************
  9. Target platforms filled in RKNN model:         ['RV1109']
  10. Target platforms supported by this RKNN model: ['RV1109', 'RK1109', 'RV1126', 'RK1126']
  11. **************************************************
  12. done
  13. --> Load RKNN model
  14. done
  15. --> Init runtime environment
  16. librknn_runtime version 1.7.1 (97198ce build: 2021-11-24 09:32:17 base: 1131)
  17. done
  18. --> get sdk version:
  19. ==============================================
  20. RKNN VERSION:
  21.   API: librknn_runtime version 1.7.1 (97198ce build: 2021-11-24 09:32:17 base: 1131)
  22.   DRV: 6.4.6.5.351518
  23. ==============================================

  24. done
  25. --> Running model
  26. resnet18
  27. -----TOP 5-----
  28. [812]: 0.9993900656700134
  29. [404]: 0.0004593880439642817
  30. [657 833]: 2.9284517950145528e-05
  31. [657 833]: 2.9284517950145528e-05
  32. [895]: 1.850890475907363e-05

  33. done
复制代码

作者: jieke@yiqisoft    时间: 2023-2-4 21:05
同样的环境,跑 C 版本的demo,耗时只需要 0.7秒。差距大了

  1. root@743eeb4de2f7:/opt/devel/yolov5_detect_demo_release# time ./yolov5_detect_demo
  2. librknn_runtime version 1.7.1 (97198ce build: 2021-11-24 09:32:17 base: 1131)
  3. time_use is 126.657997
  4. car @ (258 909 583 1109) 0.841335
  5. car @ (534 736 739 859) 0.831931
  6. bus  @ (930 413 1206 531) 0.818415
  7. car @ (1766 578 1872 657) 0.810571
  8. car @ (721 760 927 921) 0.792803
  9. car @ (563 950 801 1115) 0.770443
  10. car @ (956 809 1138 968) 0.752421
  11. car @ (801 991 1071 1115) 0.719339
  12. person @ (1431 619 1461 686) 0.699269
  13. car @ (0 495 137 598) 0.674166
  14. person @ (1819 651 1863 739) 0.639357
  15. car @ (1208 431 1261 472) 0.632317
  16. car @ (862 402 936 469) 0.618040
  17. car @ (1781 446 1845 504) 0.575020
  18. person @ (1543 677 1590 771) 0.561444
  19. person @ (375 481 399 528) 0.538842
  20. car @ (1684 431 1737 478) 0.505462
  21. motorbike  @ (1508 748 1564 836) 0.475376
  22. person @ (1200 589 1232 677) 0.471330
  23. car @ (1839 451 1878 501) 0.438286
  24. traffic light @ (1587 548 1608 607) 0.411564
  25. car @ (715 390 777 425) 0.394160
  26. truck  @ (472 451 745 557) 0.392559
  27. car @ (812 416 874 469) 0.387184
  28. car @ (466 425 575 481) 0.358873
  29. car @ (1622 410 1669 454) 0.350634
  30. car @ (1481 331 1578 378) 0.340664
  31. car @ (1191 357 1235 404) 0.321087

  32. real        0m0.690s
  33. user        0m0.454s
  34. sys        0m0.191s
复制代码

作者: wx__kvi1e9    时间: 2023-2-21 11:17
您好,请问一下,pytorch模型要怎么样转化为RKNN模型,有没有具体的实施方法。(纯小白完全不懂)
作者: 799959745    时间: 2023-2-21 17:43
wx__kvi1e9 发表于 2023-2-21 11:17
您好,请问一下,pytorch模型要怎么样转化为RKNN模型,有没有具体的实施方法。(纯小白完全不懂)

看下rk相关文档吧。这方面没有深度研究过。
作者: jieke@yiqisoft    时间: 2023-3-3 11:41
wx__kvi1e9 发表于 2023-2-21 11:17
您好,请问一下,pytorch模型要怎么样转化为RKNN模型,有没有具体的实施方法。(纯小白完全不懂)

用 RKNN API,就可以直接转换。参考这里的代码:https://github.com/rockchip-linu ... amples/rknn_convert
作者: wx__kvi1e9    时间: 2023-3-4 16:39
799959745 发表于 2023-2-21 17:43
看下rk相关文档吧。这方面没有深度研究过。

您好,今天在测试pytorch模型转化为RKNN模型运行时出现报错:
jiangzhaowei@ubuntu:~/work/rknn-toolkit/examples/pytorch/resnet18$ python test.py
2023-03-04 00:30:45.664500: W tensorflow/stream_executor/platform/default/dso_loader.cc:64] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory; LD_LIBRARY_PATH: /home/jiangzhaowei/.local/lib/python3.6/site-packages/cv2/../../lib:
--> config model
done
--> Loading model
./resnet18.pt ********************
E Catch exception when loading pytorch model: ./resnet18.pt!
E Traceback (most recent call last):
E   File "rknn/api/rknn_base.py", line 339, in rknn.api.rknn_base.RKNNBase.load_pytorch
E   File "rknn/base/RKNNlib/RK_nn.py", line 146, in rknn.base.RKNNlib.RK_nn.RKnn.load_pytorch
E   File "rknn/base/RKNNlib/app/importer/import_pytorch.py", line 128, in rknn.base.RKNNlib.app.importer.import_pytorch.ImportPytorch.run
E   File "rknn/base/RKNNlib/converter/convert_pytorch_new.py", line 2250, in rknn.base.RKNNlib.converter.convert_pytorch_new.convert_pytorch.load
E   File "rknn/base/RKNNlib/converter/convert_pytorch_new.py", line 2055, in rknn.base.RKNNlib.converter.convert_pytorch_new.PyTorchOpConverter.report_missing_conversion
E NotImplementedError: The following operators are not implemented: ['aten::linear']
Load pytorch model failed!

这是什么原因呢?





欢迎光临 Firefly开源社区 (https://dev.t-firefly.com/) Powered by Discuz! X3.1