mmdeploy icon indicating copy to clipboard operation
mmdeploy copied to clipboard

[Bug] It is recommended onnx opset 12, but your onnx model opset is 11!

Open wentaoliupai opened this issue 2 years ago • 3 comments

Checklist

  • [ ] I have searched related issues but cannot get the expected help.
  • [ ] 2. I have read the FAQ documentation but cannot get the expected help.
  • [ ] 3. The bug has not been fixed in the latest version.

Describe the bug

W init: rknn-toolkit2 version: 1.5.2+b642f30c W load_onnx: It is recommended onnx opset 12, but your onnx model opset is 11! W load_onnx: Model converted from pytorch, 'opset_version' should be set 12 in torch.onnx.export for successful convert! More details can be found in examples/pytorch/resnet18_export_onnx Loading : 100%|████████████████████████████████████████████████| 748/748 [00:00<00:00, 14909.25it/s] I base_optimize ... I base_optimize done. I I fold_constant ... E build: Catch exception when building RKNN model! E build: Traceback (most recent call last): E build: File "rknn/api/rknn_base.py", line 1958, in rknn.api.rknn_base.RKNNBase.build E build: File "rknn/api/graph_optimizer.py", line 1273, in rknn.api.graph_optimizer.GraphOptimizer.fold_constant E build: File "rknn/api/session.py", line 34, in rknn.api.session.Session.init E build: File "rknn/api/session.py", line 130, in rknn.api.session.Session.sess_build E build: File "/home/shiwentao/.local/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 360, in init E build: self._create_inference_session(providers, provider_options, disabled_optimizers) E build: File "/home/shiwentao/.local/lib/python3.8/site-packages/onnxruntime/capi/onnxruntime_inference_collection.py", line 399, in _create_inference_session E build: sess = C.InferenceSession(session_options, self._model_bytes, False, self._read_config_from_model) E build: onnxruntime.capi.onnxruntime_pybind11_state.Fail: [ONNXRuntimeError] : 1 : FAIL : Type Error: Type (tensor(float)) of output arg (3173) of node (Shape_876) does not match expected type (tensor(int64)). W If you can't handle this error, please try updating to the latest version of the toolkit2 and runtime from: https://eyun.baidu.com/s/3eTDMk6Y (Pwd: rknn) Path: RK_NPU_SDK / RK_NPU_SDK_1.X.0 / develop / If the error still exists in the latest version, please collect the corresponding error logs and the model, convert script, and input data that can reproduce the problem, and then submit an issue on: https://redmine.rock-chips.com (Please consult our sales or FAE for the redmine account) 01/18 18:16:53 - mmengine - ERROR - /home/shiwentao/.local/lib/python3.8/site-packages/mmdeploy/backend/rknn/onnx2rknn.py - onnx2rknn - 99 - Build model failed!

Reproduction

python tools/deploy.py configs/mmpose/pose-detection_rknn-int8_static-512x512.py ~/mmpose/configs/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512.py https://download.openmmlab.com/mmpose/v1/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512_ac7c17bf-20221228.pth ~/mmpose/tests/data/coco/000000000785.jpg --work-dir mmdeploy_models/mdt_mmpose --device cpu --log-level INFO --show --dump-info

Environment

python tools/deploy.py configs/mmpose/pose-detection_rknn-int8_static-512x512.py ~/mmpose/configs/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512.py  https://download.openmmlab.com/mmpose/v1/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512_ac7c17bf-20221228.pth ~/mmpose/tests/data/coco/000000000785.jpg --work-dir mmdeploy_models/mdt_mmpose --device cpu --log-level INFO --show --dump-info

Error traceback

python tools/deploy.py configs/mmpose/pose-detection_rknn-int8_static-512x512.py ~/mmpose/configs/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512.py  https://download.openmmlab.com/mmpose/v1/body_2d_keypoint/dekr/coco/dekr_hrnet-w32_8xb10-140e_coco-512x512_ac7c17bf-20221228.pth ~/mmpose/tests/data/coco/000000000785.jpg --work-dir mmdeploy_models/mdt_mmpose --device cpu --log-level INFO --show --dump-info

wentaoliupai avatar Jan 18 '24 10:01 wentaoliupai

我也有类似的错误

错误提示:

Exporting the operator 'aten::einsum' to ONNX opset version 11 is not supported. Support for this operator was added in version 12, try exporting with this version. File "D:\pytorch_proj\openmmlab\export_test.py", line 16, in torch2onnx(img, work_dir, save_file, deploy_cfg, model_cfg, torch.onnx.errors.UnsupportedOperatorError: Exporting the operator 'aten::einsum' to ONNX opset version 11 is not supported. Support for this operator was added in version 12, try exporting with this version.

转换代码

from mmdeploy.apis import torch2onnx from mmdeploy.backend.sdk.export_info import export2SDK img = 'mmdetection-3.3.0/img/001.jpg' work_dir = 'work_dir/onnx/mask2former' save_file = 'end2end.onnx' deploy_cfg = 'mmdeploy-1.3.1/configs/mmdet/instance-seg/instance-seg_onnxruntime_static.py' model_cfg = 'mmdetection-3.3.0/tools/config/mask2former_swin-s-p4-w7-224_8xb2-lsj-500e_coco_dkl.py' model_checkpoint = 'mmdetection-3.3.0/model/epoch_500_swin.pth' device = 'cpu' torch2onnx(img, work_dir, save_file, deploy_cfg, model_cfg, model_checkpoint, device) export2SDK(deploy_cfg, model_cfg, work_dir, pth=model_checkpoint, device=device)

zym198098 avatar Jan 23 '24 07:01 zym198098

可以修改源码mmdeploy-1.3.1\mmdeploy\apis\onnx\export.py;将opset_version=12;强制改为12,程序可以通过。但是还有一些错误

zym198098 avatar Mar 04 '24 02:03 zym198098

可以修改源码mmdeploy-1.3.1\mmdeploy\apis\onnx\export.py;将opset_version=12;强制改为12,程序可以通过。但是还有一些错误

我强制修改后,或许还有报其他错误,不会生成rk模型,你是已经可以生成模型了吗

wentaoliupai avatar Mar 04 '24 03:03 wentaoliupai