【问题标题】:Python TensorFlow v2, locating contrib.trainingPython TensorFlow v2,定位 contrib.training
【发布时间】:2022-08-19 16:55:52
【问题描述】:

我正在使用一些基于 Tensorflow 1.x 的 code,并且我正在使用最新版本的 TensorFlow (2.8)。

我在 python 文件上运行了tf_upgrade_v2(在these migration instructions之后)以生成一个新的兼容文件。

但是,这不适用于代码行; from TensorFlow.contrib import training as contrib_training

得到错误ModuleNotFoundError: No module named \'tensorflow.contrib\'

我知道contrib 已被弃用,因此模块已被移动。但我无法找到该培训模块已移至何处或是否已删除。我首先查找了有关此document on the status of tf.contrib 和此spreadsheet on TF2.0 Symbols map 的信息,但没有找到有关此培训模块命运的任何信息;

我也试过环顾 TensorFlow/tf.compat.v1 但没有成功。

当然,卸载此版本的 TensorFlow 并安装较早版本是一种选择。但不是我过于热衷的选择。

我觉得我可能在这里遗漏了一些相当明显的东西......

提前致谢!!

    标签: python tensorflow import


    【解决方案1】:

    此错误背后的原因 - ModuleNotFoundError: No module named 'tensorflow.contrib' 是,tf.contrib 已被弃用在 Tensorflow 2.x 中使用。您可以使用张量流插件或者TensorFlow Slimtf.contrib api 的速度。

    请查看this 链接了解更多详情。

    【讨论】:

      猜你喜欢
      • 2020-03-18
      • 1970-01-01
      • 2017-06-06
      • 1970-01-01
      • 2018-11-08
      • 1970-01-01
      • 2017-02-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多