在我的代码中:(在tf1.0上运行良好)
from tensorflow.contrib.rnn.python.ops import core_rnn
from tensorflow.contrib.rnn.python.ops import core_rnn_cell
from tensorflow.contrib.rnn.python.ops import core_rnn_cell_impl
使用tf1.2报告错误: 来自tensorflow.contrib.rnn.python.ops导入core_rnn ImportError:无法导入名称'core_rnn'
答案 0 :(得分:0)
tf.nn命名空间中的许多RNN函数和类 在1.0发布之前,现在已经转移到tf.contrib.rnn了 被移回核心命名空间。这包括RNNCell, LSTMCell,GRUCell和许多其他细胞。这些现在居住在 tf.nn.rnn_cell(tf.contrib.rnn中的别名用于向后 兼容性)。原来的tf.nn.rnn函数现在是 tf.nn.static_rnn,以及双向静态和状态保存静态 rnn函数现在也回到了tf.nn命名空间。
看起来您需要更新代码才能使用tf.nn.rnn
,tf.nn.rn_cell
而且我相当肯定您不应该关注任何'* _impl'文件,这是假设的隐藏在API中,可能随时更改。
答案 1 :(得分:0)
的
from tensorflow.contrib.rnn.python.ops import core_rnn
from tensorflow.contrib.rnn.python.ops import core_rnn_cell
from tensorflow.contrib.rnn.python.ops import core_rnn_cell_impl
在tf1.2中,它应该是一个替代品:
#cell = core_rnn_cell.OutputProjectionWrapper(cell, output_symbols)
cell = tf.nn.OutputProjectionWrapper(cell, output_symbols)
#_, enc_state = core_rnn.static_rnn(cell, encoder_inputs, dtype=dtype, scope=scope)
_, enc_state = tf.nn.static_rnn( cell, encoder_inputs, dtype=dtype, scope=scope)
#y = linear(query, attention_vec_size, True)
y = rnn_cell_impl._linear(query, attention_vec_size, True)