titu1994 / Neural-Style-Transfer

Keras Implementation of Neural Style Transfer from the paper "A Neural Algorithm of Artistic Style" (http://arxiv.org/abs/1508.06576) in Keras 2.0+
Apache License 2.0
2.28k stars 482 forks source link

Replace tf.gradients with tf.GradientTape : RuntimeError #69

Closed shahmanan5811 closed 4 years ago

shahmanan5811 commented 4 years ago

Traceback (most recent call last): File "Neural-Style-Transfer/INetwork.py", line 524, in grads = K.gradients(loss, combination_image) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/backend.py", line 3969, in gradients loss, variables, colocate_gradients_with_ops=True) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gradients_impl.py", line 172, in gradients unconnected_gradients) File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gradients_util.py", line 491, in _GradientsHelper raise RuntimeError("tf.gradients is not supported when eager execution " RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.

bomtorazek commented 4 years ago

Firstly, import tensorflow as tf

Next, just type the following snippet.

tf.compat.v1.disable_eager_execution()

MentalGear commented 4 years ago

You got to add %tensorflow_version 1.x colab now uses TF 2 by default