gpt4 book ai didi

tensorflow - 使用 tf.contrib.rnn.LayerNormBasicLSTMCell 时类型错误 'tensor' 对象不可迭代

转载 作者:行者123 更新时间:2023-12-04 00:46:13 24 4
gpt4 key购买 nike

我的tensorflow版本是1.0.0。当我使用 tf.contrib.rnn.GRUCell(n_hidden_​​units) 正常运行时,但使用 tf.contrib.rnn.LayerNormBasicLSTMCell(n_hidden_​​units) 运行时出现错误:“类型错误‘张量’对象不可迭代”

`with tf.variable_scope('init_name',initializer=tf.orthogonal_initializer()):   

cell = tf.contrib.rnn.LayerNormBasicLSTMCell(n_hidden_units)
init_state = tf.get_variable('init_state', [1, n_hidden_units],initializer=tf.constant_initializer(0.0)) #tf.constant_initializer(0.0)
init_state = tf.tile(init_state, [train_batch_size, 1])

outputs, states = tf.nn.dynamic_rnn(
cell,X,dtype=tf.float32,sequence_length=true_lenth,initial_state=init_state)`

错误是:

/usr/anaconda3/lib/python3.5/site-packages/tensorflow/python/ops/rnn.py in <lambda>()
681
682 input_t = nest.pack_sequence_as(structure=inputs, flat_sequence=input_t)--> 683 call_cell = lambda: cell(input_t, state) 684 685 if sequence_length is not None:/usr/anaconda3/lib/python3.5/site-packages/tensorflow/contrib/rnn/python/ops/rnn_cell.py in __call__(self, inputs, state, scope)1228 1229 with vs.variable_scope(scope or
"layer_norm_basic_lstm_cell"):
-> 1230 c, h = state

1231 args = array_ops.concat([输入, h], 1) 第1232章

/usr/anaconda3/lib/python3.5/site-packages/tensorflow/python/framework/ops.py in iter(self)

514       TypeError: when invoked.
515 """
--> 516 raise TypeError("'Tensor' object is not iterable.")
517
518 def __bool__(self):

TypeError: 'Tensor' object is not iterable.

有人可以帮助我吗?非常感谢。

最佳答案

LayerNormBasicLSTMCell 要求初始状态为 (num_units, num_units) 的元组。

你可以通过做你的代码来工作

    cell = tf.contrib.rnn.LayerNormBasicLSTMCell(n_hidden_units)
init_state = (tf.zeros([train_batch_size, n_hidden_units]),
tf.zeros([train_batch_size, n_hidden_units]))

outputs, states = tf.nn.dynamic_rnn(
cell, X, dtype=tf.float32,
sequence_length=true_lenth,initial_state=init_state)

关于tensorflow - 使用 tf.contrib.rnn.LayerNormBasicLSTMCell 时类型错误 'tensor' 对象不可迭代,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44216907/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com