DLS4 Week 3 - Car Detection Exercise 4 - yolo_eval

Hi all,

For the first time, properly stumped on an exercise and can’t see what to change. I get the following error message on exercise 4, yolo_eval:

The exception is in the call to yolo_non_max_suppression, but if that function passed the test cases, then it must be that you are calling it incorrectly from yolo_eval. I added print statements to my yolo_eval code to show the shapes of everything and here’s what I see from that test case:

box_confidence.shape (19, 19, 5, 1)
box_class_probs.shape (19, 19, 5, 80)
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) = 1786
boxes.shape (1786, 4) before scale_boxes
image_shape (720, 1280)
boxes.shape (1786, 4) after scale_boxes

The first thing I’d want to see is what your value is for that last boxes.shape, which is in my code right before the call to yolo_non_max_suppression.

I have the following, but no print result comes from the code:

{moderator edit - solution code removed}

It comes out in the next box though as (1786,4)

Please show the complete output that you get with that print statement in the code. It sounds like you’re saying that the exception occurs before that line, but that doesn’t seem consistent with the previous trace you showed.

Does this help? This one has me very confused about nearly 4 full courses of these assignments!

{moderator edit - solution code removed}


Please check the function definition for yolo_non_max_suppression. My reading of the code is that you are passing the arguments in the wrong order when you call it from yolo_eval.

Is this correct for the tf non-max suppression function:

{moderator edit - solution code removed}

?

Yes, but that’s not the part that you have a problem with. It’s the function you wrote that calls that TF function that is not called correctly. The bad code is in yolo_eval.

Please confirm that your yolo_non_max_suppression code passes its test cases.

To state the point more clearly: when you call yolo_non_max_suppression from yolo_eval, you are calling it incorrectly. A perfectly correct function can still throw errors if you pass it bad arguments.

yolo_non_max_suppression does pass its test cases. The below is what I have for yolo_eval. I’m blind to what I could have done wrong - seems simple to follow given the instructions but I’ve clearly managed to misinterpret something :slight_smile: I have the feeling I’ve maybe got a typo? or I’ve used the wrong argument in a line somewhere…

{moderator edit - solution code removed}

Please do what I suggested earlier: look at the definition of yolo_non_max_suppression.

As in:

def yolo_non_max_suppression(scores, boxes, classes, max_boxes = 10, iou_threshold = 0.5):
“”"
Applies Non-max suppression (NMS) to set of boxes

Arguments:
scores -- tensor of shape (None,), output of yolo_filter_boxes()
boxes -- tensor of shape (None, 4), output of yolo_filter_boxes() that have been scaled to the image size (see later)
classes -- tensor of shape (None,), output of yolo_filter_boxes()
max_boxes -- integer, maximum number of predicted boxes you'd like
iou_threshold -- real value, "intersection over union" threshold used for NMS filtering

Returns:
scores -- tensor of shape (None, ), predicted score for each box
boxes -- tensor of shape (None, 4), predicted box coordinates
classes -- tensor of shape (None, ), predicted class for each box

Note: The "None" dimension of the output tensors has obviously to be less than max_boxes. Note also that this
function will transpose the shapes of scores, boxes, classes. This is made for convenience.

I’m stumped. I’ll give up for the weekend and see if I can work it out on Monday!

Now compare that to the call you wrote: what did you pass as the first argument?

1 Like

:man_facepalming: x100

Got it - thanks for your help. This is a sign I need a break, can’t spot silly errors!

2 Likes