Skip to content

Chandanrohit/crops_disease_detector

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌿 FASALAI β€” Crop Disease Detection for Indian Farmers

FasalAI Banner

Detect crop diseases from a leaf photo. Hindi output. Offline-first. No internet needed.

License: MIT Python 3.10+ Model: EfficientNet-B0 Classes: 38 Offline: Yes Hindi: Yes


Problem Statement

India loses β‚Ή50,000+ crore annually to crop diseases. Over 86% of Indian farmers are small or marginal β€” they lack access to agronomists, can't afford lab testing, and often rely on guesswork until it's too late.

The core failure: Disease identification requires expert knowledge that most farmers simply don't have. By the time symptoms are visible and an expert is consulted, 30–70% of yield is already lost.

Pain Points

  • Rural areas have no internet connectivity for cloud-based diagnosis tools
  • Existing tools output in English only β€” inaccessible to most farmers
  • Expert consultation costs β‚Ή500–2000+ per visit β€” unaffordable at scale
  • Lab results take 3–7 days β€” crops don't wait

Our Solution β€” FasalAI

FasalAI is an offline-first, Hindi-language crop disease detector that runs entirely on a smartphone with no internet connection.

A farmer takes a photo of a diseased leaf β†’ FasalAI identifies the disease β†’ gives Hindi treatment advice in under 100ms.

Key Differentiators

Feature FasalAI Other Tools
Works offline βœ… Yes ❌ Requires internet
Hindi output βœ… Full treatment advice ❌ English only
Inference speed βœ… <100ms on CPU ⚠️ 2–5 seconds (cloud)
Model size βœ… 4MB (INT8) ❌ 100MB+
Environmental context βœ… Temp + Humidity aware ❌ Image only
Cost to farmer βœ… Free ❌ Subscription / data cost

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        FasalAI Model                            β”‚
β”‚                                                                 β”‚
β”‚  Input Image (224Γ—224)                                          β”‚
β”‚        ↓                                                        β”‚
β”‚  EfficientNet-B0 (Pretrained ImageNet)                          β”‚
β”‚  [Blocks 0-4 frozen | Blocks 5-8 fine-tuned]                    β”‚
β”‚        ↓                                                        β”‚
β”‚  CBAM Attention Module                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                       β”‚
β”‚  β”‚ Channel Attention    β”‚ ← Weights 1280 feature channels       β”‚
β”‚  β”‚ Spatial Attention    β”‚ ← Weights 7Γ—7 spatial regions         β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                       β”‚
β”‚        ↓           ↓                                            β”‚
β”‚  Avg Pool      Env Branch (Temperature + Humidity)              β”‚
β”‚  (1280-dim)    β†’ Linear(2β†’32) β†’ ReLU β†’ Dropout                  β”‚
β”‚        ↓           ↓                                            β”‚
β”‚  Concat: [1280 + 32] = 1312-dim                                 β”‚
β”‚        ↓                                                        β”‚
β”‚  Classifier: Dropout(0.4) β†’ FC(1312β†’512) β†’ ReLU β†’               β”‚
β”‚              Dropout(0.3) β†’ FC(512β†’38)                          β”‚
β”‚        ↓                                                        β”‚
β”‚  Softmax β†’ Top-1 Class + Confidence                             β”‚
β”‚        ↓                                                        β”‚
β”‚  hindi_output.py β†’ Hindi Disease Advice                         β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Why This Architecture?

  • EfficientNet-B0: Best accuracy/size tradeoff. Proven on medical imaging. 5.3M parameters vs 25M for ResNet-50.
  • CBAM Attention: Forces the model to focus on disease lesions, not background soil/sky. Improves accuracy by ~2-3% on leaf datasets.
  • Environmental Branch: Temperature and humidity are strong predictors of certain diseases (e.g., Yellow Rust thrives below 20Β°C with >75% humidity). Even without real sensors, these inputs act as soft contextual priors.
  • INT8 Quantization: Reduces model from 15MB β†’ 4MB with <0.5% accuracy drop. Runs on mid-range Android phones.

Environmental Data β€” No Sensor? No Problem

Since real IoT sensors aren't always available:

  • Default: Model uses neutral values (25Β°C, 65% humidity) β€” equivalent to a standard Indian kharif season day
  • Demo mode: User adjusts sliders manually based on current weather
  • Production path: Designed to integrate with cheap DHT11 sensors (β‚Ή50) or weather APIs
  • Dataset augmentation: Training env features are randomly sampled per realistic Indian season ranges

Dataset

PlantVillage Dataset β€” the gold standard for plant disease classification

Property Value
Total images ~54,000
Disease classes 38 (across 14 crop types)
Image format RGB JPG, 256Γ—256
Crops covered Tomato, Potato, Wheat, Corn, Apple, Grape, Pepper, Cherry, Peach, Orange, Soybean, Strawberry, Blueberry, Raspberry
Source Kaggle: emmarex/plantdisease

Quick Start

Prerequisites

git clone https://github.com/Chandanrohit/crops_disease_detector.git
cd fasalai
pip install -r requirements.txt

Run Demo (Mock Mode β€” No Model Needed)

# Works immediately, no training required
streamlit run demo.py
# Opens http://localhost:8501

Train From Scratch

# 1. Download dataset
# Place PlantVillage in ./data/PlantVillage/

# 2. Train (GPU recommended β€” or use Google Colab)
python train.py

# 3. Export to ONNX
python export_onnx.py

# 4. Quantize (optional, for production)
python quantize.py

# 5. Run real inference
# Edit demo.py: set USE_MOCK = False
streamlit run demo.py

Train on Google Colab (Recommended)

Open notebooks/FasalAI_Colab.ipynb in Google Colab for a step-by-step guided notebook with GPU support, live training graphs, and automatic Drive checkpointing.

CLI Inference

python inference.py --image leaf.jpg --temperature 22 --humidity 78

Repository Structure

fasalai/
β”œβ”€β”€  notebooks/
β”‚   └── FasalAI_Colab.ipynb        ← Full Colab training notebook
β”œβ”€β”€  checkpoints/
β”‚   β”œβ”€β”€ crop_disease_model.onnx     ← FP32 inference model

About

This project is an AI-powered Plant Disease Diagnosis System built using Deep Learning and Convolutional Neural Networks (CNNs) for detecting and classifying 38 different plant diseases from leaf images. The system is designed to help farmers and researchers identify diseases accurately using computer vision and artificial intelligence.

Resources

License

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors