Convolution_model_step_by_step_v1 Exercise 3

I am having trouble understanding the last steps on exercise 3 of the 1st convolution assignment week 1. Specifically with the final initialization of the weights and biases. I don’t see how I can get them from the a_slice_prev. I initialized the a_slice_prev using the vert start and end, the horiz start and end, and the c of number of channels.

Here are some hints:

  1. n_C refers to the number of filters in a convolution layer.
  2. Each filter has:
    a. Enough weights to perform element-wise multiplication with a slice of the input i.e. a_slice_prev.
    b. 1 bias term
  3. conv_single_step performs a single step of convolution.
1 Like

These are the print statements that I have on my code.
image
It is not running. This is the error it outputs:

I suspect I am doing something wrong in the formula, since when I put those numbers in the calculator, they don’t give me the same dimensions as n_H and n_W, but not sure honestly

There are 2 mistakes here:

  1. Weights of a filter and the image slice must be of same shape. There should be 1 bias term per filter.
  2. You’ve already coded conv_single_step to perform a single convolution operation. Make use of it instead of coding the convolution function again.

I managed to match the shape between a_slice, weights, and biases to some degree:
image

But the error keeps occuring of not being able to match.

I seem to have trouble perhaps visualizing the form the shapes need.

The shapes of a_slice_prev and weights are not the same. It would help if you saw the lecture on how a single convolution is performed. Do pay attention to what element-wise multiplication does. It’ll give you clarity on what I mean by same shape.

As far as this exercise is concerned, read the code comments and markdown to understand what each dimension of the weight array stands for. Here are some more hints:

  1. n_C_prev = number of channels in the input to the current convolution layer.
  2. n_C = number of filters in the current convolution layer.

I managed to match the weights and slice. Now I get a different error of Z’s mean:

As you can see in that image, the program seems to run for some while with the correct shape in everything then all of the sudden it stops and gives this error:

I don’t know how the shape of the slice changed so drastically

I used the f and n_C_prev to initialize the weights as random.randn(f, f+1, n_C_prev)

W and b are provided as function parameters with the correct shape. Why reinitialize again?

I mean the variables weights and biases, not W and b. I initialized weights and biases to a random.randn(f, f+1, n_C_prev) and random.randn(1, 1, 1)

I DID IT!:

wujuu! My error was that the start and end were being calculated wrong. Thanks so much for the support. Love this place

I thought I had passed the test but I didn’t. :sweat_smile: @balaji.ambresh

I am still not passing the all tests apparently. Why is the first test not passing and the second is?

Interesting. Please click my name and message your notebook as an attachment.

Note from Angel:

I just managed to fix my problem. It was that I was not using the stride in the vert_start and horiz_start. Thank you very much for all your help!

1 Like