Course 4, Week 1, Assignment 1

Hello! I am really struggeling with assignment 1exercise 3. I checked it a million times, and it says the output is not right. I will describe what I did.

  1. I selected the dimensions for W and A_prev (all the notations and order has been kep consistent throughout).
  2. I took out from hyperparameters, the pad and stride
  3. I calculated the size of n_H and n_W using the formula.
  4. I initialized Z using the dimension:(nr. of training examples, n_H, n_W , the number of filters)
  5. I padded A_prev using the previously calculated function to get the new padded image
  6. In the for loops, I loop over nr. of training examples, n_H, n_W and numbr of filters.
  7. In loop 1: I select the current training example
  8. In loop 2: I define the vertical edges by adding f to the the increment h
  9. In loop3: I define the horizontal edges by adding f to the increment w
  10. In loop4: a) I select the slice that I want to be convoluted using from from the current training example >a_prev_pad[vertical,horzontal,everything]
    b) I get the weights and biases from W and b by using W[everything, everything, everything, everything, increment for number of filters] → select the filter that want to apply
    c) apply conv_single_step(a_slice_prev, weights, biases) to get a scalar Z

The dimensions seem to be fine, the calculations too. I have no idea what to do. I am stuck on this for 3 days already and I can t move on beacause this function is required for the next exercise. I would greatly appreciate any help. Thank you!

You need to include using “stride” when you compute horiz_start and vert_start, then add ‘f’ to get horiz_end and vert_end.


Thank you! I got it in now

Mosh, in this assignment exercise why do we need to take b[:,:,:,c]? why can’t we only take b[1,1,1,c] as Andrew Ng pointed out in the videos?

Well, you could take an approach like that, but remember that indexing is “zero based” in python. myArray[1] is not the first element of the array, but the second, right?

But why not use the more general method with “:” to say “take all values for this dimension” and then you don’t have to worry about getting the index correct. :nerd_face: