Tensorflow error in import tf.nn.rnn_cell
Asked Answered
P

2

5

I am using Tensorflow 1.0.0 and Python 3.5. When I try to do:

cell = tf.nn.rnn_cell.BasicRNNCell(state_size)

I get the following error:

AttributeError

  <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'

Can someone help me?

Patio answered 19/2, 2017 at 10:42 Comment(0)
B
8

TensorFlow changes a lot of APIs before 1.0.

You'll need to replace tf.nn.rnn_cell.BasicLSTMCell by tf.contrib.rnn.BasicLSTMCell

Behead answered 19/2, 2017 at 14:48 Comment(0)
M
8

I have same problem in tensorflow 2.1 and when I used this code:

rnn_cells = tf.nn.rnn_cell.MultiRNNCell(
            [lstm_cell(size_layer) for _ in range(num_layers)],
            state_is_tuple = False,
        )

I faced with this error:

AttributeError: module 'tensorflow_core._api.v2.nn' has no attribute 'rnn_cell'

Finally, I replaced tf.nn.rnn_cell.MultiRNNCell by tf.compat.v1.nn.rnn_cell.MultiRNNCell, and then it worked well. Please, replace tf.nn.rnn_cell.BasicRNNCell(state_size) by tf.compat.v1.nn.rnn_cell.BasicRNNCell(state_size).

Mcginn answered 24/6, 2020 at 19:26 Comment(1)
this worked for me, weirdly on some tf official page the import was just nn.rnn not nn.rnn_cellHerdic

© 2022 - 2024 — McMap. All rights reserved.