Dataset 1 : /kaggle/input/corn-or-maize-leaf-disease-dataset/data
- Dataset Path:
/kaggle/input/corn-or-maize-leaf-disease-dataset/data - Detected Classes:
- π± Blight
- π Common Rust
- π Gray Leaf Spot
- β Healthy
| Split | Percentage |
|---|---|
| ποΈββοΈ Training | 80% |
| π§ͺ Validation | 10% |
| π§Ύ Test | 10% |
This program classifies maize leaf images into the above four categories using:
- π· CNN with MobileNetV2
- π§ CBAM (Convolutional Block Attention Module) for better feature attention
- π‘ Support Vector Machine (SVM) on extracted features to enhance classification performance
CBAM helps the network focus on important regions of the image.
-
π΄ Channel Attention
GlobalAvgPool + GlobalMaxPool β MLP β Add + Sigmoid -
π΅ Spatial Attention
Channel-wise mean/max β Concat β Conv2D β Sigmoid
β This is implemented in the function
cbam_block(input_feature)
Input β MobileNetV2 β CBAM β GAP β Dense(256) β BN β Dropout(0.5) β Dense(128) β BN β Dropout(0.5) β Dense(4, softmax)
| Metric | Value |
|---|---|
| π― Accuracy | 97.16% |
| π Final Loss | 0.4247 |
| β±οΈ Epochs | ~41 |
π Training Graph: Accuracy and loss plotted across epochs.
| Class | Precision | Recall | F1-Score | Support |
|---|---|---|---|---|
| π± Blight | 0.96 | 0.93 | 0.95 | 116 |
| π Common_Rust | 1.00 | 1.00 | 1.00 | 132 |
| π Gray_Leaf_Spot | 0.87 | 0.93 | 0.90 | 58 |
| β Healthy | 1.00 | 1.00 | 1.00 | 117 |
| Weighted Avg | 0.97 | 0.97 | 0.97 | 423 |
π Confusion Matrix: Displayed using Seaborn heatmap.
| π Component | π’ Result/Value |
|---|---|
| π― Deep Model Accuracy | 97.16% |
| π§ SVM Accuracy | 98.11% |
| π§© Base Architecture | MobileNetV2 + CBAM |
| π Feature Dimension | 128 |
| ποΈ Training Images | 3348 |
| π§Ύ Test Images | 423 |
| π Best Classifier | SVM on features |
| β Misclassifications | Minimal (mostly in Gray Leaf Spot) |
Dataset 2: /kaggle/input/maizeleaf/MaizeLeafDataset
- Source:
/kaggle/input/maizeleaf/MaizeLeafDataset - Classes:
- π Common Rust
- π Gray Leaf Spot
- β Healthy
- π«οΈ Northern Leaf Blight
- β Not Maize Leaf
- 4 random images per class displayed using
matplotlibto ensure data integrity.
| Split | Percentage | Destination Folder |
|---|---|---|
| ποΈββοΈ Train | 80% | /kaggle/working/split_data/train/ |
| π§ͺ Validation | 10% | /kaggle/working/split_data/val/ |
| π§Ύ Test | 10% | /kaggle/working/split_data/test/ |
-
Training Generator includes:
rescale,rotation_range,horizontal_flip,vertical_flip,brightness_range,zoom_range,fill_mode
-
Validation & Test:
- Only
rescale
- Only
-
Output Shape:
(224, 224, 3) -
Labels: One-hot encoded
The Convolutional Block Attention Module (CBAM) improves the modelβs ability to focus on relevant leaf regions.
- π΄ Channel Attention:
GlobalAvgPool + GlobalMaxPool β MLP β Add β Sigmoid - π΅ Spatial Attention:
Mean + Max β Concatenate β Conv2D β Sigmoid
π‘ Integrated via
cbam_block(input_feature)into the main model.
Input β MobileNetV2 β CBAM β GAP β Dense(256) β BN β Dropout(0.5) β Dense(128) β BN β Dropout(0.5) β Dense(5, softmax)
- π§ Backbone: MobileNetV2 (
include_top=False, pretrained on ImageNet) - π§ Trainable Parameters: ~3M
- π§ͺ Activation:
softmax - π Loss:
CategoricalCrossentropy(withlabel_smoothing=0.1) - βοΈ Optimizer: Adam (
lr=0.001)
EarlyStopping(patience=5)ReduceLROnPlateau
- π Training completed in ~45 epochs
- β Final Validation Accuracy: ~99.66%
- πΎ Model saved as:
final_trained_model.h5
- Loss: ~0.43
- Accuracy: ~99.00%
| Metric | Value |
|---|---|
| π― Precision (weighted) | 0.9903 |
| π Recall (weighted) | 0.9899 |
| π§ F1-Score (weighted) | 0.9899 |
- Visualized using Seaborn heatmap
- Minimal misclassification across all 5 classes
- 𧬠Output: 128-dimensional feature vector per image (from CBAM-enhanced MobileNetV2)
| Set | Shape |
|---|---|
| ποΈ Train | (7079, 128) |
| π§Ύ Test | (891, 128) |
| π§ͺ Metric | π Value |
|---|---|
| π― Test Accuracy | 99.44% |
| π§ F1, Precision, Recall | > 0.98 for all classes |
π SVM slightly outperforms the CNN softmax classifier!
| π§© Component | π‘ Description |
|---|---|
| π Model Backbone | MobileNetV2 (ImageNet pre-trained) + CBAM |
| π§ Classification | Softmax and SVM (on extracted 128-dim features) |
| πΌοΈ Input Size | 224x224 RGB |
| π Data Augmentation | β Applied to training set |
| π CBAM | β Channel + Spatial attention |
| π― Final Accuracy | ~99.4% (combined CNN + SVM performance) |
| π½ Use Case | Maize Leaf Disease Classification |
| π Deployment Ready | β
Saved model (.h5) and feature extractor exported |