小编Ann*_*naR的帖子

如何恢复LSTM图层

如果我能在保存和恢复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')
Run Code Online (Sandbox Code Playgroud)

保存程序保存模型,并允许我保存和恢复LSTM的权重和偏差.但是,我需要恢复此LSTM图层并为其提供一组新输入.

为了恢复整个模型,我正在做:

with tf.Session() as sess:
    saver = tf.train.import_meta_graph('test-model.meta')
    saver.restore(sess, tf.train.latest_checkpoint('./'))
Run Code Online (Sandbox Code Playgroud)
  1. 我是否可以使用预先训练过的重量和偏差来初始化LSTM细胞?

  2. 如果没有,我该如何恢复此LSTM图层?

非常感谢你!

tensorflow

7
推荐指数
1
解决办法
580
查看次数

InvalidArgumentError:节点具有来自不同帧的输入

我正在玩Tensorflow并遇到这个代码的问题:

def process_tree_tf(matrix, weights, idxs, name=None):

    with tf.name_scope(name, "process_tree", [tree, weights, idxs]).as scope():
         loop_index = tf.sub(tf.shape(matrix)[0], 1)
         loop_vars = loop_index, matrix, idxs, weights

         def loop_condition(loop_idx, *_):
             return tf.greater(loop_idx, 0)

         def loop_body(loop_idx, mat, idxs, weights):
             x = mat[loop_idx]
             w = weights
             bias = tf.Variable(tf.constant(0.1, [2], dtype=tf.float64)) # Here?

             ...
             return loop_idx-1, mat, idxs, weights

         return tf.while_loop(loop_condition, loop_body, loop_vars, name=scope)[1]
Run Code Online (Sandbox Code Playgroud)

我正在用这种方式评估函数:

height = 2
width = 2
nodes = 4
matrix = np.ones((nodes, width+height))
weights = np.ones((width+height, width))/100
idxs = [0,0,1,2]
with …
Run Code Online (Sandbox Code Playgroud)

tensorflow

5
推荐指数
1
解决办法
4212
查看次数

标签 统计

tensorflow ×2