在 tensorflow 2 中找不到 Tensorflow 模块,在哪里可以找到新方法的文档?

Tensorflow module not found with tensorflow 2, where to find docs for new way?

following this tutorial
我正在尝试 运行 TensorFlow 的预写模型,因为我正在 运行ning TensorFlow 2,而我使用的代码是针对旧版本的。具体来说,tf.contrib.

来自原始代码:

from tensorflow.contrib import legacy_seq2seq

从第一个修复中我发现:

from tensorflow.python.ops.seq2seq import sequence_loss

错误:

ModuleNotFoundError: No module named 'tensorflow.python.ops.seq2seq'

我在哪里可以找到 tf.contrib 中的方法并导入和使用它们?旧功能还存在吗?

请注意,tf.contrib 已在 TF 2.0 中删除。 Source

  • Removal of tf.contrib - These features have been either moved to TensorFlow Core, or to tensorflow/addons, or are no longer part of the TensorFlow build but are developed and maintained by their respective owners.
  • Updated and revised documentation, examples, and website, including migration docs and TF 1.x to 2.0 converter guide.

例如tf.contrib.layers.layer_norm,根据this github issue got moved to here: https://github.com/tensorflow/addons/tree/master/tensorflow_addons/layers

TF 2.0:seq2seq 现在在 tensorflow_addons 之下

您可以在 tensorflow_addons:https://github.com/tensorflow/addons/tree/master/tensorflow_addons/seq2seq 下找到关于如何为 TF 2.0 处理 seq2seq 的 github post。它为您提供了一个关于如何将 TF 1.x seq2seq 转换为 TF 2.0 的清晰示例 相等的。在 Sample code and Migration guide from TF 1.X

下查看
# TF 2.0
import tensorflow_addons as tfa
sampler = tfa.seq2seq.sampler.TrainingSampler()

TF 1.x 到 TF 2.0 升级

我建议您首先尝试将 TF 1.x 代码迁移到 TF 2.0。参考 how to automatically upgrade from TF 1.x to TF 2.0?

Recommended upgrade process