djaym7 opened a new issue #17518: MaskRCNN can't export -- solution attached
URL: https://github.com/apache/incubator-mxnet/issues/17518
 
 
   ## Description
   Parameters normalizedperclassboxcenterencoder5_means  and 
normalizedperclassboxcenterencoder5_stds are used in training but not in 
inference. This causes AssertionError while exporting symbol.
   
   ### Error Message
   AssertionError "assert name in aux_names"
   
   ## To Reproduce
   import gluoncv as gcv
   import mxnet as mx
   net = gcv.model_zoo.mask_rcnn_resnet101_v1d_coco(pretrained=True)
   net.hybridize(static_shape=True,static_alloc=True)
   _=net(mx.nd.random.randn(1,3,608,608))
   net.export('instance') #returns error 
   
   ### Steps to reproduce
   RUN the code
   
   
   ## What have you tried to solve it?
   
   1. Save the parameters manually excluding the two mentioned in description.
   2. Generalized function shown below
   
   ## Environment
   mxnet 1.6+
   
   Solution : 
   
   from mxnet.util import is_np_array
   def export_net(model,path)
       sym = net._cached_graph[1]
       sym.save('%s-symbol.json'%path, remove_amp_cast=True)
       arg_names = set(sym.list_arguments())
       aux_names = set(sym.list_auxiliary_states())
       arg_dict = {}
   
       for name, param in net.collect_params().items():
           if name[:-7] in 'normalizedperclassboxcenterencoder': 
               continue
           if name in arg_names:
               arg_dict['arg:%s'%name] = param._reduce()
           else:
               assert name in aux_names
               arg_dict['aux:%s'%name] = param._reduce()
       save_fn = _mx_npx.save if is_np_array() else mx.nd.save
       save_fn('%s-%04d.params'%(path, 0), arg_dict)

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to