Python Tensorflow Multirncell LSTM:&x201C';张量';对象不可编辑”;

Python Tensorflow Multirncell LSTM:&x201C';张量';对象不可编辑”;,python,tensorflow,deep-learning,lstm,recurrent-neural-network,Python,Tensorflow,Deep Learning,Lstm,Recurrent Neural Network,我有以下代码: self.inputs = tf.placeholder(shape=[None, num_inputs], dtype=tf.float32) # Recurrent network for temporal dependencies def make_cell(units): cell = tf.contrib.rnn.BasicLSTMCell(units, state_is_tuple=True) if mode == TRAIN and keep_pr

我有以下代码:

self.inputs = tf.placeholder(shape=[None, num_inputs], dtype=tf.float32)

# Recurrent network for temporal dependencies
def make_cell(units):
    cell = tf.contrib.rnn.BasicLSTMCell(units, state_is_tuple=True)
    if mode == TRAIN and keep_prob < 1:
        cell = tf.contrib.rnn.DropoutWrapper(cell, output_keep_prob=keep_prob)
        return cell

num_units = [h_size, h_size]
multi_rnn_cell = tf.contrib.rnn.MultiRNNCell(
    [make_cell(n) for n in num_units], state_is_tuple=True)

self.state_init = multi_rnn_cell.zero_state(1, tf.float32)
h_in = tf.placeholder(tf.float32, shape=[1, h_size])
c_in = tf.placeholder(tf.float32, shape=[1, h_size])
self.state_in = (c_in, h_in)
state_in = tf.contrib.rnn.LSTMStateTuple(c_in, h_in)

rnn_in = tf.expand_dims(self.inputs, [0])
lstm_outputs, lstm_state = tf.nn.dynamic_rnn(
    cell=multi_rnn_cell, inputs=rnn_in, initial_state=state_in, dtype=tf.float32)
self.inputs=tf.placeholder(shape=[None,num\u inputs],dtype=tf.float32)
#时间依赖的递归网络
def制造单元(单位):
cell=tf.contrib.rnn.BasicLSTMCell(单位,状态为
如果模式==训练并保持_prob<1:
单元=tf.contrib.rnn.dropoutrapper(单元,输出保持保持保持保持)
返回单元
num_units=[h_大小,h_大小]
multi_rnn_cell=tf.contrib.rnn.MultiRNNCell(
[以num\u单位为n生成单元(n),状态为\u tuple=True)
self.state\u init=多个\n\u单元.zero\u状态(1,tf.float32)
h_in=tf.placeholder(tf.float32,shape=[1,h_size])
c_in=tf.placeholder(tf.float32,形状=[1,h_大小])
self.state_in=(c_in,h_in)
state_in=tf.contrib.rnn.LSTMStateTuple(c_in,h_in)
rnn_in=tf.expand_dims(self.inputs,[0])
lstm_输出,lstm_状态=tf.nn.dynamic_rnn(
单元=多单元,输入=输入,初始状态=状态,数据类型=tf.float32)
当我运行它时,会出现以下错误:

TypeError:未启用“急切执行”时,Tensor对象不可编辑。要在这个张量上迭代,请使用tf.map\u fn

当我运行相同的代码,但只有1个LSTMCell并且没有扩展dimansions时,它运行得很好

我希望通过添加MultiRNNCell来使用不止一个层


有人能帮我吗?

我想问题在于你在中创建状态的方式。您正在使用带有单元格列表的multiRNNCell。因此,中的
state_应该是一个包含那么多
LSTMStateTuple
对象的列表,而不是一个
LSTMStateTuple