samle code@method 1@succesfull
import mxnet as mx
import os
import numpy as np
def test_lstm():
print 'test@lstm'
ctx = mx.cpu()
file_sym = '/Users/hypergroups/Desktop/wolfram.lstm-symbol.json'
file_nd = '/Users/hypergroups/Desktop/wolfram.lstm-0000.params'
_sym = mx.symbol.load(file_sym)
_nd = mx.nd.load(file_nd)
input_data = np.array([[1, 2]])
print input_data
array = mx.nd.array(input_data)
_nd["Input"] = array
_nd['4.State'] = mx.nd.array([[0, 0, 0, 0, 0]])
_nd['4.CellState'] = mx.nd.array([[0, 0, 0, 0, 0]])
_e = _sym.bind(ctx, _nd)
_out = _e.forward()
prob = _out[0].asnumpy()
prob = np.squeeze(prob)
print 'prob', prob
if __name__ == '__main__':
test_lstm()
I can run above code well.
my model is in mode-jsonl&&model-params
my above code is also in code above
My question is how can I use load_checkpoint method to load my model? or import the model by gluon
sample code@method2
def test_example_lstm():
model_prefix = "/Users/hypergroups/Nutstore/ProjectsOnline/MyProjects/MXNet/Resources/models/models_mx.mma11.3.5.raw/example.lstm"
ctx = mx.cpu()
data_name = "Input"
data_shape = (1, 2)
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)
mod.bind(for_training=False, data_shapes=[('Input',(1,2))],
)
# print 'arg_params', arg_params
# print 'aux_params', aux_params
# mod.set_params(arg_params, aux_params)
#
# input_data = np.array([[1, 2]])
# array = mx.nd.array(input_data)
#
# Batch = namedtuple('Batch', ['data'])
# mod.forward(Batch([array]))
#
# prob = mod.get_outputs()[0].asnumpy()
# prob = np.squeeze(prob)
# print prob
if __name__ == '__main__':
test_example_lstm()
sample code@method3
net=gluon.nn.SymbolBlock.imports(sym,["Input"],param_file=param)