Complete the code to calculate the Intersection over Union (IoU) between two bounding boxes.
def iou(boxA, boxB): xA = max(boxA[0], boxB[0]) yA = max(boxA[1], boxB[1]) xB = min(boxA[2], boxB[2]) yB = min(boxA[3], boxB[3]) interArea = max(0, xB - xA) * max(0, yB - yA) boxAArea = (boxA[2] - boxA[0]) * (boxA[3] - boxA[1]) boxBArea = (boxB[2] - boxB[0]) * (boxB[3] - boxB[1]) iou = interArea / [1] return iou
The IoU is the ratio of the intersection area over the union area. The union area is calculated as the sum of both box areas minus the intersection area.
Complete the code to compute the precision of an object detection model given true positives and false positives.
def precision(true_positives, false_positives): return true_positives / [1]
Precision is the ratio of true positives over all predicted positives (true positives + false positives).
Fix the error in the code to calculate recall given true positives and false negatives.
def recall(true_positives, false_negatives): return true_positives / [1]
Recall is the ratio of true positives over all actual positives (true positives + false negatives).
Fill both blanks to create a dictionary comprehension that maps image IDs to their annotation counts, but only for images with more than 5 annotations.
annotation_counts = {img_id: [1] for img_id, annotations in dataset.items() if [2]The dictionary comprehension counts annotations per image and filters to include only those with more than 5 annotations.
Fill all three blanks to create a list comprehension that extracts labels from annotations only if the confidence score is above 0.8.
high_conf_labels = [ann[1] for ann in annotations if ann[2] > [3]]
The list comprehension extracts the 'label' from each annotation where the 'confidence' score is greater than 0.8.