{"errMsg":"createInferenceSession:fail create session fail : xnet error:6: Failed to convert ONNX model to XNet modelFailed to convet onnx to xnet\n","errno":2004001}
import os
import onnx
m = onnx.load('/Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec.onnx')
init_names = {}
for i in m.graph.initializer:
init_names[i.name] = i.dims
value_info = {}
for i in m.graph.value_info:
value_info[i.name] = [d.dim_value for d in i.type.tensor_type.shape.dim]
for i in m.graph.input:
value_info[i.name] = [d.dim_value for d in i.type.tensor_type.shape.dim]
value_info.update(init_names)
def wait_for_input():
input('Press Enter to continue...')
def get_node_inputs(n):
nis = []
nia = []
for ni in n.input:
iflen(ni) > 0:
if ni in init_names:
nia.append(ni)
else:
nis.append(ni)
return nis, nia
def cmp_node_attributes(n1, n2):
iflen(n1.attribute) != len(n2.attribute):
returnFalse
na1 = {}
na2 = {}
for i in n1.attribute:
na1[i.name] = (i.type, i.f, i.i, i.s, i.t, i.g, i.floats, i.ints, i.strings, i.tensors, i.graphs)
for i in n2.attribute:
na2[i.name] = (i.type, i.f, i.i, i.s, i.t, i.g, i.floats, i.ints, i.strings, i.tensors, i.graphs)
for n in na1:
if n notin na2:
returnFalseif na1[n] != na2[n]:
returnFalsereturnTruedef same_op(n1, n2):
if n1.op_type != n2.op_type:
returnFalse
nis1, nia1 = get_node_inputs(n1)
nis2, nia2 = get_node_inputs(n2)
iflen(nis1) != len(nis2) orlen(nia1) != len(nia2):
returnFalsefor i inrange(len(nis1)):
if value_info[nis1[i]] != value_info[nis2[i]]:
returnFalsefor i inrange(len(nia1)):
if value_info[nia1[i]] != value_info[nia2[i]]:
returnFalsereturn cmp_node_attributes(n1, n2)
verify_node = []
def already_in_verify_node(n):
for vn in verify_node:
if same_op(n, vn):
returnTruereturnFalsefor n in m.graph.node:
ifnot already_in_verify_node(n):
verify_node.append(n)
print(len(verify_node))
# tt_names = [# "Conv_631",# "BatchNormalization_1318",# "Relu_1319",# "Conv_1337",# ]for n in verify_node:
# print(n.name)## if n.name not in tt_names:# continue
node_inputs = []
for ni in n.input:
if ni notin init_names andlen(ni) > 0:
node_inputs.append(ni)
onnx.utils.extract_model(
'/Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec.onnx',
'/Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec_tt.onnx',
input_names=node_inputs,
output_names=n.output,
)
os.system('mc cp /Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec_tt.onnx my/xzgj/test/aec_tt.onnx')
wait_for_input()
是否有一些ONNX规范里面不存在的算子,或者有一些非常规网络里面的算子,比如 Conv 的 Kernel 大小超过128
白搞。
你们能否把接口开给 小程序 web 页面里面?
能否输入更为详细的错误信息,好做相应调整
import os import onnx m = onnx.load('/Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec.onnx') init_names = {} for i in m.graph.initializer: init_names[i.name] = i.dims value_info = {} for i in m.graph.value_info: value_info[i.name] = [d.dim_value for d in i.type.tensor_type.shape.dim] for i in m.graph.input: value_info[i.name] = [d.dim_value for d in i.type.tensor_type.shape.dim] value_info.update(init_names) def wait_for_input(): input('Press Enter to continue...') def get_node_inputs(n): nis = [] nia = [] for ni in n.input: if len(ni) > 0: if ni in init_names: nia.append(ni) else: nis.append(ni) return nis, nia def cmp_node_attributes(n1, n2): if len(n1.attribute) != len(n2.attribute): return False na1 = {} na2 = {} for i in n1.attribute: na1[i.name] = (i.type, i.f, i.i, i.s, i.t, i.g, i.floats, i.ints, i.strings, i.tensors, i.graphs) for i in n2.attribute: na2[i.name] = (i.type, i.f, i.i, i.s, i.t, i.g, i.floats, i.ints, i.strings, i.tensors, i.graphs) for n in na1: if n not in na2: return False if na1[n] != na2[n]: return False return True def same_op(n1, n2): if n1.op_type != n2.op_type: return False nis1, nia1 = get_node_inputs(n1) nis2, nia2 = get_node_inputs(n2) if len(nis1) != len(nis2) or len(nia1) != len(nia2): return False for i in range(len(nis1)): if value_info[nis1[i]] != value_info[nis2[i]]: return False for i in range(len(nia1)): if value_info[nia1[i]] != value_info[nia2[i]]: return False return cmp_node_attributes(n1, n2) verify_node = [] def already_in_verify_node(n): for vn in verify_node: if same_op(n, vn): return True return False for n in m.graph.node: if not already_in_verify_node(n): verify_node.append(n) print(len(verify_node)) # tt_names = [ # "Conv_631", # "BatchNormalization_1318", # "Relu_1319", # "Conv_1337", # ] for n in verify_node: # print(n.name) # # if n.name not in tt_names: # continue node_inputs = [] for ni in n.input: if ni not in init_names and len(ni) > 0: node_inputs.append(ni) onnx.utils.extract_model( '/Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec.onnx', '/Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec_tt.onnx', input_names=node_inputs, output_names=n.output, ) os.system('mc cp /Users/rqg/test/fft512_128_MTFAANetV2_mini_v0.1/aec_tt.onnx my/xzgj/test/aec_tt.onnx') wait_for_input()
如何验证哪个OP 不支持的PYTHON脚本,自己写个 小程序,点下从http 上下载加载验证。
我是手动一个一个验证的 150多种op case
有些 conv相关的 case 会崩溃