【发布时间】:2019-11-11 04:54:36
【问题描述】:
我在我的 tensorflow 代码中收到以下弃用警告:
名称 tf.Session 已弃用。请改用 tf.compat.v1.Session。
- 为什么我收到此警告
- 在 tensorflow 2.0 中会发生什么。而不是
tf.session - 可以用
tf.compat.v1.Session吗
【问题讨论】:
我在我的 tensorflow 代码中收到以下弃用警告:
名称 tf.Session 已弃用。请改用 tf.compat.v1.Session。
tf.session
tf.compat.v1.Session吗
【问题讨论】:
为了让 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 中的许多改进。
【讨论】:
>>> 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 今天:|