Neural-Style-Transfer icon indicating copy to clipboard operation
Neural-Style-Transfer copied to clipboard

RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead.

Open Garfield8377 opened this issue 5 years ago • 5 comments

hi i was run this on colab and when i run this cell:

!python {dir_path}/{NETWORK} {CONTENT_IMAGE_FN} {STYLE_IMAGE_FN} {RESULT_PREFIX} \
  --image_size {IMAGE_SIZE} --content_weight {CONTENT_WEIGHT} --style_weight \
  {STYLE_WEIGHT} --style_scale {STYLE_SCALE} --total_variation_weight \
  {TOTAL_VARIATION_WEIGHT} --content_loss_type {CONTENT_LOSS_TYPE} --num_iter \
  {NUM_ITERATIONS} --model {MODEL} --rescale_image {RESCALE_IMAGE} \
  --maintain_aspect_ratio {MAINTAIN_ASPECT_RATIO} --content_layer {CONTENT_LAYER} \
  --init_image {INITIALIZATION_IMAGE} --pool_type {POOLING_TYPE} --preserve_color \
  {PRESERVE_COLOR} --min_improvement {MIN_IMPROVEMENT}

i got this error: RuntimeError: tf.gradients is not supported when eager execution is enabled. Use tf.GradientTape instead. can someone tell me where i can use tf.GradientTape? thx

Garfield8377 avatar Nov 12 '20 03:11 Garfield8377

disable eager execution tf.compat.v1.disable_eager_execution()

Mohamed209 avatar Dec 17 '20 13:12 Mohamed209

any solutions!!!

rachidd12 avatar Jan 22 '21 23:01 rachidd12

Adding these two lines to network.py worked for me. Thanks to @Mohamed209

import tensorflow as tf tf.compat.v1.disable_eager_execution()

OterLabb avatar Apr 05 '21 18:04 OterLabb

import tensorflow as tf tf.compat.v1.disable_eager_execution()

it works thanks a lot.

rachidd12 avatar Apr 06 '21 21:04 rachidd12

I had the same issue, but then got a cudNN error like this one. saying : Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above

solved everything by adding this to INetwork.py import section

import tensorflow as tf
tf.compat.v1.disable_eager_execution()
config = tf.compat.v1.ConfigProto()
config.gpu_options.allow_growth = True
tf.compat.v1.keras.backend.set_session(tf.compat.v1.Session(config=config))

sangfrois avatar Apr 17 '21 18:04 sangfrois