📚 Course contents

AI & Computer Vision, lesson 29 of 52

Clean the Field Data & Retrain

intermediate26 min readFull course

Introduction

You're back from the field with hundreds of frames. Not all of them deserve a place in your dataset. Today you'll clean the catch (blurry frames, near-copies, broken labels), split it fairly, retrain your detector on real field data, and compare it with your classroom model on the same test set, then explain the difference honestly.

By the end of this lesson you'll be able to:

  • Clean a raw field dataset: blurry frames, near-duplicates, label errors
  • Explain why we move rejected files aside instead of deleting them
  • Check class balance after cleaning and decide what to do about it
  • Split field data by session (lesson 13) so the test set is honest
  • Retrain the detector on the field data and compare it fairly with the classroom model
  • Explain the gap between classroom and field performance with evidence

Working principle

The cleaning steps, in order

StepChecksToolAction
1. Back upIs the raw data copied elsewhere?YouDo this first
2. Unreadable and blurryVariance of the Laplacian below a threshold (lesson 10)clean_dataset.pyMove to rejected/
3. Near-duplicatesAlmost identical images within one sessionPerceptual hashKeep the sharpest, move the rest
4. Label problemsMissing files, unknown classes, boxes outside the image, tiny boxesclean_dataset.pyMove for relabelling
5. Class balanceDoes one class have far fewer boxes?ReportCollect or label more of it (lesson 20)
6. Split by sessionWhole sessions in train, valid or test (lesson 13)Split scriptNo session in two sets

Why move, not delete

A threshold that is a bit too strict can throw away good data. By moving rejects into a rejected/ folder with a reason in a report, you can check, undo, and explain what you did.

Near-duplicate detection with a perceptual hash

A dHash shrinks an image to 9 by 8 grey pixels and records, for each pixel, whether it is brighter than its right neighbour. That gives 64 yes/no values describing the image's overall shape. Two nearly identical frames give almost the same 64 values: the number of differing values is the Hamming distance. At 4 or less we call it a near-duplicate. We only compare frames from the same session, because frames from different positions are not duplicates even if they look alike.

A fair comparison

It is tempting to compare "mAP on the classroom validation set" with "mAP on the field validation set". But those are different exams. To compare two models, score both on the same held-out test set, ideally made of field sessions neither model has seen. Otherwise you may be measuring a harder exam, not a worse model.

Why field performance usually drops

CauseLooks like
Distribution shiftClassroom images do not look like the pitch
Motion blur and distanceBall is a few blurry pixels
LightingSun, shadows, glare
Label noiseRushed labels on hard frames
Small test setLarge swings from a few frames
Class imbalanceToo few balls
Clean the Field Data & Retrain | Electronics Simplified