Week 3 assignment 1: Q1 shapes

hi guys for the q1 of the graded assignment , can someone help guide with regards to the shape of the box classes and the box class scores respectively ? so after a element wise multiplication on the box_confidence and box class probs is the shape of the tensor 1 by 80? if so are the box classes and box class scores 1 by n(n for the largest value and its indices respectively)

Hey @zheng_xiang1,
If you take a look at the doc-string for the yolo_filter_boxes function, you will find that box_confidence and box_class_probs have shapes of (19, 19, 5, 1) and (19, 19, 5, 80) respectively, so if we perform an element-wise multiplication on these 2 variables, the output will have a shape of (19, 19, 5, 80) due to Python broadcasting. You can always print the shape of box_scores and validate this yourself.

Now, when we perform max operations on box_scores across the last axis, that means the last axis having a size of 80, will be reduced to 1, so the resulting variables will have a shape of (19, 19, 5) or (19, 19, 5, 1) depending on how you use the max operations (by max, I am referring to all the forms of max, such as argmax, max, reduce_max, etc).

If you are still confused with the shapes of different variables, you can always use print(<var_name>.shape) to find out the shape of any variable. Let us know if this resolves your query.

Cheers,
Elemento

1 Like

As a supplement to Elemento’s detailed explanation, I added a bunch of print statements to show the shapes and types of everything and here’s what I get from the test cell for yolo_eval:

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
scores[2] = 171.60194
boxes[2] = [-1240.3483 -3212.5881  -645.78    2024.3052]
classes[2] = 16
scores.shape = (10,)
boxes.shape = (10, 4)
classes.shape = (10,)
 All tests passed!
2 Likes

thank you elemento!!! really just what i needed

thank you paul for the supplement