Skip to content

Commit

Permalink
update rknn-toolkit2 version to 1.5 (#2278)
Browse files Browse the repository at this point in the history
* update rknn-toolkit2 version to 1.5

* fix lint

* cmake ..

* fix int type

* fix
  • Loading branch information
AllentDan committed Jul 19, 2023
1 parent 0a8cbe2 commit dc6b1f3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion csrc/mmdeploy/net/rknn/rknn_net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ Result<void> 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);
}
Expand Down
4 changes: 2 additions & 2 deletions docs/en/01-how-to-build/rockchip.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 \
Expand Down
15 changes: 10 additions & 5 deletions docs/zh_cn/01-how-to-build/rockchip.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 环境中使用的安装包版本:
Expand All @@ -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 \
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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" \
Expand Down
9 changes: 8 additions & 1 deletion mmdeploy/backend/rknn/onnx2rknn.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit dc6b1f3

Please sign in to comment.