【问题标题】:The name tf.Session is deprecated. Please use tf.compat.v1.Session instead名称 tf.Session 已弃用。请改用 tf.compat.v1.Session
【发布时间】:2019-11-11 04:54:36
【问题描述】:

我在我的 tensorflow 代码中收到以下弃用警告:

名称 tf.Session 已弃用。请改用 tf.compat.v1.Session。

  • 为什么我收到此警告
  • 在 tensorflow 2.0 中会发生什么。而不是tf.session
  • 可以用tf.compat.v1.Session

【问题讨论】:

    标签: tensorflow tensorflow2.0


    【解决方案1】:

    为了让 TensorFlow 在 2.0 版中更加“Pythonic”,TF 2.0 在设计上没有 tf.Session。

    TensorFlow 1.X 要求用户通过调用 tf.* API 手动将抽象语法树(图形)拼接在一起。然后它要求用户通过将一组输出张量和输入张量传递给 session.run() 调用来手动编译抽象语法树。

    TensorFlow 2.0 急切地执行(就像 Python 通常那样),在 2.0 中,图形和会话应该感觉像是实现细节。

    你可以使用:

    import tensorflow.compat.v1 as tf
    tf.disable_v2_behavior()
    

    但是,这并不能让您利用 TensorFlow 2.0 中的许多改进。

    The better solution is:

    • 替换 tf.Session.run 调用:每个 tf.Session.run 调用都应替换为 Python 函数。
      • feed_dict 和 tf.placeholder 成为函数参数。
      • 获取的数据成为函数的返回值。

    【讨论】:

    • >>> tf.disable_v2_behavior() WARNING:tensorflow:From /usr/local/lib/python3.7/dist-packages/tensorflow_core/python/compat/v2_compat.py:65: disable_resource_variables (from tensorflow.python.ops.variable_scope) is deprecated and will be removed in a future version. Instructions for updating: non-resource variables are not supported in the long term 今天:|
    猜你喜欢
    • 2014-12-25
    • 1970-01-01
    • 2020-08-01
    • 2014-04-13
    • 2016-06-13
    • 1970-01-01
    • 1970-01-01
    • 2013-12-01
    相关资源
    最近更新 更多