1. 程式人生 > >AttributeError: module 'tensorflow.python.ops.rnn' has no attribute 'rnn'

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

TensorFlow原版本報錯:AttributeError: module 'tensorflow.python.ops.rnn' has no attribute 'rnn'

from tensorflow.python.ops import rnn, rnn_cell 
lstm_cell = rnn_cell.BasicLSTMCell(rnn_size,state_is_tuple=True) 
outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)

 

應該替換為:

from tensorflow.contrib import rnn 


lstm_cell = rnn.BasicLSTMCell(rnn_size) 
outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)