Tensorflow TypeError:'module'对象不可调用 - tf.contrib.rnn

问题描述 投票:1回答:1

调用属性错误时遇到问题:

tf.nn.rnn(cell, inputs_series, initial_state=rnn_tuple_state)

收到属性错误:

AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn'

将此更改为:

tf.contrib.rnn(cell, inputs_series, initial_state=rnn_tuple_state)

但是,现在我收到以下错误:

TypeError: 'module' object is not callable

针对以下行:

states_series, current_state = tf.contrib.rnn(cell, inputs_series, initial_state=rnn_tuple_state)

代码如下:

# Forward passes
cell = tf.contrib.rnn.LSTMCell(state_size, state_is_tuple=True)
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers, state_is_tuple=True)
states_series, current_state = tf.contrib.rnn(cell, inputs_series, initial_state=rnn_tuple_state)

完全错误:

Traceback (most recent call last):
  File "/Users/glennhealy/PycharmProjects/lstm2/lstm2.py", line 49, in <module>
    states_series, current_state = tf.contrib.rnn(cell, inputs_series, initial_state=rnn_tuple_state)
TypeError: 'module' object is not callable

有任何想法吗??

tf.nn.rnn不起作用,但tf.contrib.rnn也不起作用

提前干杯

根据回复更新了更多信息

看看这个,我已经尝试了tensorflgw_RNN信息中的所有选项,我收到了很多这样的错误:

TypeError: static_bidirectional_rnn() got an unexpected keyword argument 'initial_state'

所以,现在我迷路了。

python tensorflow typeerror attributeerror rnn
1个回答
1
投票

根据文件https://www.tensorflow.org/api_guides/python/contrib.rnn

TensorFlow提供了许多构造递归神经网络的方法。

tf.contrib.rnn.static_rnn
tf.contrib.rnn.static_state_saving_rnn
tf.contrib.rnn.static_bidirectional_rnn
tf.contrib.rnn.stack_bidirectional_dynamic_rnn

试试这个

tf.contrib.rnn.static_rnn(cell, inputs_series, initial_state=rnn_tuple_state)

要么

tf.nn.static_rnn(cell, inputs_series, initial_state=rnn_tuple_state)
© www.soinside.com 2019 - 2024. All rights reserved.