Course 4 - Week 1 - Assignment

I encounter the following error while running the last cell. I have checked the code multiple times, everything seems good. Kindly help.

ValueError Traceback (most recent call last)

in
15 stylized_image, display_images = fit_style_transfer(style_image=style_image, content_image=content_image,
16 style_weight=style_weight, content_weight=content_weight,
—> 17 optimizer=adam, epochs=10, steps_per_epoch=100)

5 frames

in fit_style_transfer(style_image, content_image, style_weight, content_weight, optimizer, epochs, steps_per_epoch)
40 ### START CODE HERE ###
41 # Update the image with the style using the function that you defined
—> 42 update_image_with_style(generated_image, style_targets, content_targets, style_weight, content_weight, optimizer)
43
44 ### END CODE HERE

in update_image_with_style(image, style_targets, content_targets, style_weight, content_weight, optimizer)
13 ### START CODE HERE ###
14 # Calculate gradients using the function that you just defined.
—> 15 gradients = calculate_gradients(image, style_targets, content_targets, style_weight, content_weight)
16
17 # apply the gradients to the given image

in calculate_gradients(image, style_targets, content_targets, style_weight, content_weight)
25 loss = get_style_content_loss(style_targets, style_features,
26 content_targets, content_features,
—> 27 style_weight, content_weight)
28
29 # calculate gradients of loss with respect to the image

in get_style_content_loss(style_targets, style_outputs, content_targets, content_outputs, style_weight, content_weight)
18 # Sum of the style losses
19 style_loss = tf.add_n([ get_style_loss(style_output, style_target)
—> 20 for style_output, style_target in zip(style_outputs, style_targets)])
21
22 # Sum up the content losses

/usr/local/lib/python3.7/dist-packages/tensorflow/python/util/traceback_utils.py in error_handler(*args, **kwargs)
151 except Exception as e:
152 filtered_tb = _process_traceback_frames(e.traceback)
→ 153 raise e.with_traceback(filtered_tb) from None
154 finally:
155 del filtered_tb

/usr/local/lib/python3.7/dist-packages/tensorflow/python/ops/math_ops.py in add_n(inputs, name)
4039 “”"
4040 if not inputs or not isinstance(inputs, collections_abc.Iterable):
→ 4041 raise ValueError("Inputs must be an iterable of at least one "
4042 “Tensor/IndexedSlices with the same dtype and shape.”)
4043 inputs = ops.convert_n_to_tensor_or_indexed_slices(inputs)

ValueError: Inputs must be an iterable of at least one Tensor/IndexedSlices with the same dtype and shape.

This is the line you need to pay attention:

for style_output, style_target in zip(style_outputs, style_targets)

It most probably either style_outputs or style_targets are not lists of the same shape so they can be zipped.