DLS 4, week 3, Programming Assignment: Car detection with YOLO, Exercise 1 - yolo_filter_boxes

Hello,
I receive the following error
AssertionError: Wrong shape in scores

My scores shape is scores.shape = (1789, 80)
whereas it is expected (1789,)

I define classes as
classes = tf.boolean_mask( box_classes,filtering_mask)
where
box_classes = tf.math.argmax(box_scores,axis=-1)
filtering_mask = = tf.dtypes.cast(box_class_scores,tf.float64) >= threshold

I added a bunch of print statements to my code to show the shape and type of everything for this case. Here’s what I see:

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'>
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!

Compare your shapes and that should point out where things go off the rails.

1 Like

I wrote
classes = tf.boolean_mask( box_classes,filtering_mask)
I havw exactly the same shape and type as you for both box_classes and filtering_mask.
but classes has shape (1789, 80)

for reference
box_classes(19, 19, 5)<dtype: ‘int64’>
filtering_mask(19, 19, 5)<dtype: ‘bool’>

You must be misinterpreting something about the shapes. My code for computing classes looks exactly the same. Please show the output of these print statements:

    print(f"boxes.shape {boxes.shape}")
    print(f"boxes.dtype {boxes.dtype}")
    print(f"box_scores.shape {box_scores.shape}")
    print(f"box_scores.dtype {box_scores.dtype}")
    print(f"box_classes.shape {box_classes.shape}")
    print(f"box_classes.dtype {box_classes.dtype}")
    print(f"box_class_scores.shape {box_class_scores.shape}")
    print(f"box_class_scores.dtype {box_class_scores.dtype}")
    print(f"filtering_mask.shape {filtering_mask.shape}")
    print(f"filtering_mask.dtype {filtering_mask.dtype}")

boxes.shape (1789, 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’>

At # Step 4: Apply the mask to box_class_scores, boxes and box_classes

I filled in the line
boxes = tf.boolean_mask( boxes, filtering_mask)

I found my error.
I replaced box_class_scores with box_scores.

Now it says ‘all tests passed!’.
Thanks.