Inspiration
Glass can be remelted forever without losing quality — and one of the main things that stops it is a decision nobody writes down. Container-glass makers can only use a limited share of mixed-colour cullet ("3-mix"), because the batch has to meet the colour their customer ordered; once cullet is sorted by colour, that limit effectively disappears (FEVE 2019; Glass Packaging Institute). Without beneficiation capacity, most 3-mix becomes road aggregate or landfill cover instead of a furnace.
That decision is made at the sink at 2am, by one person holding one bottle, with no feedback loop and no record.
I started from a smaller version: matching empty whisky bottles from bars with craft makers who turn them into vases and candle jars. It kept hitting the same wall — before a bottle can be upcycled it has to be sorted, and before it can be sold, someone has to be able to say what is in the box. ClearLot is that sorting step.
What it does
A capture station for a bar's bottle pile.
- Capture — one bottle inside the guide. A small colour model grades it flint / green / amber with a probability and a top-two margin, and it is allowed to refuse.
- Refuse — below a 45% margin, or on a frame it cannot read, the bottle goes to a review queue with both plausible colours shown. A pending bottle blocks crate closure server-side, inside the transaction. A guess never closes a crate.
- Grade the crate — bottles accumulate against a named receiver spec: target colour, minimum purity, minimum count, checklist (caps, dry, no bags, no ceramics or pyrex). Purity is scored live and every blocker is stated in words.
- Close and hand over — closing issues a receipt: every bottle's image SHA-256, what the model said and with what probability, what the person decided and why, the checklist with actors, the spec version. The hash chains to the previous receipt and is HMAC'd with a key stored outside the database, so a plant can verify the crate without trusting my app.
- Keep the evidence tiers apart — projected (my grading), recorded (the operator's word), verified (a receiver reference) are three separate rows, never added into one number that sounds better than it is.
How I built it
- Back end — Python 3.12 + FastAPI + SQLite. No build step, no CDN, no API keys; runs offline after
pip install -r requirements.txt. Closed lots reject further mutation through SQLite triggers, not only application checks. - Classifier — multinomial logistic regression on hand-built colour features: saturation-weighted hue histograms over three regions (neck and both flanks, avoiding the label), chromatic coverage, saturation and value percentiles, circular mean hue. Weights export to JSON, so runtime inference needs only numpy;
ml/features.pyis shared by training and serving so the vector cannot drift. - The step that mattered — grey-world illuminant correction estimated from the frame border. Held-out real-photo accuracy went from 0.74 to 0.87: a green soju bottle under a warm bar lamp stops drifting into amber once the lamp is removed.
- Training data — a procedural bottle renderer generates 1,008 frames with exact labels; 36 real photographs (Wikimedia Commons, CC0/PD/CC BY/CC BY-SA) give the boundary its position. 13 real photos train with augmentation, 23 are held out by source image and never seen in training.
| macro F1 | accuracy | |
|---|---|---|
| Held-out real photographs (n=23) | 0.859 | 0.870 |
| Colour-threshold baseline, same features | 0.331 | 0.565 |
| Synthetic holdout (n=252) | 0.988 | 0.988 |
Operating point: 83% auto-tagged, 2 of 30 auto-tags wrong, 17% sent to review. A frame is graded in about 12 ms on one CPU core. 23 photographs is a pilot, not a benchmark, and the README says so in the section a judge reads first.
The waste problem I targeted, and how I would measure whether it worked
Bars send their empty bottles out as mixed-colour cullet. Container-glass makers are limited in how much mixed-colour cullet they can use, because the batch has to meet the colour their customer ordered. Sorting does not remove the other contaminants — ceramics, metal and organics still have to be handled — but colour is the gate that decides whether the material is even in the container loop. Where a market has no beneficiation capacity, most of that fraction becomes road aggregate or alternative daily cover instead of a furnace.
My metric is the receiver-eligible share of incoming container glass: the percentage of bottles a station grades that end up in a crate meeting a specific receiver's documented intake spec (colour purity ≥ X%, ≥ N bottles, contaminant checklist complete). The baseline is the current path, where almost none of a bar's glass arrives as container-grade cullet on a named spec, because nothing in the chain checks colour purity or records it. To verify, I would run one bar for 20 nights — two weeks as-is, two weeks with ClearLot — and compute the acceptance rate from the plant's events: they scan the crate QR, weigh it, and record acceptance or a rejection reason against the receipt. The app's own projection is reported separately and never counted as an outcome.
Challenges
- Honest ML with almost no data. Ten photographs of one bottle are one specimen. Splitting by augmented row would have produced a beautiful, meaningless number, so the split is by source image.
- Making uncertainty load-bearing. At first confidence only changed a colour chip; now a low margin physically blocks the close inside
BEGIN IMMEDIATE. - A receipt worth something. A hash alone is rewriteable by whoever owns the database, so the hash is also HMAC'd with a key held outside it and chained to the previous receipt.
What's next
A contaminant detector for ceramics and pyrex on the same capture; a calibrated camera (fixed mat, colour card); two-way receiver events so verified becomes a counter-signature; routing strays into their own crate instead of excluding them; then a one-bar pilot, then a cluster of bars feeding one beneficiation line.
Built With
- fastapi
- ffmpeg
- html/css
- javascript
- numpy
- pillow
- playwright
- python
- scikit-learn
- sqlite