getting AssertionError: Wrong shape: (8, 7, 7, 6) != (4, 9, 9, 2)
I am using
X_pad = np.pad(X, pad_width = 2, mode=‘constant’, constant_values=(0,0))
Any corrections?
getting AssertionError: Wrong shape: (8, 7, 7, 6) != (4, 9, 9, 2)
I am using
X_pad = np.pad(X, pad_width = 2, mode=‘constant’, constant_values=(0,0))
Any corrections?
Welcome to the community.
The problem is, if “int” is set to pad_width, then, it means “before” and “after” padding will be done for all axes. I’m not sure where “2” comes from, but 'pad_width" is wrong.
The padding is applied to the height and width of an image, as illustrated in Figure 1.
As described, we need to add padding only for the height and width. Please see an example, and create an appropriate sequence for “pad_width”.
I have tried many combinations but could not resolve. Can anyone give the solution code please?
Can anyone give the solution code please?
No one can provide. That’s a violation of the community rule, and also Coursera Honor Code.
Programming is not a trial and error. It’s logical. Here is the way to think about.
From the above, you can see that you need 4 combinations of (before, after) padding. And, it is obvious that the first and last combination should be (0,0) since no addition is required.
The number of padding is given as “pad” for zero_pad(). This padding number is used for the 2nd and 3rd combination of (before, after). And, we add same number for both “before” and “after”.
The above is almost the code. Hope you can go with the above.
Following your guidance, I have written following
but still the error is AssertionError: Wrong shape: (4, 7, 7, 2) != (5, 8, 8, 3)
You need to look at each variable very carefully. What you have in zero_pad() is a local variable, “X”, capital X, not “x” which is a global variable.
By the way, please remove the above code. We should always start with a Traceback in any cases.
Finally, it ran. Thanks a lot. ![]()