C4_W1 Optional Exercise 8 - pool_backward -- Unable to Obtain the expected results

Dear community, I am trying hard to get the code works but got stuck with the above output errors - not matching the expected results. Please kindly help. Let me know what information you need & I will share. (Note: I understand I can post my coding here…)

Notice that your mean values are both correct, but it looks like perhaps you have reversed the roles of max pooling and average pooling in your logic. There are other problems as well, but maybe that’s the place to start.

sorry Paul! I don’t quite understand you by the “have reversed the roles of max pooling and average pooling in your logic…” appreciate your clarification…

to add, in …if mode == “max”: , i have:

{moderator edit - solution code removed}

any concern here?

Please compare your results in the “max” case with the “expected values” in the average case. You’ll see that the first and last rows are the same, right? But the middle row is wrong. You have at least two bugs here: the reversal of max and average and there is something wrong with your handling of the middle row. Compare your average values with the expected values for the max case. Note that the first and last rows agree, but the middle row is different.

thanks Paul. will dig in further … and update my finding…

That looks right to me for the “max” case, but why do your max results look like the average results as I pointed out above?

dunno… not sure is my jupyter notebook error… how to reset the notebook?

To restart kernel, click Kernel → Restart.

But also notice that your values for mode = average are also not the same as expected. So, I guess bug is somewhere else. Send me your code of Ex. 8 in a private message. Click my name and message.

Best,
Saif.

thanks Saif… for your kind request… that prompted me to find the accidentally error in the code. It is working now. Thanks Paul.

I am glad you found it. Just to update others, @BHTan accidentally commented out the “elif” line for mode == “average”.

Thanks Paul. I found out why - I had accidentally commented out the “elif” line during my debugging… that bypass mode = “average” case hence, all zero… while it is working as expected but I still not sure why the earlier result for the “max” case that exhibits part of the expected output for “average” case - a mystery to me… Not sure any one can help explain it… Many thanks in advance.

When you commented the average mode line, the body of average mode became the body of max mode.

thanks Saif, yes, effectively dA_prev[i,vert_start:vert_end, horiz_start:horiz_end, c] further got updated with distribute_value function … wonder does it further enhances max pooling backprop by the average pooling… interesting result.