This report presents a detailed analysis of two deep learning models developed for detecting plant diseases using image data. The project aims to create an efficient and accurate system for identifying diseased plants, which could have significant implications for agriculture and plant health management. Two models were implemented and evaluated: a custom Convolutional Neural Network (CNN) and a DenseNet121-based model. This report provides an in-depth justification for the selection of these models, a thorough evaluation and comparison of their performance, and a proposal for the best model based on the results.
You can access the plant disease detection dataset using the following link: Plant Disease Detection Dataset
The dataset used in this project consists of images of plant leaves, categorized into two classes:
- Diseased: Images of plant leaves showing signs of disease
- Healthy: Images of healthy plant leaves
The images were stored in two separate folders:
- Diseased folder:
/content/drive/MyDrive/Plant disease detection Dataset/Diseased
- Healthy folder:
/content/drive/MyDrive/Plant disease detection Dataset/Healthy
Both models used the following preprocessing steps:
- Image Resizing: All images were resized to 224x224 pixels to ensure uniform input size.
- Normalization: Pixel values were normalized to the range [0, 1] by dividing by 255.
- Label Encoding: Binary classification labels were one-hot encoded (0 for healthy, 1 for diseased).
- Train-Validation Split: The dataset was split into 80% training and 20% validation sets.
To improve model generalization and combat overfitting, data augmentation was applied using Keras' ImageDataGenerator with the following parameters:
- Rotation range: 20 degrees
- Width shift range: 20%
- Height shift range: 20%
- Shear range: 20%
- Zoom range: 20%
- Horizontal flip: Enabled
The custom CNN was selected as one of the models for the following reasons:
-
Flexibility and Control: A custom architecture allows for fine-grained control over the network's structure, enabling tailored design for the specific plant disease detection task.
-
Baseline Performance: It serves as a good baseline to understand the problem's complexity and the necessary model capacity.
-
Educational Value: Implementing a custom CNN from scratch provides valuable insights into the fundamentals of convolutional neural networks and their application to image classification tasks.
-
Resource Efficiency: Custom CNNs can be designed to be more lightweight compared to pre-trained models, which can be beneficial for deployment in resource-constrained environments.
DenseNet121 was chosen as the second model for the following reasons:
-
Feature Reuse: DenseNet's dense connectivity pattern allows for efficient feature reuse, potentially leading to improved performance with fewer parameters.
-
Gradient Flow: The direct connections between layers in DenseNet facilitate better gradient flow during training, which can lead to faster convergence and improved performance.
-
Transfer Learning: Utilizing pre-trained weights from ImageNet allows the model to leverage features learned from a large and diverse dataset, potentially improving performance on the plant disease detection task.
-
State-of-the-Art Performance: DenseNet has shown excellent performance on various image classification benchmarks, making it a strong candidate for this task.
The custom CNN model consists of the following layers:
- Three convolutional blocks, each containing:
- Conv2D layer (32, 64, and 128 filters respectively, 3x3 kernel)
- Batch Normalization
- ReLU activation
- MaxPooling2D (2x2 pool size)
- Flatten layer
- Two dense layers (256 and 128 units) with ReLU activation and Dropout (0.5)
- Output dense layer (2 units) with softmax activation
Total parameters: Approximately 1.7 million
The DenseNet121 model architecture includes:
- Pre-trained DenseNet121 base (weights from ImageNet, exclude top layer)
- Global Average Pooling 2D
- Dense layer (128 units) with ReLU activation
- Output dense layer (2 units) with softmax activation
Total parameters: Over 8 million
Both models were trained using similar hyperparameters and techniques:
- Optimizer: Adam (learning rate = 0.001)
- Loss function: Categorical Cross-Entropy
- Metrics: Accuracy
- Batch size: 32
- Maximum epochs: 50 (Custom CNN), 8 (DenseNet121)
- Callbacks:
- EarlyStopping (monitor='val_loss', patience=10, restore_best_weights=True)
- ReduceLROnPlateau (monitor='val_loss', factor=0.2, patience=5, min_lr=0.0001)
- Validation Accuracy: 0.8659 (86.59%)
- Training Time: Moderate
Strengths:
- Good baseline performance
- Flexibility in architecture design
- Lighter computational requirements
Weaknesses:
- Lower accuracy compared to DenseNet121
- May require more fine-tuning to achieve optimal performance
- Validation Accuracy: 0.902 (90.2%)
- Training Time: Longer than Custom CNN
Strengths:
- Higher accuracy
- Efficient feature utilization
- Benefited from transfer learning
Weaknesses:
- Higher computational requirements
- Longer training time
- More complex architecture, potentially harder to fine-tune
Aspect | Custom CNN | DenseNet121 |
---|---|---|
Validation Accuracy | 86.59% | 90.2% |
Model Size | ~1.7M params | >8M params |
Training Time | Moderate | Longer |
Flexibility | High | Moderate |
Feature Utilization | Basic | Advanced |
Transfer Learning | No | Yes |
The DenseNet121 model outperforms the custom CNN in terms of validation accuracy, demonstrating the benefits of its advanced architecture and pre-trained weights. However, this comes at the cost of increased computational requirements and longer training times.
Based on the evaluation and comparison, the DenseNet121 model is recommended as the best model for the plant disease detection task. Its higher accuracy (90.2% vs 86.59%) suggests better performance in identifying diseased plants.
Recommendations:
- Use the DenseNet121 model for deployment if computational resources allow.
- Consider the custom CNN for scenarios where computational efficiency is crucial.
- Further fine-tune the DenseNet121 model to potentially improve its performance.
- Explore techniques to reduce the computational requirements of the DenseNet121 model, such as pruning or quantization.