|
【技术讨论】
使用 rknn-toolkit2,我的 onnx 模型转换 rknn 模型失败
发表于 2023-4-20 11:45:05
浏览:4153
|
回复:6
打印
只看该作者
[复制链接]
楼主
问题描述及复现步骤:
本帖最后由 hhdy 于 2023-4-20 11:45 编辑
转换脚本(Demo中的 onnx 模型可以成功转换):
- import os
- import urllib
- import traceback
- import time
- import sys
- import numpy as np
- from rknn.api import RKNN
- ONNX_MODEL = 'test4.onnx'
- RKNN_MODEL = 'test.rknn'
- if __name__ == '__main__':
- rknn = RKNN(verbose=True)
- # pre-process config
- print('--> Config model')
- rknn.config(target_platform='rk3588', optimization_level=0)
- print('Config model done')
- # Load ONNX model
- print('--> Loading model')
- ret = rknn.load_onnx( model=ONNX_MODEL ) #, inputs=['inputs', 'buffer'], input_size_list=[[514],[27724] ], outputs=['out', 'out_buffer'])
- if ret != 0:
- print('Load model failed!')
- exit(ret)
- print('Loading model done')
- # Build model
- print('--> Building model')
- ret = rknn.build(do_quantization=False)
- if ret != 0:
- print('Build model failed!')
- exit(ret)
- print('Building model done')
- # Export RKNN model
- print('--> Export rknn model')
- ret = rknn.export_rknn(RKNN_MODEL)
- if ret != 0:
- print('Export rknn model failed!')
- exit(ret)
- print('Export rknn model done')
- rknn.release()
复制代码
错误信息:
- W __init__: rknn-toolkit2 version: 1.4.0-22dcfef4
- --> Config model
- Config model done
- --> Loading model
- W load_onnx: The config.mean_values is None, zeros will be set for input 0!
- W load_onnx: The config.std_values is None, ones will be set for input 0!
- W load_onnx: The config.mean_values is None, zeros will be set for input 1!
- W load_onnx: The config.std_values is None, ones will be set for input 1!
- Loading model done
- --> Building model
- E build: Catch exception when building RKNN model!
- E build: Traceback (most recent call last):
- E build: File "rknn/api/ir_graph.py", line 78, in rknn.api.ir_graph.IRGraph.infer_shapes
- E build: File "/home/hhdy/.local/lib/python3.6/site-packages/onnx/shape_inference.py", line 37, in infer_shapes
- E build: inferred_model_str = C.infer_shapes(model_str, check_type, strict_mode)
- E build: onnx.onnx_cpp2py_export.shape_inference.InferenceError: [ShapeInferenceError] (op_type:Reshape, node name: _0_expand1): [ShapeInferenceError] Inferred shape and existing shape differ in dimension 2: (1) vs (5)
- E build: During handling of the above exception, another exception occurred:
- E build: Traceback (most recent call last):
- E build: File "rknn/api/rknn_base.py", line 1546, in rknn.api.rknn_base.RKNNBase.build
- E build: File "rknn/api/graph_optimizer.py", line 1335, in rknn.api.graph_optimizer.GraphOptimizer.fuse_ops
- E build: File "rknn/api/ir_graph.py", line 343, in rknn.api.ir_graph.IRGraph.rebuild
- E build: File "rknn/api/ir_graph.py", line 185, in rknn.api.ir_graph.IRGraph._clean_model
- E build: File "rknn/api/ir_graph.py", line 76, in rknn.api.ir_graph.IRGraph.infer_shapes
- E build: File "rknn/api/ir_graph.py", line 84, in rknn.api.ir_graph.IRGraph.infer_shapes
- E build: File "/home/hhdy/.local/lib/python3.6/site-packages/onnx/shape_inference.py", line 37, in infer_shapes
- E build: inferred_model_str = C.infer_shapes(model_str, check_type, strict_mode)
- E build: onnx.onnx_cpp2py_export.shape_inference.InferenceError: [ShapeInferenceError] (op_type:Reshape, node name: _0_expand1): [ShapeInferenceError] Inferred shape and existing shape differ in dimension 2: (1) vs (5)
- Build model failed!
复制代码
|
|