A hybrid deep learning system that combines YOLOv8 for real-time object detection with a fine-tuned MobileNetV2 CNN for accurate cat/dog classification.
| 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.
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
git clone https://github.com/amiitt001/Dogs-Vs-Cat-detection.git
cd Dogs-Vs-Cat-detectionpython -m venv venv
# Windows
venv\Scripts\activate
# macOS / Linux
source venv/bin/activatepip install -r requirements.txtpython -m src.trainThis runs two phases:
- Feature Extraction — trains only the classification head (5 epochs)
- Fine-Tuning — unfreezes the last 30 layers of MobileNetV2 (3 epochs)
The trained model is saved as cat_dog_finetuned.h5.
python -m src.predict path/to/image.jpgpython -m src.hybrid_detect path/to/video.mp4 -o output.mp4MobileNetV2 (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)
Cats vs Dogs from TensorFlow Datasets — ~25,000 labeled images, split 80/20 for train/validation.
| Accuracy | Loss |
|---|---|
![]() |
![]() |
| Phase | Metric | Value |
|---|---|---|
| Feature Extraction | Val Accuracy | ~98.4% |
| Fine-Tuning | Val Accuracy | ~99% |
YOLO detects the animal → CNN refines the classification as CAT (0.98) confidence.
- Python 3.9+
- TensorFlow / Keras
- Ultralytics YOLOv8
- OpenCV
- TensorFlow Datasets


