【发布时间】:2017-01-10 20:03:11
【问题描述】:
def biLSTM(data, n_steps):
n_hidden= 24
data = tf.transpose(data, [1, 0, 2])
# Reshape to (n_steps*batch_size, n_input)
data = tf.reshape(data, [-1, 300])
# Split to get a list of 'n_steps' tensors of shape (batch_size, n_input)
data = tf.split(0, n_steps, data)
lstm_fw_cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
# Backward direction cell
lstm_bw_cell = tf.nn.rnn_cell.BasicLSTMCell(n_hidden, forget_bias=1.0)
outputs, _, _ = tf.nn.bidirectional_rnn(lstm_fw_cell, lstm_bw_cell, data, dtype=tf.float32)
return outputs, n_hidden
在我的代码中,我调用此函数两次以创建 2 个双向 LSTM。然后我遇到了重用变量的问题。
ValueError: 变量 lstm/BiRNN_FW/BasicLSTMCell/Linear/Matrix 已经存在,不允许。你的意思是设置reuse=True 变量范围?
为了解决这个问题,我在 with tf.variable_scope('lstm', reuse=True) as scope: 的函数中添加了 LSTM 定义
这导致了一个新问题
ValueError: 变量 lstm/BiRNN_FW/BasicLSTMCell/Linear/Matrix 确实 不存在,不允许。您的意思是在 VarScope 中设置 reuse=None 吗?
请帮助解决这个问题。
【问题讨论】:
标签: python tensorflow