Course 4 week 1 assignment (Neural Style Transfer)

hi .
in the last section of neural style transfer i encounter with below error . i’ll be very thankful if someone help me to find the right solution .


TypeError 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)

6 frames
/usr/local/lib/python3.7/dist-packages/tensorflow/python/framework/constant_op.py in convert_to_eager_tensor(value, ctx, dtype)
104 dtype = dtypes.as_dtype(dtype).as_datatype_enum
105 ctx.ensure_initialized()
→ 106 return ops.EagerTensor(value, ctx.device_name, dtype)
107
108

TypeError: Cannot convert ‘input_2’ to EagerTensor of dtype float

Hi, assuming you haven’t changed anything in last cell, check the implementation of the previous function “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)”. the error points there but it might be on its dependencies too. A good thing thing would be to check all the previous implementations of your other functions.

i’ve already stacked all the cells together and error came from choosing intermediate layers where i defined content and style layers in the primary cells .

problem happen in
----> def inception_model(layer_names):
where output_layers iterate over layers name

so according to the instructions , i fill content and style layers respectively with
[‘conv2d_87’]
and
[‘conv2d’ , ‘conv2d_1’ , ‘conv2d_2’ , ‘conv2d_3’ ,‘conv2d_4’]
(and of course i tested other layers base on the tf.keras.utils.plot_model priority and maxpoolings locations as the lessons but they didn’t work)

how should i specify correct layers

1 Like

The first, content_layer is not right, the instructions tell you a different number.

Hey @gent.spah, I think the layer names in the post by @Mohammadreza_Zarei above are correct. Since the names are 0-indexed, it’s the instance number minus 1. First is ‘conv2d’. Second is ‘conv2d_1’, Eighty-eighth is ‘conv2d_87’

At least that’s what worked for me

In the official solution is the conv2d_88 but even the 87 could work (this is a huge extraction network) if the shapes comply (but I haven’t tried it), maybe it might need more training epochs with the 87 I guess.

Thanks for the clarification. As I wrote over here [Confused about layer indexing in C4W1] I found the instructions about layer indexing confusing. ‘conv2d_87’ did get me through the grader, but I think the guidance on content layer choice could be clearer since we’re required to produce highly similar results.

Here is a fragment from that section of the network summary…

Is there magic about conv2d_88 to separate it from its neighbors in this context? Or its choice is arbitrary?

1 Like

I dont know why they choose the 88th maybe the grader expected results are a match for that, but I see here they all seem to have the same shape, but of course the output is not the same on each one of them.

1 Like