Back to Portfolio

Custom CNN-Based Plant Disease Detection

AI / Smart Agriculture2025

A lightweight custom CNN for plant disease detection trained on 70K+ leaf images across 38 classes, achieving 98.96% validation accuracy using PyTorch and OneCycleLR scheduling.

Custom CNN-Based Plant Disease Detection

The Problem

Plant diseases cause massive agricultural and economic losses globally. Manual diagnosis requires expert knowledge and time, which is impractical for large farms or rural areas. There was a need for an automated, accurate, and lightweight system to detect plant diseases early using image-based AI models.

Problem illustration

The Solution

A lightweight Convolutional Neural Network (CNN) was developed to classify plant leaf diseases efficiently. The model was trained on an augmented dataset of 70,000+ images spanning 38 classes. Using residual connections, batch normalization, and adaptive pooling, the model reached 98.96% validation accuracy in just 5 epochs, proving both speed and accuracy. Optimized with Adam optimizer, OneCycleLR scheduling, and cross-entropy loss, it offers strong generalization while remaining suitable for mobile deployment.

Dataset Preparation

Collected and augmented plant leaf images from Kaggle dataset by vipoooool. Resized to 128x128, normalized, and split into train/validation/test sets.

Model Design

Designed a custom CNN with residual connections, batch normalization, and adaptive pooling layers for better stability and learning efficiency.

Training & Optimization

Trained using Adam optimizer, OneCycleLR scheduling, and cross-entropy loss over 5 epochs in Google Colab GPU environment.

Architecture

Custom CNN architecture with convolutional, batch normalization, residual, and pooling layers designed for high performance on agricultural imagery.

  • Conv2D + BatchNorm + ReLU blocks for feature extraction
  • Residual skip connections to improve gradient flow
  • MaxPooling + AdaptiveAvgPooling for downsampling
  • Fully connected dense layer for 38-class classification
  • Softmax output activation for multi-class probabilities

Dataset

Source: Kaggle – vipoooool / New Plant Diseases Dataset

  • Train folder: ~70,000 augmented images (38 classes)
  • Validation folder: ~17,000 images
  • Test folder: 33 manually selected unseen images

Total: ~87,000 total images (augmented)

Split: 80% training / 20% validation

Image Size: 128x128 pixels

Training Details

  • epochs: 5
  • batchSize: 16
  • optimizer: Adam
  • learningRate: 0.01 with OneCycleLR Scheduler
  • lossFunction: Cross Entropy Loss
  • framework: PyTorch
  • hardware: Google Colab GPU

Results & Analysis

Metrics:

  • validationAccuracy: 98.96%
  • trainingLoss: 0.0537
  • validationLoss: 0.0343

Observations:

  • Achieved high accuracy within only 5 epochs due to efficient architecture.
  • OneCycleLR scheduling enabled fast convergence after early instability.
  • Residual connections prevented overfitting and enhanced feature learning.
  • Model generalized well to unseen test samples.

Future Improvements

  • Integrate Grad-CAM for model interpretability.
  • Deploy on mobile devices and drones for real-time leaf scanning.
  • Add pest recognition alongside disease classification.
  • Incorporate multispectral and sensor data for richer diagnostics.
  • Compress model using pruning and quantization for edge deployment.

Technologies Used

PythonPyTorchNumPyMatplotlibTorchVisionGoogle ColabOneCycleLRCross Entropy LossBatch Normalization
Custom CNN-Based Plant Disease Detection | Abdulrahman Hamdi