【发布时间】:2017-03-24 10:54:39
【问题描述】:
我想从https://www.tensorflow.org/api_docs/python/tf/contrib/rnn/static_rnn 重新实现 RNN 步进循环 但这对我不起作用。 当重用设置为 True 时,我得到“变量 test/basic_lstm_cell/weights 已经存在”而没有重用和“变量 test/basic_lstm_cell/weights 不存在”。
import tensorflow as tf
batch_size = 32
n_steps = 10
lstm_size = 10
n_input = 17
words = tf.placeholder(tf.float32, [batch_size, n_steps, n_input])
words = tf.transpose(words, [1, 0, 2])
words = tf.reshape(words, [-1, n_input])
words = tf.split(words, n_steps, 0)
with tf.variable_scope('test', reuse=True):
cell = tf.contrib.rnn.BasicLSTMCell(lstm_size)
state = cell.zero_state(batch_size, dtype=tf.float32)
outputs = []
for input_ in words:
output, state = cell(input_, state)
outputs.append(output)
【问题讨论】:
标签: python machine-learning tensorflow lstm recurrent-neural-network