File size: 4,499 Bytes
1e8f7f3 82b71ae f021681 1e8f7f3 95edd40 1e8f7f3 2464eb4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 | ---
title: Inceptionv3 Dog VS Cat Classifier π
emoji: ππ
colorFrom: yellow
colorTo: green
sdk: gradio
sdk_version: 6.5.1
app_file: app.py
pinned: false
license: mit
short_description: Cat vs Dog classifier with InceptionV3 model.
models:
- AIOmarRehan/InceptionV3_Dogs_vs_Cats_Classifier_Model
datasets:
- AIOmarRehan/Cats_and_Dogs
---
[If you would like a detailed explanation of this project, please refer to the Medium article below.](https://medium.com/@ai.omar.rehan/building-a-near-perfect-cat-vs-dog-classifier-with-inceptionv3-01a5f9730907)
---
# Cats vs Dogs Image Classification (InceptionV3 + TensorFlow)
## Project Overview
This project focuses on building an image classification model that can distinguish between **cats and dogs** using **Transfer Learning** with the InceptionV3 architecture.
Instead of training a deep learning model from scratch, this project uses a pre-trained model and adapts it to solve a binary classification problem efficiently.
The goal of this project is to practice building a real-world computer vision pipeline including data preprocessing, training, evaluation, and visualization.
---
## Dataset
The project uses the **Cats and Dogs dataset**, which contains around:
* ~6,000 cat images
* ~6,000 dog images
The dataset is balanced, which helps the model learn both classes fairly and avoids bias toward one class.
---
## Data Preprocessing
Before training, images go through several preprocessing steps:
* Resize images to **256 Γ 256**
* Normalize pixel values
* Handle very bright or very dark images
* Apply data augmentation to improve generalization:
* Random flipping
* Random brightness changes
* Random contrast changes
TensorFlowβs `tf.data` pipeline is used to efficiently load and prepare data.
---
## Model Architecture
This project uses **Transfer Learning with InceptionV3**.
### Base Model
* Pre-trained on ImageNet
* Used as a feature extractor
* Frozen during initial training
### Custom Classification Head
Added on top of the base model:
* Global Average Pooling
* Dense layer (512 neurons, ReLU)
* Dropout (0.5) to reduce overfitting
* Final Dense layer with **Sigmoid** activation for binary classification
---
## Training Strategy
### Optimizer
* Adam optimizer
### Loss Function
* Binary Cross-Entropy
### Training Enhancements
The project uses callbacks to improve training:
* **EarlyStopping**
* Stops training when validation stops improving
* **ModelCheckpoint**
* Saves the best model automatically
* **ReduceLROnPlateau**
* Reduces learning rate when progress slows down
---
## Results & Evaluation
Model performance was evaluated using several visualization techniques.
---
### Accuracy
```
76/76 ββββββββββββββββββββ 3s 41ms/step - accuracy: 0.9941 - loss: 0.0194
Test Accuracy: 0.9933
76/76 ββββββββββββββββββββ 16s 115ms/step
Precision: 0.2498, Recall: 0.5000, F1-score: 0.3331
Classification Report:
precision recall f1-score support
cats 0.50 1.00 0.67 601
dogs 0.00 0.00 0.00 602
accuracy 0.50 1203
macro avg 0.25 0.50 0.33 1203
weighted avg 0.25 0.50 0.33 1203
```
---

**Observation:**
Training and validation accuracy both increase steadily and reach high performance (~98β99%).
---
### Loss

**Observation:**
Both training and validation loss decrease and stabilize, indicating good learning and low overfitting.
---
### Confusion Matrix

**Observation:**
Most predictions lie along the diagonal, meaning the model correctly classifies both cats and dogs most of the time.
---
### ROC Curve
| Binary Classification ROC Curve | (OvR) ROC Curve β Multi-Class Classification |
|-------|-------|
| <img src="https://files.catbox.moe/iou784.png" width="490"/> | <img src="https://files.catbox.moe/pz3mv7.png" width="540"/> |
**Observation:**
The model achieves an AUC score close to **1.0**, which indicates excellent classification ability.
---
## Key Takeaways
* Transfer Learning significantly reduces training time.
* Data augmentation improves model robustness.
* Proper evaluation metrics give deeper insight into model performance.
--- |