Skip to content

Transfer learning efficientNet to classification disease on plants. Build web application with React and FastAPI

Notifications You must be signed in to change notification settings

tinh2044/PlantDisease_classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

56 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌱 Plant Disease Classification

Background Image

πŸ“Œ Introduction

This project leverages the power of EfficientNet, a state-of-the-art deep learning model, to help farmers and gardeners quickly and accurately identify plant diseases using images of plant leaves. Upon detecting a disease, the application provides detailed information, including the disease's name, cause, and symptoms.


⚑ EfficientNet: Why It Matters for Plant Disease Detection

EfficientNet is a convolutional neural network (CNN) designed to balance accuracy and efficiency. Unlike traditional models that scale only in width, depth, or resolution, EfficientNet scales all three dimensions simultaneously, leading to better performance with fewer computations.

πŸ† Why EfficientNet for Plant Disease Classification?

βœ… Higher Accuracy – Outperforms ResNet, MobileNet, and Inception models.
βœ… Fewer Parameters – Uses 5x fewer parameters than ResNet-50 while achieving higher accuracy.
βœ… Optimized for Mobile & Edge AI – Enables deployment on smartphones, drones, and Raspberry Pi.
βœ… Faster Inference – Runs efficiently in real-time agricultural applications.

πŸ”¬ EfficientNet vs. Traditional Models

Model Parameters Accuracy (ImageNet) FLOPs (B)
ResNet-50 25.6M 76.6% 4.1
MobileNetV2 3.4M 72.0% 0.3
EfficientNet-B0 5.3M 77.1% 0.4
EfficientNet-B7 66M 84.4% 37.0

πŸ“Š Key Takeaways:

  • EfficientNet-B0 achieves similar accuracy to ResNet-50 but with 5x fewer parameters.
  • EfficientNet-B7 outperforms most CNN architectures with 84.4% top-1 accuracy.
  • Lower FLOPs (floating-point operations) mean faster inference on low-power devices.

πŸ“œ EfficientNet Architecture

EfficientNet Architecture

EfficientNet scales a model in three dimensions:
1️⃣ Depth – More layers for complex pattern recognition.
2️⃣ Width – Wider layers to retain fine-grained details.
3️⃣ Resolution – Larger input size to detect subtle disease features.

By combining these factors, EfficientNet achieves higher accuracy while using fewer resources.

🌍 Real-World Applications

🚜 Smartphone Apps – Farmers can use mobile apps to detect diseases instantly.
🌱 IoT & Edge AI – EfficientNet models can run on Raspberry Pi & Jetson Nano.
☁️ Cloud-Based APIs – Agricultural platforms can integrate real-time plant disease detection.
πŸ“‘ Drone & Smart Camera Systems – Automate plant health monitoring in large-scale farms.

πŸ“„ Reference Paper:
πŸ”— Mingxing Tan, Quoc V. Le. EfficientNet: Rethinking Model Scaling for Convolutional Neural Networks
πŸ“– Read on arXiv


πŸ—οΈ Project Overview

This project consists of three main components:

1️⃣ Training Pipeline – Train multiple models on the plant disease dataset.
2️⃣ Server – Build a FastAPI server to serve predictions.
3️⃣ Client – Create a React-based web application for user interaction.


πŸ“‚ Dataset

The dataset is collected from various Kaggle sources and includes 22 plant types with multiple disease classes.

πŸ”Ή Data Overview

  • 🌿 22 plant types
  • πŸ”¬ Multiple diseases per plant
  • πŸ–ΌοΈ Dataset split: Train, Validation, and Test
🌱 Plant Type 🦠 Disease Classes
Apple 4 (e.g., brown spot, gray spot)
Bell Pepper 2 (e.g., bacterial spot, healthy)
Potato 3 (e.g., early blight, late blight, healthy)
Tomato 8 (e.g., bacterial spot, leaf mold, late blight)
... ...

πŸ“₯ Download Dataset: Kaggle Dataset Link


βš™οΈ Set-up

1️⃣ Clone the Repository

git clone [email protected]:tinh2044/PlantDisease_classification.git
cd PlantDisease_classification

2️⃣ Create a Virtual Environment (Python 3.9 Recommended)

conda create --name plantDisease python=3.9
conda activate plantDisease

3️⃣ Install Dependencies

pip install -r requirements.txt

πŸ‹οΈβ€β™‚οΈ Training the Model

πŸ“₯ Download Dataset

Download the dataset manually: Kaggle Dataset

Or use Kaggle CLI:

kaggle datasets download -d nguyenchitinh/plantdisease-with-20-plant

πŸš€ Train the Model

python train_multiple_model.py --epoch 100 --batch_size 32 --root_dir ./Datasets --img_size 224 --export_dir ./SavedModels --h5_dir ./Models

πŸ’Ύ After training, model weights will be saved in:

  • ./Models/ β†’ Trained .h5 model weights.
  • ./SavedModels/ β†’ TensorFlow SavedModel format.

πŸ“Š Evaluate the Model

python evaluate.py --root_dir ./Datasets --h5_dir ./Models

πŸ”„ Convert Model to TFLite

python convert_tflite.py

🌐 Server

Ensure that all TFLite models are copied to:

server/ModelLight/

▢️ Run the Server

cd server
uvicorn app.main:app --host 127.0.0.1 --port 5000

βœ… API will be accessible at: http://127.0.0.1:5000

🐳 Run with Docker

docker compose up

πŸ–₯️ Client

Move to the client directory:

cd client

▢️ Run the Client

npm start

πŸ”§ Configure Environment Variables

Create a .env file in the client/ folder and add:

REACT_APP_API_URL=http://127.0.0.1:5000

πŸ“š References

Releases

No releases published

Packages

No packages published