Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将代码(基于Tensorflow 1.0.1 Python 3构建)升级到与TF1.2兼容?_Tensorflow - Fatal编程技术网

如何将代码(基于Tensorflow 1.0.1 Python 3构建)升级到与TF1.2兼容?

如何将代码(基于Tensorflow 1.0.1 Python 3构建)升级到与TF1.2兼容?,tensorflow,Tensorflow,在我的代码中:(在tf1.0上运行良好) 使用tf1.2报告错误: 从tensorflow.contrib.rnn.python.ops导入核心 导入错误:无法从以下位置导入名称“core\n”: tf.nn命名空间中的许多RNN函数和类 在1.0版本之前,已迁移到tf.contrib.rnn的 已移回核心命名空间。这包括RNNCell, LSTMCell、GRUCell和许多其他单元格。这些现在居住在 tf.nn.rnn_单元格(tf.contrib.rnn中的别名用于向后 兼容性)。原来的t

在我的代码中:(在tf1.0上运行良好)

使用tf1.2报告错误: 从tensorflow.contrib.rnn.python.ops导入核心 导入错误:无法从以下位置导入名称“core\n”:

tf.nn命名空间中的许多RNN函数和类 在1.0版本之前,已迁移到tf.contrib.rnn的 已移回核心命名空间。这包括RNNCell, LSTMCell、GRUCell和许多其他单元格。这些现在居住在 tf.nn.rnn_单元格(tf.contrib.rnn中的别名用于向后 兼容性)。原来的tf.nn.rnn函数现在是 tf.nn.static\u rnn,以及双向静态和状态保存静态 rnn函数现在也回到tf.nn名称空间中

看起来您需要更新您的代码以使用
tf.nn.rnn
tf.nn.rn\u单元
,我相当确定您不应该关心任何“*\u impl”文件,该文件应该对API隐藏并且可能随时更改。

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)

请编辑这个问题,注释是放置代码段的最糟糕的地方,因为格式总是丢失。我最终通过“find”+“grep”tensorflow源代码找到了正确的名称路径来解决这个问题。谢谢Gphilo
#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)