File size: 4,893 Bytes
c18b08b |
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 |
---
language: en
license: mit
library_name: keras
pipeline_tag: image-classification
tags:
- cat-emotion
- vgg16
- transfer-learning
- cnn
- tensorflow
- keras
- image-classification
- computer-vision
- depi
datasets:
- custom
metrics:
- accuracy
---
# π± Cat Emotion Classification with VGG16
A deep learning model for classifying cat emotions from images using **VGG16 transfer learning**, achieving **82.19% validation accuracy** across 5 emotion classes.
## Model Description
This model classifies cat facial expressions into one of five emotional categories. It uses VGG16 (pre-trained on ImageNet) as a feature extractor with a custom classification head featuring GlobalAveragePooling2D, BatchNormalization, and two Dense layers.
**Part of:** Digital Egypt Pioneers Initiative (DEPI) Machine Learning Internship
| Property | Value |
|----------|-------|
| **Architecture** | VGG16 + GAP + BN + Dense(512, 256) |
| **Input Size** | 224Γ224Γ3 RGB |
| **Output** | 5 classes (softmax) |
| **Parameters** | ~15.3M (trainable: ~2.1M) |
| **Framework** | TensorFlow / Keras |
| **Accuracy** | 82.19% |
## Classes
| Index | Class | Description |
|-------|-------|-------------|
| 0 | `angry` | Cat displaying angry expressions |
| 1 | `normal` | Cat in a neutral/normal state |
| 2 | `rested` | Cat in a relaxed/resting state |
| 3 | `sad` | Cat displaying sad expressions |
| 4 | `surprised` | Cat displaying surprised expressions |
## Quick Start
```python
from tensorflow.keras.models import load_model
import numpy as np
from PIL import Image
# Load model
model = load_model('best_vgg16_model.keras')
# Predict
img = Image.open('cat.jpg').resize((224, 224))
img_array = np.expand_dims(np.array(img) / 255.0, axis=0)
prediction = model.predict(img_array)
classes = ['angry', 'normal', 'rested', 'sad', 'surprised']
predicted_class = classes[np.argmax(prediction)]
confidence = np.max(prediction)
print(f"Emotion: {predicted_class} ({confidence:.2%})")
```
## Training Details
### Architecture (V2 β Final)
```
VGG16 (ImageNet, last 8 layers unfrozen)
β
GlobalAveragePooling2D
β
BatchNormalization
β
Dense(512, ReLU) β Dropout(0.5)
β
BatchNormalization
β
Dense(256, ReLU) β Dropout(0.3)
β
Dense(5, Softmax)
```
### Training Strategy
| Phase | Epochs | Learning Rate | Description |
|-------|--------|--------------|-------------|
| Phase 1 β Feature Extraction | 15 | 1e-4 | All VGG16 layers frozen |
| Phase 2 β Fine-Tuning | 25 | 1e-5 | Last 8 VGG16 layers unfrozen |
- **Optimizer:** Adam
- **Loss:** Categorical Crossentropy
- **Class Weights:** Balanced (computed with sklearn)
- **Callbacks:** EarlyStopping (patience=5), ReduceLROnPlateau, ModelCheckpoint
### Data Augmentation
- Rotation: 30Β°
- Width/Height shift: 0.25
- Zoom: 0.25
- Horizontal flip
- Brightness: [0.8, 1.2]
- Shear: 0.15
## Performance
### Model Comparison
| Version | Input | Architecture | Accuracy |
|---------|-------|-------------|----------|
| V1 (Baseline) | 128Γ128 | Flatten β Dense(256) | 81.18% |
| **V2 (Final)** | **224Γ224** | **GAP β BN β Dense(512,256)** | **82.19%** |
### Dataset
- **Training:** ~11,513 images
- **Validation:** ~2,880 images
- **Source:** [Kaggle β Cats Data Set](https://www.kaggle.com/datasets/bilalmahmoud/cats-data-set)
## Files
- `best_vgg16_model.keras` β Trained VGG16 model (V1, 134MB)
- `README.md` β This model card
## Intended Use
- **Primary use:** Classifying cat emotions from images
- **Users:** Researchers, students, pet tech developers
- **Out of scope:** Other animal species, real-time production systems
## Limitations
- Trained on a specific cat emotion dataset β may not generalize to all cat breeds or lighting conditions
- 5 emotion categories only β does not cover all possible feline emotional states
- Best results with clear, well-lit frontal images of cats
## Links
- π± **GitHub:** [Bolaal/Cat-Emotion-Classification-with-CNN](https://github.com/Bolaal/Cat-Emotion-Classification-with-CNN)
- π **Dataset:** [Kaggle β Cats Data Set](https://www.kaggle.com/datasets/bilalmahmoud/cats-data-set)
## Citation
```bibtex
@misc{cat-emotion-vgg16-2025,
author = {Belal Mahmoud Hussien},
title = {Cat Emotion Classification with VGG16},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/Belall87/Cat-Emotion-Classification-with-CNN}
}
```
## Author
**Belal Mahmoud Hussien**
- π§ Email: belalmahmoud8787@gmail.com
- πΌ LinkedIn: [belal-mahmoud-husien](https://linkedin.com/in/belal-mahmoud-husien)
- π± GitHub: [@Bolaal](https://github.com/Bolaal)
- π€ Hugging Face: [@Belall87](https://huggingface.co/Belall87)
|