(1) I try to convert onnx model to mlmodel, but it's error:
Error while converting op of type: BatchNormalization. Error message: provided number axes -1 not supported
Trace
Traceback (most recent call last):
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1741, in
main()
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1735, in main
globals = debugger.run(setup['file'], None, None, is_module)
File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1135, in run
pydev_imports.execfile(file, globals, locals) # execute the script
File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile
exec(compile(contents+"\n", file, 'exec'), glob, loc)
File "/Users/vipkid/PycharmProjects/ai/ai-teacher/apps/landmark_to_image/onnx_to_mlModel.py", line 27, in
minimum_ios_deployment_target='13')
File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/converter.py", line 627, in convert
_convert_node_nd(builder, node, graph, err)
File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/_operators_nd.py", line 2395, in _convert_node_nd
return converter_fn(builder, node, graph, err)
File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/_operators_nd.py", line 349, in _convert_bn
err.unsupported_op_configuration(builder, node, graph, "provided number axes {} not supported".format(rank))
File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/_error_utils.py", line 62, in unsupported_op_configuration
self.rerun_suggestion)
TypeError: Error while converting op of type: BatchNormalization. Error message: provided number axes -1 not supported
Please try converting with higher minimum_ios_deployment_target.
You can also provide custom function/layer to convert the model.
it may be a break at the name of BatchNormalization_31, the input[0] rank name is -1
To Reproduce
If a python script can reproduce the error, please paste the code snippet
(2) convert onnx model to mlmodel code is:
import os
import onnx
from onnx import onnx_pb
from onnx_coreml import convert
existing_inputs = {v.name for v in model.graph.input}
model.graph.input.extend([
onnx.helper.make_tensor_value_info(
name = tensor.name,
elem_type = tensor.data_type,
shape = list(tensor.dims),
)
for tensor in model.graph.initializer
if tensor.name not in existing_inputs
])
🐞Describe the bug
(1) I try to convert onnx model to mlmodel, but it's error: Error while converting op of type: BatchNormalization. Error message: provided number axes -1 not supported
Trace
Traceback (most recent call last): File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1741, in main() File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1735, in main globals = debugger.run(setup['file'], None, None, is_module) File "/Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py", line 1135, in run pydev_imports.execfile(file, globals, locals) # execute the script File "/Applications/PyCharm.app/Contents/helpers/pydev/_pydev_imps/_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "/Users/vipkid/PycharmProjects/ai/ai-teacher/apps/landmark_to_image/onnx_to_mlModel.py", line 27, in minimum_ios_deployment_target='13') File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/converter.py", line 627, in convert _convert_node_nd(builder, node, graph, err) File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/_operators_nd.py", line 2395, in _convert_node_nd return converter_fn(builder, node, graph, err) File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/_operators_nd.py", line 349, in _convert_bn err.unsupported_op_configuration(builder, node, graph, "provided number axes {} not supported".format(rank)) File "/Users/vipkid/anaconda3/lib/python3.7/site-packages/onnx_coreml/_error_utils.py", line 62, in unsupported_op_configuration self.rerun_suggestion) TypeError: Error while converting op of type: BatchNormalization. Error message: provided number axes -1 not supported Please try converting with higher minimum_ios_deployment_target. You can also provide custom function/layer to convert the model.
it may be a break at the name of BatchNormalization_31, the input[0] rank name is -1
To Reproduce
dataset_dir = "./"
model_in = os.path.join(dataset_dir, "model.patched.onnx") model_out = os.path.join(dataset_dir, "vgnet.mlmodel") model_file = open(model_in, 'rb') model_proto = onnx_pb.ModelProto() model_proto.ParseFromString(model_file.read()) print("prepare to convert...") model = onnx.load_model('vgnet.onnx') coreml_model = convert(model_proto, minimum_ios_deployment_target='13')
System environment (please complete the following information):
I had us the following code to convert model:
import onnx import onnx.helper import onnx.shape_inference
model = onnx.load("./vgnet.onnx")
Add graph input for each initializer
existing_inputs = {v.name for v in model.graph.input} model.graph.input.extend([ onnx.helper.make_tensor_value_info( name = tensor.name, elem_type = tensor.data_type, shape = list(tensor.dims), ) for tensor in model.graph.initializer if tensor.name not in existing_inputs ])
Check if it passes shape inference now
onnx.shape_inference.infer_shapes(model)
Save the resulting model
onnx.save(model, "model.patched.onnx")