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/06/21 07:26:29 UTC

[GitHub] [incubator-mxnet] smartwell opened a new issue #15307: from Pytorch model to ONNX model to MXNet model

smartwell opened a new issue #15307: from Pytorch model to ONNX model to MXNet model
URL: https://github.com/apache/incubator-mxnet/issues/15307
 
 
   i try transform pytorch model to mxnet,  here i just test an example,  conv,bn,LRule
   ```
   import mxnet as mx
   import torch
   import torch.nn as t_nn
   import numpy as np
   
   randx = np.random.randint(0, 1, (1, 3, 512, 512))
   
   # creat pytorch model and save to onnx model
   class Baseblock(t_nn.Module):
       def __init__(self, inc, outc, k=3, s=2, p=1, ):
           super(Baseblock, self).__init__()
           self.cnnblock_1 = t_nn.Sequential(
               t_nn.Conv2d(inc, outc, kernel_size=k, stride=s, padding=p),
               t_nn.BatchNorm2d(outc),
               t_nn.LeakyReLU(inplace=True),
           )
       def forward(self, x,):
           cnnout = self.cnnblock_1(x)
           return cnnout
   
   input_ = torch.Tensor(randx)
   t_net = Baseblock(3, 16)
   t_net(input_)
   torch.onnx.export(t_net, input_, 'test.proto', verbose=True)
   
   # mxnet load model
   sym, arg, aux = mx.contrib.onnx.onnx2mx.import_model.import_model("test.proto")
   
   mx.visualization.print_summary(sym)
   
   data_names = ['0']
   ctx = mx.cpu()
   shape = [1, 3, 512, 512]
   mod = mx.mod.Module(symbol=sym, data_names=data_names, context=ctx, label_names=None)
   mod.bind(for_training=False,  data_shapes=[('0', tuple(shape))], label_shapes=None)
   mod.set_params(arg_params=arg, aux_params=aux, allow_missing=True, allow_extra=True)
   
   input_nd = mx.ndarray.array(randx)
   cc = mod.predict(input_nd)
   ```
   
   yes, you can run it successfully. However,  when you visual this net, you will see like this:
   
   ```
   Layer (type)            Output Shape      Param #     Previous Layer                  
   0(null)                                                                                        
   pad0(Pad)                                                                              
   convolution0(Convolution)                                                 
   batchnorm0(BatchNorm)                                       
   leakyrelu0(LeakyReLU)                        
   Total params: 16
   ```
   OP : Pad cames where?  even though i debug i can't find this OP. why i discuss this details, because, TVM doesn't have this OP
   
   
   
   

----------------------------------------------------------------
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