The problem
Thambi Stores, a made-up neighbourhood shop and café in Madurai, runs out of bottled drinks and paper cups on busy days and over-orders on quiet ones. The owner already photographs the shelf every morning; the ordering still happens by feel, by phone, between customers.
The work is the same every day: count what is left, judge what will sell before each supplier's next van, round up to whole cases, and tell every supplier. Each step is simple. Doing all four well, every morning, is what slips, and it needs all four kinds of AI on this site working as one.
The data
Three shelf photos from Wikimedia Commons stand in for the owner's morning photos: Soft drinks on supermarket shelves by SMC at English Wikipedia (Public domain); Soda and lemonade stand, Rishikesh by David Lisbona (CC BY 2.0); Paper and clay cups at a tea stall, Kolkata by juggadery (CC BY 2.0). Each has a made-up shelf plan: boxes that say which part of the photo holds which product, such as "middle shelf, green bottles: lime soda, 2 litres". For each zone I also counted every bottle or stack of cups I can see, front or back: 101 in all.
Two years of daily sales for 6 products, from a seeded generator, so they are the same on every visit: a weekly pattern (drinks sell more at the weekend, the café's cups on weekdays), a slow trend, busier days around Pongal and Deepavali on the dates Tamil Nadu observed them, and day-to-day chance. A slow seller moves one or two 2-litre bottles a day; lemon soda about twenty. These are not real sales.
4 made-up suppliers with their terms: Vaigai Beverages delivers on Tuesdays and Fridays, two days after an order; Annam Aqua and Thirumalai Soda Works deliver Monday to Saturday, the next day; Kalai Paper Products on Mondays and Thursdays, three days after. Each product has a pack size and each supplier a minimum order.
The model
Deep learning: COCO-SSD, the 9 MB detector from my Object Counter, served from this site. It sees every picture at 300 × 300 pixels, where a shelf's bottles are too small to find, so the planner cuts each zone of the shelf plan into squares of at most 320 pixels, runs the network on each, and merges the boxes: two boxes of the same class that overlap by more than half are one object, and a piece cut off at a square's edge gives way to the whole bottle from the next square. An object counts for a product when it is the right class, at least 40% sure and at least half inside the product's zone. A count the detector is less than 60% sure of is flagged, and a person can type over any count.
Machine learning: Holt-Winters from my own library, with a weekly season and a slowly changing, damped trend: one model per product, trained in your browser. Festival days are replaced by an ordinary day before it learns, then come back as a lift learnt from past years and pulled towards no lift by 10 ordinary sales, because a slow seller's few festival days are mostly chance. Its typical one-day error, σ, sets the safety stock.
Automation: reorder rules. Today's order lands on the supplier's first delivery day after its lead time. The reorder point is the expected sales until then plus safety stock, z × σ × √days, with z from the service level you choose; the order-up-to level covers until the delivery after that. A product at or below its reorder point is ordered up to that level, rounded up to whole packs, and a supplier's minimum is met by adding packs of the order's fastest seller. Every line says why.
Generative AI: SmolLM2 360M Instruct writes each supplier's email from the order's facts, given as a list with one worked example, in polite Tamil Nadu business English. Before the model loads, a template fills the same facts, so the step always works. Every draft is checked line by line: each product's packs, units and pack size, the weekday, the date and the greeting must match the order, and the Copy Writer's fact check (checkFacts) flags any other number or claim, such as a price or free delivery.
The pipeline
- 01Count
COCO-SSD looks at 12 squares cut from the three photos: about 0.8 s on the graphics chip of the computer I measured on.
- 02Check
Counts under 60% confidence are flagged; a person corrects any count, and the correction flows straight on.
- 03Forecast
Holt-Winters learns each product's two years of sales and forecasts 14 days ahead with an 80% range, in well under a second for all six.
- 04Plan
Reorder points, order-up-to levels, whole packs and supplier minimums for every product, with the reason for each line.
- 05Write
A template at once; SmolLM2 when you ask, its draft checked against the order before anyone sends it.
- 06Send
Copy each email to the supplier, and download the order as CSV for the accounts.
Results
The detector's counts come from tools/restock-planner/bench.mjs, which runs the network in Edge on 23 November 2026 and passes its output through the page's own tiling, merging and zone code. The forecast and order figures were computed when this page was built, with the same code the demo runs: Holt-Winters has a lower RMSE than same-day-last-week on 6 of 6 products, and the template email passes its own check for every supplier.
For a client
For a real shop I would start with the photos it already takes: a fixed spot to shoot each shelf from, the shelf plan drawn once, and a detector fine-tuned on a few hundred photos of its own products. COCO-SSD knows bottles and cups in general, not this shop's brands, and it cannot see a bottle hidden behind another; for deep shelves I would photograph from above or count facings and depth.
Sales would come from the billing software instead of a generator, with the days the shelf ran empty marked, since sales on those days understate demand. Holt-Winters is a sound first model for a few hundred products; with more history I would add the weather, school holidays and local festivals.
The rules would live where the owner can see and change them: lead times, pack sizes, minimums and the service level for each product. One tap approves the order, and the emails go out by email or WhatsApp. A person stays in the loop for flagged counts and for any order above a set value.
All of it can run on the shop's own phone, as here, or as a small service that reads the photos as they arrive.
Stack
| Part | What it does here | Licence |
|---|---|---|
| COCO-SSD (Lite MobileNet v2) | The detector, from TensorFlow's model library, served from this site | Apache 2.0 |
| TensorFlow.js | Runs the detector on the graphics chip (WebGL), or the processor without it | Apache 2.0 |
| SmolLM2 360M Instruct | Writes the order emails, loaded only when you ask | Apache 2.0 |
| Transformers.js | Runs the language model in a background worker, on WebGPU or WebAssembly | Apache 2.0 |
| My machine-learning library | Holt-Winters, the metrics and the seeded sample generator, in TypeScript with unit tests | Mine |
| My planning and checking code | Tiling and zones, the reorder rules, the email check and the Copy Writer's fact check, with unit tests | Mine |
| Sample photos | Three photos from Wikimedia Commons, credited above | Public domain and CC BY 2.0 |
| Preact and Astro | The interactive demo and the static page | MIT |
Privacy
Everything runs in your browser. The sample photos, any photo you add or take with the camera, the counts and the order stay on your device: nothing is uploaded.
The detector comes from this site. The language model downloads once from its public host when you ask for it, then stays in your browser's cache.
Limits
- The detector counts what it can see. On the sample shelves it found nearly every bottle at the front but few of those behind them: 33 of the 60 bottles on the soda stand, and 2 of the 13 stacks of paper cups, which it hardly knows. That is why the counts table shows how sure it was, flags the unsure counts, and lets a person correct them before anything is ordered.
- The sales are generated, so the forecast's accuracy shows how well it recovers the rules I wrote, not how it would do on a real shop's sales. A day's sales of a slow seller swing a lot, so its daily percentage error is high whatever the method.
- The festival lifts come from two past years each; other festivals, the weather, school holidays and price changes are not in the model.
- SmolLM2 is a small model: its email is a draft, checked against the order line by line, and the template stays the dependable fallback.