Belall87's picture
Upload folder using huggingface_hub
c18b08b verified
---
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)