Conv_forward function, Week 1 Assignment 1

Ok. I think I’ve implemented what you’re saying but it still isn’t working. My loops now look like:

for h in range(n_H)
vert_start = hstride
vert_end = h
stride + f

It passes the first test case where the stride is 2, but for the second test case when the stride is 1 it for some reason I’m getting the following error. I don’t understand why all

I realized that when I wrote the line to use the padding function I put in a pad value of 1 instead of using the “pad” variable that is taken from the hparameters dictionary. I’m now failing one of the test cases and passing the other ones.

1 Like

Great to see that you’re making progress!

The problem now appears to be that the values for Z are ints when they should be floats. The cause for this could be in conv_single_step (did you cast b to a float before adding it to Z?), or it may result from casting a value to an int somewhere.

I did cast b as a float in the conv_single_step function. I think the only place that I use the int() function is for the n_H and n_W calculation

I tried doing this to automatically cast it as a float but the print statement is saying that each Z[i,h,w,c] is a <class ‘numpy.int64’>

Did you pass the test just below conv_single_step, with a value for Z of -6.999089450680221 (or close to it)?

1 Like

Yes I passed that test

OK, I can replicate that error if I use dtype=np.int64 in the initialization of Z with zeros (Z=np.zeros(()). If that is the case with you, this should be removed so that Z can be a float.

That was it. I initialized Z as such: Z = np.full((m, n_H, n_W, n_C), 0) but I guess I needed to initialize it like: Z = np.full((m, n_H, n_W, n_C), float(0))

Thank you so much renoudbosch I really really appreciate all the help

You’re welcome. Great that you made it through! Please do remember to remove the code snippets from your posts. Enjoy the rest of the course!

It seems that is the key post for undertstanding the stride. I understood that when we move from 1 in the Output volume it is corresponding of a movement of stride in a input Volume . But i still do not understand how and where to to that in code.

Hi luroten,

Maybe these suggestions help? Good luck!