基于mxnet.symbol的基本使用以及模型加载与保存
mxnet基本使用以及模型加载与保存
mxnet.symbolRNN-GRU-LSTM-Bi官网教程
基于mxnet的LSTM实现(mx.rnn.LSTMCell+symbol)
基于mxnet.gluon.rnn的基本使用以及模型加载与保存
LSTM Mxnet Implementation-手写
mxnet.gluon.rnn.LSTM中文教程
mxnet.gluon.rnn.GRU官网教程
模型导出
import mxnet as mx
hidden_size = 128
num_layer = 2
word_emb_dim = 128
seq_len = 64
layer = mx.gluon.rnn.GRU(hidden_size, num_layer, bidirectional=True, )
layer.initialize()
# seq_len = 5 batch_size = 3 input_size = 128
input = mx.nd.random.uniform(shape=(seq_len, 3, word_emb_dim))
# by default zeros are used as begin state
output = layer(input)
# manually specify begin state.
# num_layers = 6 batch_size = 3 num_hidden = 128
h0 = mx.nd.random.uniform(shape=(num_layer*2, 3, hidden_size))
output, hn = layer(input, h0)
# 模型保存
layer.export('model')
# 模型加载
sym = mx.sym.load('model-symbol.json')
mod = mx.mod.Module(symbol=sym, context=mx.cpu(), label_names=None)
mod.bind(data_shapes=[('data', (5, 3, hidden_size))])
mod.load_params('model-0000.params')
print('Load Successfully!')