One of KilimoPRO's most powerful features is on-device crop disease detection. A farmer points their phone at a diseased leaf, and within seconds — without any internet connection — the AI identifies the disease, shows a confidence score, and provides treatment recommendations. This article explains how it works.
The Model: MobileNetV3
I chose MobileNetV3Small as the base model for its excellent accuracy-to-size ratio. MobileNetV3 was designed by Google specifically for mobile devices, using depthwise separable convolutions and inverted residuals to reduce computation. The model takes a 224×224 pixel image as input and outputs a probability distribution across disease classes.
Training: Transfer Learning
Training from scratch would require millions of images and weeks of GPU time. Instead, I used transfer learning: starting from a MobileNetV3 model pre-trained on ImageNet (which already knows how to recognize visual features like edges, textures, and shapes), I replaced the final classification layers and fine-tuned them on the PlantVillage dataset (54,305 images of 14 crop species and 26 diseases).
The training process: (1) freeze the pre-trained base model, (2) train only the new classification layers for 20 epochs, (3) unfreeze the top 20 layers of the base model, (4) fine-tune with a lower learning rate for 10 more epochs. This two-stage approach produces models that generalize well without overfitting.
Quantization: float32 → int8
The trained model in float32 format is approximately 25MB — too large to bundle with an app targeting low-end Android phones with limited storage. Quantization converts the model's weights from 32-bit floating-point numbers to 8-bit integers, reducing the model size by 75% (from 25MB to ~5MB) with less than 1% accuracy loss.
TensorFlow Lite provides built-in quantization through the TFLiteConverter. I set converter.optimizations = [tf.lite.Optimize.DEFAULT], converter.target_spec.supported_types = [tf.int8], and specified int8 for both input and output types.
On-Device Inference
The TFLite model runs entirely on the farmer's Android phone using the tflite_flutter package. No internet connection is required. On a typical Android device with 2GB RAM, the model produces a diagnosis in 200-500 milliseconds — fast enough for real-time use in the field.
The inference pipeline: (1) capture photo with the camera, (2) resize to 224×224, (3) normalize pixel values to [0,1], (4) run TFLite model, (5) get probability distribution, (6) display the disease with highest probability and its confidence score.
PlantVillage Nuru Inspiration
This approach is directly inspired by PlantVillage Nuru (developed by Penn State University), which has been deployed in Kenya, Tanzania, and Uganda. Nuru uses on-device CNN models to diagnose crop diseases in cassava, maize, and potato. KilimoPRO adopts the same technical approach but extends it to a broader range of crops and integrates the disease detection with the platform's other intelligence modules.
Results
The trained model achieves 95%+ accuracy on the PlantVillage test set. In real-world conditions (photos taken by farmers in the field with varying lighting, angles, and backgrounds), accuracy drops to approximately 85-90%. For cases where confidence is below 70%, the app recommends consulting an extension officer and provides the ExtensionLink to connect to the nearest available expert.