Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Crop Disease Detector — Edge AI Desktop System

Real-time crop disease classification running entirely on-device on an Orange Pi AI Pro board. No internet connection required at inference time. Built for Nigerian smallholder farmers.

First Prize — Huawei AI Innovation Challenge


The problem this system addresses

Nigeria has approximately 33 million smallholder farming households. Together they produce around 80 percent of the country's food supply, cultivating the six crops that anchor Nigerian food security: cassava, maize, rice, tomato, yam, and beans. Crop diseases are the single largest source of preventable yield loss, causing up to 40 percent annual losses across sub-Saharan Africa. For a smallholder farming on two hectares, that loss is not a statistic — it is the difference between feeding a family and not.

The conventional response is the agricultural extension officer. Nigeria has approximately one extension officer per 3,000 farmers. In practice, most smallholders never receive a farm visit in a given growing season. By the time a farmer identifies a disease visually, contacts someone with knowledge, and receives a diagnosis, the infection has often spread beyond economic recovery.

Existing AI-based crop disease tools do not solve this. They require smartphone cameras, reliable internet connectivity, and the ability to read English interface output. They were built for users who already have access — not for the smallholder farmer in Katsina or Benue who has none of these things.

This system was built to serve that farmer directly.


What this system does

A farmer or agricultural extension worker points a camera at a crop leaf. The system detects the affected region, classifies the disease in real time, maps the result to a curated treatment and management recommendation, and delivers that recommendation through audio output in the farmer's own language. The entire pipeline runs on the device. Nothing is sent to a server. No internet connection is required at any point.

Output is delivered in Hausa, Yoruba, and Igbo — the three most widely spoken languages in Nigeria, together covering the majority of the smallholder farming population. The audio guidance makes the system usable by farmers with no English literacy and no prior experience with digital technology.


Hardware

The system runs on an Orange Pi AI Pro board, selected for its on-device AI inference performance on ARM architecture. The board is fitted with:

  • USB camera module for live crop leaf capture
  • 7-inch touchscreen display
  • 20,000mAh USB-C PD power bank for full-day field operation without mains power

The hardware was chosen for field deployability: portable, power-independent, and operable by a single extension worker carrying it between farms.

Hardware assembly Device in use on farm
Hardware assembly Deployed in the field

Application

Home screen

The Electron frontend provides a live camera feed, disease detection and classification result view, treatment recommendations, prediction history, soil analysis dashboard, and language selection for audio output.

Language selection


System architecture

Orange Pi AI Pro (OpenEuler OS)
|
+-- Electron Frontend (TypeScript)
|   +-- Live camera feed
|   +-- Disease detection and classification result
|   +-- Prediction history
|   +-- Soil analysis dashboard
|   +-- Language selector (Hausa / Yoruba / Igbo)
|   +-- Multilingual audio output
|
+-- Flask REST API (Python) -- localhost:5000
    +-- YOLO Detector          Localizes diseased leaf regions in the live feed
    +-- TFLite Classifier      MobileNetV2, quantized, on-device inference
    +-- Soil Recommender       Scikit-learn (.pkl), soil sensor input
    +-- SQLite Database        Local persistence, no server required

All models run at inference time on-device. No data leaves the hardware.

System flow: camera to model to result


Disease detection (YOLO)

Before a leaf image reaches the classifier, a YOLO object detection model localizes the diseased region on the leaf in the live camera feed, drawing a bounding box around the affected area. This serves two purposes: it gives the farmer immediate visual confirmation that the system is looking at the right part of the leaf, and it crops the region of interest before classification, improving the classifier's effective signal-to-noise ratio compared to classifying the full, unguided frame.

Running detection and classification concurrently — rather than one at a time — was the main systems engineering challenge in this project: both models need to coexist in memory and share the same limited compute budget on a board with no dedicated GPU, while still keeping the feed responsive in real time.

YOLO detection flow

YOLO detection snippet


The classification model

Architecture: MobileNetV2 with custom classification head Format: TensorFlow Lite (.tflite), post-training quantized File: python-backend/models/crop_disease_model.tflite

Why MobileNetV2

MobileNetV2 was selected specifically for deployment on constrained ARM hardware. Its depthwise separable convolution architecture dramatically reduces parameter count and multiply-add operations compared to standard CNNs, enabling real-time inference on the Orange Pi AI Pro without a dedicated GPU. Post-training quantization further reduces the model footprint and inference latency while preserving classification accuracy within acceptable bounds for field use.

Training data

The model was trained on a labeled dataset of Nigerian crop leaf images covering disease categories across all six target crops: cassava, maize, rice, tomato, yam, and beans. The dataset combines publicly available plant disease image sources with field-collected samples representing Nigerian growing conditions, lighting environments, and soil backgrounds that differ meaningfully from datasets collected in controlled laboratory or temperate-climate settings.

Dataset sample

Training procedure

Fine-tuning was conducted in two phases on Google Colab (Tesla T4 GPU):

Phase 1 — Head training: The MobileNetV2 base is frozen. Only the custom classification head is trained for 10 epochs. This establishes a stable feature mapping before the base weights are modified.

Phase 2 — Full fine-tuning: The entire network is unfrozen and trained end-to-end at a reduced learning rate of 1e-5. The lower learning rate prevents catastrophic forgetting of the ImageNet-derived feature representations while allowing the base to adapt to the visual characteristics of Nigerian crop disease imagery.

Data augmentation

Augmentation was applied during training to improve generalization to real field conditions. The augmentation strategy was designed around the specific visual challenges a farmer encounters when photographing a leaf in the field:

Augmentation Parameter Rationale
Horizontal flip p=0.5 Leaf orientation is arbitrary in field photography
Vertical flip p=0.5 Camera angle varies, especially for low-growing crops
Rotation up to 30 degrees Farmers photograph at varying angles
Zoom 0.8x to 1.2x Distance from leaf to camera is inconsistent
Width and height shift 10% Subject centering is imprecise in field conditions
Brightness adjustment +/- 30% Outdoor lighting varies across time of day and weather
Shear transformation 10% Perspective distortion from non-perpendicular shots

This augmentation set simulates the distribution of real field images more faithfully than training on clean, centered, laboratory-photographed samples, which is the dominant failure mode in crop disease models that do not generalize beyond benchmark datasets.

Inference pipeline

At inference time, a captured frame first passes through the YOLO detector, which localizes the diseased leaf region and crops it. The cropped region is preprocessed to the MobileNetV2 input dimensions, passed through the quantized TFLite classifier, and the output class index is mapped through reduceId copy.json to a disease ID. The disease ID is then looked up in complete-diseases.json to retrieve the disease name, description, and treatment recommendations. The recommendations are passed to the audio output module, which plays the corresponding pre-recorded guidance in the selected language.

Data flow into the classifier


Soil analysis

File: python-backend/models/crop_recommendation_model.pkl

A Scikit-learn model trained on soil sensor input features: Nitrogen (N), Phosphorus (P), Potassium (K), temperature, humidity, pH, and soil moisture. Outputs the most suitable crop for the given soil profile. This extends the system beyond disease detection into pre-planting advisory, allowing a single device to support the full decision cycle from soil assessment to harvest.


Multilingual audio output

Pre-recorded audio guidance in Hausa, Yoruba, and Igbo is mapped to disease outputs and played automatically after classification. The three languages were selected to maximize coverage of Nigeria's smallholder farming population. The audio-first design means the system requires no reading ability and no prior technology experience from the end user.


API endpoints

Method Endpoint Description
GET / Health check
POST /predict Detect region, classify leaf image, return disease and recommendations
GET /history Classification prediction history
POST /clear_history Clear session history
POST /soil_analysis Crop recommendation from soil sensor data
GET /sensor-data Simulated soil sensor readings

Local database

SQLite provides local file-based persistence with no database server dependency.

predictions table: disease name, confidence score, treatment recommendations (JSON), raw image bytes, timestamp.

History is cleared on server startup. The system is designed for session-based field use where persistent cross-session storage is not required.


Project structure

cdd_electron/
+-- src/                             Electron frontend (TypeScript)
+-- assets/                          Static assets
+-- images/                          Hardware photos and application screenshots
+-- python-backend/
    +-- app.py                       Flask REST API
    +-- models/
    |   +-- crop_disease_model.tflite     MobileNetV2 TFLite classifier (6 crops)
    |   +-- yolo_detector.pt              YOLO detection model
    |   +-- crop_recommendation_model.pkl Soil analysis model
    +-- reduceId copy.json           Model output index to disease ID mapping
    +-- complete-diseases.json       Disease names and treatment recommendations
    +-- predictions.db               SQLite (auto-created on first run)

Setup

Requirements: Python 3.9 or higher, Node.js 18 or higher

Backend

cd python-backend
pip install flask flask-cors tensorflow numpy pillow scikit-learn ultralytics
python app.py

Server starts on http://localhost:5000. Keep this terminal running.

Frontend

npm install
npm run dev

The Electron app connects to the Flask backend automatically on launch.


Mobile companion

A React Native mobile app deploying the same MobileNetV2 TFLite model on Android is available at: https://github.com/Hardeezah/cdd-mobile

The mobile app targets individual farmers who own a smartphone. This desktop system targets agricultural extension workers operating in the field with the Orange Pi hardware. Both deployments run identical model weights.

Mobile app screen one Mobile app screen two
Mobile classification view Mobile results and recommendations view

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages