0
0
Computer Visionml~20 mins

IoU (Intersection over Union) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
IoU Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding IoU Calculation

Given two bounding boxes, what does the Intersection over Union (IoU) metric measure?

AThe sum of the areas of the two boxes without considering overlap.
BThe ratio of the overlapping area of the two boxes to the total area covered by both boxes combined.
CThe difference between the areas of the two boxes.
DThe ratio of the smaller box area to the larger box area.
Attempts:
2 left
💡 Hint

Think about how much two boxes overlap compared to their combined size.

Predict Output
intermediate
2:00remaining
Calculate IoU for Two Boxes

What is the output of the following Python code that calculates IoU for two bounding boxes?

Computer Vision
def iou(box1, box2):
    x_left = max(box1[0], box2[0])
    y_top = max(box1[1], box2[1])
    x_right = min(box1[2], box2[2])
    y_bottom = min(box1[3], box2[3])

    if x_right < x_left or y_bottom < y_top:
        return 0.0

    intersection_area = (x_right - x_left) * (y_bottom - y_top)

    box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1])
    box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1])

    iou_value = intersection_area / float(box1_area + box2_area - intersection_area)
    return round(iou_value, 2)

box1 = [1, 1, 4, 4]
box2 = [2, 2, 5, 5]
print(iou(box1, box2))
A0.14
B0.25
C0.11
D0.29
Attempts:
2 left
💡 Hint

Calculate intersection and union areas carefully.

Model Choice
advanced
1:30remaining
Choosing IoU Threshold for Object Detection

In object detection, which IoU threshold is commonly used to decide if a predicted bounding box is a true positive?

A0.1
B0.75
C0.5
D0.9
Attempts:
2 left
💡 Hint

Think about a balance between strictness and leniency in overlap.

Metrics
advanced
2:00remaining
Effect of IoU Threshold on Precision and Recall

What happens to precision and recall when the IoU threshold for true positive detection is increased from 0.5 to 0.75?

APrecision increases, recall decreases
BPrecision decreases, recall increases
CBoth precision and recall increase
DBoth precision and recall decrease
Attempts:
2 left
💡 Hint

Higher IoU threshold means stricter matching.

🔧 Debug
expert
2:30remaining
Debugging IoU Calculation Code

What error does the following IoU calculation code produce when run, and why?

Computer Vision
def iou(box1, box2):
    x_left = min(box1[0], box2[0])
    y_top = min(box1[1], box2[1])
    x_right = max(box1[2], box2[2])
    y_bottom = max(box1[3], box2[3])

    if x_right < x_left or y_bottom < y_top:
        return 0.0

    intersection_area = (x_right - x_left) * (y_bottom - y_top)

    box1_area = (box1[2] - box1[0]) * (box1[3] - box1[1])
    box2_area = (box2[2] - box2[0]) * (box2[3] - box2[1])

    iou_value = intersection_area / float(box1_area + box2_area - intersection_area)
    return iou_value

box1 = [1, 1, 4, 4]
box2 = [2, 2, 5, 5]
print(iou(box1, box2))
AThe code returns IoU greater than 1 because it uses min and max incorrectly for intersection coordinates.
BThe code raises a ZeroDivisionError because intersection_area is zero.
CThe code returns zero because the boxes do not overlap.
DThe code runs correctly and returns the correct IoU.
Attempts:
2 left
💡 Hint

Check how intersection coordinates are calculated.