Simple_bind error when loading model?

test model is in my Repo@

json
params

model={wolfram.lstm.json, wolfram.lstm-0000.params}
script is in {wolfram_v2/wolfram.lstm.py}

code
import mxnet as mx
import numpy as np
model_prefix=’/Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MXNetFinal/1.0/model-wolfram/wolfram.lstm’
# model_prefix=’/home/hypergroups/Nutstore/ProjectsOnline/MyProjects/MXNetFinal/1.0/model-wolfram/wolfram.lstm’

ctx=mx.cpu()
sym, arg_params, aux_params = mx.model.load_checkpoint(model_prefix, 0)
mod = mx.mod.Module(symbol=sym, context=ctx,
                    data_names=['Input'],
                    label_names=None)

arg_params['4.State']=mx.nd.array([[0,0,0,0,0]])
arg_params['4.CellState']=mx.nd.array([[0,0,0,0,0]])

mod.bind(for_training=False, data_shapes=[('Input', (1,2))],
          label_shapes=None)
         # label_shapes=mod._label_shapes)

ErrorInfo:
/Users/hypergroups/anaconda2/bin/python /Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MXNetFinal/1.0/script/wolfram_v2/wolfram.lstm.py
/Users/hypergroups/anaconda2/lib/python2.7/site-packages/h5py/init.py:34: FutureWarning: Conversion of the second argument of issubdtype from float to np.floating is deprecated. In future, it will be treated as np.float64 == np.dtype(float).type.
from ._conv import register_converters as _register_converters
/Users/hypergroups/anaconda2/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py:46: DeprecationWarning: OpenSSL.rand is deprecated - you should use os.urandom instead
import OpenSSL.SSL
[11:06:20] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.0.1. Attempting to upgrade…
[11:06:20] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded!
Traceback (most recent call last):
File “/Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MXNetFinal/1.0/script/wolfram_v2/wolfram.lstm.py”, line 17, in
label_shapes=mod._label_shapes)
File “/Users/hypergroups/anaconda2/lib/python2.7/site-packages/mxnet/module/module.py”, line 430, in bind
state_names=self._state_names)
File “/Users/hypergroups/anaconda2/lib/python2.7/site-packages/mxnet/module/executor_group.py”, line 265, in init
self.bind_exec(data_shapes, label_shapes, shared_group)
File “/Users/hypergroups/anaconda2/lib/python2.7/site-packages/mxnet/module/executor_group.py”, line 361, in bind_exec
shared_group))
File “/Users/hypergroups/anaconda2/lib/python2.7/site-packages/mxnet/module/executor_group.py”, line 639, in _bind_ith_exec
shared_buffer=shared_data_arrays, **input_shapes)
File “/Users/hypergroups/anaconda2/lib/python2.7/site-packages/mxnet/symbol/symbol.py”, line 1519, in simple_bind
raise RuntimeError(error_msg)
RuntimeError: simple_bind error. Arguments:
Input: (1, 2)
[11:06:20] src/executor/graph_executor.cc:456: InferShape pass cannot decide shapes for the following arguments (0s means unknown dimensions). Please consider providing them as inputs:
4.State: ,

Stack trace returned 8 entries:
[bt] (0) 0   libmxnet.so                         0x000000010ecae3b4 libmxnet.so + 21428
[bt] (1) 1   libmxnet.so                         0x000000010ecae16f libmxnet.so + 20847
[bt] (2) 2   libmxnet.so                         0x000000010fd6f3a4 MXNDListFree + 188484
[bt] (3) 3   libmxnet.so                         0x000000010fd7a9a7 MXNDListFree + 235079
[bt] (4) 4   libmxnet.so                         0x000000010fd7e16a MXNDListFree + 249354
[bt] (5) 5   libmxnet.so                         0x000000010fd0e9b0 MXExecutorSimpleBind + 8656
[bt] (6) 6   libffi.6.dylib                      0x000000010e024884 ffi_call_unix64 + 76
[bt] (7) 7   ???                                 0x00007ffee1f51d10 0x0 + 140732689358096



Process finished with exit code 1

the model was trained by Mathematica in MXNet Version 1.0.1
and can be load by MXNet-Python in the another way, show like the following code.

code2
import sys
sys.path.append(’…’)
import numpy as np
import PIL
import os
from myPath import *

if __name__=='__main__':
    ctx=mx.cpu()
    from myPath import *
    file_sym=os.path.join(root_dir, 'model-wolfram/wolfram.lstm-symbol.json')
    file_nd=os.path.join(root_dir, 'model-wolfram/wolfram.lstm-0000.params')

    _sym= mx.symbol.load(file_sym)
    _nd= mx.nd.load(file_nd)

    _nd['4.State']=mx.nd.array([[0,0,0,0,0]])
    _nd['4.CellState']=mx.nd.array([[0,0,0,0,0]])
    input_data=np.array([[1,2]])

    print input_data

    array = mx.nd.array(input_data)

    _nd["Input"] = array
    _e = _sym.bind(ctx, _nd)

    _out = _e.forward()
    prob = _out[0].asnumpy()
    prob = np.squeeze(prob)
    print 'prob', prob
    print 'prob_sort', sorted(prob, reverse=True)
    idx = np.argsort(prob)[::-1]
    print 'top_idx', idx

for reference, question is tracked by this github issue: https://github.com/apache/incubator-mxnet/issues/10998

Copying github answer for reference:

@HyperGroups can you please show or point me to how you export it from Mathematica?
The reason why you have this error is because only models saved using the module API or the .export function of HybridBlock in Gluon can be loaded using the load_checkpoint function.

As of 1.2.1, you can load your model in Gluon using the HybridBlock.imports function:

import mxnet as mx
from mxnet import gluon

net = gluon.nn.SymbolBlock.imports('example-symbol.json',
                                   ['Input'], 
                                   param_file='example-0000.params',
                                   ctx=mx.cpu())

Hi,@ThomasDelteil

Mathematica 11.3 uses 1.0 version of mxnet

But when we I use MXNet 11.3 to import the old model generated by Wolfram Mathematica 11.3 in the post, it gives me
net=gluon.nn.SymbolBlock.imports(sym,[“Input”], param_file=param)

[17:52:40] src/nnvm/legacy_json_util.cc:209: Loading symbol saved by previous version v1.0.1. Attempting to upgrade…
[17:52:40] src/nnvm/legacy_json_util.cc:217: Symbol successfully upgraded!
Traceback (most recent call last):
File “/Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MathematicaMXNet/1.3/model_format_convert.py”, line 16, in
convert(mod_export, sym_,nd_)
File “/Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MathematicaMXNet/1.3/model_format_convert.py”, line 8, in convert
net=gluon.nn.SymbolBlock.imports(sym,[“Input”], param_file=param)
File “/Users/hypergroups/Program/anaconda2/lib/python2.7/site-packages/mxnet/gluon/block.py”, line 1025, in imports
ret.collect_params().load(param_file, ctx=ctx)
File “/Users/hypergroups/Program/anaconda2/lib/python2.7/site-packages/mxnet/gluon/parameter.py”, line 909, in load
name[lprefix:], filename, _brief_print_list(arg_dict.keys()))
AssertionError: Parameter ‘4.State’ is missing in file ‘/Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MathematicaMXNet/model.wolfram.11.3/wolfram.lstm-0000.params’, which contains parameters: ‘4.OutputGateStateWeights’, ‘4.InputGateInputWeights’, ‘5.Biases’, …, ‘4.OutputGateBiases’, ‘4.MemoryGateInputWeights’, ‘4.ForgetGateStateWeights’, ‘4.ForgetGateBiases’. Please make sure source and target networks have the same prefix.