This project demonstrates flower classification using Convolutional Neural Networks (CNN) with TensorFlow and Keras. It involves encoding and splitting the data into training and test sets, building a CNN model, and evaluating its performance.
The dataset used for this project contains images of various types of flowers. The images are stored in folders based on their categories.
-
Clone the repository or download the code.
-
Ensure you have the required libraries installed, including NumPy, OpenCV, Matplotlib, Scikit-learn, TensorFlow, and Keras.
-
Set the
folder_dirvariable to the directory where your flower dataset is stored. -
Adjust the
SIZEvariable to define the dimensions to which the images will be cropped (e.g., 128x128 pixels).
-
The images are loaded, resized, and normalized to values between 0 and 1.
-
Labels are encoded using one-hot encoding.
-
The dataset is split into training and testing sets using a specified test size.
-
The CNN model is created using the Sequential API from Keras.
-
It consists of convolutional layers, max-pooling layers, and fully connected layers.
-
Data augmentation techniques are applied to improve model generalization. These include rotation, zoom, and shift range, along with horizontal and vertical flips.
-
The model is compiled using the Adam optimizer and categorical cross-entropy loss.
-
Training parameters such as batch size and number of epochs can be adjusted as needed.
-
The model is trained using the
model.fit_generatormethod with data generated by the ImageDataGenerator. -
Training progress is displayed with loss and accuracy metrics.
-
The trained model is evaluated using a randomly selected set of test images.
-
Predicted categories are compared with the ground truth labels.
-
Images are displayed with green labels for correct predictions and red labels for incorrect predictions.
-
Make sure you have installed all the required libraries.
-
Set the
folder_dirvariable to your dataset directory and adjust theSIZEvariable if necessary. -
Run the code.
-
Monitor training progress and evaluate model performance on test images.
Feel free to experiment with different hyperparameters and data augmentation techniques to improve model accuracy.
Happy flower classification!