Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌸 Flower Detection & Classification

A deep learning-powered web application that classifies flower images using a Convolutional Neural Network (CNN). Upload an image and instantly identify whether it's a daisy, sunflower, tulip, dandelion, or rose with confidence scores.

Python TensorFlow FastAPI License

🌟 Features

  • Real-time Classification: Upload flower images and get instant predictions
  • 5 Flower Types: Classifies daisy, sunflower, tulip, dandelion, and rose
  • Confidence Scores: View probability distribution across all classes
  • Modern UI: Clean, responsive web interface with dark mode design
  • Fast API Backend: Built with FastAPI for high performance
  • Deep Learning Model: Custom CNN architecture trained for flower recognition

πŸš€ Demo

Upload any flower image and the model will:

  1. Process the image
  2. Classify it into one of 5 categories
  3. Display confidence percentages for each class

πŸ› οΈ Tech Stack

Backend

  • FastAPI - Modern, fast web framework
  • TensorFlow/Keras - Deep learning framework
  • Pillow - Image processing
  • Uvicorn - ASGI server
  • NumPy - Numerical computations

Frontend

  • HTML5 - Structure
  • CSS3 - Modern styling with gradients and animations
  • Vanilla JavaScript - Interactive functionality

Model

  • Architecture: Custom CNN with 4 convolutional layers
  • Input Size: 64x64 RGB images
  • Layers: Conv2D, BatchNormalization, MaxPooling, Dropout, Dense
  • Output: 5-class softmax classification

πŸ“¦ Installation

Prerequisites

  • Python 3.8 or higher
  • pip package manager

Setup

  1. Clone the repository
git clone https://github.com/yourusername/flower_detection_classification.git
cd flower_detection_classification-main
  1. Install backend dependencies
cd backend
pip install -r requirements.txt
  1. Verify model file exists Ensure models/my_model_exp2.h5 is present in the backend directory.

🎯 Usage

Running Locally

  1. Start the Backend Server
cd backend
python app.py

Backend will run on http://localhost:8000

  1. Start the Frontend Server
cd frontend
python -m http.server 5500

Frontend will run on http://localhost:5500

  1. Open your browser Navigate to http://localhost:5500 and start classifying flowers!

API Endpoints

  • GET /health - Health check endpoint
  • POST /predict - Upload image for classification

Example API usage:

curl -X POST "http://localhost:8000/predict" \
  -H "Content-Type: multipart/form-data" \
  -F "file=@flower.jpg"

Response:

{
  "prediction": "rose",
  "confidence": 0.9523,
  "probabilities": {
    "daisy": 0.0123,
    "sunflower": 0.0089,
    "tulip": 0.0156,
    "dandelion": 0.0109,
    "rose": 0.9523
  }
}

🧠 Model Architecture

Conv2D (32 filters, 5x5) β†’ BatchNorm β†’ MaxPool2D
    ↓
Conv2D (64 filters, 3x3) β†’ BatchNorm β†’ MaxPool2D
    ↓
Conv2D (96 filters, 3x3) β†’ BatchNorm β†’ MaxPool2D
    ↓
Conv2D (96 filters, 3x3) β†’ BatchNorm β†’ MaxPool2D
    ↓
Flatten β†’ Dense(512) β†’ BatchNorm β†’ Dropout(0.5)
    ↓
Dense(5, softmax)

Input Shape: (64, 64, 3)
Output: 5 classes with probability distribution

πŸ“Š Supported Flower Classes

  1. 🌼 Daisy
  2. 🌻 Sunflower
  3. 🌷 Tulip
  4. 🌼 Dandelion
  5. 🌹 Rose

🎨 Frontend Features

  • Drag-and-drop image upload
  • Image preview before prediction
  • Real-time confidence visualization
  • Responsive design for all devices
  • Modern dark-mode UI with gradients
  • Smooth animations and transitions

πŸ“ Project Structure

flower_detection_classification-main/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app.py                 # FastAPI application
β”‚   β”œβ”€β”€ requirements.txt       # Python dependencies
β”‚   └── models/
β”‚       └── my_model_exp2.h5   # Trained CNN model
β”œβ”€β”€ frontend/
β”‚   └── index.html             # Web interface
β”œβ”€β”€ Copy_of_EXP_FLOWER_CNN_F1.ipynb  # Model training notebook
└── README.md

πŸ”§ Configuration

Environment Variables

  • MODEL_PATH - Path to the model file (default: models/my_model_exp2.h5)

CORS Settings

The backend is configured to accept requests from http://localhost:5500. Update in app.py if needed:

allow_origins=["http://localhost:5500"]

πŸš€ Deployment

Option 1: Hugging Face Spaces (Recommended for ML)

Free hosting specifically for ML models with unlimited usage.

Option 2: Render.com

Free tier with auto-deployment from GitHub.

Option 3: Docker

Build and deploy as a container:

docker build -t flower-classifier .
docker run -p 8000:8000 flower-classifier

🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the project
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Author

Your Name - @mukesh-843

πŸ™ Acknowledgments

  • TensorFlow and Keras teams for the amazing framework
  • FastAPI for the excellent web framework
  • Flower dataset contributors

πŸ“§ Contact

For questions or feedback, please open an issue or reach out via email.


⭐ Star this repository if you found it helpful! ⭐

About

🌸 AI-powered flower classification web app using CNN. Upload images to identify daisy, sunflower, tulip, dandelion, or rose with confidence scores. Built with TensorFlow, FastAPI, and modern web technologies.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages