Firefly开源社区

打印 上一主题 下一主题

[技术讨论] 使用 rknn-toolkit2,我的 onnx 模型转换 rknn 模型失败

12

积分

0

威望

0

贡献

技术小白

积分
12

使用 rknn-toolkit2,我的 onnx 模型转换 rknn 模型失败

发表于 2023-4-20 11:45:05      浏览:2419 | 回复:6        打印      只看该作者   [复制链接] 楼主
问题描述及复现步骤:
本帖最后由 hhdy 于 2023-4-20 11:45 编辑

转换脚本(Demo中的 onnx 模型可以成功转换):
  1. import os
  2. import urllib
  3. import traceback
  4. import time
  5. import sys
  6. import numpy as np
  7. from rknn.api import RKNN

  8. ONNX_MODEL = 'test4.onnx'
  9. RKNN_MODEL = 'test.rknn'

  10. if __name__ == '__main__':

  11.     rknn = RKNN(verbose=True)

  12.     # pre-process config
  13.     print('--> Config model')
  14.     rknn.config(target_platform='rk3588', optimization_level=0)
  15.     print('Config model done')

  16.     # Load ONNX model
  17.     print('--> Loading model')
  18.     ret = rknn.load_onnx( model=ONNX_MODEL )   #, inputs=['inputs', 'buffer'], input_size_list=[[514],[27724] ], outputs=['out', 'out_buffer'])  

  19.     if ret != 0:
  20.         print('Load model failed!')
  21.         exit(ret)
  22.     print('Loading model done')

  23.     # Build model
  24.     print('--> Building model')
  25.     ret = rknn.build(do_quantization=False)
  26.     if ret != 0:
  27.         print('Build model failed!')
  28.         exit(ret)
  29.     print('Building model done')

  30.     # Export RKNN model
  31.     print('--> Export rknn model')
  32.     ret = rknn.export_rknn(RKNN_MODEL)
  33.     if ret != 0:
  34.         print('Export rknn model failed!')
  35.         exit(ret)
  36.     print('Export rknn model done')

  37.     rknn.release()
复制代码


错误信息:
  1. W __init__: rknn-toolkit2 version: 1.4.0-22dcfef4
  2. --> Config model
  3. Config model done
  4. --> Loading model
  5. W load_onnx: The config.mean_values is None, zeros will be set for input 0!
  6. W load_onnx: The config.std_values is None, ones will be set for input 0!
  7. W load_onnx: The config.mean_values is None, zeros will be set for input 1!
  8. W load_onnx: The config.std_values is None, ones will be set for input 1!
  9. Loading model done
  10. --> Building model
  11. E build: Catch exception when building RKNN model!
  12. E build: Traceback (most recent call last):
  13. E build:   File "rknn/api/ir_graph.py", line 78, in rknn.api.ir_graph.IRGraph.infer_shapes
  14. E build:   File "/home/hhdy/.local/lib/python3.6/site-packages/onnx/shape_inference.py", line 37, in infer_shapes
  15. E build:     inferred_model_str = C.infer_shapes(model_str, check_type, strict_mode)
  16. 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)
  17. E build: During handling of the above exception, another exception occurred:
  18. E build: Traceback (most recent call last):
  19. E build:   File "rknn/api/rknn_base.py", line 1546, in rknn.api.rknn_base.RKNNBase.build
  20. E build:   File "rknn/api/graph_optimizer.py", line 1335, in rknn.api.graph_optimizer.GraphOptimizer.fuse_ops
  21. E build:   File "rknn/api/ir_graph.py", line 343, in rknn.api.ir_graph.IRGraph.rebuild
  22. E build:   File "rknn/api/ir_graph.py", line 185, in rknn.api.ir_graph.IRGraph._clean_model
  23. E build:   File "rknn/api/ir_graph.py", line 76, in rknn.api.ir_graph.IRGraph.infer_shapes
  24. E build:   File "rknn/api/ir_graph.py", line 84, in rknn.api.ir_graph.IRGraph.infer_shapes
  25. E build:   File "/home/hhdy/.local/lib/python3.6/site-packages/onnx/shape_inference.py", line 37, in infer_shapes
  26. E build:     inferred_model_str = C.infer_shapes(model_str, check_type, strict_mode)
  27. 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)
  28. Build model failed!
复制代码



错误消息+日志.txt

32.23 KB, 下载次数: 1

回复

使用道具 举报

12

积分

0

威望

0

贡献

技术小白

积分
12
发表于 2023-4-20 11:46:27        只看该作者  沙发
如果解决问题, 需要 我的模型, 也可以提供
回复

使用道具 举报

1万

积分

14

威望

13

贡献

管理员

Rank: 9Rank: 9Rank: 9

积分
11139

优秀版主

发表于 2023-4-20 16:11:18        只看该作者  板凳
提供一下模型
回复

使用道具 举报

12

积分

0

威望

0

贡献

技术小白

积分
12
发表于 2023-4-21 09:52:23        只看该作者  地板
模型

gateconvnet.pt.sim.onnx

2.61 MB, 下载次数: 1

回复

使用道具 举报

12

积分

0

威望

0

贡献

技术小白

积分
12
发表于 2023-4-21 11:15:49        只看该作者  5#

大神  模型发出来了。 你看下
回复

使用道具 举报

12

积分

0

威望

0

贡献

技术小白

积分
12
发表于 2023-4-21 19:15:19        只看该作者  6#
本帖最后由 hhdy 于 2023-4-21 20:01 编辑

+++++
回复

使用道具 举报

4

积分

0

威望

0

贡献

吃瓜的群众

积分
4
发表于 2023-7-24 15:41:50        只看该作者  7#
问题解决了么?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

友情链接 : 爱板网 电子发烧友论坛 云汉电子社区 粤ICP备14022046号-2
快速回复 返回顶部 返回列表