A deep learning-powered web application for classifying 13 different types of Bangladeshi flowers using MobileNetV2 architecture with transfer learning.
π Try the app now: https://flower-image-classify.streamlit.app/
Upload any flower image and get instant classification results with confidence scores!
This project uses a fine-tuned MobileNetV2 model to identify and classify Bangladeshi flowers with an impressive 99.87% validation accuracy. The model was trained on the ColoredFlowersBD dataset containing 13 different flower species commonly found in Bangladesh.
- Chandramallika - Chrysanthemum
- Cosmos Phul - Cosmos flower
- Gada - Marigold
- Golap - Rose
- Jaba - Hibiscus
- Kagoj Phul - Bougainvillea
- Noyontara - Vinca/Periwinkle
- Radhachura - Flame of the Forest
- Rangan - Ixora
- Salvia - Sage flower
- Sandhyamani - Four o'clock flower
- Surjomukhi - Sunflower
- Zinnia - Zinnia flower
- Base Model: MobileNetV2 (pretrained on ImageNet)
- Transfer Learning: Fine-tuned last 50 layers
- Input Size: 224Γ224Γ3
- Output: 13 classes (softmax activation)
- Custom Head: GlobalAveragePooling2D β Dropout(0.4) β Dense(13)
- Optimizer: Adam (learning rate: 1e-4)
- Loss Function: Categorical Crossentropy
- Training Accuracy: 99.89%
- Validation Accuracy: 99.87%
- Dataset Split: 80% Training, 20% Validation
- Total Images: 7,927 images
- Training Images: 6,332 images
- Validation Images: 1,595 images
- Data Augmentation: Rotation, width/height shift, shear, zoom, horizontal flip
- Normalization: Pixel values scaled to [0,1]
- Image Resizing: All images resized to 224Γ224 pixels
- Batch Size: 32
If you encounter TensorFlow version compatibility issues during deployment, the requirements.txt has been updated with flexible version constraints that work across different Python versions and deployment platforms.
-
Clone the repository:
git clone <repository-url> cd Image_Classification
-
Install dependencies:
pip install -r requirements.txt
-
Ensure model files exist:
best_model.h5orflower_classifier.h5class_names.pkl(optional - defaults will be used)
-
Run the Streamlit app:
streamlit run app.py
-
Open your browser and navigate to
http://localhost:8501
- Push code to GitHub repository
- Connect to Streamlit Community Cloud
- Deploy directly from GitHub
- Create
Procfile:web: streamlit run app.py --server.port=$PORT --server.address=0.0.0.0 - Deploy using Heroku CLI or GitHub integration
If you encounter TensorFlow version errors:
- The requirements.txt uses flexible versioning (
tensorflowinstead oftensorflow==2.13.0) - This allows the deployment platform to choose the compatible version
- For local development, you may need:
pip install tensorflow>=2.15.0
- Ensure either
best_model.h5orflower_classifier.h5exists in the project directory - Model files are large (24MB) - some platforms may have size limits
- Consider using Git LFS for model files in version control
- TensorFlow models require sufficient RAM (recommend at least 1GB)
- Consider using smaller model architectures for resource-constrained environments
- Create Dockerfile
- Build and push container image
- Deploy to Cloud Run
Image_Classification/
βββ Image_Classification_Improved_Model.ipynb # Main training notebook
βββ app.py # Streamlit web application
βββ requirements.txt # Python dependencies
βββ best_model.h5 # Trained model (24MB)
βββ flower_classifier.h5 # Alternative model file
βββ class_names.pkl # Class names (optional)
βββ dataset/ # Dataset folder (excluded from git)
β βββ train/ # Training images
β βββ val/ # Validation images
βββ README.md # This file
- π Real-time Classification: Upload and classify flower images instantly
- π Confidence Scores: View prediction confidence and top-3 results
- π¨ Beautiful UI: Modern, responsive design with custom CSS
- π± Mobile Friendly: Works seamlessly on desktop and mobile devices
- βΉοΈ Model Information: Sidebar with model details and supported classes
- πΌοΈ Multiple Formats: Supports JPG, JPEG, and PNG image formats
- Deep Learning: TensorFlow/Keras
- Web Framework: Streamlit
- Image Processing: PIL, OpenCV
- Data Manipulation: NumPy, Pandas
- Visualization: Matplotlib
- Model Architecture: MobileNetV2
- Data Collection: ColoredFlowersBD dataset from Kaggle
- Data Preprocessing: Image augmentation and normalization
- Model Building: MobileNetV2 with custom classification head
- Transfer Learning: Fine-tuning approach with frozen initial layers
- Training: With callbacks (EarlyStopping, ModelCheckpoint, ReduceLROnPlateau)
- Evaluation: 99.87% validation accuracy achieved
# Data Augmentation
train_datagen = ImageDataGenerator(
rescale=1./255,
rotation_range=30,
width_shift_range=0.1,
height_shift_range=0.1,
shear_range=0.2,
zoom_range=0.2,
horizontal_flip=True,
fill_mode='nearest'
)
# Base Model
base_model = MobileNetV2(weights='imagenet', include_top=False, input_shape=(224, 224, 3))
# Fine-tuning: Unfreeze last 50 layers
for layer in base_model.layers[:-50]:
layer.trainable = False
for layer in base_model.layers[-50:]:
layer.trainable = True
# Custom Head
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dropout(0.4)(x)
output = Dense(13, activation='softmax')(x)- Loss: Categorical Crossentropy
- Metrics: Accuracy
- Validation Strategy: 20% holdout
- Early Stopping: Patience of 10 epochs
- Learning Rate Reduction: Factor of 0.2 when plateau detected
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Dataset: ColoredFlowersBD from Kaggle
- Architecture: MobileNetV2 by Google
- Framework: TensorFlow/Keras team
- Deployment: Streamlit team
- Inspiration: Bangladeshi flora and biodiversity
For questions, suggestions, or collaboration opportunities, please reach out through the repository issues or discussions.
Happy Flower Classification! πΈπΊπ»