Conveyor Waste Detection
Real-time detection of recyclables on a conveyor, from zero-shot to fine-tuned YOLO11.
- Computer vision
- Role
- Computer-vision engineer (AI/CV workstream)
- Client
- An industrial recycling client
- Timeline
- Jul - Aug 2026
- Status
- PrototypePublic prototype (v1)
Output of the public v1 zero-shot pipeline: stable IDs, fused labels, confidences, and '~' on interpolated boxes. The input is a synthetic, AI-generated test clip (note the generator watermark), not real factory footage.
- FPS: zero-shot on Apple MPS, then fine-tuned on an A100
- 1.67 → 58.8
- FPS: zero-shot on Apple MPS, then fine-tuned on an A100
- per frame end-to-end, against a 41.67 ms budget
- 17.01 ms
- per frame end-to-end, against a 41.67 ms budget
- label flips on the hardest object after class fusion
- 14 → 3
- label flips on the hardest object after class fusion
- mislabelled training images caught and excluded
- 7,329
- mislabelled training images caught and excluded
- pytest tests, no GPU or network needed
- 191
- pytest tests, no GPU or network needed
The problem
A recycling line has to identify four material classes on a moving belt inside a 41.67 ms frame budget (24 FPS) and hand stable events to a downstream sorting core through a strict event contract. Two of the classes (aluminium can, cardboard) do not exist in COCO, no labelled data was provided, and the objects are shiny or transparent on a grey belt.
Open-vocabulary models were far too slow for real time, so a closed-vocabulary model had to be trained on public data. That data turned out to be mislabelled in ways validation metrics could not see, and it had to satisfy the client's material-identity annotation policy.
Architecture
Frames into the plugin
The client core hands each frame to the plugin's infer(). The detector runs with class-agnostic NMS, so one shiny object cannot survive as three classes.
- Service
- Data
- AI model
- External
Hard problems I solved
One object, three labels, seven tracks
A shiny can was detected as aluminium can, paper cup and plastic bottle on the same frame. Class-aware NMS kept all three boxes, the tracker spawned parallel tracks, and each track voted a different label. No single resolution worked either: 640 px found the transparent bottle but missed flat cardboard, 1536 px the reverse.
Approach. Run both scales and merge them with class-agnostic NMS, keeping one best box per object regardless of class. Boxes larger than 35% of the frame are dropped, since real conveyor objects are small.
That can went from 7 tracks to 1, and the total object count roughly halved.
Label flicker inside a clean track
Even a cleanly tracked can (no gaps) flipped between paper cup, bottle and can 14 times in 97 frames. Downstream sorting needs one class per object.
Approach. Temporal class fusion, per the client's tracking spec: the class is the confidence-weighted winner across the object's history so far. The handover says plainly that fusion fixes stability, not correctness: a can could still stay confidently labelled as a cup.
Label flips on that object: 14 to 3. The remaining wrong labels are what justified fine-tuning.
Measuring without ground truth
No labelled data existed, yet the client needed numbers. A first evaluation of NVIDIA LocateAnything-3B reported '95% accuracy' that was really box tightness on true positives.
Approach. Failure-signal tooling (weak detections, edge clipping, empty frames, label instability) with boxes rendered to check each reading; this overturned two plausible but wrong readings of the raw numbers. After review, a ground truth of 44 hand-labelled frames (79 boxes) replaced the first VLM report, with precision, recall and F1 per mode.
Baseline: 599.5 ms per frame (1.67 FPS). LocateAnything-3B: recall about 0.92, precision 0.50 to 0.59, about 3 s per frame and a non-commercial licence, so a pre-labelling aid, not a detector.
Mislabelled data that validation mAP could not see
Rendering training boxes showed one public dataset labelling plastic bottles and cardboard as 'Food Packet'. The model learned it perfectly: 216 of 320 detections on the test clip were confident and wrong, while val mAP looked excellent because val had the same error. A cup fallback also mapped Bottle, Can and Cup to paper_cup, inflating cups from 27 to 17,009 labels.
Approach. Contaminated images excluded by source class, explicit mapping rules that raise on unknown names, a blanket-map report and a starved-class check (under 300 instances) before training. Mappings were also corrected to the client's policy: no beverage cartons as cardboard, no catch-all class.
7,329 contaminated images excluded before the final run.
Real time, with an honest per-class number
Open-vocabulary YOLO-World took 599.5 ms per frame and 2.3 GB of VRAM against a 41.67 ms budget.
Approach. A closed-vocabulary YOLO11m at 640 px, 100 epochs on Colab, exported to ONNX with an equivalence check and the Ultralytics version pinned to match the plugin. Results were reported per class, and the zero PET-bottle recall on the test clip was diagnosed before the next run.
17.01 ms end-to-end, 58.79 FPS on an A100, peak VRAM 425 MB. Headline mAP50 0.838, belt-relevant classes about 0.55. Bottle recall on held-out transparent bottles from another plant was 47 of 60, so the gap is the domain, not calibration.
Code
The fix for the main bug: suppressing across classes keeps one box per physical object, so the tracker forms one track instead of three competing ones.
def merge_frame(scale_frames, frame_id, names, frame_area, args):
boxes, scores, classes = [], [], []
for per_frame in scale_frames:
if frame_id < len(per_frame):
for x1, y1, x2, y2, cls, conf in per_frame[frame_id]:
boxes.append([x1, y1, x2, y2]); scores.append(conf); classes.append(cls)
if not boxes:
return []
# Class-AGNOSTIC NMS: the detector often fires several class boxes on one
# shiny object (can vs cup vs bottle). Suppressing across classes keeps a
# single best box per object, so it forms one track instead of fragmenting.
keep = nms(torch.tensor(boxes), torch.tensor(scores), args.iou)
merged = []
for i in keep.tolist():
x1, y1, x2, y2 = (int(v) for v in boxes[i])
if (x2 - x1) * (y2 - y1) > args.max_area_frac * frame_area:
continue # spurious full-frame box: real conveyor objects are small
merged.append((x1, y1, x2, y2, canonical_label(names[classes[i]]), scores[i]))
return mergeddef _fuse_class(self, oid: int, observed: str, conf: float) -> str:
"""The object's class is the confidence-weighted winner across its whole
history so far, not the latest frame."""
votes = self._class_votes[oid]
votes[observed] += conf
stable = votes.most_common(1)[0][0]
self._stable_class[oid] = stable
return stable
def infer(self, frame) -> list[DetectionEvent]:
result = self.model.predict(frame, imgsz=self.imgsz, conf=self.conf,
iou=self.nms_iou, agnostic_nms=True,
device=self.device, verbose=False)[0]
...
ids = self.tracker.update(self.frame_id, boxes)
for (x1, y1, x2, y2, name, conf), oid in zip(dets, ids):
canonical = self.LABELS.get(name)
if canonical is None:
# An unmapped raw label must not silently enter the canonical stream.
self._unknown_labels[name] += 1
continue
stable = self._fuse_class(oid, canonical, conf)
events.append(self.build_detection_event(..., class_label=stable, ...))# Every class of a source collapsing into one canonical class can be
# legitimate (WaRP's ten bottle variants) or a blanket-map bug: mapping a
# Bottle/Can/Cup dataset wholesale to paper_cup filed 17,009 bottles and
# cans as cups. Reported, not raised, because both cases are real.
targets = set(rules.values())
if len(rules) > 1 and len(targets) == 1 and len(rules) == len(names):
blanket_maps[label] = {
"target": sorted(targets)[0],
"source_classes": sorted(rules),
}
...
VIABLE_MIN_INSTANCES = 300
def starved_classes(counts: dict, class_names: list[str],
viable: int = VIABLE_MIN_INSTANCES) -> dict[str, int]:
"""A detection head can carry a class the data cannot teach: it trains
without complaint and simply never fires. Naming those up front stops an
eight-hour run producing a head whose fourth output is decorative."""
return {n: counts.get(n, 0) for n in class_names if counts.get(n, 0) < viable}What I built
Zero-shot prototype (public v1)
- YOLO-World with the 4-class vocabulary baked into the weights, so run time is fully offline
- Inference at 640 and 1536 px merged with class-agnostic NMS and an oversized-box filter
- IoU tracker with gap tolerance, per-track label vote and short-track removal
- JSONL detection events plus an annotated video with interpolated gaps
Production plugin
- Fills the client core's plugin slot: metadata, health, load, infer, unload
- Schema-validated events, temporal class fusion, unknown labels dropped and counted
- Latency benchmark (p50/p95), failure scan, SHA-256 provenance manifest, ONNX equivalence check
- Licence audit flagging Ultralytics AGPL-3.0 as a production blocker
Training pipeline
- Generated 44-cell Colab notebook with a static checker for per-cell syntax and names
- Merger for three public datasets: explicit class rules, collision-safe filenames, per-source caps
- Starved-class and blanket-map reports before any GPU time is spent
- YOLO11m at 640 px for 100 epochs, exported to .pt and ONNX
Evaluation
- Ground-truth benchmark of NVIDIA LocateAnything-3B on 44 hand-labelled frames (79 boxes)
- Browser annotation tool built for that ground truth
- Baseline vs fine-tuned report with per-class improve and regress verdicts
- Exporter to the client's 22-column annotation schema, validated with jsonschema
Screens
Fine-tuned model, read per class. Headline mAP50 is 0.838, but belt-relevant classes sit near 0.55, and empty frames got worse. Drawn from the delivered evaluation files.
v1 output on the synthetic test clip: '~' marks a box interpolated across a detection gap, and a falling piece draws a spurious low-confidence box.
Stack
Models
- YOLO-World v2 (yolov8x-worldv2)
- YOLO11m
- NVIDIA LocateAnything-3B
- CLIP ViT-B/32 (vocabulary baking)
Vision
- Ultralytics 8.4.87
- PyTorch
- OpenCV
- torchvision NMS
Deployment
- ONNX (opset 12)
- TensorRT build notes
- CUDA and Apple MPS
Data and training
- Google Colab (L4, A100)
- Kaggle API
- Roboflow SDK
- WaRP-D
Quality
- pytest
- jsonschema
- Generated notebook + static checker
How it was built
Built with an AI-native workflow: I made the engineering calls (class-agnostic NMS, the dataset forensics, refusing to ship a starved class, the per-class reporting) and Claude Code wrote most of the implementation, though only 5 of 40 commits carry its co-author trailer. The client's core platform and plugin template are not my code.
Client work under confidentiality: only the first zero-shot version is public, and the plugin, training pipeline and model are described without client data, documents or footage.