This repository was archived by the owner on Mar 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
This repository was archived by the owner on Mar 26, 2019. It is now read-only.
MXNetError: Invalid Parameter format for shape expect Shape(tuple) but value='<Symbol identity1>', in operator Reshape(name="", shape="<Symbol identity1>") #50
Copy link
Copy link
Open
Labels
Description
I use the example from
https://github.com/onnx/tutorials/blob/master/tutorials/PytorchCaffe2SuperResolution.ipynb
to export super_resolution.onnx
and run in MXNET , this error occurs
I did run programming with GPU on Jupyter notebook
Error Message(Import model with MXNET)
MXNetErrorTraceback (most recent call last)
<ipython-input-2-330c0ff72e5d> in <module>()
1 import onnx_mxnet
2 from IPython.core.display import display
----> 3 sym, params = onnx_mxnet.import_model('super_resolution.onnx')
/usr/local/lib/python3.6/dist-packages/onnx_mxnet/__init__.py in import_model(model_file)
33 # loads model file and returns ONNX protobuf object
34 model_proto = onnx.load(model_file)
---> 35 sym, params = graph.from_onnx(model_proto.graph)
36 return sym, params
/usr/local/lib/python3.6/dist-packages/onnx_mxnet/import_onnx.py in from_onnx(self, graph)
139 op = self._fix_squeeze(inputs, mx_attr)
140 else:
--> 141 op = new_op(name=node_name, *inputs, **mx_attr)
142
143 node_output = self._fix_outputs(op_name, node.output)
/usr/local/lib/python3.6/dist-packages/mxnet/symbol/register.py in reshape(data, shape, reverse, target_shape, keep_highest, name, attr, out, **kwargs)
/usr/local/lib/python3.6/dist-packages/mxnet/_ctypes/symbol.py in _symbol_creator(handle, args, kwargs, keys, vals, name)
123 c_str_array(keys),
124 c_str_array([str(v) for v in vals]),
--> 125 ctypes.byref(sym_handle)))
126
127 if args and kwargs:
/usr/local/lib/python3.6/dist-packages/mxnet/base.py in check_call(ret)
144 """
145 if ret != 0:
--> 146 raise MXNetError(py_str(_LIB.MXGetLastError()))
147
148
MXNetError: Invalid Parameter format for shape expect Shape(tuple) but value='<Symbol identity1>', in operator Reshape(name="", shape="<Symbol identity1>")
this is my export model code
import io
import numpy as np
from torch import nn
from torch.autograd import Variable
import torch.utils.model_zoo as model_zoo
import torch.onnx
import torch.nn as nn
import torch.nn.init as init
class SuperResolutionNet(nn.Module):
def __init__(self, upscale_factor, inplace=False):
super(SuperResolutionNet, self).__init__()
self.relu = nn.ReLU(inplace=inplace)
self.conv1 = nn.Conv2d(1, 64, (5, 5), (1, 1), (2, 2))
self.conv2 = nn.Conv2d(64, 64, (3, 3), (1, 1), (1, 1))
self.conv3 = nn.Conv2d(64, 32, (3, 3), (1, 1), (1, 1))
self.conv4 = nn.Conv2d(32, upscale_factor ** 2, (3, 3), (1, 1), (1, 1))
self.pixel_shuffle = nn.PixelShuffle(upscale_factor)
self._initialize_weights()
def forward(self, x):
x = self.relu(self.conv1(x))
x = self.relu(self.conv2(x))
x = self.relu(self.conv3(x))
x = self.pixel_shuffle(self.conv4(x))
return x
def _initialize_weights(self):
init.orthogonal(self.conv1.weight, init.calculate_gain('relu'))
init.orthogonal(self.conv2.weight, init.calculate_gain('relu'))
init.orthogonal(self.conv3.weight, init.calculate_gain('relu'))
init.orthogonal(self.conv4.weight)
torch_model = SuperResolutionNet(upscale_factor=3)
model_url = 'https://s3.amazonaws.com/pytorch/test_data/export/superres_epoch100-44c6958e.pth'
batch_size = 1 # just a random number
torch_model.load_state_dict(model_zoo.load_url(model_url))
torch_model.train(False)
x = Variable(torch.randn(batch_size, 1, 224, 224), requires_grad=True)
torch_out = torch.onnx._export(torch_model , x , "super_resolution.onnx" , export_params=True)
this is my import model code
import onnx_mxnet
from IPython.core.display import display
sym, params = onnx_mxnet.import_model('super_resolution.onnx')
my Python Environment
python 3.6.3
apt-get install protobuf-compiler libprotoc-dev
pip install git+https://github.com/onnx/onnx.git@master
and I try to do
pip install onnx-mxnet
pip install Pillow
and
git clone https://github.com/onnx/onnx-mxnet.git
cd onnx-mxnet
sudo python setup.py install
but both of two methods occurred the same error
Could you please advice how to solve out this error
Thank you