This project aims to classify images of dogs and cats using a custom Convolutional Neural Network (CNN) built with PyTorch. The project demonstrates the steps of data preprocessing, model building, training, and evaluation.
dog_vs_cat_classification.ipynb: Jupyter notebook containing the complete workflow from data loading to model training and evaluation.data/: Directory containing the dataset.README.md: Documentation for the project.
The dataset contains images of dogs and cats, divided into training and testing directories. Each subdirectory within train and test corresponds to a different category (dog or cat).
data/train/: Training imagesdata/test1/: Testing images
The preprocessing steps include:
- Loading the dataset from the specified directories.
- Renaming and organizing images into separate directories for each category.
- Applying transformations such as resizing, random horizontal flip, color jitter, random rotation, and conversion to tensor.
A simple CNN with:
- Two convolutional layers followed by ReLU activations.
- Two max-pooling layers.
- A flattening layer and a linear layer.
An enhanced CNN with:
- Four convolutional layers with increasing number of filters followed by ReLU activations.
- Two max-pooling layers.
- A flattening layer and a linear layer.
Similar to dogvscatv2 with potential further enhancements or adjustments.
The training process involves:
- Defining the loss function (BCEWithLogitsLoss) and optimizer (SGD).
- Training the model for a specified number of epochs (3 in this case).
- Recording the training and testing losses and accuracies for each epoch.
The model's performance is evaluated by printing the training and testing accuracies and losses over the epochs.
- torch
- torchvision
- matplotlib
- torchinfo
- PIL (Pillow)
The training and testing losses and accuracies are recorded and can be visualized in the notebook.
This project demonstrates how to build and train custom CNNs to classify images of dogs and cats. Further improvements can be made by tuning the model architecture, experimenting with different loss functions and optimizers, and using more advanced data augmentation techniques.