This project implements a Convolutional Neural Network (CNN) to classify images of dogs and cats. The model is trained using TensorFlow and Keras, and it leverages the OpenCV (cv2) library for image preprocessing.
- Python 3.x
- TensorFlow 2.x
- Keras
- OpenCV (cv2)
The model is trained on a dataset consisting of labeled images of dogs and cats. The dataset was preprocessed using OpenCV to resize images to a uniform size (256x256 pixels) and normalize pixel values.
The CNN model architecture used for this classification task is as follows:
-
Convolutional Layers:
- 3 convolutional layers with increasing filter sizes (32, 64, 128) and ReLU activation.
- Each convolutional layer is followed by Batch Normalization and Max Pooling to extract features and reduce spatial dimensions.
-
Flatten Layer:
- Flattens the 3D output from the convolutional layers into a 1D vector to be fed into the dense layers.
-
Dense Layers:
- 2 fully connected dense layers with ReLU activation (128 units, 64 units) and dropout regularization (0.1).
- Final output layer with 1 unit and sigmoid activation function for binary classification (dog or cat).
-
Model Compilation:
- Loss function: Binary Crossentropy
- Optimizer: Adam
- Metrics: Accuracy
The model is trained on a GPU-enabled environment to expedite training due to the complexity of convolutional operations and the size of the dataset.
The performance of the model is evaluated using metrics such as accuracy, precision, recall, and F1-score on a separate test dataset.
-
Data Preparation:
- Ensure your images are organized into 'dog' and 'cat' folders or labeled accordingly.
-
Model Training:
- Use the provided script or Jupyter Notebook to train the model on your dataset.
-
Model Evaluation:
- Evaluate the trained model on a separate test dataset to assess its performance metrics.
-
Inference:
- Use the trained model to classify new images of dogs and cats.
- Fine-tuning hyperparameters (learning rate, batch size, etc.) for better performance.
- Experimenting with different CNN architectures (e.g., VGG, ResNet) for improved accuracy.
- Data augmentation techniques to enhance model generalization.
- Srijan Singh