Advanced computer vision saliency maps week 4 assignment ssim score

When creating a post, please add:i

  • Week # must be added in the tags option of the post.
  • Link to the classroom item you are referring to:
  • Description (include relevant info but please do not post solution code or your entire notebook): Structural Similarity Index

Filename: Structural Similarity Index

0/100Score: 0 of 100

Hide grader output

Grader output

Your images achieved an average structural similarity index of 0.91. At least 0.95 is required to pass. Detailed list: structural similarity index for ‘salientcat1.jpg’: 0.92. structural similarity index for ‘salientcat2.jpg’: 0.90. structural similarity index for ‘salientcatanddog.jpg’: 0.93. structural similarity index for ‘salientdog1.jpg’: 0.89. structural similarity index for ‘salientdog2.jpg’: 0.90.

based on the 15 epochs of pretrained weightsi cannot get passed an avg of 91 ive been trying for a number of days - ill be open to pointers

1 Like


Did you go through all the pointers for correction of code I responded to your previous post?

No need to be sorry. We all are learning and you can surely ask n number of questions but only hoping full effort from learners as I really gave point by point where your codes are incorrect. Send your updated notebook where you got 91 similarity index via personal DM



Check your DM, I have sent you a corrected notebook where corrections were required.

Kindly let me know once your issue is resolved and close all the public post threads you created related to this assignment by explaining how you resolved and what mistakes you did, so others learner could also learn.



Hi @Deepti, I have followed your instructions in other post threads, but I’m seen something similar:

Your images achieved an average structural similarity index of 0.90. At least 0.95 is required to pass.
Detailed list:
structural similarity index for ‘salientcat1.jpg’: 0.92.
structural similarity index for ‘salientcat2.jpg’: 0.90.
structural similarity index for ‘salientcatanddog.jpg’: 0.92.
structural similarity index for ‘salientdog1.jpg’: 0.88.
structural similarity index for ‘salientdog2.jpg’: 0.90.

I receive that but do not understand why. It is really frustrating do not understand the requirements considered to pass the assignment.

1 Like

Which instructions I gave you :thinking:

Hi @Deepti, not to me. To Paul. I tried to follow your conversation in different threads

Hello Jorge_Murria,

Please send your copy renamed with your name by personal DM. Click on my name and then message.


1 Like

Hello Jorge_Murria,

required corrections in your notebook

  1. In def augmentimages(image, label):
    for defining the function for label you do not need to tf.cast, just use the tf.one_hot
    You first masked the label that step is not required as in the instructions it clearly mentioned to only cast the image to float32 and not label.

  2. in def do_salience
    Define the expected output array by one-hot encoding the label
    The length of the array is equal to the number of classes
    class_index = label(THIS IS NOT REQUIRED) Use label directly in the expected output code

Although I noticed one more thing few of your grader cell seem to be edited out, I would sincerely suggest you to re-do with a fresh copy where you do not remove any of the instructions messages or ##YOUR CODE HERE and by referring the copy you did complete it and submit it again with the correction I mentioned. You actually have done pretty great job just here and there missed out.

Kindly let me know once your issue is resolved.



Hi! After fixing some issues, the key point to pass this assignment has been run it fallback as is explained here:

Thanks a lot Deepti for your help!

1 Like

Happy to help Jorge and thank you for posting the explanation so others learners can learn too.

Keep learning!!!



Hi! Run it using the fallback also let me pass the assignment with the exact same code. Could anyone explain why this could happen?

1 Like

Hello David @fdavidsen8 ,

the course assignment is facing this issue because of incompatibility between newer version of package like tensorflow. So as stated in the linked post by Chris, the GPU gets affected for that particular notebook requiring older version.

By using fallback runtime, one can resolve this issue. Not everyone faces this issue, this is happening only for some learners.


1 Like

Hi @Deepti_Prasad,

I’m facing a similar problem, i.e., the average structural similarity index is lower than 0.95.


  • I am using the fallback runtime version;
  • I am hot-encoding the labels to have a shape suitable for predictions (I won’t write the explicit code because of the code of conduct):
def augmentimages(image, label): 
    label = tf.one_hot(label, ...)
  • I have tried different combinations of both categorical losses and activation functions.

That being said, I’ve never achieved the average structural similarity index of 0.95 but the model is learning as you can see by the images of the cat and the dog.

Any suggestion or review of the notebook would be really appreciated.
Thank you :slight_smile:

1 Like

Hi @Deepti_Prasad ,

Should I have created a new thread, or did I do the right thing by posting here?
In case I was wrong I can delete it and start a new one.


1 Like

Hello @Luca_Macis,

Always create a new post even if you find similar week assignment problems as your. You could tag this post thread to the post you create by referring you referred this post and it didn’t get much help. Only DMs directly to the mentors with codes is not allowed until asked by a mentor to DM your codes.

The reason creating a post is more encouraged as it will not confuse the mentor or learners if your issue matches totally with the previous learner issue, and also sometimes if the post is already solved, mentors could miss your post comment. These are reason why always creating a new post is encouraged. I hope you understand and follow this way of learning journey. I agree sometime we end up commenting on older post threads thinking that our problem could be same, I myself have got told by other mentors to do this :slight_smile: for NLP course where currently I am learner.

But this time it is okay, I already saw your post. I was stuck in some other work. Give me sometime to go through your comments and reply back.

Thank you for your patience.


  1. is this the way you recalled the labels or included label with 2?

  2. Please give detail about which activation you have used for the last dense layer in your model?

  3. The most common mistake by learners in this assignment was related def do salience grader cell where the learner missed converting the image from BGR to RGB, check if you have done this.

  4. The next usual mistake one can do in the below statement of def do salience grader cell
    Define the expected output array by one-hot encoding the label, how have you recalled image shape in this code.

  5. Next let me which loss you used in GradientTape block

  6. Next create your model compile statement based on the instructions given below

  7. The last thing you need to confirm is if you have run the Optional: Saliency Maps at 95 epochs.

Kindly do so.

Let me know if you have done assignment as per the instructions shared and yet facing the same issue. If any change that what I have stated, kindly give details about what step you missed or you used instead of sharing codes. This way you are also learning on how to debug your assignment.


1 Like

First of all, I wanted to thank you for the mentor job and point out that I asked the question about creating the new post or not to simplify the whole process of teaching you and learning us.
Getting back to the problem:

I don’t know if I understood your question well, but this is the way I’m dealing with converting the labels in augmentimages, example:

indices before one hot encoding:
[0, 1]
indices after one hot encoding:
[[1. 0.]
 [0. 1.]], shape=(2, 2), dtype=float32)

Currently I’m using softmax because I want “the sum of the probabilities adds up to 1.” I also used the sigmoid just to see if the accuracy could have improved.

I did this (not writing the whole because of the CoC):
tf.reverse(..., ...)

First, I expanded the dimensionality of the image as requested with tf.expand_dims where I added the batch dimension. Then I defined the expected output using the batch dimensionality of the new expanded image. That is, I used tf.one_hot and multiplied [label] by the batch size of the new expanded image, and depth set equal to the number of classes.

Categorical Cross Entropy, since dealing with 2 classes. I also tried the Binary with no improvement. Am I wrong in using them?

Yes, I did it.

Yes (but not every time), because I wanted to see if do_salience() was working as expected.

Thank you again :slight_smile:


1 Like

The problem was not among those listed in the previous post but was within the do_salience() function.
I was using the tensorflow library functions to read the image and convert the color order from BGR to RGB instead of using the OpenCV library functions.

Based on your both response, you catched the right error in your codes.

Yes your bgr to RGB codes were incorrect and you catched the culprit :grin:

Keep Learning!!!


1 Like

Well, in my case is strange. I wanted to run the jupyter on my laptop because the Google Colab is slow. So, I downloaded the notebook and work on my laptop, then upload the, it fails. Then I copy my code and run it on Google Colab, reupload the, it works. The difference is that the filename extension .jpeg on my laptop and .jpg on Google Colab. The zip size is a bit different. That’s it.