Week 1 Assignment 1 Conv_forward function

Getting the following error:

Z’s mean =
0.28648854269868845
Z[0,2,1] =
[0. 0. 0. 0. 0. 0. 0. 0.]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
First Test: Z’s mean is incorrect. Expected: 0.5511276474566768

First Test: Z[0,2,1] is incorrect. Expected: [-2.17796037, 8.07171329, -0.5772704, 3.36286738, 4.48113645, -2.89198428, 10.99288867, 3.03171932]
Your output: [0. 0. 0. 0. 0. 0. 0. 0.]

Second Test: All tests passed!

Vivek. Move your post to the right topic. Don’t forget to remove code from a public thread.

Thank you, Balajji. This must be in DLS.

@vivek_mehta, please change the category to “Deep Learning Specialization (DLS)”.

Here is an overview of a convolutional step.

Key iteration counters are based on the output shape, Z.
So, what we need to adjust is an input side to set the start points (horiz, vert) to consider the stride.
What you did is to use this stride as a step for iteration counters. This is not correct. We need to keep the counter, which is the output shape, as is. What we need to do is to adjust vert_start and horiz_start (and vert_end and horiz_end correspondingly) with considering a stride.

Hope this helps.

I updated the figure. (n_W and n_H were not set correctly).

Corrected the topic.

This is what i am asking. How to set the vert_start, vert_end, horiz_start and horiz_end. I nowhere found any formula for the same in the lectures.

This is what i am asking. How to set the vert_start, vert_end, horiz_start and horiz_end. I nowhere found any formula for the same in the lectures.

That’s not a matter of formula, but an algorithm that you need to implement.
And, this is an important convolutional step that we need to learn through this exercise.
(Actually, this algorithm is hidden under Tensorflow/Keras API like Conv2D, but this is a good exercise to learn what Conv2D is doing.)

I think the above figure shows what a convolution is doing, and what you need to implement. If you still have an issue, please elaborate.

I went through one of them but it didn’t help. Pls reply with few links.

What you did is to use this stride as a step for iteration counters. This is not correct. We need to keep the counter, which is the output shape, as is. What we need to do is to adjust vert_start and horiz_start (and vert_end and horiz_end correspondingly) with considering a stride.

You need to fix

1. “range” for iterations for h and w. No need to set “stride” in here, since, as I wrote, its counter is based on output size. Need a continuous index.
2. horiz_start/vert_start. Now you have a correct counter h, w. You need to consider the stride in here to set the correct position. That is also in my figure.
3. horiz_end/vert-end. It is quite easy. Just add a filter size (f), to the start points.

Hope this helps.

Finally, I made the it. start=stride*(h or w) and end = start + f. Thanks a lot. I must say, these discussion forums are really helpful.

1 Like

I want to ask the question: Why the the Resnet50 model shown in Exercise 3 contains “50” in it? I could not figure out the 50 layers in it.

Assuming that you are talking W2A1, have you executed a following cell ?

model = ResNet50(input_shape = (64, 64, 3), classes = 6)
print(model.summary())

You can see several layers in there, since both convolutional_block and identify_block include multiple layers in there.

By the way, if you start to talk about a different assignment, then, it is better to create a new topics so that others can easily search relevant topics.

I executed the above code, approximately 180 layers are there if I count each and every row shown in the output.

Just count the convolutional layers in the main path + last FC layer.
For more detail, see this paper.

This solved my issue as well, thanks for posting the issue and concluding the solution.