nncase
nncase copied to clipboard
nncase 模型转换报错
Describe the bug nncase 2.9模型转换报错
To Reproduce 安装.net7、nncase2.9以及nncase-kpu-2.9,做了一个很小的onnx模型测试,转换模型报错
Expected behavior 模型转换脚本输出:
warn: Nncase.Hosting.PluginLoader[0]
NNCASE_PLUGIN_PATH is not set.
Unhandled exception. System.InvalidOperationException: Handle is not initialized.
at System.Runtime.InteropServices.GCHandle.FromIntPtr(IntPtr value)
at Nncase.Compiler.Interop.CApi.Get[T](IntPtr handle)
at Nncase.Compiler.Interop.CApi.ClrHandleDispose(IntPtr handle)
Aborted
Origin model and code 模型生成代码:
import numpy as np, onnx
from onnx import helper, TensorProto
weight = np.random.randint(-2, 3, size=(4, 3, 3, 3), dtype=np.int8)
bias = np.zeros((4,), dtype=np.int32)
inp = helper.make_tensor_value_info("input", TensorProto.FLOAT, [1, 3, 8, 8])
out = helper.make_tensor_value_info("output", TensorProto.FLOAT, [1, 4, 6, 6])
conv = helper.make_node("Conv", inputs=["input", "w", "b"], outputs=["output"],
kernel_shape=[3, 3])
w_init = helper.make_tensor("w", TensorProto.FLOAT, weight.shape, weight.astype(np.float32).flatten())
b_init = helper.make_tensor("b", TensorProto.FLOAT, bias.shape, bias.astype(np.float32))
graph = helper.make_graph([conv], "tiny_conv", [inp], [out], [w_init, b_init])
model = helper.make_model(graph, opset_imports=[helper.make_operatorsetid("", 13)])
onnx.save(model, "tiny_conv.onnx")
模型转换代码:
import nncase
compile_options = nncase.CompileOptions()
compile_options.target = "k230"
compile_options.dump_ir = False
compiler = nncase.Compiler(compile_options)
import_options = nncase.ImportOptions()
compiler.import_onnx("tiny_conv.onnx", import_options)
compiler.compile()
with open("tiny_conv.kmodel", "wb") as f:
f.write(compiler.get_kmodel())
Environment (please complete the following information):
- OS: [Ubuntu22.04(wsl2)]
- nncase version [2.9]
- DL Framework [onnx 1.20]
Additional context