Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I want you to help me! ! The MXNet-Gluon network got an error. #208

Closed
ys-yamashita opened this issue May 23, 2018 · 9 comments
Closed

I want you to help me! ! The MXNet-Gluon network got an error. #208

ys-yamashita opened this issue May 23, 2018 · 9 comments

Comments

@ys-yamashita
Copy link

Platform: Ubuntu 16.04.4 LTS
Python version: Python 3.6.4(Anaconda)
Source framework with version : MXNet 1.0.0 (GPU)
Destination framework with version: IR (I will convert it to Tensorflow code after that)
Pre-trained model path: https://github.com/ys-yamashita/mxnet_gluon
Running scripts: MMdnn/mmdnn/conversion/_script/convertToIR.py


  • I will try to convert the model created by MXNet (Gluon) to IR, resulting in an error.

Traceback (most recent call last):
File "/root/anaconda3/envs/vision_pose/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 185, in
_main()
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 180, in _main
ret = _convert(args)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 98, in _convert
parser.run(args.dstPath)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/common/DataStructure/parser.py", line 22, in run
self.gen_IR()
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 264, in gen_IR
func(current_node)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 499, in rename_Convolution
weight = self.weight_data.get(source_node.name + "_weight").asnumpy()
AttributeError: 'NoneType' object has no attribute 'asnumpy'

*The executed command

$ python3 -m mmdnn.conversion._script.convertToIR -f mxnet -n resnet18-stand-json_500-symbol.json -w resnet18-stand-json_500-0000.params -d mxnet_resnext50 --inputShape 3 64 64

The python code that created the model uses Gluon HybridBlocks.
I think that it is probably caused by the fact that the symbol name has the suffix "_fwd" as its origin.

It is reference page of Gluon HybridBlocks
https://gluon.mxnet.io/chapter07_distributed-learning/hybridize.html

Can I convert it to IR?
Help me.

@namizzz
Copy link
Contributor

namizzz commented May 23, 2018

Hi @ys-yamashita ,
yes, you can change all the source_node.name + "_something" to source_node.name.replace("fwd", "something"). I think it can work for the Gluon format MXNet.

@ys-yamashita
Copy link
Author

Thank you for your reply.
All "_fwd" of resnet18-stand-json_500-symbol.json have been replaced with "_something".
However, it will result in an error in the same place.
Is the approach wrong?

Does "source_node.name.replace" need to be inserted somewhere in convertToIR.py?
Is it necessary for Gluon of MXNet?
please tell me.

@namizzz
Copy link
Contributor

namizzz commented May 24, 2018

Hi @ys-yamashita

eg. change weight = self.weight_data.get(source_node.name + "_weight").asnumpy() to weight = self.weight_data.get(source_node.name.replace("fwd", "weight")).asnumpy()

I have tried and got a (32, 3, 3, 3) weight matrix, it's right.

@ys-yamashita
Copy link
Author

Thank you for your advice.

Follow "weight"
"bias" of the rename_Convolution() function
"gamma", " beta", "
running_mean", "
running_var" of the rename_BatchNorm() function
Also edited.
However, it got an error.

File "/root/anaconda3/envs/vision_pose/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 185, in
_main()
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 180, in _main
ret = _convert(args)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 98, in _convert
parser.run(args.dstPath)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/common/DataStructure/parser.py", line 22, in run
self.gen_IR()
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 267, in gen_IR
self.rename_UNKNOWN(current_node)
File "/root/anaconda3/envs/vision_pose/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 379, in rename_UNKNOWN
raise NotImplementedError()
NotImplementedError

An error occurred in the if statement

if source_node.type == "null" and source_node.name != 'label':
else:

source_node.type is confirmed by print () "relu"
source_node.name is "resnet0_residual0_relu0"

"relu" is used within hybrid_foward(MXNet-Gluon)

def hybrid_forward(self, F, x):
    out = F.relu(self.bn1(self.conv1(x)))
    out = self.bn2(self.conv2(out))
    if not self.same_shape:
        x = self.conv3(x)
    return F.relu(out + x)

I do not know what to do. Help me

@namizzz
Copy link
Contributor

namizzz commented May 24, 2018

Yes, you've got this!

You also need to change some code in mxnet_parser:

  1. Add rename_relu and rename_Reshape
def rename_relu(self, source_node):
        self._convert_identity_operation(source_node, new_op="Relu")

def rename_Reshape(self, source_node):
        self.rename_Flatten(source_node)
  1. follow the former way to change other weights and bias

@ys-yamashita
Copy link
Author

Thank you very much. I was able to create an IR. Appreciation

@mifan0208
Copy link

Hello, I have another problem. How did you solve it
Traceback (most recent call last):
File "/usr/local/lib/python3.6/runpy.py", line 193, in _run_module_as_main
"main", mod_spec)
File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/usr/local/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 197, in
_main()
File "/usr/local/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 192, in _main
ret = _convert(args)
File "/usr/local/lib/python3.6/site-packages/mmdnn/conversion/_script/convertToIR.py", line 80, in _convert
parser = MXNetParser(model)
File "/usr/local/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 243, in init
self.model, self.weight_data = MXNetParser._load_model(input_arg[1], input_arg[2])
File "/usr/local/lib/python3.6/site-packages/mmdnn/conversion/mxnet/mxnet_parser.py", line 176, in _load_model
sym, arg_params, aux_params = mx.model.load_checkpoint(weights, int(epoch))
File "/usr/local/lib/python3.6/site-packages/mxnet/model.py", line 420, in load_checkpoint
symbol = sym.load('%s-symbol.json' % prefix)
File "/usr/local/lib/python3.6/site-packages/mxnet/symbol/symbol.py", line 2494, in load
check_call(_LIB.MXSymbolCreateFromFile(c_str(fname), ctypes.byref(handle)))
File "/usr/local/lib/python3.6/site-packages/mxnet/base.py", line 146, in check_call
raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: Cannot find argument 'layout', Possible Arguments:

global_pool : boolean, optional, default=0
Ignore kernel size, do global pooling based on current input feature map.
cudnn_off : boolean, optional, default=0
Turn off cudnn pooling and use MXNet pooling operator.
kernel : Shape(tuple), required
pooling kernel size: (y, x) or (d, y, x)
pool_type : {'avg', 'max', 'sum'}, required
Pooling type to be applied.
pooling_convention : {'full', 'valid'},optional, default='valid'
Pooling convention to be applied.
stride : Shape(tuple), optional, default=[]
stride: for pooling (y, x) or (d, y, x)
pad : Shape(tuple), optional, default=[]
pad for pooling: (y, x) or (d, y, x)
, in operator Pooling(name="pool0_fwd", stride="(1, 1)", pooling_convention="full", pool_type="avg", pad="(0, 0)", layout="NCHW", kernel="(1, 1)", global_pool="True")

@simomagi
Copy link

simomagi commented May 27, 2020

Yes, you've got this!

You also need to change some code in mxnet_parser:

  1. Add rename_relu and rename_Reshape
def rename_relu(self, source_node):
        self._convert_identity_operation(source_node, new_op="Relu")

def rename_Reshape(self, source_node):
        self.rename_Flatten(source_node)
  1. follow the former way to change other weights and bias

Yes, you've got this!

You also need to change some code in mxnet_parser:

  1. Add rename_relu and rename_Reshape
def rename_relu(self, source_node):
        self._convert_identity_operation(source_node, new_op="Relu")

def rename_Reshape(self, source_node):
        self.rename_Flatten(source_node)
  1. follow the former way to change other weights and bias

I have the same issue; I have not understood what is the second step. After adding methods rename_relu, rename_Reshape, what should i do?
My issue is little different. The NotImplementedError is raised but the print statement in the function RENAME_UNKNOWN() says:
"Warning: MXNet Parser has not supported operator clip with name mobilenetv20_features_relu60_relu6"

@XiaoXYe
Copy link
Collaborator

XiaoXYe commented May 28, 2020

Hi @simomagi , MMdnn has not supported the operator 'clip' in mxnet model, we will add this operator in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants