Belall87 commited on
Commit
c18b08b
·
verified ·
1 Parent(s): 7a831bc

Upload folder using huggingface_hub

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. README.md +168 -0
  3. best_vgg16_model.keras +3 -0
  4. config.json +47 -0
  5. results_v2.json +38 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ best_vgg16_model.keras filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ library_name: keras
5
+ pipeline_tag: image-classification
6
+ tags:
7
+ - cat-emotion
8
+ - vgg16
9
+ - transfer-learning
10
+ - cnn
11
+ - tensorflow
12
+ - keras
13
+ - image-classification
14
+ - computer-vision
15
+ - depi
16
+ datasets:
17
+ - custom
18
+ metrics:
19
+ - accuracy
20
+ ---
21
+
22
+ # 🐱 Cat Emotion Classification with VGG16
23
+
24
+ A deep learning model for classifying cat emotions from images using **VGG16 transfer learning**, achieving **82.19% validation accuracy** across 5 emotion classes.
25
+
26
+ ## Model Description
27
+
28
+ 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.
29
+
30
+ **Part of:** Digital Egypt Pioneers Initiative (DEPI) Machine Learning Internship
31
+
32
+ | Property | Value |
33
+ |----------|-------|
34
+ | **Architecture** | VGG16 + GAP + BN + Dense(512, 256) |
35
+ | **Input Size** | 224×224×3 RGB |
36
+ | **Output** | 5 classes (softmax) |
37
+ | **Parameters** | ~15.3M (trainable: ~2.1M) |
38
+ | **Framework** | TensorFlow / Keras |
39
+ | **Accuracy** | 82.19% |
40
+
41
+ ## Classes
42
+
43
+ | Index | Class | Description |
44
+ |-------|-------|-------------|
45
+ | 0 | `angry` | Cat displaying angry expressions |
46
+ | 1 | `normal` | Cat in a neutral/normal state |
47
+ | 2 | `rested` | Cat in a relaxed/resting state |
48
+ | 3 | `sad` | Cat displaying sad expressions |
49
+ | 4 | `surprised` | Cat displaying surprised expressions |
50
+
51
+ ## Quick Start
52
+
53
+ ```python
54
+ from tensorflow.keras.models import load_model
55
+ import numpy as np
56
+ from PIL import Image
57
+
58
+ # Load model
59
+ model = load_model('best_vgg16_model.keras')
60
+
61
+ # Predict
62
+ img = Image.open('cat.jpg').resize((224, 224))
63
+ img_array = np.expand_dims(np.array(img) / 255.0, axis=0)
64
+
65
+ prediction = model.predict(img_array)
66
+ classes = ['angry', 'normal', 'rested', 'sad', 'surprised']
67
+
68
+ predicted_class = classes[np.argmax(prediction)]
69
+ confidence = np.max(prediction)
70
+ print(f"Emotion: {predicted_class} ({confidence:.2%})")
71
+ ```
72
+
73
+ ## Training Details
74
+
75
+ ### Architecture (V2 — Final)
76
+
77
+ ```
78
+ VGG16 (ImageNet, last 8 layers unfrozen)
79
+
80
+ GlobalAveragePooling2D
81
+
82
+ BatchNormalization
83
+
84
+ Dense(512, ReLU) → Dropout(0.5)
85
+
86
+ BatchNormalization
87
+
88
+ Dense(256, ReLU) → Dropout(0.3)
89
+
90
+ Dense(5, Softmax)
91
+ ```
92
+
93
+ ### Training Strategy
94
+
95
+ | Phase | Epochs | Learning Rate | Description |
96
+ |-------|--------|--------------|-------------|
97
+ | Phase 1 — Feature Extraction | 15 | 1e-4 | All VGG16 layers frozen |
98
+ | Phase 2 — Fine-Tuning | 25 | 1e-5 | Last 8 VGG16 layers unfrozen |
99
+
100
+ - **Optimizer:** Adam
101
+ - **Loss:** Categorical Crossentropy
102
+ - **Class Weights:** Balanced (computed with sklearn)
103
+ - **Callbacks:** EarlyStopping (patience=5), ReduceLROnPlateau, ModelCheckpoint
104
+
105
+ ### Data Augmentation
106
+ - Rotation: 30°
107
+ - Width/Height shift: 0.25
108
+ - Zoom: 0.25
109
+ - Horizontal flip
110
+ - Brightness: [0.8, 1.2]
111
+ - Shear: 0.15
112
+
113
+ ## Performance
114
+
115
+ ### Model Comparison
116
+
117
+ | Version | Input | Architecture | Accuracy |
118
+ |---------|-------|-------------|----------|
119
+ | V1 (Baseline) | 128×128 | Flatten → Dense(256) | 81.18% |
120
+ | **V2 (Final)** | **224×224** | **GAP → BN → Dense(512,256)** | **82.19%** |
121
+
122
+ ### Dataset
123
+
124
+ - **Training:** ~11,513 images
125
+ - **Validation:** ~2,880 images
126
+ - **Source:** [Kaggle — Cats Data Set](https://www.kaggle.com/datasets/bilalmahmoud/cats-data-set)
127
+
128
+ ## Files
129
+
130
+ - `best_vgg16_model.keras` — Trained VGG16 model (V1, 134MB)
131
+ - `README.md` — This model card
132
+
133
+ ## Intended Use
134
+
135
+ - **Primary use:** Classifying cat emotions from images
136
+ - **Users:** Researchers, students, pet tech developers
137
+ - **Out of scope:** Other animal species, real-time production systems
138
+
139
+ ## Limitations
140
+
141
+ - Trained on a specific cat emotion dataset — may not generalize to all cat breeds or lighting conditions
142
+ - 5 emotion categories only — does not cover all possible feline emotional states
143
+ - Best results with clear, well-lit frontal images of cats
144
+
145
+ ## Links
146
+
147
+ - 🐱 **GitHub:** [Bolaal/Cat-Emotion-Classification-with-CNN](https://github.com/Bolaal/Cat-Emotion-Classification-with-CNN)
148
+ - 📊 **Dataset:** [Kaggle — Cats Data Set](https://www.kaggle.com/datasets/bilalmahmoud/cats-data-set)
149
+
150
+ ## Citation
151
+
152
+ ```bibtex
153
+ @misc{cat-emotion-vgg16-2025,
154
+ author = {Belal Mahmoud Hussien},
155
+ title = {Cat Emotion Classification with VGG16},
156
+ year = {2025},
157
+ publisher = {Hugging Face},
158
+ url = {https://huggingface.co/Belall87/Cat-Emotion-Classification-with-CNN}
159
+ }
160
+ ```
161
+
162
+ ## Author
163
+
164
+ **Belal Mahmoud Hussien**
165
+ - 📧 Email: belalmahmoud8787@gmail.com
166
+ - 💼 LinkedIn: [belal-mahmoud-husien](https://linkedin.com/in/belal-mahmoud-husien)
167
+ - 🐱 GitHub: [@Bolaal](https://github.com/Bolaal)
168
+ - 🤗 Hugging Face: [@Belall87](https://huggingface.co/Belall87)
best_vgg16_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:718c5c99a46b14b58d1aaccb34627a25f962dcb3df7331b9235bd3e2f1793639
3
+ size 140773696
config.json ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_type": "vgg16-transfer-learning",
3
+ "architecture": "VGG16 + GlobalAveragePooling2D + BatchNorm + Dense(512,256)",
4
+ "framework": "tensorflow",
5
+ "library_name": "keras",
6
+ "input_shape": [224, 224, 3],
7
+ "num_classes": 5,
8
+ "class_labels": ["angry", "normal", "rested", "sad", "surprised"],
9
+ "preprocessing": {
10
+ "resize": [224, 224],
11
+ "rescale": 0.00392156862,
12
+ "color_mode": "rgb"
13
+ },
14
+ "training": {
15
+ "base_model": "VGG16",
16
+ "base_weights": "imagenet",
17
+ "unfrozen_layers": 8,
18
+ "optimizer": "adam",
19
+ "loss": "categorical_crossentropy",
20
+ "phase1_lr": 1e-4,
21
+ "phase2_lr": 1e-5,
22
+ "batch_size": 32,
23
+ "class_weights": true
24
+ },
25
+ "head": {
26
+ "layers": [
27
+ "GlobalAveragePooling2D",
28
+ "BatchNormalization",
29
+ "Dense(512, relu)",
30
+ "Dropout(0.5)",
31
+ "BatchNormalization",
32
+ "Dense(256, relu)",
33
+ "Dropout(0.3)",
34
+ "Dense(5, softmax)"
35
+ ]
36
+ },
37
+ "performance": {
38
+ "v1_accuracy": 0.8118,
39
+ "v2_accuracy": 0.8219,
40
+ "improvement": 0.0101
41
+ },
42
+ "dataset": {
43
+ "train_samples": 11513,
44
+ "val_samples": 2880,
45
+ "source": "https://www.kaggle.com/datasets/bilalmahmoud/cats-data-set"
46
+ }
47
+ }
results_v2.json ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_version": "V2",
3
+ "architecture": "VGG16 + GAP + BN + Dense(512,256)",
4
+ "input_size": "224x224x3",
5
+ "classes": [
6
+ "angry",
7
+ "normal",
8
+ "rested",
9
+ "sad",
10
+ "surprised"
11
+ ],
12
+ "num_classes": 5,
13
+ "training_samples": 11513,
14
+ "validation_samples": 2880,
15
+ "V1_accuracy": 0.8118,
16
+ "V2_accuracy": 0.8219,
17
+ "V2_loss": 0.3639,
18
+ "improvement": 0.0101,
19
+ "per_class_accuracy": {
20
+ "angry": 0.9677,
21
+ "normal": 0.6082,
22
+ "rested": 0.6611,
23
+ "sad": 0.8484,
24
+ "surprised": 0.9952
25
+ },
26
+ "training_phases": {
27
+ "phase1": {
28
+ "epochs": 15,
29
+ "lr": 0.0001,
30
+ "frozen": "all VGG16"
31
+ },
32
+ "phase2": {
33
+ "epochs": 25,
34
+ "lr": 1e-05,
35
+ "unfrozen": "last 8 layers"
36
+ }
37
+ }
38
+ }