ariwaranosai opened a new issue #10601: load parameters error  with the same 
code exported by HybridBlock
URL: https://github.com/apache/incubator-mxnet/issues/10601
 
 
   Note: Providing complete information in the most concise form is the best 
way to get help. This issue template serves as the checklist for essential 
information to most of the technical issues and bug reports. For non-technical 
issues and feature requests, feel free to present the information in what you 
believe is the best form.
   
   For Q & A and discussion, please start a discussion thread at 
https://discuss.mxnet.io 
   
   ## Description
   
   HybridBlock export don't remove self.prefix in name, but load_params will 
insert_prefix. This is confusing for 
   
   ```python
   net = get_mode()
   # some train step
   net.export(filename)
   
   new_net = get_model()
   new_net.load_params("path to params", ctx=mx.cpu()) // this will raise error 
AssertionError: Parameter XXX is missing in file XXX
   ```
   since prefix will be insert twice during load params.
   
   It would be nice, give a parameter to control whether remove  self.prefix or 
not. 
   
   ## Environment info (Required)
   
   ```
   ----------Python Info----------
   Version      : 3.6.3
   Compiler     : GCC 4.2.1 Compatible Clang 4.0.1 (tags/RELEASE_401/final)
   Build        : ('default', 'Oct  6 2017 12:04:38')
   Arch         : ('64bit', '')
   ------------Pip Info-----------
   Version      : 9.0.1
   Directory    : /Users/feiquan/anaconda3/lib/python3.6/site-packages/pip
   ----------MXNet Info-----------
   
/Users/feiquan/anaconda3/lib/python3.6/site-packages/urllib3/contrib/pyopenssl.py:46:
 DeprecationWarning: OpenSSL.rand is deprecated - you should use os.urandom 
instead
     import OpenSSL.SSL
   Version      : 1.0.0
   Directory    : /Users/feiquan/anaconda3/lib/python3.6/site-packages/mxnet
   Commit Hash   : 25720d0e3c29232a37e2650f3ba3a2454f9367bb
   ----------System Info----------
   Platform     : Darwin-16.7.0-x86_64-i386-64bit
   system       : Darwin
   node         : feiquandeMacBook-Pro.local
   release      : 16.7.0
   version      : Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; 
root:xnu-3789.70.16~2/RELEASE_X86_64
   ----------Hardware Info----------
   machine      : x86_64
   processor    : i386
   b'machdep.cpu.extfeatures: SYSCALL XD 1GBPAGE EM64T LAHF LZCNT PREFETCHW 
RDTSCP TSCI'
   b'machdep.cpu.leaf7_features: SMEP ERMS RDWRFSGS TSC_THREAD_OFFSET BMI1 HLE 
AVX2 BMI2 INVPCID RTM SMAP RDSEED ADX IPT SGX FPU_CSDS MPX CLFSOPT'
   b'machdep.cpu.features: FPU VME DE PSE TSC MSR PAE MCE CX8 APIC SEP MTRR PGE 
MCA CMOV PAT PSE36 CLFSH DS ACPI MMX FXSR SSE SSE2 SS HTT TM PBE SSE3 PCLMULQDQ 
DTES64 MON DSCPL VMX SMX EST TM2 SSSE3 FMA CX16 TPR PDCM SSE4.1 SSE4.2 x2APIC 
MOVBE POPCNT AES PCID XSAVE OSXSAVE SEGLIM64 TSCTMR AVX1.0 RDRAND F16C'
   b'machdep.cpu.brand_string: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz'
   ```
   
   Package used (Python/R/Scala/Julia):
   I'm using Python
   
   ## Error Message:
   Traceback (most recent call last):
     File "/Users/feiquan/Code/work/wai-models/tachikoma/audio/tdcnn_mxnet.py", 
line 126, in <module>
       check_model.load_params("checkpoints/res-0000.params", ctx=mx.cpu())
     File 
"/Users/feiquan/anaconda3/envs/tf1.3/lib/python3.5/site-packages/mxnet/gluon/block.py",
 line 317, in load_params
       self.prefix)
     File 
"/Users/feiquan/anaconda3/envs/tf1.3/lib/python3.5/site-packages/mxnet/gluon/parameter.py",
 line 673, in load
       "Parameter %s is missing in file %s"%(name[lprefix:], filename)
   AssertionError: Parameter batchnorm0_gamma is missing in file 
checkpoints/res-0000.params
   
   ## Minimum reproducible example
   
   ```python
   net = get_mode() # create model by HybridBlock or gluon
   # some train step
   net.export(filename) 
   
   new_net = get_model()
   new_net.load_params("path to params", ctx=mx.cpu()) // this will raise error 
AssertionError: Parameter XXX is missing in file XXX
   ```
   
   ## What have you tried to solve it?
   
   I try to solve it by change HybridBlock's export function in 
`mxnet/gluon/block.py` 
   
   ```python
           for name, param in self.collect_params().items():
               if name in arg_names:
                   name = name[name.startswith(self.prefix) and 
len(self.prefix):]
                   arg_dict['arg:%s'%name] = param._reduce()
               else:
                   assert name in aux_names
                   name = name[name.startswith(self.prefix) and 
len(self.prefix):]
                   arg_dict['aux:%s'%name] = param._reduce()
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to