Skip to content

Latest commit

 

History

3 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hybrid Cat-Dog Detection

A hybrid deep learning system that combines YOLOv8 for real-time object detection with a fine-tuned MobileNetV2 CNN for accurate cat/dog classification.

Overview

Component Role
YOLOv8 Detects and localizes animals in video frames
MobileNetV2 (fine-tuned) Classifies cropped detections as Cat or Dog

The pipeline first uses YOLO to find bounding boxes for cats/dogs, then passes each crop to the CNN for refined classification — yielding higher accuracy than either model alone.

Project Structure

Hybrid-Cat-Dog-Detection/
├── src/
│   ├── __init__.py
│   ├── config.py          # Hyperparameters & paths
│   ├── data.py            # Dataset loading & preprocessing
│   ├── model.py           # MobileNetV2 architecture
│   ├── train.py           # Training pipeline (feature extraction + fine-tuning)
│   ├── predict.py         # Single-image prediction
│   └── hybrid_detect.py   # YOLO + CNN hybrid video detection
├── notebooks/
│   └── cat.py             # Original Colab notebook (reference)
├── samples/               # Place sample images/videos here
├── results/               # Training graphs & detection samples
│   ├── accuracy.png
│   ├── loss.png
│   └── detection_sample.png
├── requirements.txt
├── LICENSE
├── .gitignore
└── README.md

Setup

1. Clone the repository

git clone https://github.com/amiitt001/Dogs-Vs-Cat-detection.git
cd Dogs-Vs-Cat-detection

2. Create a virtual environment

python -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activate

3. Install dependencies

pip install -r requirements.txt

Usage

Train the model

python -m src.train

This runs two phases:

  1. Feature Extraction — trains only the classification head (5 epochs)
  2. Fine-Tuning — unfreezes the last 30 layers of MobileNetV2 (3 epochs)

The trained model is saved as cat_dog_finetuned.h5.

Predict on a single image

python -m src.predict path/to/image.jpg

Run hybrid video detection

python -m src.hybrid_detect path/to/video.mp4 -o output.mp4

Model Architecture

MobileNetV2 (ImageNet, frozen) → GlobalAveragePooling2D → Dense(128, ReLU) → Dropout(0.5) → Dense(1, Sigmoid)
  • Phase 1: Base model frozen, only head layers train (Adam, lr=0.001)
  • Phase 2: Last 30 layers unfrozen, full model fine-tuned (Adam, lr=1e-5)

Dataset

Cats vs Dogs from TensorFlow Datasets — ~25,000 labeled images, split 80/20 for train/validation.

Results

Training Curves

Accuracy Loss
Model Accuracy Model Loss
Phase Metric Value
Feature Extraction Val Accuracy ~98.4%
Fine-Tuning Val Accuracy ~99%

Hybrid Detection Sample

Detection Sample

YOLO detects the animal → CNN refines the classification as CAT (0.98) confidence.

Technologies

  • Python 3.9+
  • TensorFlow / Keras
  • Ultralytics YOLOv8
  • OpenCV
  • TensorFlow Datasets

License

MIT

About

Hybrid Cat-Dog detection using YOLOv8 for real-time object detection and fine-tuned MobileNetV2 for accurate classification.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages