Tensorflow 2 API:名称 tf.get_default_graph 已弃用。请改用 tf.compat.v1.get_default_graph
Tensorflow 2 API: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead
我是 Tensorflow 的新手,我正在 Google Colaboratory 开发笔记本。
在我的第一个笔记本上,我收到一条消息,要求更新到 Tensorflow v.2。
现在,在另一个笔记本中,我收到以下消息:
The name tf.get_default_graph is deprecated. Please use
tf.compat.v1.get_default_graph instead.
如果我这样做,我使用的是 Tensorflow v2 吗?
我很困惑,因为 tf.compat.v1.get_default_graph
中的 v1
。
所有的错误信息是:
WARNING:tensorflow:From
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:66:
The name tf.get_default_graph is deprecated. Please use
tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:541:
The name tf.placeholder is deprecated. Please use
tf.compat.v1.placeholder instead.
WARNING:tensorflow:From
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4432:
The name tf.random_uniform is deprecated. Please use tf.random.uniform
instead.
WARNING:tensorflow:From
/usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4267:
The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d
instead.
我想我无法在 keras 上更改该代码。
即使您使用 TF 1.1X,您仍然会遇到其中一些错误,其中 X = 3/4/5。
一些库已被弃用,但在 TF 1.13/1.14/1.15 中可用。请注意,TF 1.15 是 1.X.
版本的最新版本
为确保您使用的是 TensorFlow 2.0,请使用:
import tensorflow as tf
print(tf.__version__)
TensorFlow 1.X API 和 TensorFlow 2.X API 之间存在一些显着差异;由于您是初学者,我强烈建议您坚持使用最新版本并考虑每一个弃用警告,以便使用最新的更新。
函数 tf.compat.v1.get_default_graph()
是 TensorFlow 2.0 的一部分 API:https://www.tensorflow.org/api_docs/python/tf/Graph?version=stable
很正常。正如您在问题中提到的,这个警告 returns 给 Keras。 Keras 是高水平的api。它与 theano 和 tensorflow 一起作为底层计算的后端。如果 Keras 发现任何版本的 tensorflow 或 theano 特定代码执行,包括这部分:
tf.get_default_graph
另一边tensorflow不知道是谁调用的。它会在未来的版本中引发警告 tf.get_default_graph
将被删除!请保持未来主义,不要将其用于代码一致性。
它 returns 到 Keras 不是你的代码。 Keras 在 tf v2.
之前发布
我是 Tensorflow 的新手,我正在 Google Colaboratory 开发笔记本。
在我的第一个笔记本上,我收到一条消息,要求更新到 Tensorflow v.2。
现在,在另一个笔记本中,我收到以下消息:
The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
如果我这样做,我使用的是 Tensorflow v2 吗?
我很困惑,因为 tf.compat.v1.get_default_graph
中的 v1
。
所有的错误信息是:
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:66: The name tf.get_default_graph is deprecated. Please use tf.compat.v1.get_default_graph instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:541: The name tf.placeholder is deprecated. Please use tf.compat.v1.placeholder instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4432: The name tf.random_uniform is deprecated. Please use tf.random.uniform instead.
WARNING:tensorflow:From /usr/local/lib/python3.6/dist-packages/keras/backend/tensorflow_backend.py:4267: The name tf.nn.max_pool is deprecated. Please use tf.nn.max_pool2d instead.
我想我无法在 keras 上更改该代码。
即使您使用 TF 1.1X,您仍然会遇到其中一些错误,其中 X = 3/4/5。
一些库已被弃用,但在 TF 1.13/1.14/1.15 中可用。请注意,TF 1.15 是 1.X.
版本的最新版本为确保您使用的是 TensorFlow 2.0,请使用:
import tensorflow as tf
print(tf.__version__)
TensorFlow 1.X API 和 TensorFlow 2.X API 之间存在一些显着差异;由于您是初学者,我强烈建议您坚持使用最新版本并考虑每一个弃用警告,以便使用最新的更新。
函数 tf.compat.v1.get_default_graph()
是 TensorFlow 2.0 的一部分 API:https://www.tensorflow.org/api_docs/python/tf/Graph?version=stable
很正常。正如您在问题中提到的,这个警告 returns 给 Keras。 Keras 是高水平的api。它与 theano 和 tensorflow 一起作为底层计算的后端。如果 Keras 发现任何版本的 tensorflow 或 theano 特定代码执行,包括这部分:
tf.get_default_graph
另一边tensorflow不知道是谁调用的。它会在未来的版本中引发警告 tf.get_default_graph
将被删除!请保持未来主义,不要将其用于代码一致性。
它 returns 到 Keras 不是你的代码。 Keras 在 tf v2.