From dc6b1f35b8e08398898796a0fcb08b22c89faa89 Mon Sep 17 00:00:00 2001 From: AllentDan <41138331+AllentDan@users.noreply.github.com> Date: Wed, 19 Jul 2023 11:15:06 +0800 Subject: [PATCH] update rknn-toolkit2 version to 1.5 (#2278) * update rknn-toolkit2 version to 1.5 * fix lint * cmake .. * fix int type * fix --- csrc/mmdeploy/net/rknn/rknn_net.cpp | 2 +- docs/en/01-how-to-build/rockchip.md | 4 ++-- docs/zh_cn/01-how-to-build/rockchip.md | 15 ++++++++++----- mmdeploy/backend/rknn/onnx2rknn.py | 9 ++++++++- 4 files changed, 21 insertions(+), 9 deletions(-) diff --git a/csrc/mmdeploy/net/rknn/rknn_net.cpp b/csrc/mmdeploy/net/rknn/rknn_net.cpp index 9e3a58a345..2582bb98c7 100644 --- a/csrc/mmdeploy/net/rknn/rknn_net.cpp +++ b/csrc/mmdeploy/net/rknn/rknn_net.cpp @@ -170,7 +170,7 @@ Result RKNNNet::Init(const Value& args) { MMDEPLOY_ERROR("rknn query 'RKNN_QUERY_INPUT_ATTR' fail! ret: {}", ret); return Status(eFail); } - if (attr.type != RKNN_TENSOR_UINT8) { + if (!(attr.type == RKNN_TENSOR_UINT8 || attr.type == RKNN_TENSOR_INT8)) { MMDEPLOY_ERROR("MMDeploy SDK only supports RKNN-INT8 model"); return Status(eInvalidArgument); } diff --git a/docs/en/01-how-to-build/rockchip.md b/docs/en/01-how-to-build/rockchip.md index c85514b4a5..bb5da8e427 100644 --- a/docs/en/01-how-to-build/rockchip.md +++ b/docs/en/01-how-to-build/rockchip.md @@ -23,7 +23,7 @@ It is recommended to create a virtual environment for the project. 2. Install RKNN python package following [rknn-toolkit2 doc](https://github.com/rockchip-linux/rknn-toolkit2/tree/master/doc) or [rknn-toolkit doc](https://github.com/rockchip-linux/rknn-toolkit/tree/master/doc). When installing rknn python package, it is better to append `--no-deps` after the commands to avoid dependency conflicts. RKNN-Toolkit2 package for example: ``` - pip install packages/rknn_toolkit2-1.2.0_f7bb160f-cp36-cp36m-linux_x86_64.whl --no-deps + pip install packages/rknn_toolkit2-1.4.0_22dcfef4-cp36-cp36m-linux_x86_64.whl --no-deps ``` 3. Install ONNX==1.8.0 before reinstall MMDeploy from source following the [instructions](../01-how-to-build/build_from_source.md). Note that there are conflicts between the pip dependencies of MMDeploy and RKNN. Here is the suggested packages versions for python 3.6: @@ -50,7 +50,7 @@ Example: ```bash python tools/deploy.py \ - configs/mmpretrain/classification_rknn_static.py \ + configs/mmpretrain/classification_rknn-fp16_static-224x224.py \ /mmpretrain_dir/configs/resnet/resnet50_8xb32_in1k.py \ https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_batch256_imagenet_20200708-cfb998bf.pth \ /mmpretrain_dir/demo/demo.JPEG \ diff --git a/docs/zh_cn/01-how-to-build/rockchip.md b/docs/zh_cn/01-how-to-build/rockchip.md index 45cf88b1db..b44e10b8da 100644 --- a/docs/zh_cn/01-how-to-build/rockchip.md +++ b/docs/zh_cn/01-how-to-build/rockchip.md @@ -63,7 +63,7 @@ MMDeploy 支持把模型部署到瑞芯微设备上。已支持的芯片:RV112 2.2 参考表中的安装指南,安装 RKNN python 安装包。建议在安装时,使用选项 `--no-deps`,以避免依赖包的冲突。以 rknn-toolkit2 为例: ``` - pip install packages/rknn_toolkit2-1.2.0_f7bb160f-cp36-cp36m-linux_x86_64.whl --no-deps + pip install packages/rknn_toolkit2-1.4.0_22dcfef4-cp36-cp36m-linux_x86_64.whl --no-deps ``` 2.3 先安装onnx==1.8.0,跟着 [instructions](../01-how-to-build/build_from_source.md),源码安装 MMDeploy。 需要注意的是, MMDeploy 和 RKNN 依赖的安装包间有冲突的内容. 这里提供建议在 python 3.6 环境中使用的安装包版本: @@ -88,7 +88,7 @@ git clone https://github.com/open-mmlab/mmpretrain # 执行转换命令 cd /the/path/of/mmdeploy python tools/deploy.py \ - configs/mmpretrain/classification_rknn_static.py \ + configs/mmpretrain/classification_rknn-fp16_static-224x224.py \ /the/path/of/mmpretrain/configs/resnet/resnet50_8xb32_in1k.py \ https://download.openmmlab.com/mmclassification/v0/resnet/resnet50_batch256_imagenet_20200708-cfb998bf.pth \ /the/path/of/mmpretrain/demo/demo.JPEG \ @@ -130,8 +130,13 @@ git clone https://github.com/open-mmlab/mmdetection # 执行转换命令 python tools/deploy.py \ - configs/mmpretrain/detection_rknn_static.py \ - + configs/mmdet/detection/detection_rknn-int8_static-320x320.py \ + /the/path/of/mmdet/configs/yolov3/yolov3_mobilenetv2_320_300e_coco.py \ + https://download.openmmlab.com/mmdetection/v2.0/yolo/yolov3_mobilenetv2_320_300e_coco/yolov3_mobilenetv2_320_300e_coco_20210719_215349-d18dff72.pth \ + /the/path/of/mmdet/demo/demo.jpg \ + --work-dir mmdeploy_models/mmdet/yolov3 \ + --device cpu \ + --dump-info ``` - RTMDet @@ -299,7 +304,7 @@ export OpenCV_AARCH64_INSTALL_DIR=$(pwd)/install cd /path/to/mmdeploy mkdir -p build && cd build export LD_LIBRARY_PATH=$RKNN_TOOL_CHAIN/lib64:$LD_LIBRARY_PATH -cmake \ +cmake ..\ -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchains/rknpu2-linux-gnu.cmake \ -DMMDEPLOY_BUILD_SDK=ON \ -DMMDEPLOY_TARGET_BACKENDS="rknn" \ diff --git a/mmdeploy/backend/rknn/onnx2rknn.py b/mmdeploy/backend/rknn/onnx2rknn.py index a0d0583567..dead71fa1f 100644 --- a/mmdeploy/backend/rknn/onnx2rknn.py +++ b/mmdeploy/backend/rknn/onnx2rknn.py @@ -2,6 +2,7 @@ from typing import Optional, Union import mmengine +from packaging import version from rknn.api import RKNN from mmdeploy.utils import (get_common_config, get_normalization, @@ -50,10 +51,16 @@ def onnx2rknn(onnx_model: str, onnx_params = get_onnx_config(deploy_cfg) quantization_cfg = get_quantization_config(deploy_cfg) + package_info = rknn_package_info() input_names = onnx_params.get('input_names', None) output_names = onnx_params.get('output_names', None) input_size_list = get_backend_config(deploy_cfg).get( 'input_size_list', None) + # rknn-toolkit 1.5+ can not pass input output info, which is weird + if package_info['name'] == 'rknn-toolkit2' and version.parse( + package_info['version']) > version.parse('1.4'): + input_names, output_names, input_size_list = [None] * 3 + # update norm value if get_rknn_quantization(deploy_cfg) is True and model_cfg is not None: transform = get_normalization(model_cfg) @@ -85,7 +92,7 @@ def onnx2rknn(onnx_model: str, if dataset_file is None: quantization_cfg.update(dict(do_quantization=False)) logger.warning('no dataset passed in, quantization is skipped') - if rknn_package_info()['name'] == 'rknn-toolkit2': + if package_info['name'] == 'rknn-toolkit2': quantization_cfg.pop('pre_compile', None) ret = rknn.build(**quantization_cfg) if ret != 0: