Plant-disease demos are everywhere. Upload a leaf photo, get a disease label, celebrate 97% accuracy. I've built those demos too. The problem shows up the moment you put one in front of an actual farmer: field photos are bad. Blurry, overexposed, shot at the wrong leaf, or not even a leaf.
A classifier that always returns an answer turns those bad inputs into confident nonsense. For a demo, that's a funny screenshot. For a triage tool that decides whether someone should scout their field for disease today, it's worse than useless — it teaches the user to ignore the tool.
So when I built LeafSentry, I made a different bet: the most valuable label the model can output is "not enough evidence."
Gate the input before the model sees it
The first line of defense isn't ML at all. Every upload passes a quality gate that checks format, dimensions, and pixel statistics before inference runs. A failing image never reaches the model — it gets rejected with specific findings: which check failed, and the actual pixel metrics measured on the request.
This sounds obvious, and it is — in the same way flossing is. Nearly every demo pipeline skips it because the model "handles" bad inputs. It doesn't. It just labels them with a straight face.
Expose the uncertainty, don't average it away
When an image does pass the gate, the API doesn't return just a label. Every response carries three calibrated signals:
- confidence — the top class probability
- margin — the gap between the top two classes
- normalized entropy — how spread out the evidence is overall
A softmax layer will happily put 96% on "angular leaf spot" for an image of a finger. Those three signals are what let the service tell the difference between a decisive answer and a guess dressed up as one. When the evidence is too weak to triage, the decision field says abstained — explicitly, in the response contract, not as a side-channel the client has to guess at.
The abstention threshold is a product decision, not a model artifact. A triage tool should err toward abstaining; a different application might tune the same signals to always answer. Decoupling that choice from training is what made the model reusable across the product's actual needs.
Pin the model, not the vibes
Inference runs against one pinned HuggingFace revision. Bumping the model is a deliberate change, not whatever the registry serves today. That sounds like a small thing until the day you're trying to reproduce a prediction from three weeks ago and "the model" turns out to be four different models depending on when each request landed.
Numbers, with their receipts attached
The headline benchmark: 96.875% top-1 on 128 pinned upstream test images — model-level evidence from the published benchmark report, reproducible from the repo.
What I won't do is present that as a field-performance claim. It's a number on a fixed test set, and the abstention layer exists precisely because real inputs fall outside what any test set covers. Warm inference on the live API is under a second end-to-end (cold start is the honest exception: the first request after a deploy loads ~343 MB of weights and takes ~13 seconds — the health endpoint reports readiness so callers never see that).
Operating it like a service, not a notebook
LeafSentry runs as a FastAPI service behind nginx, Dockerized, with live/ready health endpoints and Prometheus metrics. The ready check gates on the model actually being loaded. The API is public and unauthenticated, so the response contract has to do the defensive work: explicit decisions, explicit findings, explicit uncertainty.
The live demo on this site sends your photo to the real production API and renders the actual response — including the quality findings when it rejects your upload. If it abstains on your photo, that's the system working, not failing.
The lesson
Accuracy was never the hard part of this project. The hard parts were deciding when the model is allowed to speak, making that boundary visible in the API contract, and keeping the benchmark honest about what it measures. That's the difference between a model and a service — and it's the part that doesn't show up in the accuracy number.