ele*_*ena 2 machine-learning deep-learning tensorflow recurrent-neural-network
我正在使用 Tensorflow 1.0.0 和 Python 3.5。当我尝试做:
cell = tf.nn.rnn_cell.BasicRNNCell(state_size)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
属性错误
<ipython-input-25-41a20d8458a7> in <module>()
1 # Forward pass
2 print(tf.__version__)
--->3 cell = tf.nn.rnn_cell.BasicRNNCell(state_size)
4 states_series, current_state = tf.nn.dynamic_rnn(cell, inputs_series, initial_state = init_state)
AttributeError: module 'tensorflow.python.ops.nn' has no attribute 'rnn_cell'
Run Code Online (Sandbox Code Playgroud)
有人能帮我吗?
我在tensorflow 2.1中遇到同样的问题,当我使用此代码时:
rnn_cells = tf.nn.rnn_cell.MultiRNNCell(
[lstm_cell(size_layer) for _ in range(num_layers)],
state_is_tuple = False,
)
Run Code Online (Sandbox Code Playgroud)
我遇到了这个错误:
AttributeError: module 'tensorflow_core._api.v2.nn' has no attribute 'rnn_cell'
Run Code Online (Sandbox Code Playgroud)
最后我换成tf.nn.rnn_cell.MultiRNNCell了tf.compat.v1.nn.rnn_cell.MultiRNNCell,然后就成功了。请替换tf.nn.rnn_cell.BasicRNNCell(state_size)为tf.compat.v1.nn.rnn_cell.BasicRNNCell(state_size).
TensorFlow 在 1.0 之前改变了很多 API。
你需要替换tf.nn.rnn_cell.BasicLSTMCell为tf.contrib.rnn.BasicLSTMCell