C4W1 NST Assignment


I am currently finishing up all the remaining assignments of Course 4 of the TFAT specialization. There is one assignment in particular with which I am having extreme difficulty obtaining the desired final result. More specifically, I’m referring to the Dog Style Transfer assignment.

When I run the inception model on the images without adjusting any of the hyperparameters (as indicated in the notebook), I end up with a stylized image that is extremely noisy and grainy. It is very difficult to make out the dog in the image.

Despite having checked my notebook for potential coding errors and compared it to the ungraded lab at least a dozen times, I am unable to determine why my stylized image is producing such a low similarity index (roughly 0.2-0.3) every time I run the cell. I’ve tried tweaking the style and content layers, the corresponding weights and even the number of epochs (even though I’m supposed to leave the latter two parameters alone), but to no avail. When I adjust the style weight to about 1e-5, I get an image that is a lot less grainy, but still produces a low index.

I don’t really know what more I can do to achieve the desired result. Any assistance would be greatly appreciated.



Hi Caleb,

To take a guess is difficult, perhaps you are not using the right content and style layers or most probably not calculating the righ total loss, or maybe you are not training the model properly…

I think its best to refresh the entire notebook and do it from the begining.

I’ve been using the same style and content layers as specified in the notebook for each of my model runs. A recurring problem I’ve read about for other people having similar issues is the order in which the layers are concatenated. However, I made sure to place the style layers before the content layer. I also checked my total loss multiple times for any possible errors and compared it to the one in the ungraded lab, but everything checks out.

Can I share my notebook with you so you can see what’s going on?



Sure I will try and have a look at it later on.

Right, so I saw your notebook and at the inception_model() fuction I see you are not loading up the weights of the pretrained model.

Thats what I could pick at this time.

I figured that since the weights are set to imagenet by default that I wouldn’t have to explicitly write out this setting. Unless there is a separate step that you’re referring to that I missed.

Nonetheless, I did what you suggested and the result is still unfortunately the same.

Can you pass the assignment or you fail it?

When I submitted the image for comparison, I did not pass. I received an index score of 0.23.

Hmm I will have another look at the file tomorrow again.

Sorry I can not see any problems through my inspection of the notebook. I would suggest at this point maybe perform a force refresh and redo it entirely.

I redid the entire assignment and ran the model again in a notebook on my other gmail account, but the result is still exactly the same as before.

Is there someone else that could maybe take a look at my notebook? Maybe we need a third set of eyes.

Hi Caleb,

In this post another student is having issues with the same assignamet:

Maybe you can find some inspiration.

If not, feel free to send me the notebook, i will try to check it today :slight_smile:


Hello Caleb,

I went back to the notebook and paid more attention to it this time,

at get_style_loss(features, targets) you are not supposed to use tf.reduce_sum() but it says "The style loss is the average of the squared differences "…

Try this now I think this should solve your problem (it actually does) and I am also testing it right now myself with this change, but if still persists send over the notebook to @Pere_Martra his eye might catch it!

1 Like

I am pleased to report that it did! I can’t believe I missed that little detail in my previous walkthroughs of the notebook.

Nonetheless, I very much appreciate your help and patience. Thank you very much for the assistance!


Hi Pere,

Thank you for referring me to this post. Fortunately, Gent spotted the error that was preventing the notebook from outputting the desired result. I was able to fix it in no time.

Nonetheless, I very much appreciate your offer of assistance!

1 Like