test model is in my Repo@
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