我在循环神经网络上关注this tutorial。
这是导入:
import tensorflow as tf
from tensorflow.examples.tutorials.mnist import input_data
from tensorflow.python.ops import rnn
from tensorflow.contrib.rnn import core_rnn_cell这是输入处理的代码:
x = tf.transpose(x, [1,0,2])
x = tf.reshape(x, [-1, chunk_size])
x = tf.split(x, n_chunks, 0)
lstm_cell = core_rnn_cell.BasicLSTMCell(rnn_size)
outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)对于outputs, states,我得到以下错误
AttributeError: module 'tensorflow.python.ops.rnn' has no attribute 'rnn'TensorFlow最近进行了更新,那么问题行的新代码应该是什么呢
发布于 2017-02-18 13:55:41
对于使用较新版本的tensorflow的用户,请将以下内容添加到代码中:
from tensorflow.contrib import rnn
lstm_cell = rnn.BasicLSTMCell(rnn_size)
outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)而不是
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)PS:@BrendanA建议用tf.nn.rnn_cell.LSTMCell代替rnn_cell.BasicLSTMCell
发布于 2019-08-27 23:22:27
谢谢@suku
我得到以下错误:ImportError: No module named 'tensorflow.contrib.rnn.python.ops.core_rnn'
要解算,请执行以下操作:
from tensorflow.contrib.rnn.python.ops import core_rnn替换为:
from tensorflow.python.ops import rnn, rnn_cell在我的代码中,我使用了core_rnn.static_rnn
outputs,_ = core_rnn.static_rnn(cell, input_list, dtype=tf.float32)我得到了this错误:
NameError: name 'core_rnn' is not defined
通过将该行替换为:
outputs,_ = rnn.static_rnn(cell, input_list, dtype=tf.float32)python: 3.6 64位rensorflow:1.10.0
发布于 2021-01-31 21:08:43
使用static_rnn方法代替rnn。
outputs, states = rnn.static_rnn(lstm_cell, x, dtype=tf.float32)而不是:
outputs, states = rnn.rnn(lstm_cell, x, dtype=tf.float32)https://stackoverflow.com/questions/42311007
复制相似问题