# C3W4 assignment: cannot get the required 0.95 accuracy

**URL:** <https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255>\
**Category:** Advanced Computer Vision with TensorFlow\
**Tags:** week-module-4\
**Created:** [January 8, 2024, 1:54am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255 "2024-01-08T01:54:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yan\_Du](https://avatars.discourse-cdn.com/v4/letter/y/85f322/32.png) [@Yan\_Du](https://community.deeplearning.ai/u/Yan_Du)\
**Post date:** [January 8, 2024, 1:54am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/1 "2024-01-08T01:54:30Z")

</div>

Hi,

I have difficulties reaching the desired 0.95 accuracy for C3W4 assignment. I have searched the previous posts and have checked my code for loss function, optimizer, etc. But still could not figure out why. Here is my loss function:

{mentor edit: code removed}

Any help would be highly appreciated!

---

<div class="post-metadata">

**Author:** ![TMosh](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/tmosh/32/9321_2.png) [@TMosh](https://community.deeplearning.ai/u/TMosh)\
**Post date:** [January 8, 2024, 3:15am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/2 "2024-01-08T03:15:39Z")

</div>

Please do not post your code on the forum. That is not allowed by the Code of Conduct.

Perhaps a mentor for this course will be able to provide some guidance.

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [January 8, 2024, 5:46am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/3 "2024-01-08T05:46:50Z")

</div>

Well, where do you think could be the issue?

---

<div class="post-metadata">

**Author:** ![Yan\_Du](https://avatars.discourse-cdn.com/v4/letter/y/85f322/32.png) [@Yan\_Du](https://community.deeplearning.ai/u/Yan_Du)\
**Post date:** [January 9, 2024, 1:29am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/4 "2024-01-09T01:29:45Z")

</div>

Hi Gent,

Could I get a hint? I really could not figure out which part of the code goes wrong. Thanks!

---

<div class="post-metadata">

**Author:** ![Yan\_Du](https://avatars.discourse-cdn.com/v4/letter/y/85f322/32.png) [@Yan\_Du](https://community.deeplearning.ai/u/Yan_Du)\
**Post date:** [January 9, 2024, 1:39am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/5 "2024-01-09T01:39:28Z")

</div>

Hi Gent,

I sent a copy of my assignment to you via DM. Could you take a look? Many thanks!

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [January 9, 2024, 6:54am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/6 "2024-01-09T06:54:09Z")

</div>

Hello Yan,

I saw your code which seems to be alright, the only thing is this line:

# Add an additional dimension (for the batch), and save this in a new variable

can you try to use a new named variable here! and let us know the result!

---

<div class="post-metadata">

**Author:** ![Yan\_Du](https://avatars.discourse-cdn.com/v4/letter/y/85f322/32.png) [@Yan\_Du](https://community.deeplearning.ai/u/Yan_Du)\
**Post date:** [January 9, 2024, 7:10am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/7 "2024-01-09T07:10:35Z")

</div>

Hi Gent,

Thanks for your reply!

After I use a new variable, the accuracy is still 0.91. Is there any other suggested solution? Thanks!

---

<div class="post-metadata">

**Author:** ![gent.spah](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/gent.spah/32/136423_2.png) [@gent.spah](https://community.deeplearning.ai/u/gent.spah)\
**Post date:** [January 9, 2024, 7:18am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/8 "2024-01-09T07:18:09Z")

</div>

Hmm, my eye did not catch any other issues. On gradient tape loop you have to use the new variable not img anymore!

Maybe go through the assignment from scratch again you might catch a mistake somewhere!

---

<div class="post-metadata">

**Author:** ![i.khozhanov](https://avatars.discourse-cdn.com/v4/letter/i/43a26b/32.png) [@i.khozhanov](https://community.deeplearning.ai/u/i.khozhanov)\
**Post date:** [January 9, 2024, 12:00pm UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/9 "2024-01-09T12:00:01Z")

</div>

Hi, try to use fallback runtime:

> [@TF-AT: Using the Fallback Runtime](https://community.deeplearning.ai/t/tf-at-using-the-fallback-runtime-to-avoid-slow-training-in-colab/530596):
>
> Google Colab updates its runtime periodically to use newer versions of packages like Tensorflow. This can sometimes affect the use of GPUs for notebooks that require older versions, or cause problems in installing required packages. To get around it, please use the fallback runtime before running any of the code in your notebook. Here are the steps: Make sure that you are already connected to a runtime (CPU or GPU, depending on the default used in the assignment). You can click on that on the…

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 9, 2024, 12:30pm UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/10 "2024-01-09T12:30:50Z")

</div>

Hello Yan\_Du,

1. You did not define function that could taken on label, you only did for image.  
Please define label using tf.one\_hot function in the def augment image. grader cell.

2. The below statement is an optional steps but if you are not getting the desired accuracy, I would suggest you to explore this option but not mandatory.

optional: superimpose the saliency map with the original image, then display it.  
we encourage you to do this to visualize your results better.

1. For you model compile statement you loss choice is incorrect, it is not a multicategorial classification but only categorical classification with 2 class, so using sparse is incorrect.

Let me know if you are still stuck, sorry for the delay in response, not keeping well.

Also @Yan_Du kindly make sure once you do these correction, then follow the steps of fallback runtime and then run all the cells one by one, then submit your model for successful submission.

Regards  
DP

---

<div class="post-metadata">

**Author:** ![Yan\_Du](https://avatars.discourse-cdn.com/v4/letter/y/85f322/32.png) [@Yan\_Du](https://community.deeplearning.ai/u/Yan_Du)\
**Post date:** [January 9, 2024, 8:51pm UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/11 "2024-01-09T20:51:48Z")

</div>

Thank you!! The fallback runtime works!!

---

<div class="post-metadata">

**Author:** ![Deepti\_Prasad](https://sea1.discourse-cdn.com/dlai/user_avatar/community.deeplearning.ai/deepti_prasad/32/165831_2.png) [@Deepti\_Prasad](https://community.deeplearning.ai/u/Deepti_Prasad)\
**Post date:** [January 10, 2024, 7:18am UTC](https://community.deeplearning.ai/t/c3w4-assignment-cannot-get-the-required-0-95-accuracy/538255/12 "2024-01-10T07:18:45Z")

</div>

Hello @Yan_Du,

Do you mean without doing the correction the fallback runtime helping with the score??

I had sent you the same link to try first before reviewing your notebook.

Just let me know if that’s the case.

Regards  
DP
