Skip to content
VigneshVarshaPublic

About

Dogs vs Cats Image Classification using CNN and MobileNetV2 | A deep learning image classification project that distinguishes between cats and dogs using transfer learning with MobileNetV2. The project uses TensorFlow and Keras, image augmentation, model evaluation, and prediction scripts. The trained model achieve

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Dogs vs Cats Image Classification using MobileNetV2

A deep learning image classification project that distinguishes between cats and dogs using a MobileNetV2-based convolutional neural network with transfer learning.

Python TensorFlow MobileNetV2 Status


πŸ“‹ Table of Contents


🎯 Overview

This project is part of the SkillCraft Technology Machine Learning Internship and focuses on binary image classification between cats and dogs.

Workflow:

  • Loading and organizing the dataset
  • Splitting data into training and validation sets
  • Applying data augmentation
  • Using MobileNetV2 pretrained on ImageNet
  • Adding a custom binary classification head
  • Training the model
  • Evaluating performance on test data
  • Generating classification report and confusion matrix
  • Predicting the class of a single image

🎯 Project Objective

Build a CNN model capable of classifying whether an image contains a cat or a dog with high accuracy using transfer learning and image preprocessing.


πŸ›  Technologies Used

  • Python 3
  • TensorFlow / Keras
  • MobileNetV2
  • NumPy
  • Scikit-learn
  • Matplotlib
  • Seaborn
  • Transfer Learning

πŸ— Model Architecture

The model uses MobileNetV2 as the feature extractor, with the pretrained base model frozen and a new binary classification layer added on top.

Input Image (160 x 160 x 3)
         |
         v
Data Augmentation
         |
         v
MobileNetV2 (ImageNet pretrained)
         |
         v
Global Average Pooling
         |
         v
Dropout (0.3)
         |
         v
Dense Layer (1 unit, Sigmoid)
         |
         v
CAT / DOG Prediction

πŸ“Š Dataset

The project uses the standard cats-vs-dogs dataset organized as follows:

dataset/
β”œβ”€β”€ train/
β”‚   β”œβ”€β”€ cats/
β”‚   └── dogs/
β”œβ”€β”€ test/
β”‚   β”œβ”€β”€ cats/
β”‚   └── dogs/
└── README.md

Dataset Summary:

Split Cats Dogs Total
Training 5,001 5,001 10,002
Validation 750* 750* 1,500
Testing 450 501 951

*Validation is created automatically from 15% of the training set during training.


πŸ“ Project Structure

SCT_ML_Task3/
β”œβ”€β”€ README.md
β”œβ”€β”€ requirements.txt
β”œβ”€β”€ dataset/
β”‚   β”œβ”€β”€ train/
β”‚   β”‚   β”œβ”€β”€ cats/
β”‚   β”‚   └── dogs/
β”‚   └── test/
β”‚       β”œβ”€β”€ cats/
β”‚       └── dogs/
β”œβ”€β”€ models/
β”‚   β”œβ”€β”€ dogs_cats_mobilenetv2.keras
β”‚   └── dogs_cats_mobilenetv2_final.keras
β”œβ”€β”€ results/
β”‚   β”œβ”€β”€ cnn_classification_report.txt
β”‚   β”œβ”€β”€ cnn_confusion_matrix.png
β”‚   β”œβ”€β”€ cnn_training_accuracy.png
β”‚   └── cnn_training_loss.png
└── src/
    β”œβ”€β”€ train_cnn.py
    β”œβ”€β”€ evaluate_cnn.py
    └── predict_cnn.py

πŸ“¦ Requirements

Make sure Python 3.10+ is installed, then install dependencies:

pip install -r requirements.txt

βš™οΈ Setup

1. Clone the repository

git clone https://github.com/VigneshVarsha/SCT_ML-3.git
cd SCT_ML-3

2. Create and activate a virtual environment

Windows PowerShell:

python -m venv .venv
.\.venv\Scripts\Activate.ps1

Windows Command Prompt:

python -m venv .venv
.venv\Scripts\activate.bat

3. Install dependencies

pip install -r requirements.txt

▢️ How to Run

Train the model

python src/train_cnn.py

This script:

  • Loads the dataset
  • Creates the validation split
  • Applies augmentation
  • Builds the MobileNetV2 model
  • Compiles the model
  • Trains for 5 epochs
  • Saves the trained model in models/

Evaluate the model

python src/evaluate_cnn.py

This generates:

  • results/cnn_confusion_matrix.png
  • results/cnn_classification_report.txt

Predict a single image

python src/predict_cnn.py "dataset/test/cats/cat_test_00010.jpg"

Example output:

Prediction: CAT
Confidence: 84.93%

Another example:

python src/predict_cnn.py "dataset/test/dogs/dog_test_00019.jpg"

πŸ“ˆ Model Performance

The trained model achieved strong results on the test set.

Metric Value
Test Accuracy 98.00%
Test Loss 0.0674

Classification Report

              precision    recall  f1-score   support

      cats       0.98      0.98      0.98       450
      dogs       0.98      0.98      0.98       501

      accuracy                           0.98       951
     macro avg       0.98      0.98      0.98       951
  weighted avg       0.98      0.98      0.98       951

Confusion Matrix

                  Predicted
                  Cat    Dog
Actual Cat       440     10
Actual Dog         9    492

Interpretation:

  • βœ… 440 cats correctly classified as cats
  • βœ… 492 dogs correctly classified as dogs
  • πŸ“Š 932 correct predictions out of 951 total images

πŸ“‚ Generated Outputs

The project creates visual and textual artifacts in the results/ folder:

File Description
cnn_training_accuracy.png Training accuracy visualization
cnn_training_loss.png Training loss visualization
cnn_confusion_matrix.png Confusion matrix heatmap
cnn_classification_report.txt Detailed classification metrics

πŸŽ“ Learning Outcomes

This project demonstrates:

  • Image classification with deep learning
  • CNN architecture design
  • Transfer learning using MobileNetV2
  • Data augmentation for image data
  • Binary classification with sigmoid output
  • Model evaluation using precision, recall, F1-score, and accuracy
  • Prediction on unseen images
  • Saving and loading TensorFlow/Keras models

πŸš€ Future Improvements

  • Fine-tuning deeper MobileNetV2 layers
  • Trying additional pretrained architectures (EfficientNet, ResNet, etc.)
  • Increasing image resolution
  • Experimenting with more augmentation techniques
  • Building a web or GUI-based prediction interface
  • Deploying the model as an application (Flask/FastAPI/Streamlit)

πŸ‘¨β€πŸ’» Author

Devarakonda Vignesh Varsha


πŸ“Œ Internship Details

Detail Information
Internship SkillCraft Technology
Domain Machine Learning
Task Task 03 - Dogs vs Cats Image Classification
Final Test Accuracy 98.00%

Built with ❀️ during SkillCraft Technology ML Internship

About

Dogs vs Cats Image Classification using CNN and MobileNetV2 | A deep learning image classification project that distinguishes between cats and dogs using transfer learning with MobileNetV2. The project uses TensorFlow and Keras, image augmentation, model evaluation, and prediction scripts. The trained model achieve

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages