问题
I'm trying to convert a pytorch "tiramisu" UNet (from: https://github.com/bfortuner/pytorch_tiramisu) to coreml, via onnx, and I'm getting this error in onnx-coreml's _operators.py
:
TypeError: Error while converting op of type: Concat. Error message: Unsupported axis 1 in input of shape
Any thoughts about how I might work around this? The layers file is here, for reference: https://github.com/bfortuner/pytorch_tiramisu/blob/master/models/layers.py
UPDATE 1: So, digging down further into this, I've noticed that some of my graph.shape_dicts contain keys with no values/shapes: e.g., '422': (1, 324, 2, 4), '423': (1, 324, 2, 4), '424': (1, 12, 2, 4), '425': (1, 48, 2, 4), '426': (), '427': (), '428': (), '429': (), '430': () [...]
I'm really not sure how this is happening, or whether its my original model, onnx, or onnx-coreml that's the problem. But with this in mind, I changed if node.inputs[0] in graph.shape_dict:
to if len(graph.shape_dict[node.inputs[0]]) != 0:
) in _operators.py
. This allows the conversion to complete, though I won't know until I try it whether the model is actually converted correctly...
UPDATE 2: Okay, so the resulting mlmodel fails validation in Xcode with validator error: Layer '427' of type 320 has 1 inputs but expects at least 2.
I'm guessing this is a consequence of (simplistically) ignoring the empty shape_dict values I found in "UPDATE 1" above. But clearly the model is incorrect. Could the error be originating in onnx?
来源:https://stackoverflow.com/questions/51605747/errors-converting-pytorch-unet-tiramisu-into-coreml-via-onnx