如果我能在挽救和修复LSTM方面得到一些帮助,我会非常感激的。
我有这个LSTM层-
# LSTM cell
cell = tf.contrib.rnn.LSTMCell(n_hidden)
output, current_state = tf.nn.dynamic_rnn(cell, word_vectors, dtype=tf.float32)
outputs = tf.transpose(output, [1, 0, 2])
last = tf.gather(outputs, int(outputs.get_shape()[0]) - 1)
# Saver function
saver = tf.train.Saver()
saver.save(sess, 'test-model')保护程序保存模型,并允许我保存和恢复LSTM的权重和偏差。但是,我需要恢复这个LSTM层,并为它提供一组新的输入。
为了恢复整个模型,我正在做:
with tf.Session() as sess:
saver = tf.train.import_meta_graph('test-model.meta')
saver.restore(sess, tf.train.latest_checkpoint('./'))非常感谢!
发布于 2017-07-17 23:42:31
您已经在加载模型,因此模型的权重。您所需要做的就是使用get_tensor_by_name从图中获取任何张量,并使用它进行推理。
示例:
with tf.Session() as sess:
saver = tf.train.import_meta_graph('test-model.meta')
saver.restore(sess, tf.train.latest_checkpoint('./'))
# Get the tensors by their variable name
word_vec = = detection_graph.get_tensor_by_name('word_vec:0')
output_tensor = detection_graph.get_tensor_by_name('outputs:0')
sess.run(output_tensor, feed_dict={word_vec: ...}) 在上面的示例中,word_vec和outputs是在创建图形期间分配给张量的名称。确保您指定了名称,以便可以按其名称调用它们。
https://stackoverflow.com/questions/45154459
复制相似问题