rockchip-linux / rknn-toolkit

BSD 3-Clause "New" or "Revised" License
808 stars 173 forks source link

pytorch efficientnet_b7 转onnx 再转rknn无法进行推理 #403

Open gao-001 opened 11 months ago

gao-001 commented 11 months ago

平台: 1808 tookit 版本: 1.7.3 报错日志: --> Export RKNN model mix/output_rk1808.rknn done --> Load rknn model mix/output_rk1808.rknn --> Init runtime environment librknn_runtime version 1.7.3 (5047ff8 build: 2022-08-13 12:11:22 base: 1131) status error, line: 5451, file:gc_vx_graph_optimization.c python: gc_vx_graph_optimization.c:5451: vxoGraphOptimization_unrollDWConv: Assertion `0' failed. Aborted (core dumped)

onnx模型文件太大无法上传,可用以下代码导出: import torchvision import torch

input_size= (3,299,299) model = torchvision.models.efficientnet_b7() model = torch.jit.script(model) model = torch.jit.freeze(model) save_onnx_path = "test.onnx" dummy_input = torch.randn(1, *input_size, requires_grad=False).to("cpu") torch.onnx.export(model, # model being run dummy_input, # model input (or a tuple for multiple inputs) save_onnx_path , # where to save the model (can be a file or file-like object) export_params=True, # store the trained parameter weights inside the model file opset_version=11, # the ONNX version to export the model to, please ensure at least 11. default 13 do_constant_folding=True, # whether to execute constant folding for optimization input_names = ['input'], # the model's input names output_names = ['output'], # the model's output names verbose=False, )

from onnxsim import simplify as onnx_simplify import onnx

model_simp, check = onnx_simplify(onnx.load(save_onnx_path)) assert check, "Simplified ONNX model could not be validated" path_sim = save_onnx_path.replace(".onnx", "_sim.onnx") onnx.save(model_simp, path_sim) print('ONNX model simplified', path_sim)