Course 4 week 1 assignment 1 - Exercise 5 : conv_backward()

dA_mean = 0.6347704472654743
dW_mean = 1.5572657428497354
db_mean = 7.839232564616838

AssertionError Traceback (most recent call last)
22 assert dW.shape == (2, 2, 3, 8), f"Wrong shape for dW {dW.shape} != (2, 2, 3, 8)"
23 assert db.shape == (1, 1, 1, 8), f"Wrong shape for db {db.shape} != (1, 1, 1, 8)"
—> 24 assert np.isclose(np.mean(dA), 1.4524377), “Wrong values for dA”
25 assert np.isclose(np.mean(dW), 1.7269914), “Wrong values for dW”
26 assert np.isclose(np.mean(db), 7.8392325), “Wrong values for db”

AssertionError: Wrong values for dA


Looks like the shape of some of your variables is incorrect.


How come “AssertionError: Wrong values for dA” involves some shape mistake? I think there are other errors designed to get triggered if a bad shaping was present, which (I think) it is not the case.

PS.: I am having the exact same error, but my results show the following, and I don’t know where my error could be:

dA_mean = 0.24130207158952496
dW_mean = 5.721264942488976
db_mean = -1.2483155349054407

Any help would be appreciated, thanks.

1 Like

did you slove it? i got the same results

dA_mean = 0.24130207158952496
dW_mean = 5.721264942488976
db_mean = -1.2483155349054407

1 Like

hi, i had same problem. i solve it. i think you don’t multiply strides. vert_start and horiz_start is strides * (h or w). i was very tired to realize this. good luck.


Hello there @sagi_levi ,

In my case, it was exactly what @aiba_masaru suggested right above this comment. In other words:

axis_start = dimension*stride
axis_end = dimension*stride+f

Where axis could be vert or horiz, and dimension could be h or w, depending on your code section case.

Check your implementation very carefully, I am very sure you’ll figure it out :wink: :v:

Best regards!


yes is it ! thanks

‫בתאריך יום ה׳, 23 בדצמ׳ 2021 ב-22:43 מאת ‪David Espinosa via DeepLearning.AI‬‏ <‪‬‏>:‬

1 Like

Dave - thanks for this suggestion. I actually did account for this (after not properly implementing stride on a previous example) and had the following:

# Find the corners of the current "slice"
% mentor edit: code removed

However, this gave some other garbage #s:

dA_mean = -0.9370722652151867
dW_mean = -0.8767934077414234
db_mean = -1.2483155349054407

Turns out when I actually removed stride from the calculations I ended up with the numbers you and others in this thread calculated (db didn’t change).

Do you have any suggestions on where I might be going wrong? Currently going a bit crazy…thanks!


Ah!!! The bug was not in my conv_backward code, but rather in the mishandling of stride in my conv_forward code!!! I guess by sheer luck I caught this.

I guess the tests really need to be augmented to catch further errors in conv_forward, pool_forward, etc especially with regard to stride before they become needles in haystacks for later exercises.

Yes, there is a bug filed with the course staff about the fact that the unit tests for conv_forward and pool_forward do not catch that error. It’s been open for > one month at this point.

Although you could have noticed your code was wrong if you had examined the output of the stride = 2 test case for pool_forward carefully enough. All the values need to agree, not just most of them. It’s just that it doesn’t “throw” when they don’t all match.

1 Like

Thanks for the quick reply Paul. Yes, totally agree. I think the only difference (in the current iteration of the notebook) is that with the pool_forward exercise the second test cell does help catch stride issues despite not throwing, as you said, which is what helped me catch my bug there. However, I think there was only one conv_forward test cell (w/ stride = 1) which is why I failed to catch my bug there until the conv_backward exercise.

Enjoying this assignment quite a bit though!

Great! Yes, this assignment is pretty challenging, but it’s fun to really get a detailed view of how convolutions actually work. Pretty soon, we’ll switch to using TensorFlow for all that, but Prof Ng has the philosophy that we really need to have the intuition that comes from understanding how the algorithms actually work. If you just treat everything as a “canned” black box from TF, then you miss out on that level of understanding.

1 Like

Thank You for this question!!!

1 Like

Hello Vivek,

Sorry about the delayed reply :face_with_head_bandage: ! Have had lots of duties lately, so I could not reply you in time, my bad!

However, I saw somewhere down this thread, that you figured out where was the mistake, good! It means you are learning :stuck_out_tongue_winking_eye: :v:

Best regards, and have a nice learning!

1 Like