AgriVision: Plant disease classification based on ConvNeXt-Tiny
2 min readupdated
The agrivision-plant-disease model is a compact image classification system that recognizes 177 leaf conditions across 36 different agricultural crops from a single smartphone photo. The solution is built on the ConvNeXt-Tiny architecture (a convolutional neural network architecture with an efficiency close to a Vision Transformer) and exported to a quantized INT8 ONNX format weighing just 28 MB to run on mobile and edge devices. The main feature of the model is honest confidence calibration: if the correct answer probability drops below the 0.77 threshold, the model does not guess randomly, but instead outputs an "unsure" status, which is critically important for field conditions.
Key features
- Offline operation on mobile devices: The lightweight INT8 ONNX format allows running the model directly on a smartphone without a server connection.
- Temperature calibration: Using a temperature coefficient of T = 0.77 eliminates the overconfidence of raw softmax scores.
- Built-in rejection mechanism: The model consciously refrains from making predictions when confidence is low instead of producing random errors.
- Large-scale database: Training was conducted on a dataset of 157,001 images collected from 14 global and local sources.
What you can do
- Embed in a mobile app: Use the model in offline apps to help farmers diagnose crop diseases.
- Integrate into agronomic services: Create a bot or service for primary screening of plant conditions from a leaf photo.
- Perform local analysis: Run inference in Python using onnxruntime for automated sorting and assessment of crop damage.
Example
import json
import numpy as np
import onnxruntime as ort
from PIL import Image
classes = json.load(open("classes.json"))
cfg = json.load(open("inference_config.json"))
T, ABSTAIN = cfg["temperature"], cfg["abstain_below"]
img = Image.open("leaf.jpg").convert("RGB").resize((224, 224))
x = np.asarray(img, dtype=np.float32) / 255.0
x = (x - np.array(cfg["mean"])) / np.array(cfg["std"])
x = x.transpose(2, 0, 1)[None].astype(np.float32)
sess = ort.InferenceSession("agrivision_int8.onnx", providers=["CPUExecutionProvider"])
logits = sess.run(["logits"], {"image": x})[0][0]
z = logits / T
p = np.exp(z - z.max()); p /= p.sum()
top = int(p.argmax())
if p[top] < ABSTAIN:
print("unsure — retake the photo")
else:
print(classes[top], f"{p[top]:.1%}")Read more
DetailsBenchmarks: overall accuracy is 0.9590, Macro F1 is 0.8469, field data accuracy is 0.9292.
Hardware requirements: lightweight model for CPU and mobile devices (28.3 MB in INT8 ONNX).
Limitations: no "non-leaf" class (when photographing foreign objects, it relies solely on the confidence threshold), does not replace official agronomic expertise.
Training details: 14 epochs, AdamW optimizer, ImageNet-22k base weights.










Comments