A machine learning project that classifies leaf images into different species using multiple classification models.
This project implements a leaf classification system with both backend machine learning models and a frontend web interface. Users can upload images of leaves, and the system will identify the species using one of several machine learning models.
- Multiple machine learning models for leaf classification (KNN, SVM, Decision Tree, Random Forest, ANN)
- Image feature extraction for shape, texture, and margin characteristics
- Web interface for easy leaf image upload and analysis
- Real-time prediction and species identification
leaf-classification:
backend:
# Flask API server
app.py: # Main API implementation
requirements.txt: # Backend dependencies
uploads: {} # Temporary storage for uploaded images
frontend:
# React frontend application
src:
components:
ImageUpload.jsx: # Image upload component
ResultsDisplay.jsx: # Results display component
ModelSelection.jsx: # Model selection component
App.jsx: # Main application component
other-files: ... # Other frontend files/configs
data:
# Data directory
raw:
train.csv: # Training data with features
test.csv: # Test data with features
processed: {} # Processed data files
models:
# Trained model storage
knn: {}
svm: {}
decision_tree: {}
random_forest: {}
ann: {}
scaler.pkl: # Feature scaler
label_encoder.pkl: # Label encoder
pca_reducer.pkl: # PCA model
lda_reducer.pkl: # LDA model
src:
# Source code for model training
data_preprocessing.py: # Data preprocessing functions
feature_extraction.py: # Feature extraction utilities
model_training.py: # Model training functions
evaluation.py: # Model evaluation metrics
main.py: # Main script for training models
requirements.txt: # Project dependencies
README.md: # Project documentation- Python 3.8+
- Node.js and npm
- Git
-
Clone the repository: bash git clone https://github.com/yourusername/leaf-classification.git cd leaf-classification
-
Create a virtual environment and activate it: bash python -m venv venv
venv\Scripts\activate
source venv/bin/activate
-
Install backend dependencies: bash cd backend pip install -r requirements.txt
-
Run the Flask API server: bash python app.py
The server will start on http://localhost:5000
-
Navigate to the frontend directory: bash cd ../frontend
-
Install frontend dependencies: bash npm install
-
Start the development server: bash npm start
The frontend will be available at http://localhost:3000
The project uses the Leaf Classification dataset from Kaggle (https://www.kaggle.com/competitions/leaf-classification). The dataset contains:
- Margin, shape, and texture features for various leaf species
- Images of leaf samples
- 99 species of plants represented
-
K-Nearest Neighbors (KNN)
- Fast classification based on similarity metrics
-
Support Vector Machine (SVM)
- High accuracy with good generalization capability
- Optimal hyperplane for classification in high-dimensional space
-
Decision Tree (DT)
- Simple interpretable model for leaf classification
-
Random Forest (RF)
- Ensemble method with improved robustness and accuracy
-
Artificial Neural Network (ANN)
- Deep learning approach for complex feature relationships
The system extracts three types of features from leaf images:
- Shape Features: Using elliptic Fourier descriptors
- Texture Features: Using Local Binary Patterns (LBP)
- Margin Features: Based on distance from centroid along the contour
- Open the web interface at http://localhost:3000
- Upload a leaf image through the interface
- The system will process the image and extract relevant features
- The selected model will classify the leaf species
- Results will display the predicted species name and confidence level
- If models return consistent class numbers (e.g., always class 19 or 64), check the label encoding between training and inference
- Verify that the feature extraction process matches between training and inference
- Ensure all preprocessing tools (scaler, reducer) are properly loaded
- Backend: Flask, TensorFlow, scikit-learn, OpenCV
- Frontend: React, TailwindCSS
- Data Processing: NumPy, Pandas, scikit-image
This project is licensed under the MIT License - see the LICENSE file for details.