Sub topic 11
Quality control: review passes, audits and validation scripts
This chapter assumes you can write basic Python, read COCO-style JSON, compute box IoU, and know why label noise hurts a trained detector. It also assumes you have seen the inter-annotator agreement idea from the previous chapter. Here you will combine those pieces into a quality control (QC) process: automated checks, human review, sampled audits, and a feedback loop into the guidelines.
Why QC is a process, not a final check
A single labeller will make mistakes even with good guidelines. Typical errors fall into three groups:
- Mechanical errors. Boxes outside the image, zero-size boxes, swapped width and height, wrong class ID after a format conversion, duplicate boxes.
- Judgement errors. Missed objects, loose or tight boxes, a polygon that cuts off a limb, inconsistent treatment of occluded or truncated objects.
- Systematic errors. The guideline is ambiguous, so every annotator is wrong in the same way, or the annotation tool exports a coordinate convention you did not expect.
Each group needs a different tool. Scripts catch mechanical errors cheaply and completely. Human review catches judgement errors. Audits and agreement metrics expose systematic problems, because they show where annotators disagree with each other or with a trusted reference.
Layer 1: validation scripts
Run validation before any human looks at a batch. A reviewer's time is expensive, and a script finds a box that extends past the image edge in milliseconds.
Good validation checks are cheap, deterministic and specific. Start with these:
- Every
image_idandcategory_idin an annotation refers to an existing image and class. - Annotation IDs are unique.
- Boxes have positive width and height, above a minimum size you choose per project.
- Boxes lie inside the image.
- No two boxes of the same class on one image overlap almost completely (a likely duplicate).
- Polygons have at least three points, and polygon points lie inside the image.
The script below implements the first five checks over a COCO dictionary and returns a list of (annotation_id, message) pairs. It runs as written.
from collections import defaultdict
def iou_xywh(a, b):
"""IoU for COCO boxes given as [x_min, y_min, width, height]."""
ax2, ay2 = a[0] + a[2], a[1] + a[3]
bx2, by2 = b[0] + b[2], b[1] + b[3]
ix = max(0, min(ax2, bx2) - max(a[0], b[0]))
iy = max(0, min(ay2, by2) - max(a[1], b[1]))
inter = ix * iy
union = a[2] * a[3] + b[2] * b[3] - inter
return inter / union if union > 0 else 0.0
def validate_coco(data, dup_iou=0.9, min_side=2):
images = {im["id"]: im for im in data["images"]}
categories = {c["id"] for c in data["categories"]}
problems = []
seen_ids = set()
by_image = defaultdict(list)
for ann in data["annotations"]:
aid = ann["id"]
if aid in seen_ids:
problems.append((aid, "duplicate annotation id"))
seen_ids.add(aid)
im = images.get(ann["image_id"])
if im is None:
problems.append((aid, "unknown image_id"))
continue
if ann["category_id"] not in categories:
problems.append((aid, "unknown category_id"))
x, y, w, h = ann["bbox"]
if w < min_side or h < min_side:
problems.append((aid, "box smaller than min side"))
if x < 0 or y < 0 or x + w > im["width"] or y + h > im["height"]:
problems.append((aid, "box outside image"))
by_image[ann["image_id"]].append(ann)
for anns in by_image.values():
for i in range(len(anns)):
for j in range(i + 1, len(anns)):
a, b = anns[i], anns[j]
same_class = a["category_id"] == b["category_id"]
if same_class and iou_xywh(a["bbox"], b["bbox"]) >= dup_iou:
problems.append((b["id"], f"near-duplicate of annotation {a['id']}"))
return problems
data = {
"images": [{"id": 1, "file_name": "street_001.jpg", "width": 640, "height": 480}],
"categories": [{"id": 1, "name": "car"}],
"annotations": [
{"id": 1, "image_id": 1, "category_id": 1, "bbox": [50, 40, 100, 50]},
{"id": 2, "image_id": 1, "category_id": 1, "bbox": [600, 40, 100, 50]},
{"id": 3, "image_id": 1, "category_id": 1, "bbox": [50, 40, 100, 50]},
{"id": 4, "image_id": 9, "category_id": 1, "bbox": [0, 0, 10, 10]},
{"id": 5, "image_id": 1, "category_id": 7, "bbox": [10, 10, 1, 1]},
],
}
for aid, message in validate_coco(data):
print(aid, message)The script prints:
2 box outside image
4 unknown image_id
5 unknown category_id
5 box smaller than min side
3 near-duplicate of annotation 1Annotation 4 stops at the first check because later checks need the image's size. Annotation 5 reports two problems, so collect all problems per annotation instead of raising on the first one. Annotators then fix a whole batch in one round.
Treat warnings and errors differently
Not every finding is a mistake. Two overlapping boxes of the same class are an error in a street scene with single cars, but normal in a crowd of people. Split your checks into two levels:
- Errors block the batch: out-of-image boxes, unknown classes, zero-size boxes.
- Warnings go to a reviewer: very small boxes, extreme aspect ratios, near-duplicates, images with no annotations, images with unusually many.
A warning list is also useful for finding systematic problems. If one annotator's images are all flagged for tiny boxes, ask whether they are labelling distant objects that the guideline says to skip.
Layer 2: review passes
A review pass means a second person looks at each annotated image and accepts, edits or rejects the labels. Decide these points before you start:
- Who reviews. A reviewer should be more experienced than the annotator, or at least someone who did not label that image. Self-review misses the errors the annotator already believes are correct.
- What a reviewer may change. Allowing direct edits is faster. Allowing only accept or reject gives you a clean error signal, because every rejection is counted. Many teams let reviewers edit and log each edit.
- What reviewers look for. Give them a short checklist taken from the guidelines: missed objects, wrong class, loose boxes, occlusion and truncation rules applied correctly, polygon edges following the object.
Review all of the first batches from a new annotator. Once their error rate is stable and low, move to sampling. Review everything for a new class or a newly changed guideline, because those are the points where mistakes cluster.
Layer 3: audits against gold labels
An audit measures quality instead of fixing it. You take a random sample of finished work and compare it with gold labels, which are labels produced by an expert or by consensus of several experts. The comparison gives an error rate per annotator, per class and per batch.
Sample at random but with a floor per annotator, so a low-volume annotator is not skipped:
import random
def audit_sample(ids_by_annotator, rate=0.1, min_per_annotator=5, seed=0):
rng = random.Random(seed)
sample = {}
for annotator, ids in ids_by_annotator.items():
k = min(len(ids), max(min_per_annotator, round(rate * len(ids))))
sample[annotator] = rng.sample(sorted(ids), k)
return sample
work = {"ana": list(range(100)), "ben": list(range(100, 130))}
picked = audit_sample(work)
print({name: len(ids) for name, ids in picked.items()})This prints {'ana': 10, 'ben': 5}. The fixed seed makes the audit reproducible, which matters when an annotator disputes it.
Scoring an audited image
Match each annotated box to a gold box of the same class by IoU. A common choice is to count a match at IoU of 0.5 or higher for detection tasks. Use a higher threshold for tight-fit tasks such as segmentation, where you would compare mask IoU instead. After matching:
- Unmatched annotated boxes are false positives: extra boxes, wrong class, or badly placed boxes.
- Unmatched gold boxes are false negatives: missed objects.
- Matched pairs with IoU below your tightness bar are imprecise boxes.
Report error counts per class. A class with many false negatives usually has a guideline problem, such as unclear rules for small or occluded instances.
How big should the audit be?
Small samples give weak guarantees. If you audit 50 images and find zero errors, the 95% upper bound on the true error rate is still about 3 / 50, which is 6%. This is the "rule of three". To claim an error rate below 1% you need around 300 clean samples. Choose the acceptance threshold and the sample size together, and write both down before the audit starts.
Closing the loop: feedback to guidelines
The goal of QC is to prevent errors, not only to catch them. After each audit, group the rejected items by cause:
| Cause | Typical sign | Fix |
|---|---|---|
| Ambiguous guideline | Several annotators make the same mistake | Add a rule and example images to the guideline |
| Missing edge case | Reviewers disagree with each other | Decide the case, record it in the guideline, and relabel affected images |
| Tool problem | Errors at image borders or in one export format | Fix the tool configuration or the converter |
| Annotator skill | Errors concentrated in one person | Give targeted feedback and increase review rate |
| Fatigue or speed pressure | Errors rise late in long sessions | Shorten sessions or adjust throughput targets |
When you change a guideline, version it, and record which guideline version each batch followed. Otherwise you cannot tell whether an old batch is wrong or simply labelled under an older rule. Relabel old data under the new rule only when the change affects a rule the model will learn.
Common mistakes
- Running validation only at the end. Run it at export time and also on each batch as it arrives, so annotators get feedback while the context is fresh.
- Validating the converted file but not the source. A converter that normalises coordinates can hide errors. A box that was off the image in COCO may become a valid-looking number after clamping. Validate before and after conversion.
- Reviewing without a checklist. Reviewers then drift toward their own preferences, and review becomes another source of inconsistency.
- Using the same person as annotator and gold labeller. Audit scores then measure self-consistency, not accuracy.
- Ignoring class imbalance in audits. A random image sample may contain only a few examples of a rare class. Stratify the sample by class when rare classes matter.
Exercise
An audit of 60 images finds no errors. A colleague says the labels are therefore at least 99% accurate. What is wrong with that claim, and what does the rule of three suggest instead?
Show answer
With 60 clean samples, the 95% upper bound on the true error rate is about 3 / 60 = 5%, so accuracy of about 95% is the most you can claim, not 99%. Zero observed errors only shows that the error rate is probably small. To support a claim of under 1% errors you need about 300 clean samples.
Exercise
Your validation script flags a COCO box [0, 0, 640, 480] on a 640x480 image as valid, but a reviewer says it is wrong. Give two reasons the box can pass validation and still be an error, and name one extra check you could add as a warning.
Show answer
The box is fully inside the image with positive size and could carry a valid class, so a format-level check cannot see that it is the wrong object or a placeholder covering the whole image. Reasons: the annotator may have used a default full-image box by mistake, or the box may be a real label on a class that does not fill the frame. A useful warning is to flag boxes whose area is above a high fraction of the image, for example more than 90%, for the classes where that is unlikely.