Python 为什么会有AttributeError:module';tensorflow.contrib.eager';没有属性';变量';在TensorFlow 1.15中?

Python 为什么会有AttributeError:module';tensorflow.contrib.eager';没有属性';变量';在TensorFlow 1.15中?,python,tensorflow,eager-execution,Python,Tensorflow,Eager Execution,大约一个月前,我在谷歌Colab上成功地运行了一个神经风格转移笔记本教程。但是,本周我无法成功运行完全相同的笔记本,错误消息如下: AttributeError:模块“tensorflow.contrib.eager”没有属性“Variable” 我检查了Google Colab中的笔记本是否使用TensorFlow 1.15,当我检查API文档时,变量方法存在: 出现此错误消息的原因是什么?在Tensorflow 1.15中,Tensorflow.contrib.eager.Variable不

大约一个月前,我在谷歌Colab上成功地运行了一个神经风格转移笔记本教程。但是,本周我无法成功运行完全相同的笔记本,错误消息如下: AttributeError:模块“tensorflow.contrib.eager”没有属性“Variable”

我检查了Google Colab中的笔记本是否使用TensorFlow 1.15,当我检查API文档时,变量方法存在:


出现此错误消息的原因是什么?

在Tensorflow 1.15
中,Tensorflow.contrib.eager.Variable
不存在。尽管在文档中有显示,但它被标记为已弃用,并且似乎根本不在代码中

改用常规的旧
tf.变量
。以下代码在1.15中运行良好:

import tensorflow as tf

tf.compat.v1.enable_eager_execution()

x = tf.Variable(1, dtype=tf.float32)
with tf.GradientTape() as tape:
    f = x * x
print(tape.gradient(f, x))

Tensorflow 1.15中的tf.Tensor(2.0,shape=(),dtype=float32)Tensorflow.contrib.eager.Variable不存在。尽管在文档中有显示,但它被标记为已弃用,并且似乎根本不在代码中

改用常规的旧
tf.变量
。以下代码在1.15中运行良好:

import tensorflow as tf

tf.compat.v1.enable_eager_execution()

x = tf.Variable(1, dtype=tf.float32)
with tf.GradientTape() as tape:
    f = x * x
print(tape.gradient(f, x))

>tf.Tensor(2.0,shape=(),dtype=float32)

请发布带有完整错误回溯的最小代码示例。请发布带有完整错误回溯的最小代码示例。