7x4x5. Yes, youre right. Thanks. Have a good night. Hopefully Ill get it or by tomorrow maybe.
on another note that is weird… a prev 0 is supposed to be m, number of samples, how would that be a 3D array of floats?!? a problem for another day
The point is that A_prev[0]
is a whole different thing than A_prev.shape[0]
, right?
Thank you., you’re right. I’ll try that.
Just to get a jump start whenever you’re available the next few days. Here is a next error I’ve come across. At this point I’ve printed out shapes of everything and they look good. I’ve printed weight and bias values and they are not zeros. But when I run it I get this.
Z’s mean =
0.22395833333333334
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
Your output: 0.22395833333333334
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]
AssertionError Traceback (most recent call last)
in
15
16 conv_forward_test_1(z_mean, z_0_2_1, cache_0_1_2_3)
—> 17 conv_forward_test_2(conv_forward)
~/work/release/W1A1/public_tests.py in conv_forward_test_2(target)
117 [-0.47552486, -0.16577702, -0.64971742, 1.63138295]])
118
→ 119 assert np.isclose(Z_means, expected_Z), f"Wrong Z mean. Expected: {expected_Z} got: {Z_means}"
120 assert np.allclose(cache_conv[0][1, 2], expected_conv), f"Values in Z are wrong"
121
AssertionError: Wrong Z mean. Expected: -0.5384027772160062 got: -0.016666666666666666
I feel like Z (021) coming out as all zeros is the clue to what the problem is. maybe I’m wrongn. But I’m utilizing the conv single step from a previous exercise to calculate Z. My conv single step in the previous exercise passed so it should work so it must not be that. Maybe I’m using incorrect variables. I know that in other posts you have made many comments about how it is the stride that messes people up. Perhaps its messing me up to but I got it “right” compared to what ive seen others you’ve corrected end up with. Or at least it always made sense to me how the vert start/vert end related to stride and f. i could be misunderstanding how you always state that it needs to touch everything from the input data to go into the output data. but I have vert start defined by n_W not by w or anything so I’m having it interact with input data.
Anyways no rush. Thanks for all your help so far. Talk to you later.
Hi @zac_builta!
Have you tried this?
Furthermore, how are you implementing the below formula?
Are you using the hint below:
# Compute the dimensions of the CONV output volume using the formula given above.
# Hint: use int() to apply the 'floor' operation. (≈2 lines)
# n_H = None
# n_W = None
Best,
Saif.
n_H type is float 64. so when I use it in zeroing Z and in the for loop I do np.int(n_H))
for calculating n_H I use the formula n_H = (np.floor((np.int(n_H_prev-f+(2*pad))/stride)))+1
There might be an extra set of parenthesis in there. I might be able to get away with (np.floor(np.int(n_h_prev-f+(2*pad))/stride))+1 but I feel like the extra parenthesis shouldn’t interfere with order of operations. but who knows maybe in python or np
OK. Using your equation, n_H = (np.floor((np.int(n_H_prev-f+(2*pad))/stride)))+1, I got this: n_H type is <class 'numpy.float64'>
And Using the equation suggested by a hint, I got: n_H type is <class 'int'>
# Hint: use int() to apply the 'floor' operation.
So, why not make the things simple. Just use the suggested way for n_H
and n_W
and then use these, without np.int() or dtype = int
, in Z. Using np.int(n_H)) or dtype = int
in Z gives error.
By the way, I just found that np.int()
and int()
are not the same, and using the former gives an error.
Right. You don’t need the np.floor
or np.int
in order to implement the “floor” operation. Saif has pointed out the solution that they gave you in the comment. So you’re working way harder there than you needed to, but it looks like the rest of it is correct.
The most likely reason that Z[0,2,1] is all zeros is that you are implementing the loops incorrectly. Did you include the “stride” as a “step” value in the for loop range? That’s a mistake because the loops here are over the output space (the dimensions of Z) and we can’t skip any positions. The striding (skipping) happens in the input space, which is on the A_prev
side, right?
Oh thanks. I thought np.int WAS doing what they said in the hint. I didn’t know they were two different things I guess.
my used stride as in vert start = h x stride, vert end = vert start + f . for h in range np.int(n_H)(output space). I’ll fix the np.int stuff here too
That sounds right, although (as you say) n_H
should already be an integer there. So the problem must be elsewhere …
what does it mean when it says hint use int() for the floor operation. Some of the ways i’ve found to convert from float to int are: 1. np.int(), 2. dtype = int, 3. astype(int).
I tried:
(n_H_prev-f+(2*pad)).int() for calculating n_H
and got error:
int object has no attribute int
can you link me to what you saw that showed how np.int and int() are different?
is it just used like this:
(n_H_prev-f+(2*pad)).int()
I tried this and it didn’t work as well.
The way you know they are different is that np.int()
is a numpy function: that’s what the np
means, right? So it operates on arrays. But int()
is just a python function, so it operates on scalars.
You are trying to use int()
as a “method” of an object, but the underlying value is just a python scalar, which is why you get that message about not having an attribute. Try this:
x = int(3/2)
print(x)
print(type(x))
to see how it works.
okay so it translates int3/2 into 1 and int. so when I try that to apply the floor operation
n_H = (np.floor(int(n_H_prev-f+(2*pad))/stride))+1 I once again get the error that float64 cant be interpreted as int in the Zeros function.
similar to an earlier exercise. In order to do floor it wants the int() to be applied first. I dont apply int after foor?
even when I apply int() as
n_H = (np.floor(int(n_H_prev)-f+(2*pad))/stride))+1
I still get the float 64 isn’t int.
I want to clarify, I’m trying to follow the instructions : 2 lines. It would work just as well to take the float output of n_H and just say n_H = int(n_H), that would just involve extra lines?