This repository contains a deep learning project aimed at classifying images of cats and dogs. The project includes:
- A custom Convolutional Neural Network (CNN) built in Pytorch.
- A fine-tuned ResNet50 model pre-trained on Images Dataset from Kaggle.
Both models have been trained on a dataset imported from Kaggle, and the trained models along with the corresponding Jupyter notebooks are available in this repository.
The dataset used for training and validation is imported from Kaggle. It contains labeled images of cats and dogs.
A custom Convolutional Neural Network (CNN) was built from scratch and trained on the dataset to classify the images into two categories: cats and dogs.
A pre-trained ResNet50 model, available in the PyTorch library, was fine-tuned on the dataset. The fine-tuned model is located in the "Finetuning Pretrained model" directory.
- Clone the repository:
git clone https://github.com/Ich-Asadullah/Simple-ANN_cats-and-dogs_classifier_using_pytorch/ cd Simple-ANN_cats-and-dogs_classifier_using_pytorch
Use the Simple-ANN_cats-and-dogs_classifier_using_pytorch.ipynb
notebook.
To train the fine-tuned ResNet50:
Use the finetuning_RsNet50-CNN.ipynb
notebook.
To load and use the pre-trained models, refer to the following script:
checkpoint = torch.load('model_path') # Load the saved checkpoint file
model = MyCNN().to(device) # Create an instance of the model
# Create a new state dict that excludes unexpected keys
model_state_dict = model.state_dict()
for k in checkpoint['model_state_dict']:
if k in model_state_dict and model_state_dict[k].shape == checkpoint['model_state_dict'][k].shape:
model_state_dict[k] = checkpoint['model_state_dict'][k]
# Load the model state dict
model.load_state_dict(model_state_dict)
- Training Accuracy: 76.18%
- Validation Accuracy: 73.5%
- Testing Accuracy: 98.5%
Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or new features to add.