Skip to content

Mahakpadlaya/Cats-And-Dogs-Classifier-Using-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cats and Dogs Classifier Using CNN

Project Overview

This project implements a Convolutional Neural Network (CNN) using PyTorch to classify images of cats and dogs. The model learns visual patterns from thousands of labeled images and predicts whether a given image contains a cat or a dog. A simple GUI built with Tkinter allows users to upload an image and receive real-time predictions.


Model Used

The project uses a Convolutional Neural Network (CNN) implemented in PyTorch. The architecture contains:

  • Convolution layers for feature extraction
  • ReLU activation
  • Max pooling layers
  • Fully connected layers for classification

The model outputs two classes:

  • Cat
  • Dog

Time Taken

Training time on different systems:

Mac Mini M4 Pro

  • ~30 minutes to train the dataset

Windows (Intel i5)

  • ~2 hours training time

Dataset Information

Dataset Size:

~800 MB

Number of Images:

  • Dogs: ~12,000 images
  • Cats: ~12,000 images

Total dataset size: ~24,000 images


Project Directory Structure

Cats-Vs-Dogs-Classifier/
│
├── data/
│   ├── train/
│   │   ├── Cat/
│   │   └── Dog/
│
├── models/
│   └── cnn_model.py
│
├── images/
│   ├── gui_demo.png
│   ├── dog.jpg
│   └── cat.jpg
|__ clean_dataset.py
├── train.py
├── predict.py
├── predict_gui.py
├── requirements.txt
└── README.md

How the Model Works

  1. Images are loaded from the dataset directory.
  2. Each image is resized and converted into tensors.
  3. The CNN extracts important visual features using convolution layers.
  4. Fully connected layers classify the extracted features.
  5. The model outputs the predicted label Cat or Dog.

Installing Virtual Environment

Mac / Linux

Create virtual environment:

python3 -m venv .venv

Activate environment:

source .venv/bin/activate

Windows

Create virtual environment:

python -m venv .venv

Activate environment:

.venv\Scripts\activate

Install Requirements

pip install -r requirements.txt

Downloading the Dataset

In this model , the dataset is download from Microsoft Kaggle Cats and Dogs Dataset

https://download.microsoft.com/download/3/e/1/3e1c3f21-ecdb-4869-8368-6deba77b919f/kagglecatsanddogs_5340.zip

Training the Model

Run the training script:

python train.py

After training completes, the model will be saved as:

cat_dog_cnn.pth

Cleaning the dataset

As the dataset contains some corrupt/broken image so I have created a script to Delete these images.

run python clean_dataset.py

Predict Without GUI

You can run prediction using the command line.

Edit the image path inside:

predict.py

Change the image path:

img = Image.open("path_to_image.jpg")

Then run:

python predict.py

Using GUI

Run the graphical interface:

python predict_gui.py

Steps:

  1. Click Upload Image
  2. Select a cat or dog image
  3. Click Predict
  4. The model will display the prediction

Requirements

Main libraries used:

torch
torchvision
pillow
numpy
tkinter

Author

Developed as a deep learning project using PyTorch for learning computer vision concepts and CNN-based image classification.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages