Sub topic 10
Measuring Consistency with IoU and Annotator Agreement
Prerequisites and the basic question
This chapter assumes you understand Python functions, lists, dictionaries, JSON, image dimensions, and the purpose of supervised model training. It also assumes that you can draw bounding boxes or polygons in an annotation tool.
Annotation quality has two separate dimensions:
- Accuracy: does a label describe the object correctly?
- Consistency: would another trained annotator create a similar label?
Intersection over union, or IoU, measures the overlap between two regions. A region can be a bounding box or a segmentation mask.
IoU for bounding boxes
For two regions, IoU is:
area of intersection / area of union
The intersection is the part shared by both regions. The union is the area covered by either region. IoU ranges from 0 to 1:
- 0 means no overlap.
- 1 means identical regions.
- Higher values usually mean stronger agreement.
Boxes are often represented as (x_min, y_min, x_max, y_max). The first point is the top-left corner, and the second is the bottom-right corner.
def box_iou(a, b):
"""Boxes use (x_min, y_min, x_max, y_max) coordinates."""
ix1 = max(a[0], b[0])
iy1 = max(a[1], b[1])
ix2 = min(a[2], b[2])
iy2 = min(a[3], b[3])
intersection = max(0, ix2 - ix1) * max(0, iy2 - iy1)
area_a = (a[2] - a[0]) * (a[3] - a[1])
area_b = (b[2] - b[0]) * (b[3] - b[1])
union = area_a + area_b - intersection
return intersection / union if union else 0.0
first = (50, 40, 150, 90)
second = (60, 45, 160, 95)
print(box_iou(first, second))The coordinate convention matters. A COCO box uses (x_min, y_min, width, height), so convert it before calling this function. Mixing conventions can produce plausible but incorrect scores.
A project may set a minimum agreement target such as IoU 0.7. The correct target depends on the task. Small objects and highly crowded scenes often need different rules from large, isolated objects.
IoU for segmentation masks
A binary mask is an array in which 1 marks object pixels and 0 marks background pixels. For masks, intersection is the number of pixels where both masks equal 1. Union is the number of pixels where either mask equals 1.
import numpy as np
def mask_iou(mask_a, mask_b):
mask_a = mask_a.astype(bool)
mask_b = mask_b.astype(bool)
intersection = np.logical_and(mask_a, mask_b).sum()
union = np.logical_or(mask_a, mask_b).sum()
return intersection / union if union else 0.0
label_a = np.array([[1, 1, 0], [1, 0, 0]])
label_b = np.array([[1, 0, 0], [1, 1, 0]])
print(mask_iou(label_a, label_b))Mask IoU is sensitive to boundary differences. Two annotators can agree about the object while tracing slightly different edges. Record whether the disagreement comes from a loose boundary, a missed object part, or an incorrect object identity.
Measuring annotator agreement
A useful review workflow is:
- Give the same image batch to two annotators independently.
- Match labels that refer to the same object and class.
- Calculate IoU for each matched pair.
- Record unmatched labels as missed objects or false extra objects.
- Inspect low-scoring examples and update the guideline if needed.
For class labels, report the percentage of matched objects with the same class. If the dataset has many possible classes, use a confusion matrix to show which classes are being confused.
Raw agreement can be misleading when one class dominates. Cohen’s kappa adjusts for agreement that could occur by chance, but it does not replace inspecting the actual annotations. For detection, missed and extra objects also matter, so report counts alongside IoU.
Exercise
Exercise
Two annotators draw boxes with IoU 0.62, while the project target is 0.70. What should you do before simply rejecting one label?
Show answer
Inspect the disagreement, check the coordinate convention, determine whether the guideline covers the case, and have a reviewer decide which box better represents the rule.