I am trying to follow @Bakir’s logic description and have come up with the following running log:
m:2, n_H:3, n_W:4, n_C:8
b: [[[[-1.39881282 0.08176782 -0.45994283 0.64435367 0.37167029
1.85300949 0.14225137 0.51350548]]]]
A_prev.shape: (2, 5, 7, 4) a_prev_pad: (5, 7, 4)
vstart: 1 vend:4
hstart: 1 hend: 4
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:-1.3988128186664763
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.08176781880561644
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:-0.45994283084068716
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.6443536660303223
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.37167029121186534
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:1.853009485069379
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.14225137252631778
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.5135054799885475
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
hstart: 1 hend: 4
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:-1.3988128186664763
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.08176781880561644
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:-0.45994283084068716
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.6443536660303223
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.37167029121186534
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:1.853009485069379
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.14225137252631778
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.5135054799885475
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
hstart: 3 hend: 6
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:-1.3988128186664763
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.08176781880561644
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:-0.45994283084068716
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.6443536660303223
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.37167029121186534
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:1.853009485069379
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.14225137252631778
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
a_slice_prev.shape: (3, 3, 4) weights: (3, 3, 4) bias:0.5135054799885475
a_slice_prev.shape: (3, 3, 4), W.shape: (3, 3, 4)
hstart: 5 hend: 8
a_slice_prev.shape: (3, 2, 4) weights: (3, 3, 4) bias:-1.3988128186664763
a_slice_prev.shape: (3, 2, 4), W.shape: (3, 3, 4)
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
<ipython-input-51-7e580406a9e8> in <module>
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]
<ipython-input-50-342532606697> in conv_forward(A_prev, W, b, hparameters)
86 bias = b[0, 0, 0, c]
87 print(f'a_slice_prev.shape: {a_slice_prev.shape} weights: {weights.shape} bias:{bias}')
---> 88 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, bias)
89 pass
90 # YOUR CODE ENDS HERE
<ipython-input-40-ae92196f3681> in conv_single_step(a_slice_prev, W, b)
24 # YOUR CODE STARTS HERE
25 print(f'a_slice_prev.shape: {a_slice_prev.shape}, W.shape: {W.shape}')
---> 26 s = a_slice_prev * W
27 Z = np.sum(s)
28 Z += np.asscalar(b)
ValueError: operands could not be broadcast together with shapes (3,2,4) (3,3,4)
When hstart=5 and hend=8, the matrix shapes don’t match: (3,2,4) & (3,3,4).
Based on n_H and n_W formula, I got the following formula to caculate:
# moderator edit; code removed
Is this in the right direction? Also another question that might cause the issue is that, I didn’t make use of this reminder:
Use array slicing (e.g.`varname[0:1,:,3:5]` ) for the following variables:
`a_prev_pad` ,`W` , `b`
Instead, without using slicing as above, I got a_prev_pad by indexing into A_prev through the ‘i’, which is the training example index.