Spaces:
Sleeping
A newer version of the Gradio SDK is available: 6.12.0
license: mit
title: Plant Disease Detection App
sdk: gradio
emoji: 🚀
colorFrom: red
colorTo: blue
5CCSAGAP: AI/Robotics Group Project - Plant Disease Detection
This repository contains the source code for the "Plant Disease Detector" application, developed for the 5CCSAGAP module.
1. Project Overview
The goal of this project is to build an AI system capable of detecting plant diseases from leaf images. The application is built with a Python backend using PyTorch and is deployed with a Gradio user interface. The system supports two models: a custom-built CNN and a high-performance model based on ResNet18 transfer learning.
Team 4 Members:
- Oguzhan Cagirir
- Janit Bhardwaj
- Hristina Georgieva
- Hissan Omar
- Kasim Morsel
- Mark Soltyk
2. Running the Application
This guide is for running the Gradio application locally to demonstrate its functionality.
Prerequisites
- Python 3.10+
- An active internet connection (for downloading model weights on first run).
- Git LFS is not required as large files are hosted externally.
Setup Instructions
Clone the repository:
git clone https://github.kcl.ac.uk/k23136072/Small-group-project.git cd Small-group-projectCreate and activate a Python virtual environment:
On Windows:
python -m venv .venv .venv\Scripts\activateOn Linux/macOS:
python3 -m venv .venv source .venv/bin/activateInstall dependencies:
pip install -r requirements.txt
Launching the Gradio UI
Once the setup is complete, launch the application:
python app.py
The application will start and provide a local URL (e.g., http://127.0.0.1:7860). Open this URL in your web browser.
Note on First Run: The first time you make a prediction with a specific model (e.g., "ResNet18"), the application will automatically download the required model weights (~45MB) from Hugging Face Hub. This may take a moment. Subsequent runs will use the cached local copy.
3. Repository Structure
app.py: The main Gradio application entry point.src/: Contains all core source code.src/inference.py: The core API for running model predictions. Handles model downloading and preprocessing.src/models/: Contains the PyTorch model definitions (cnn_model.py,resnet18_finetune.py).src/DataLoader/: Contains the data loading and processing logic used for training.src/train/: Contains the training (train.py) and evaluation (evaluate.py) scripts.src/utils/: Configuration and helper utilities.
configs/: Contains the YAML configuration file for training.requirements.txt: Project dependencies.process_dataset.py: Utility script to download and prepare the dataset from Hugging Face.README.md: This file.
4. Model Information
The application supports two models, selectable via the UI dropdown:
- ResNet18 (Default): A high-performance model using transfer learning from a pretrained ResNet18. Achieves ~96% accuracy on the test set.
- CNN: A custom-built baseline CNN, trained from scratch. Achieves ~78% accuracy on the test set.
Model weights are hosted on Hugging Face Hub at MZaik/Plant_Disease_Detection and are downloaded automatically by the application.
5. Training and Evaluation (Advanced)
To reproduce the training or evaluation runs, the repository is integrated with ClearML for experiment tracking.
Training:
- Configure
configs/train_cnn.yaml(setmodel_typetoresnet18orcnn). - Run
python -m src.train.train.- This will automatically trigger data processing if the dataset is missing.
- It will execute on the configured ClearML server if credentials are present, or locally if not.
Evaluation:
- Obtain a Model Task ID from a successful training run on ClearML.
- Run
python -m src.evaluate --model_type resnet18 --task_id [TASK_ID].- This generates the confusion matrix and classification report artifacts.