Yolo_filter_boxes() passes unit tests and fails when called from later function

I’m having an issue with yolo_filter_boxes, specificallly when applying my filtering mask. I have a mask with shape (19, 19, 5, 1) and it works for scores but not for boxes or classes. For the latter two, I get an error saying ValueError: Shapes (19, 19, 5, 4) and (19, 19, 5, 1) are incompatible

I was able to get around this by using np.squeeze() around the filtering_mask for these two calls, which makes the unit tests pass. However, when the function is called later on in predict(), I get the error ValueError: Shapes (1, 19, 19) and (19, 19, 5) are incompatible.

I think it has something to do with rank 1 array weirdness, but I can’t put my finger on it.

Thanks in advance.

I added print statements to show the shapes of all the objects in that function. Here’s what I see with code that passes:

boxes.shape (19, 19, 5, 4)
boxes.dtype <dtype: 'float32'>
box_scores.shape (19, 19, 5, 80)
box_scores.dtype <dtype: 'float32'>
box_classes.shape (19, 19, 5)
box_classes.dtype <dtype: 'int64'>
box_class_scores.shape (19, 19, 5)
box_class_scores.dtype <dtype: 'float32'>
filtering_mask.shape (19, 19, 5)
filtering_mask.dtype <dtype: 'bool'>
sum(filtering_mask) = 1789
scores[2] = 9.270486
boxes[2] = [ 4.6399336  3.2303846  4.431282  -2.202031 ]
classes[2] = 8
scores.shape = (1789,)
boxes.shape = (1789, 4)
classes.shape = (1789,)
 All tests passed!

Let us know if that sheds any light.

I tried submitting it as it was to see if it clarified anything, and apparently it passes all of the grader’s tests because it gives me 100%.

Will definitely take another look at my shapes.

Fixed one place where I was keeping the dims and needed to discard them, but that didn’t fix my problem.

I also got this the second time I submitted:

`Sorry, your submission was incorrect. Please try again. [Errno 2] No such file or directory: ‘/shared/submission/submission.json’`

The 0% grading problem was transient; it went back to 100% on the next try.

I fixed my errors. I think was using np.squeeze() to compensate for an earlier keepdims=True. Still not sure exactly how the error worked though. (I saved a copy of the notebook that demonstrated the issue, failing the unit test with a ValueError but passing the grading assessment).

Thanks again!

It’s great that you found the solution. Thanks for confirming!

how to solve this problem

Please show us the output from the test you failing.

That type of problem (different behavior with different inputs) typically means that your code is not general. E.g. you are referencing global variables instead of the formal parameters of the function or are hard-coding some other assumption that happens to match one test case.

Sorry, your submission was incorrect. Please try again. [Errno 2] No such file or directory: ‘/shared/submission/submission.json’

That is the output from the grader. Does it work when you do “Cell → Run All” in the notebook?

Also that output sounds like there is something structural wrong, not some problem with your algorithm. Are you doing this on the Coursera website or on your local computer? You can’t access the grader if you are running locally.

Yes, I am working directly on the Coursera Jupyter Notebook, not on a local computer

Sir, I kindly request your guidance, as my Coursera subscription is scheduled to expire at 12 o’clock today

Ok, I’ll need to look at your notebook. We can’t do that on a public thread, but check your DMs for a message from me.