DEV Community

Taskmonk Team
Taskmonk Team

Posted on

Measuring Annotator Agreement with IoU and Cohen's Kappa in Python

Before you trust a labeled dataset, check whether annotators agree with each other. Two quick metrics cover most cases: IoU for boxes and Cohen's kappa for class labels.

IoU between two annotators' boxes

Intersection over union compares the overlap of two boxes with their combined area.

def iou(a, b):
    # boxes as [x1, y1, x2, y2]
    ix1, iy1 = max(a[0], b[0]), max(a[1], b[1])
    ix2, iy2 = min(a[2], b[2]), min(a[3], b[3])
    inter = 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])
    return inter / (area_a + area_b - inter) if inter else 0.0

print(iou([10, 10, 110, 110], [20, 20, 120, 120]))  # 0.68
Enter fullscreen mode Exit fullscreen mode

A common rule of thumb: IoU above 0.8 is tight agreement for large objects. Small objects need a looser threshold, because a few pixels change the score a lot.

Cohen's kappa for class labels

Raw percentage agreement overstates quality when one class dominates. Kappa corrects for agreement by chance.

from sklearn.metrics import cohen_kappa_score

annotator_a = ["car", "car", "truck", "bus", "car", "truck"]
annotator_b = ["car", "truck", "truck", "bus", "car", "car"]
print(cohen_kappa_score(annotator_a, annotator_b))  # ~0.45
Enter fullscreen mode Exit fullscreen mode

Rough reading: below 0.4 is weak, 0.4–0.6 moderate, 0.6–0.8 substantial and above 0.8 strong.

Turning numbers into action

  • Low kappa on one class usually means the guideline for that class is unclear.
  • Low IoU on one annotator means retraining, not a guideline change.
  • Track both per batch, so you catch drift early.

Do it continuously

Running these checks once is useful. Running them on every batch, with a hidden gold set, is what keeps quality stable on long projects.

Platforms like Taskmonk build agreement checks and gold-set sampling into the review workflow, so you get these metrics without writing the scripts yourself.

Top comments (0)