This project trains a CNN model to recognize and classify 5 different types of flowers:
- 🌼 Daisy
- 🌾 Dandelion
- 🌹 Rose
- 🌻 Sunflower
- 🌷 Tulip
- ✅ Reading and preprocessing images
- ✅ Automatic resize of images to standard dimensions
- ✅ Normalize pixel values
- ✅ Data Augmentation to improve model generalization
- ✅ Training of Convolutional Neural Network (CNN)
- ✅ Automatic saving of the best model
- ✅ Early Stopping and Learning Rate Scheduling
- ✅ Drawing accuracy and loss graphs
- ✅ Predicting new images with graphical result display
Image-Classification/
│
├── dataset/
│ ├── train/ # Training data (5 subfolders for each class)
│ │ ├── daisy/
│ │ ├── dandelion/
│ │ ├── rose/
│ │ ├── sunflower/
│ │ └── tulip/
│ └── validation/ # Validation data
│ ├── daisy/
│ ├── ...
│
├── model.py # CNN model architecture
├── train.py # Training script
├── predict.py # Prediction script
├── prepare_dataset.py # Dataset preparation and splitting
├── requirements.txt # Dependencies
├── README.md
└── flower_model.h5 # Saved model (after training)
- Python
- TensorFlow / Keras - Deep Learning Framework
- OpenCV - Image Processing
- NumPy - Numerical Computations
- Matplotlib - Plot Visualization
pip install -r requirements.txtDownload the dataset from Kaggle: 🔗 Flowers Recognition Dataset
curl -L -o ~/flowers-recognition.zip\
https://www.kaggle.com/api/v1/datasets/download/alxmamaev/flowers-recognitionAfter extraction, use the preparation script:
python prepare_dataset.py --source path/to/flowers --split 0.8This command splits the dataset into train and validation with 80/20 ratio.
python train.pyOutputs:
flower_model.h5- Trained modeltraining_history.png- Accuracy and loss graphclass_indices.txt- Class mapping
python predict.py path/to/image.jpgOr with options:
python predict.py rose_sample.jpg --model flower_model.h5The designed CNN model includes 4 convolutional blocks:
| Layer | Filters | Kernel | Activation |
|---|---|---|---|
| Conv2D + BN + MaxPool | 32 | 3×3 | ReLU |
| Conv2D + BN + MaxPool | 64 | 3×3 | ReLU |
| Conv2D + BN + MaxPool | 128 | 3×3 | ReLU |
| Conv2D + BN + MaxPool | 128 | 3×3 | ReLU |
| Flatten + Dropout(0.5) | - | - | - |
| Dense + BN + Dropout(0.3) | 512 | - | ReLU |
| Dense (Output) | 5 | - | Softmax |
Optimizer: Adam (lr=0.001)
Loss: Categorical Crossentropy
Metrics: Accuracy
With default settings and 30 epochs of training, the model usually reaches 80-88% accuracy on validation data.
⭐ If this project was useful to you, please give it a star!


