You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2019/05/08 08:20:54 UTC
[GitHub] [incubator-mxnet] nicklhy opened a new issue #14916: Failed to
convert pytorch networks with "torch.view()" to mxnet with ONNX
nicklhy opened a new issue #14916: Failed to convert pytorch networks with "torch.view()" to mxnet with ONNX
URL: https://github.com/apache/incubator-mxnet/issues/14916
Hi, there!
It seems that the current mxnet could not convert basic CNN models like alexnet, resnet from pytorch simply because the shape in ONNX is defined as a Tensor rather than attribute (which is mentioned [here](https://github.com/apache/incubator-mxnet/issues/13395#issuecomment-443304545)).
Are there any specific plans of solving this problem ?
Notice that the error could even occur when it is not a dynamic reshape. A simple script to produce is like below
```python
import torch
import torch.nn as nn
import mxnet as mx
from mxnet.contrib import onnx as onnx_mxnet
class A(nn.Module):
def __init__(self):
super(A, self).__init__()
pass
def forward(self, x):
return x.view(-1, 2)
if __name__ == "__main__":
net = A()
x = torch.randn(1, 3, 224, 224)
torch.onnx.export(net, x, 'test_view.onnx', verbose=True)
sym, arg_params, aux_params = onnx_mxnet.import_model('test_view.onnx')
```
Error message is
```
$ test_view_bug.py
graph(%0 : Float(1, 3, 224, 224)) {
%1 : Tensor = onnx::Constant[value=-1 2 [ CPULongType{2} ]](), scope: A
%2 : Float(75264, 2) = onnx::Reshape(%0, %1), scope: A
return (%2);
}
Traceback (most recent call last):
File "test_view_bug.py", line 23, in <module>
sym, arg_params, aux_params = onnx_mxnet.import_model('test_view.onnx')
File "/home/lhy/Documents/Lib/incubator-mxnet/python/mxnet/contrib/onnx/onnx2mx/import_model.py", line 59, in import_model
sym, arg_params, aux_params = graph.from_onnx(model_proto.graph)
File "/home/lhy/Documents/Lib/incubator-mxnet/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py", line 116, in from_onnx
mxnet_sym = self._convert_operator(node_name, op_name, onnx_attr, inputs)
File "/home/lhy/Documents/Lib/incubator-mxnet/python/mxnet/contrib/onnx/onnx2mx/import_onnx.py", line 62, in _convert_operator
op_name, new_attrs, inputs = convert_map[op_name](attrs, inputs, self)
File "/home/lhy/Documents/Lib/incubator-mxnet/python/mxnet/contrib/onnx/onnx2mx/_op_translations.py", line 462, in reshape
reshape_shape = list(proto_obj._params[inputs[1].name].asnumpy())
KeyError: 'identity0'
```
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
With regards,
Apache Git Services