A deep learning project to build, train, and evaluate a Convolutional Neural Network (CNN) from scratch using TensorFlow and Keras.
View Demo
·
Report Bug
Table of Contents
This project is a comprehensive, end-to-end implementation of a Convolutional Neural Network (CNN) designed for a binary image classification task. The primary goal was to build and train a deep learning model from the ground up capable of accurately distinguishing between images of cats and dogs.
The entire development process is documented here, from setting up a GPU-accelerated environment using WSL2 to tackling common machine learning challenges like overfitting. The final model achieves a stable validation accuracy, demonstrating a solid understanding of fundamental deep learning principles.
- Custom CNN Architecture: A sequential model built from scratch with multiple convolutional, batch normalization, and max-pooling layers.
- GPU Acceleration: Configured to train on an NVIDIA GPU using TensorFlow's WSL2 support for significantly faster computation.
- Overfitting Mitigation: Implemented key regularization techniques including aggressive Data Augmentation (random flips, rotations, zoom) and Dropout layers.
- Efficient Data Handling: Utilized
tf.data.Datasetfor an optimized input pipeline, including file-based caching to handle datasets larger than available RAM. - Performance Evaluation: Scripts to visualize model performance (accuracy/loss) and to test the trained model on new, unseen images.
This project was built using the following technologies and libraries:
To get a local copy up and running, follow these simple steps.
You will need a Python environment with GPU support. The recommended setup is using WSL2 on Windows.
- NVIDIA GPU with CUDA-enabled drivers
- WSL2 with an Ubuntu distribution
- Python 3.10+
- Clone the repository:
git clone [https://github.com/Icey067/Cat-Dog-Image-Classifier.git](https://github.com/Icey067/Cat-Dog-Image-Classifier.git)
- Navigate to the project directory:
cd Cat-Dog-Image-Classifier - Create and activate a virtual environment:
python3 -m venv venv source venv/bin/activate - Install the required packages:
pip install -r requirements.txt
The original dataset can be downloaded from Kaggle. Ensure your images are in train/ and test/ subdirectories, then run the training script.
To test the pre-trained model on a new image, place your image in the root project folder. Run the Predictor.py script from your terminal, passing the image name as an argument.
The model was trained until the EarlyStopping callback concluded the training, as the validation loss was no longer improving.
Here is a snapshot of the model training on the GPU, showing the progression of epochs.

The final plots show a well-fitting model where the training and validation metrics track each other closely.

The model correctly identifies new images of cats and dogs that it has never seen before.

