iany-crop-v1
An on-device crop-health classifier β point a camera at a leaf and get its crop + condition (healthy / disease). A MobileNetV2 trained from open leaf datasets + community photos, exported to ONNX to run in the browser via onnxruntime-web. Built for iAny, the offline, on-device Khmer AI platform.
β οΈ Status: Experiment. Try it at iany.app/crop-scan β fully on-device, nothing uploaded. Help improve it by contributing photos at iany.app/crop.
What it does
Classifies a single crop leaf into a <crop>_<condition> class, for early, offline triage β "healthy vs a problem" β with advice that can be read aloud in Khmer. It is a suggestion, not an agronomist or a lab.
Labels (output order β this order matters)
10 classes (alphabetical β the softmax output order). labels.txt in this repo is authoritative and grows as more crops/conditions are trained.
0 cashew_disease
1 cashew_healthy
2 cassava_disease
3 cassava_healthy
4 maize_disease
5 maize_healthy
6 mango_disease
7 mango_healthy
8 vegetable_disease
9 vegetable_healthy
vegetable bundles tomato/potato/bell-pepper (not distinct iAny crops).
Input / preprocessing (important)
- Input:
float32, shape[1, 224, 224, 3](NHWC). - Normalization: MobileNetV2 β scale pixels
[0,255] β [-1,1](i.e.x/127.5 - 1). - Center-crop the frame to a square before resizing to 224Γ224. Identical input contract to
iany-waste-v1, so the same runtime serves both.
Usage
Python (onnxruntime)
import onnxruntime as ort, numpy as np
from PIL import Image
labels = open("labels.txt").read().split()
img = Image.open("leaf.jpg").convert("RGB").resize((224, 224))
x = (np.asarray(img, np.float32) / 127.5 - 1.0)[None] # [1,224,224,3], [-1,1]
sess = ort.InferenceSession("model.onnx")
probs = sess.run(None, {sess.get_inputs()[0].name: x})[0][0]
print(labels[int(probs.argmax())], float(probs.max()))
Browser (onnxruntime-web) β see src/lib/wasteOnnx.ts (generic [-1,1] MobileNetV2 classifier) and src/views/CropScanView.tsx for the live-camera implementation.
Training data
v1 is bootstrapped from open datasets (not yet fine-tuned on Cambodian photos):
- CCMT (Cashew, Cassava, Maize, Tomato; Ghana, field-captured, expert-validated) β cashew, cassava, maize, and
vegetable(tomato) - MangoLeafBD (CC BY 4.0) β mango
- PlantVillage β bell-pepper / potato / tomato β
vegetable - (optional) Cassava Leaf Disease 2020 (Kaggle) β harder real-field cassava
Base: MobileNetV2 (ImageNet weights), transfer learning. Full recipe: docs/CROP-MODEL.md.
Limitations
- v1 / Experiment β do not trust the headline accuracy. Reported validation accuracy is high (~0.99) but in-distribution: each crop comes from one dataset, so the model separates classes partly by dataset style (background, camera), not pathology. On real Cambodian phone photos accuracy is materially lower. The
/crop-scanUI labels this a guess for exactly this reason. - The fix is data, not training. Folding in real
/cropfield photos (and retraining) is what makes it trustworthy β expect the number to drop then, which is the point. - Coarse conditions (healthy / disease) by design; CCMT's maize "diseases" include some pests. Naming the exact disease needs a later, finer model.
- Best on one leaf filling the frame, decent light.
Intended use
Offline crop-health triage + education; the /crop-scan experiment; pre-filling labels in the /crop collector. Not a certified diagnostic or a replacement for an agronomist β present results as guidance and encourage a second opinion for serious decisions.
License & attribution
Released under CC-BY-4.0 β please credit the source datasets (PlantVillage, MangoLeafBD β CC BY 4.0, Cassava, rice sets, iBean per their terms) and iAny. Verify each source dataset's terms before commercial redistribution.
Credit & recipe
Trained and released by iAny (E-KHMER Technology). Full training + deploy recipe: github.com/sengtha/iAny Β· docs/CROP-MODEL.md.