1
votes

I had run a neural style transfer notebook tutorial in Google Colab successfully around one month ago. However, this week I can't run the exact same notebook successfully, with the following error message: AttributeError: module 'tensorflow.contrib.eager' has no attribute 'Variable'.

I checked that the Notebook in Google Colab is using TensorFlow 1.15, and when I checked the API documentation, the Variable method exist: https://www.tensorflow.org/versions/r1.15/api_docs/python/tf/contrib/eager/Variable

What is the reason for this error message?

1
Please post a minimal code example with a full error traceback. - xdurch0

1 Answers

0
votes

In Tensorflow 1.15 tensorflow.contrib.eager.Variable doesn't exist. Although shown in the documentation, it is marked as deprecated and doesn't seem to be in the code at all.

Use the regular old tf.Variable instead. The following code works fine in 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)