The Dataset Field Guide
object detection from first photo to blinking Raspberry Pi — collection, consent, labeling, balance, training, honest evaluation, and edge deployment. written around Ultralytics YOLO, true for any detector. everything on this page runs offline, right here.
1Collect like the deployment, not like the demo
A detector learns exactly the world you show it. The most common failure is a dataset that looks like your desk on a sunny afternoon, deployed into a warehouse at night. Before one photo, write down where the model will run — then collect that.
- Vary what will vary: lighting, distance (objects at 20px and 400px), angle, clutter, weather, partial occlusion.
- Same camera family as deployment — phone photos train phone models; a Pi camera deserves Pi-camera training data.
- Rules of thumb (search “Ultralytics tips for best training results”): ≥1,500 images and ≥10,000 instances per class for production work. Hobby models survive on far less — expect it to show.
- ~10% background images with no objects at all, unlabeled: the cheapest false-positive medicine there is.
2Consent — the chapter people skip, and shouldn’t
Every photo of a person is a photo of a person. The craft standard: collect people only with their knowledge and agreement, minimize what you keep, strip what you don’t need.
- Ask first. If a person is the subject, get agreement — written, for anything shared. People say yes surprisingly often when asked honestly.
- Incidental people: blur faces and plates before an image enters the dataset.
- Children: just don’t. Guardian consent and review sit beyond hobby scope — redesign the collection instead.
- Strip EXIF: phone photos embed GPS — often someone’s home. Remove metadata before sharing anything.
- Other people’s images: visible online ≠ licensed for training. Check the license or ask the photographer.
3Label with craft — the box is the curriculum
Your boxes teach the model what an object is. Loose boxes teach it that ducks include a foot of pond. A visible-but-unlabeled object is an active lie — the model learns to ignore it, then keeps ignoring it in production.
- Tight boxes: every visible pixel in, as little background as possible.
- Label every instance in every image.
- Occlusion rule: pick one convention and write it down. Consistency beats philosophy.
- Class definition doc: a paragraph per class with edge cases (“is a decoy a duck? no”).
YOLO stores one .txt per image — one object per line, normalized 0–1:
class x_center y_center width height 0 0.481 0.634 0.212 0.187 2 0.104 0.512 0.334 0.406
4Balance — the quiet saboteur
If 90% of your instances are one class, the model becomes an enthusiast of that class and shrugs at the rest. Count instances per class early — yolo prints the table at train time, but by then you’ve already collected.
- Keep the max:min instance ratio in single digits; under 3:1 is comfortable.
- Fix imbalance by collecting more of the rare class — augmentation stretches data, it does not create information.
- Split hygiene: train/val/test must not share scenes. Split by session or location, not by random frame, or your val score becomes fan fiction.
5Train & track — dials worth touching
What the model actually is
backbone → neck → head. modern YOLO is anchor-free: the head predicts box coordinates directly at three scales.
Pick a size you can afford
| model | params | COCO mAP50-95 | who it’s for |
|---|---|---|---|
| yolov8n | ~3.2M | ~37 | edge devices, the Pi — start here |
| yolov8s | ~11M | ~45 | laptops, decent CPUs |
| yolov8m | ~26M | ~50 | desktop GPUs |
| yolov8l/x | ~44–68M | ~53–54 | server GPUs, when accuracy pays rent |
Arguments worth touching (and leaving alone)
| dial | start at | touch it when… |
|---|---|---|
| epochs | 100 | curves still improving at the end → more; val worsens early → fewer + patience |
| imgsz | 640 | tiny objects → up; edge latency hurts → 320–416 |
| batch | largest that fits | out-of-memory errors → down |
| patience | 50 | early-stops too eagerly on noisy small datasets → up |
| lr0 | default | almost never first — data fixes beat learning-rate séances |
| seed | set one | always — reproducibility is a gift to future-you |
Track your runs or repeat your mistakes
Loss curves and per-epoch mAP live in runs/ — but a tracker turns runs into an experiment log. Search by name: Weights & Biases (W&B — Ultralytics integrates it; enable and every run logs itself), TensorBoard, MLflow. Whatever you use, log: the dataset version, the full args, and per-class AP. The question you’ll ask in three weeks is “what changed?” — make it answerable.
6Evaluate — read the numbers like a skeptic
- Precision — of the boxes drawn, how many were real? Low = hallucinating.
- Recall — of the real objects, how many were found? Low = missing.
- mAP50 — a box counts at IoU ≥ 0.5. The friendly number.
- mAP50-95 — averaged over IoU 0.5→0.95. Harsh, honest, the one to report.
7Deploy — the Raspberry Pi 4 road
The main road of this guide: train on your PC, shrink, and run on a Raspberry Pi 4 (4GB). It has no neural accelerator — just four honest ARM cores — which makes it the perfect teacher: every millisecond you save, you understand.
The beginner walkthrough
- Train small, elsewhere. yolov8n, your dataset, on your PC or a free cloud notebook. The Pi is for running models, never training them.
- Validate before you ship. yolo val — check per-class AP, not just the average.
- Export for ARM: yolo export format=ncnn imgsz=320 — NCNN is the ARM-CPU specialist. (ONNX is the portable fallback.) Export at the size you’ll run.
- Prepare the Pi: 64-bit Raspberry Pi OS, then install the Ultralytics package. A fan or heatsink keeps the cores from throttling mid-demo.
- Test offline first. Run detection on 20 saved photos and eyeball every output — before any camera, network, or audience is involved.
- Then attach the camera and time it honestly: milliseconds per frame, averaged over a minute, box drawn on screen.
- Too slow? In order: drop to imgsz=320 → skip frames (detect every 3rd) → INT8 quantization → and only then, exotic hardware.
Export formats — the comparison
All exports come from one command — yolo export format=… — but they are not interchangeable citizens. On the Pi road the choice that matters most is NCNN vs ONNX:
| format | best on | Pi 4 CPU speed | why you’d choose it |
|---|---|---|---|
| ncnn | ARM CPUs (the Pi) | ~1× · fastest here | hand-tuned ARM kernels; the Pi specialist. Less tooling elsewhere. |
| onnx | almost everywhere | ~1.3–1.6× slower | the portable interchange — one file, many runtimes (ONNX Runtime), easiest Python, the right default when you don’t know your final hardware yet. |
| tflite | phones, MCUs | ~1.2–1.5× slower | where INT8 quantization lives; the road to NPUs and microcontrollers. |
| .pt (raw PyTorch) | your training PC | ~2–3× slower | zero export friction, worst edge speed — fine for the saved-images test, not for the demo. |
| tensorrt · coreml · openvino | NVIDIA · Apple · Intel | n/a on Pi | vendor specialists — huge wins, only on their own hardware. |
Quantization — smaller numbers, faster math
The hardware, honestly compared
latency figures are ballparks for orientation, not benchmarks — measure on your own bench.
Raspberry Pi 4 · 4GB the main road
- brain
- 4× Cortex-A72 @ 1.5GHz · no NPU
- memory
- 4GB RAM — roomy; the model is the least of it
- realistic model
- yolov8n · imgsz 320–640
- ballpark latency
- ~150–300ms @320 · ~0.5–1s @640 (NCNN, CPU)
- export path
- NCNN (best) or ONNX · FP32 fine, INT8 helps
- best for
- learning deployment end-to-end; full Linux, real Python, easy debugging
Grove Vision AI V2 the specialist
- brain
- Himax WiseEye2 · Cortex-M55 + Ethos-U55 NPU
- memory
- megabytes, not gigabytes — the model must be tiny
- realistic model
- quantized yolov8n-class @ 192–256px
- ballpark latency
- ~40–80ms — the NPU earns its keep
- export path
- TFLite INT8 mandatory, compiled for the NPU (SenseCraft flow)
- best for
- fast inference on coin-cell power; less flexible, more magical
ESP32-S3 the ascetic
- brain
- 2× LX7 @ 240MHz · SIMD, no NPU
- memory
- ~512KB SRAM + up to 8MB PSRAM
- realistic model
- full YOLO does not fit. micro-models (FOMO-class) @ 96×96
- ballpark latency
- ~200–600ms for micro-models, INT8 only
- export path
- TFLite Micro / ESP-DL · INT8 mandatory
- best for
- presence/counting on a few dollars; honesty about limits required
Where to go from here — search by name (names age better than links): Ultralytics YOLO docs (“Raspberry Pi” and “NCNN” guides), Label Studio / CVAT for annotation, Weights & Biases for tracking, Edge Impulse for the microcontroller road, and the COCO paper for where the metrics were born.