W4: Running Neural Style Transfer notebook on my computer error

When I ran the jupyter notebook of the programming assignment of Neural Style Transfer in Coursera everything worked fine and I got a perfect grade. However when I tried to run it on my computer I got the this error:
ValueError: No gradients provided for any variable: [‘generated_image:0’].

My tensorflow version is 2.5.0, please help!

Full error stack:

Traceback (most recent call last):
in main
File “tensorflow\python\eager\def_function.py”, line 889, in call
result = self._call(*args, **kwds)
File “tensorflow\python\eager\def_function.py”, line 933, in _call
self._initialize(args, kwds, add_initializers_to=initializers)
File “tensorflow\python\eager\def_function.py”, line 763, in _initialize
self._stateful_fn._get_concrete_function_internal_garbage_collected( # pylint: disable=protected-access
File “tensorflow\python\eager\function.py”, line 3050, in _get_concrete_function_internal_garbage_collected
graph_function, _ = self._maybe_define_function(args, kwargs)
File “tensorflow\python\eager\function.py”, line 3444, in _maybe_define_function
graph_function = self._create_graph_function(args, kwargs)
File “tensorflow\python\eager\function.py”, line 3279, in _create_graph_function
File “tensorflow\python\framework\func_graph.py”, line 999, in func_graph_from_py_func
func_outputs = python_func(*func_args, **func_kwargs)
File “tensorflow\python\eager\def_function.py”, line 672, in wrapped_fn
out = weak_wrapped_fn().wrapped(*args, **kwds)
File “tensorflow\python\framework\func_graph.py”, line 986, in wrapper
raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

train_step  *
    optimizer.apply_gradients([(grad, generated_image)])
tensorflow\python\keras\optimizer_v2\optimizer_v2.py:630 apply_gradients  **
    grads_and_vars = optimizer_utils.filter_empty_gradients(grads_and_vars)
tensorflow\python\keras\optimizer_v2\utils.py:75 filter_empty_gradients
    raise ValueError("No gradients provided for any variable: %s." %

ValueError: No gradients provided for any variable: ['generated_image:0'].

Please help!

I found out what made the error. In the notebook during one of the tests there is this line once again:
generated_image = tf.Variable(tf.image.convert_image_dtype(content_image, tf.float32))

and this line made the code work.

When running the content_image with the added noise it didn’t work because the noise changed the type of generated_image to EagerTensor.
All I needed to do was to make it a ResourceVariable again:
generated_image = tf.Variable(generated_image)


Thanks for your report.

man you are amazing thank you, but it well be nice if you explain it in easy way