onnx/onnx-coreml

IndexError: index -2 is out of bounds for axis 0 with size 0

l0stpenguin opened this issue · 1 comments

❓Question

I am trying to convert the model in MiDaS repository to coreml.

So i first converted the pretrained pytorch model to onnx using this script:
https://gist.github.com/l0stpenguin/ea52c28eb54288a61f21af48ceccd24d

Here is the graph output generated:
https://gist.github.com/l0stpenguin/336565ac678cd3e9e5020135f18f0954

I have uploaded the onnx file on Google drive for inspection:
https://drive.google.com/file/d/1fPxzqBzzON-XCJcpgmyJYpDnyc1z7mpz/view?usp=sharing

Then i used onnx_coreml to convert the onnx file using this snippet:

from onnx_coreml import convert 
coreml_model = convert("midas.onnx",minimum_ios_deployment_target='13')
coreml_model.save("midas.mlmodel")

The conversation to coreml fails with this error:
index -2 is out of bounds for axis 0 with size 0
Here is part of the log:

/Users/lostpenguin/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint8 = np.dtype([("qint8", np.int8, 1)])
/Users/lostpenguin/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/Users/lostpenguin/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint16 = np.dtype([("qint16", np.int16, 1)])
/Users/lostpenguin/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/Users/lostpenguin/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  _np_qint32 = np.dtype([("qint32", np.int32, 1)])
/Users/lostpenguin/Library/Python/3.7/lib/python/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
  np_resource = np.dtype([("resource", np.ubyte, 1)])
1/480: Converting Node Type Conv
2/480: Converting Node Type BatchNormalization
3/480: Converting Node Type Relu
4/480: Converting Node Type MaxPool
5/480: Converting Node Type Conv
61/480: Converting Node Type Mul
.
.
.
.
362/480: Converting Node Type Cast
363/480: Converting Node Type Floor
364/480: Converting Node Type Unsqueeze
365/480: Converting Node Type Unsqueeze
366/480: Converting Node Type Concat
367/480: Converting Node Type Cast
368/480: Converting Node Type Concat
369/480: Converting Node Type Resize
Traceback (most recent call last):
  File "tocoreml.py", line 2, in <module>
    coreml_model = convert("midas.onnx",minimum_ios_deployment_target='13')
  File "/usr/local/lib/python3.7/site-packages/onnx_coreml/converter.py", line 626, in convert
    _convert_node_nd(builder, node, graph, err)
  File "/usr/local/lib/python3.7/site-packages/onnx_coreml/_operators_nd.py", line 2390, in _convert_node_nd
    return converter_fn(builder, node, graph, err)
  File "/usr/local/lib/python3.7/site-packages/onnx_coreml/_operators_nd.py", line 1735, in _convert_resize
    scaling_factor_h=scale[-2],
IndexError: index -2 is out of bounds for axis 0 with size 0

System Information

OS: Mac OS 10.14.6
python: 3.7
onnx-coreml: 1.2
coremltools: 3.3
onnx: 1.6.0
numpy: 1.18.2
torch: 1.3.0
torchvision: 0.4.0

How can i fix this issue?

@bhushan23 any ideas?