There error i’m working with is a very common one on this forum I am aware.
ValueError Traceback (most recent call last)
in
6 “stride”: 2}
7
----> 8 Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
9 z_mean = np.mean(Z)
10 z_0_2_1 = Z[0, 2, 1]
in conv_forward(A_prev, W, b, hparameters)
79 weights = W[:,:,:,c]
80 biases = b[:,:,:,c]
—> 81 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
82
83 # YOUR CODE ENDS HERE
in conv_single_step(a_slice_prev, W, b)
24 # YOUR CODE STARTS HERE
25
—> 26 s = a_slice_prev * W
27 Z = np.sum(s)
28 Z = Z + np.float64(b)
ValueError: operands could not be broadcast together with shapes (3,3) (3,3,4).
I will try to mention a few of the things that have been in these other posts and explain my reasoning.
To begin, “a slice prev” is a since slice in the for loops of the ‘c’ index. I’ve tried calculating a slice prev by taking the padded version of a prev, a prev pad, and using the index of vertical start and end, horizontal start and end, and the c channel.
To move forward I must go backward a step. How did I get a prev pad, this came from iterating over the ‘i’ samples of A prev pad. A prev pad came from A prev using the padding function. A prev was a 4D array (1,2,3,4) so A prev pad was also 4D (1,2,3,4). a prev pad came from iterating the ith dimension of A prev pad. This was the first index, index zero. a prev pad would be the varying indexes of A prev pad(i,2,3,4) a single slice of the different m samples.
Here I find my first slight confusion. At first I think if a prev pad is the ith iteration of A prev pad I might say it was also a 4D array. But maybe it could also be a 3D array since it itself doesn’t have an ith dimension of m, it just is a single slice of that stack of many a prev pads. So I’m not sure about 3 vs 4 dimension when looking at a a prev pad. I think 3.
Now to go back to where we started. I have a singe slice of index i of m samples called a prev pad. I then take this and use the vert start/end, horiz start end, and c to get a slice prev. There are three dimensions there with (vertstart:end, horiz start end, and c) which leads me again to believe a prev pad is 3D, this would then make a slice prev 3D.
But just like earlier going from A prev pad to a prev pad I selected for one index. I am iterating over the c channel of a prev pad to get a slice prev so maybe a slice prev is now just 2D since each one is just a 2D height and width of channel c?
My weights and biases are set to 4D with c being the 4th input. Z(i,h,w,c) I used a previous function conv single step which takes a slice prev, weights, and biases. so weights is 4D, a slice prev is 2D? or maybe 3. so multiplying a slice prev * weights is already gonna be a mistake there. Z in the original function output a scalar of the array x W + b. here Z is some form of (i,h,w,c)? so is it 4 dimensional array or can it be a scalar and that just means its Z as a function of thsoe 4 variables?
my original error being cant broadcast together 3,3 and 3,3,4 and the first arrow above the message is to s = a slice prev * W which leads me to believe I’ve somehow covered the mistake here because I see that a slice prev is probably 2D maybe 3D as it is a slice an ith sample of a cth channel leaving height and width. and my weights are a 4D array of fxfxn_c_prev x n_c. and W is the channel index of that so it would be 3D maybe. so a slice_prev (2D) x W(3D) would seem to be the problem but as I’ve explained the way I came to those values seems to make sense to me a bit. I may be misunderstanding how these arrays change shape as I select for individual samples(m) and channels(c)
Sorry for the long post but I wanted to clarify that I’ve looked through the forum and worked through the problem so just saying “your Z is the wrong shape” although helpful, is not something I haven’t thought through so I think theres something fundamental I’m missing. I also haven’t figured out how to put in print statements that actually show up in the output. I try print statements and my errors just come out and I don’t see anything printed. so i’m doing all of this without printing out any of the various w.shape, z.shape type stuff.
Thanks