As far as I can tell my code doesn’t have any gaping holes and the shapes of all the arrays are correct based on previous comments.
However, as my code executes and the nested for loop for h,w and c does it’s thing, the shape of a_slice_prev changes from 3,3,4 to 3,0,4 after 10 or so iterations.
Any help on fixing this issue would be hugely appreciated!
Right! The key thing to remember in this chunk of code is that the loops are over the output space, not the input space. As Tom describes, you compute the start and end position in the input space based on the loop variable (h or w in the output space) and then taking into account the stride and the filter size. The symptom you show means that you are running off the end of the input array in the w dimension. Note that the test case here is not typical of actual problems in that the nH_{prev} and nW_{prev} values are not symmetrical. The nW_{prev} is bigger. So perhaps you have to h and w reversed or something of that nature.
As one way to debug, try adding some print statements to show the various shapes that you get. For comparison, here’s what I get for the one test test for conv_block with some print statements as I am suggesting:
Thanks. My for loop is on the output value and my start values include multiplication by stride. My end values are the same +f.
The shape of the arrays also match Paul’s comment above. I don’t suppose I could direct message either of you my code to take a look where I’m going wrong?