Update README.md
Browse files
README.md
CHANGED
|
@@ -8,22 +8,85 @@ pipeline_tag: image-classification
|
|
| 8 |
library_name: keras
|
| 9 |
---
|
| 10 |
|
|
|
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
This project focused on maximizing the performance of the pre-trained ResNet-50 architecture on this particularly challenging, noisy, and imbalanced dataset.
|
| 15 |
-
Training Details
|
| 16 |
-
Architecture
|
| 17 |
|
| 18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
| 23 |
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
High Dropout Increased dropout to 0.5 to aggressively regularize the model and prevent the divergence seen in earlier training runs.
|
| 29 |
-
Optimizer Adam with a very low fine-tuning learning rate of 5e−6.
|
|
|
|
| 8 |
library_name: keras
|
| 9 |
---
|
| 10 |
|
| 11 |
+
That's a fantastic final step\! A clear **README** is essential for your Hugging Face page to explain the model's purpose, performance, and usage, especially since you optimized a challenging transfer learning task.
|
| 12 |
|
| 13 |
+
Here is a comprehensive README template based on your final results and methodology.
|
| 14 |
+
|
| 15 |
+
-----
|
| 16 |
+
|
| 17 |
+
# Model Card: ResNet-50 Fine-Tuned for FER-2013 Facial Expression Recognition
|
| 18 |
+
|
| 19 |
+
## Model Description
|
| 20 |
+
|
| 21 |
+
This model is a **ResNet-50** deep convolutional neural network fine-tuned for the **FER-2013 (Facial Expression Recognition 2013)** dataset. The dataset consists of low-resolution ($48 \times 48$) grayscale images of faces categorized into seven core emotional states.
|
| 22 |
|
| 23 |
This project focused on maximizing the performance of the pre-trained ResNet-50 architecture on this particularly challenging, noisy, and imbalanced dataset.
|
|
|
|
|
|
|
| 24 |
|
| 25 |
+
## Training Details
|
| 26 |
+
|
| 27 |
+
### Architecture
|
| 28 |
+
|
| 29 |
+
* **Base Model:** ResNet-50 (pre-trained on ImageNet).
|
| 30 |
+
* **Head:** Custom dense layers ($224$ units) with a high $\mathbf{0.5}$ dropout rate.
|
| 31 |
+
* **Transfer Learning Strategy:** **Deep Freezing**. The model base was frozen up to the `conv5` block, meaning only the final convolutional block (`conv5`) and the custom head were fine-tuned. This prevents early layers, which are optimized for high-resolution images, from being corrupted by the $48 \times 48$ input.
|
| 32 |
+
|
| 33 |
+
### Optimization & Regularization
|
| 34 |
+
|
| 35 |
+
| Technique | Rationale |
|
| 36 |
+
| :--- | :--- |
|
| 37 |
+
| **Class Weighting** | Applied inverse frequency weights to mitigate the severe class imbalance (e.g., Disgust is rare, Happy is abundant). |
|
| 38 |
+
| **Data Augmentation** | Used random flips, translations, rotations, and zooms to artificially expand the small dataset and combat overfitting. |
|
| 39 |
+
| **High Dropout** | Increased dropout to $\mathbf{0.5}$ to aggressively regularize the model and prevent the divergence seen in earlier training runs. |
|
| 40 |
+
| **Optimizer** | Adam with a very low fine-tuning learning rate of $5e-6$. |
|
| 41 |
+
|
| 42 |
+
## Evaluation Results
|
| 43 |
+
|
| 44 |
+
The final model achieved its **highest stability and best performance** after 50 epochs of fine-tuning, demonstrating strong generalization given the difficulty of the data.
|
| 45 |
+
|
| 46 |
+
### Overall Performance
|
| 47 |
+
|
| 48 |
+
| Metric | Result |
|
| 49 |
+
| :--- | :--- |
|
| 50 |
+
| **Test Accuracy** | **$45.70\%$** |
|
| 51 |
+
| **Test Loss** | $1.4929$ |
|
| 52 |
+
| **Training Accuracy (End)** | $63.25\%$ |
|
| 53 |
+
|
| 54 |
+
### Per-Class F1-Scores
|
| 55 |
+
|
| 56 |
+
The F1-Score highlights the model's difficulty with ambiguous negative emotions.
|
| 57 |
+
|
| 58 |
+
| Emotion | F1-Score | Support (Test Count) | Notes |
|
| 59 |
+
| :--- | :--- | :--- | :--- |
|
| 60 |
+
| **Neutral** | **0.6386** | 831 | Highest precision, well-distinguished class. |
|
| 61 |
+
| **Happy** | $0.6037$ | 1774 | Strongest recall, the most abundant class. |
|
| 62 |
+
| **Disgust** | $0.4659$ | 111 | Significantly improved performance on this rare class. |
|
| 63 |
+
| **Sad** | $0.3995$ | 1233 | Ambiguous. |
|
| 64 |
+
| **Surprise** | $0.3531$ | 1247 | Ambiguous. |
|
| 65 |
+
| **Fear** | $0.3374$ | 1024 | Ambiguous. |
|
| 66 |
+
| **Angry** | **0.3312** | 958 | Lowest F1-score, indicating high confusion. |
|
| 67 |
+
|
| 68 |
+
## 💡 Usage and Limitations
|
| 69 |
+
|
| 70 |
+
### Inputs
|
| 71 |
+
|
| 72 |
+
* **Image Format:** Grayscale ($48 \times 48$ pixels).
|
| 73 |
+
* **Normalization:** Pixel values must be scaled to $\mathbf{[0, 1]}$ (by dividing by $255.0$).
|
| 74 |
+
|
| 75 |
+
### Recommended Libraries
|
| 76 |
+
|
| 77 |
+
* `tensorflow` (for loading the model)
|
| 78 |
+
* `numpy` (for array manipulation)
|
| 79 |
+
|
| 80 |
+
### Limitations
|
| 81 |
+
|
| 82 |
+
1. **Low Accuracy:** The $45.70\%$ accuracy is limited by the **low resolution** ($48 \times 48$) and **noisy labels** of the FER-2013 dataset. It is not comparable to modern human performance ($\approx 65\%-68\%$ on FER-2013) or models trained on high-quality, high-resolution "in-the-wild" datasets like AffectNet.
|
| 83 |
+
2. **Overfitting:** Despite aggressive regularization, the model remains highly overfit (Training vs. Test gap), which is characteristic of this dataset.
|
| 84 |
|
| 85 |
+
### ❓ Troubleshooting the Error
|
| 86 |
|
| 87 |
+
If you encounter `ValueError` upon loading, ensure you are loading the model with the `.keras` extension:
|
| 88 |
|
| 89 |
+
```python
|
| 90 |
+
import tensorflow as tf
|
| 91 |
+
loaded_model = tf.keras.models.load_model("./best_fer_resnet_local/best_model.keras")
|
| 92 |
+
```
|
|
|
|
|
|