PlantDoc: Plant Disease Classification

A state-of-the-art deep learning system for plant disease identification using CBAM-augmented ResNet18

Introduction

PlantDoc is a complete implementation of a plant disease classification system using a CBAM (Convolutional Block Attention Module) augmented ResNet18 architecture. The system is designed to accurately identify various plant diseases from images, leveraging attention mechanisms to focus on the most relevant features for diagnosis.

Plant diseases cause significant crop losses worldwide, with estimates suggesting 20-40% of global crop production is lost to pests and diseases annually. Early and accurate detection is crucial for effective management and sustainable agriculture. Traditional disease diagnosis relies on manual inspection by experts, which is time-consuming and often subjective.

This project implements a state-of-the-art deep learning approach that combines ResNet18 with attention mechanisms to improve classification accuracy for plant disease diagnosis, enabling faster and more reliable identification of diseases across 39 different plant disease classes.

PyTorch 2.1+ Python 3.8+ CBAM Attention ResNet18 Deep Learning
Classification examples

Dataset Overview

The PlantDoc project utilizes a comprehensive plant disease dataset with the following characteristics:

Total Classes
39
Total Images
61,486
Image Format
JPEG (100%)
Median Resolution
256×256 px
Class Imbalance
5.5:1
Square Images
97.84%
Dataset Analysis Dashboard

Class Distribution

The dataset contains 39 classes representing different plant diseases and healthy plants, with some class imbalance:

Class Distribution Pie Chart
File Size by Class

The largest classes include Orange_Haunglongbing_Citrus_greening (8.96%), Tomato_Tomato_Yellow_Leaf_Curl_Virus (8.71%), and Soybean_healthy (8.28%), while many classes have approximately 1.63% of the total dataset (about 1,000 images each).

Image Properties

Feature Correlation Matrix

Data Preprocessing and Augmentation

To address class imbalance and improve model generalization, the project implements a comprehensive data pipeline including:

Augmentation Examples

Methodology

The PlantDoc system leverages a dual-attention enhanced architecture to significantly improve classification performance. The key components of our methodology include:

CBAM: Dual Attention Mechanism

CBAM sequentially infers attention maps along two separate dimensions:

  1. Channel Attention Module: Focuses on "what" is meaningful in the input image channels by applying attention weights to emphasize important feature channels using average and max pooling operations processed through shared MLPs.
  2. Spatial Attention Module: Focuses on "where" the informative parts are located in the feature map, generating 2D spatial attention using aggregated channel information through convolutional layers.
  3. Integration with ResNet: CBAM blocks are inserted after each residual block in the ResNet18 architecture, refining feature representations at multiple levels of abstraction.

This dual attention mechanism allows the model to dynamically emphasize salient features in both channel and spatial dimensions, leading to improved performance, especially on images with complex backgrounds or subtle disease symptoms.

Feature Visualization

t-SNE Visualization

Experiments

Multiple experimental configurations were evaluated to determine the optimal architecture and training strategy. Key experiments included:

Training Approach

Model Variants

Two primary model variants were systematically explored:

  1. CBAM-ResNet18 v1: The initial implementation with baseline attention parameters, trained for 150 epochs
  2. CBAM-ResNet18 v2: An improved version with optimized training parameters and a more efficient training schedule (100 epochs)

Both models were evaluated using a comprehensive set of metrics including accuracy, precision, recall, F1 score, confusion matrices, ROC curves, and precision-recall curves to provide a holistic performance assessment.

Training History

Performance Results

CBAM-ResNet18 v1 Performance

Accuracy
97.46%
Precision
99.21%
Recall
99.17%
F1 Score
99.16%
Training Time
9h 46m 44s
Epochs
150

CBAM-ResNet18 v2 Performance

Accuracy
96.71%
Precision
99.19%
Recall
99.16%
F1 Score
99.17%
Training Time
3h 14m 43s
Epochs
100
Confusion Matrix

Confidence Analysis

The models become increasingly well-calibrated over time, as shown by the decreasing Expected Calibration Error (ECE). This indicates that the predicted confidence levels closely match the actual accuracy of predictions.

Confidence Distribution

By the final epoch, both models show high confidence (>85%) for the vast majority of predictions, with minimal low-confidence predictions. This demonstrates the models' ability to make decisive classifications with high certainty.

Conclusion

The CBAM-augmented ResNet18 architecture demonstrates significant improvements over standard classification approaches for plant disease identification. Key findings include:

These results highlight the potential of attention-enhanced deep learning approaches for practical agricultural applications. By providing accurate, reliable disease identification, this system could significantly contribute to sustainable farming practices through early detection and targeted treatment of plant diseases.

Future Work

Ongoing and planned improvements to the PlantDoc system include:

ROC Curves

Model Training Reports

CBAM-ResNet18 v1

Plant Disease Classification Model v1

Accuracy
97.46%
F1 Score
99.16%
Precision
99.21%
Recall
99.17%

Detailed performance report for CBAM-augmented ResNet18 model trained for multi-class classification with 39 classes.

CBAM-ResNet18 v2

Plant Disease Classification Model v2

Accuracy
96.71%
F1 Score
99.17%
Precision
99.19%
Recall
99.16%

Detailed performance report for optimized CBAM-augmented ResNet18 model (v2) with faster training schedule (100 epochs vs 150).

View on GitHub