Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,246 +1,488 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
-
|
| 12 |
-
|
| 13 |
-
-
|
| 14 |
-
|
| 15 |
-
- age-
|
| 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 |
This model performs age group classification on facial images, predicting one of 5 age categories instead of exact ages. It was specifically designed to solve the common bias problem where older adults (70+) are incorrectly predicted as young adults (30s).
|
| 45 |
|
|
|
|
|
|
|
| 46 |
### Key Features
|
| 47 |
-
|
|
|
|
|
|
|
| 48 |
- **Practical Categories**: Returns useful age ranges rather than potentially inaccurate exact ages
|
| 49 |
-
|
|
|
|
|
|
|
| 50 |
- **Stable Architecture**: ResNet50V2 backbone with proven reliability
|
| 51 |
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
### Architecture
|
| 55 |
- **Base Model**: ResNet50V2 (pre-trained on ImageNet)
|
| 56 |
-
- **Task**: Multi-class classification (5 categories)
|
| 57 |
-
- **Input**: RGB facial images (224x224)
|
| 58 |
-
- **Output**: Age group probabilities
|
| 59 |
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
- **Group 2**: Middle Age (41-60 years)
|
| 64 |
-
|
| 65 |
-
- **Group
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
### Performance
|
| 68 |
-
- **Validation Accuracy**: 75.5%
|
| 69 |
-
- **Training Accuracy**: 79.1%
|
| 70 |
-
- **Generalization Gap**: 3.6% (healthy)
|
| 71 |
-
- **Training Epochs**: 13 (with early stopping)
|
| 72 |
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
Traditional age regression models often exhibit severe bias:
|
| 77 |
-
- 70-year-old faces predicted as 30-year-olds
|
| 78 |
-
- Inconsistent predictions across age ranges
|
| 79 |
-
- Poor handling of seniors and elderly individuals
|
| 80 |
|
| 81 |
-
|
| 82 |
-
- **Age Group Classification**: More robust than exact age regression
|
| 83 |
-
- **Balanced Training**: Proper representation across all age groups
|
| 84 |
-
- **Transfer Learning**: Leverages ResNet50V2 features optimized for facial analysis
|
| 85 |
|
| 86 |
-
|
| 87 |
|
| 88 |
-
```python
|
| 89 |
-
from transformers import pipeline
|
| 90 |
-
import numpy as np
|
| 91 |
from PIL import Image
|
| 92 |
|
| 93 |
-
|
| 94 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
model="your-username/age-group-classifier")
|
| 96 |
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
| 98 |
image = Image.open("face_image.jpg")
|
| 99 |
-
results = classifier(image)
|
| 100 |
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 104 |
|
| 105 |
-
### Example Output
|
| 106 |
-
```python
|
| 107 |
[
|
| 108 |
-
|
| 109 |
-
{'label': '
|
| 110 |
-
|
| 111 |
-
{'label': '
|
| 112 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 113 |
]
|
| 114 |
-
```
|
| 115 |
|
| 116 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 117 |
|
| 118 |
-
### Dataset
|
| 119 |
-
- **Source**: UTKFace dataset
|
| 120 |
-
- **Size**: 23,687 facial images
|
| 121 |
-
- **Split**: 80% training, 20% validation
|
| 122 |
-
- **Preprocessing**: Stratified sampling to ensure balanced age group representation
|
| 123 |
|
| 124 |
-
### Training Process
|
|
|
|
| 125 |
1. **Phase 1**: Frozen ResNet50V2 base, train classification head only
|
| 126 |
-
2. **Phase 2**: Fine-tune top layers with reduced learning rate
|
| 127 |
-
3. **Early Stopping**: Automatic termination when validation plateaus
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
- **Batch Size**: 32
|
| 134 |
-
- **Callbacks**: Early stopping, model checkpointing, learning rate reduction
|
| 135 |
|
| 136 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
|
| 138 |
-
### Test Cases
|
| 139 |
-
| Input Age | Predicted Group | Correct? |
|
| 140 |
-
|-----------|----------------|----------|
|
| 141 |
-
| 25 years | Young Adult (21-40) | β
|
|
| 142 |
| 35 years | Young Adult (21-40) | β
|
|
| 143 |
-
| 45 years | Middle Age (41-60) | β
|
|
| 144 |
-
| 55 years | Middle Age (41-60) | β
|
|
| 145 |
-
| 65 years | Senior (61-80) | β
|
|
| 146 |
-
| 75 years | Senior (61-80) | β
**Fixed!** |
|
| 147 |
-
| 85 years | Elderly (81-100) | β
|
|
| 148 |
|
| 149 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 150 |
|
| 151 |
-
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 155 |
|
| 156 |
## Ethical Considerations
|
| 157 |
|
|
|
|
|
|
|
| 158 |
- **Bias Mitigation**: Specifically designed to reduce age prediction bias
|
| 159 |
-
- **Fairness**: Balanced training across age groups
|
| 160 |
-
- **Transparency**: Clear category boundaries rather than black-box exact ages
|
| 161 |
-
- **Privacy**: Consider consent when processing facial images
|
| 162 |
|
| 163 |
-
|
| 164 |
|
| 165 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
|
| 167 |
-
```bibtex
|
| 168 |
-
@misc{age-group-classifier-2025,
|
| 169 |
-
title={Age Group Classification Model: Bias-Free Facial Age Estimation},
|
| 170 |
author={SammyHarris},
|
| 171 |
-
|
|
|
|
|
|
|
| 172 |
publisher={Hugging Face},
|
| 173 |
-
|
|
|
|
|
|
|
| 174 |
}
|
| 175 |
-
```
|
| 176 |
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
-
This model is released under the MIT License.
|
| 180 |
|
| 181 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 182 |
|
| 183 |
-
For questions or issues, please open a discussion on the model repository.
|
| 184 |
-
datasets:
|
| 185 |
-
- UTKFace
|
| 186 |
-
metrics:
|
| 187 |
-
- mae
|
| 188 |
-
- mean_absolute_error
|
| 189 |
model-index:
|
| 190 |
-
|
|
|
|
|
|
|
| 191 |
results:
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 195 |
dataset:
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
name: UTKFace Dataset
|
| 198 |
-
|
| 199 |
-
|
|
|
|
|
|
|
|
|
|
| 200 |
value: 19.96
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
pipeline_tag: image-regression
|
| 207 |
-
|
|
|
|
|
|
|
| 208 |
---
|
| 209 |
|
| 210 |
-
|
| 211 |
|
| 212 |
-
|
| 213 |
|
| 214 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
```python
|
| 217 |
-
import tensorflow as tf
|
| 218 |
-
import numpy as np
|
| 219 |
-
from PIL import Image
|
| 220 |
from tensorflow.keras.applications.resnet50 import preprocess_input
|
| 221 |
|
|
|
|
|
|
|
| 222 |
# Load the model
|
| 223 |
-
model = tf.keras.models.load_model('best_model.h5')
|
| 224 |
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
|
| 231 |
-
# Predict age
|
| 232 |
-
predicted_age = model.predict(arr)[0][0]
|
| 233 |
-
print(f"Predicted age: {predicted_age:.1f} years")
|
| 234 |
```
|
| 235 |
|
|
|
|
|
|
|
| 236 |
## π― Model Overview
|
| 237 |
|
| 238 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
|
| 240 |
## π Model Performance
|
| 241 |
|
|
|
|
|
|
|
| 242 |
| Metric | Value | Description |
|
| 243 |
-
|
|
|
|
| 244 |
| **Mean Absolute Error (MAE)** | **9.77 years** | Average prediction error (51% improvement) |
|
| 245 |
| **Architecture** | ResNet50 | Pre-trained on ImageNet |
|
| 246 |
| **Input Resolution** | 256Γ256Γ3 | RGB facial images |
|
|
|
|
| 1 |
+
------
|
| 2 |
+
|
| 3 |
+
language: enlanguage: en
|
| 4 |
+
|
| 5 |
+
license: mitlicense: mit
|
| 6 |
+
|
| 7 |
+
library_name: tensorflowlibrary_name: tensorflow
|
| 8 |
+
|
| 9 |
+
tags:tags:
|
| 10 |
+
|
| 11 |
+
- computer-vision- computer-vision
|
| 12 |
+
|
| 13 |
+
- image-classification- image-classification
|
| 14 |
+
|
| 15 |
+
- age-estimation- age-estimation
|
| 16 |
+
|
| 17 |
+
- face-analysis- face-analysis
|
| 18 |
+
|
| 19 |
+
- resnet50v2- resnet50v2
|
| 20 |
+
|
| 21 |
+
- tensorflow- tensorflow
|
| 22 |
+
|
| 23 |
+
- keras- keras
|
| 24 |
+
|
| 25 |
+
- utkface- utkface
|
| 26 |
+
|
| 27 |
+
- bias-correction- bias-correction
|
| 28 |
+
|
| 29 |
+
- age-groups- age-groups
|
| 30 |
+
|
| 31 |
+
- classification- classification
|
| 32 |
+
|
| 33 |
+
- deep-learning- deep-learning
|
| 34 |
+
|
| 35 |
+
- facial-analysis- facial-analysis
|
| 36 |
+
|
| 37 |
+
- demographic-estimation- demographic-estimation
|
| 38 |
+
|
| 39 |
+
- transfer-learning- transfer-learning
|
| 40 |
+
|
| 41 |
+
datasets:datasets:
|
| 42 |
+
|
| 43 |
+
- UTKFace- UTKFace
|
| 44 |
+
|
| 45 |
+
metrics:metrics:
|
| 46 |
+
|
| 47 |
+
- accuracy- accuracy
|
| 48 |
+
|
| 49 |
+
model-index:model-index:
|
| 50 |
+
|
| 51 |
+
- name: age-group-classifier- name: age-group-classifier
|
| 52 |
+
|
| 53 |
+
results: results:
|
| 54 |
|
| 55 |
+
- task: - task:
|
| 56 |
|
| 57 |
+
type: image-classification type: image-classification
|
| 58 |
+
|
| 59 |
+
name: Age Group Classification name: Age Group Classification
|
| 60 |
+
|
| 61 |
+
dataset: dataset:
|
| 62 |
+
|
| 63 |
+
type: UTKFace type: UTKFace
|
| 64 |
+
|
| 65 |
+
name: UTKFace name: UTKFace
|
| 66 |
+
|
| 67 |
+
metrics: metrics:
|
| 68 |
+
|
| 69 |
+
- type: accuracy - type: accuracy
|
| 70 |
+
|
| 71 |
+
value: 0.755 value: 0.755
|
| 72 |
+
|
| 73 |
+
name: Validation Accuracy name: Validation Accuracy
|
| 74 |
+
|
| 75 |
+
pipeline_tag: image-classification---
|
| 76 |
+
|
| 77 |
+
base_model: tensorflow/resnet50v2
|
| 78 |
+
|
| 79 |
+
widget:# Age Group Classification Model
|
| 80 |
+
|
| 81 |
+
- src: https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/image-classification-input.jpg
|
| 82 |
+
|
| 83 |
+
example_title: Sample Face Image## Model Description
|
| 84 |
+
|
| 85 |
+
---
|
| 86 |
|
| 87 |
This model performs age group classification on facial images, predicting one of 5 age categories instead of exact ages. It was specifically designed to solve the common bias problem where older adults (70+) are incorrectly predicted as young adults (30s).
|
| 88 |
|
| 89 |
+
# Age Group Classification Model π―π₯
|
| 90 |
+
|
| 91 |
### Key Features
|
| 92 |
+
|
| 93 |
+
A breakthrough age group classification model that **solves the age prediction bias problem** where 70-year-olds are incorrectly predicted as 30-year-olds. Instead of exact age regression, this model classifies faces into 5 practical age groups with **75.5% validation accuracy**.- **Bias-Free Predictions**: Correctly classifies seniors instead of mispredicting them as young adults
|
| 94 |
+
|
| 95 |
- **Practical Categories**: Returns useful age ranges rather than potentially inaccurate exact ages
|
| 96 |
+
|
| 97 |
+
## π Quick Start- **High Performance**: 75.5% validation accuracy on 5-class classification
|
| 98 |
+
|
| 99 |
- **Stable Architecture**: ResNet50V2 backbone with proven reliability
|
| 100 |
|
| 101 |
+
### Using Hugging Face Transformers
|
| 102 |
+
|
| 103 |
+
```python## Model Details
|
| 104 |
+
|
| 105 |
+
from transformers import pipeline
|
| 106 |
+
|
| 107 |
+
from PIL import Image### Architecture
|
| 108 |
|
|
|
|
| 109 |
- **Base Model**: ResNet50V2 (pre-trained on ImageNet)
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
+
# Load the classifier- **Task**: Multi-class classification (5 categories)
|
| 112 |
+
|
| 113 |
+
classifier = pipeline("image-classification", - **Input**: RGB facial images (224x224)
|
| 114 |
+
|
| 115 |
+
model="Sharris/age-group-classifier")- **Output**: Age group probabilities
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
# Classify an image### Age Groups
|
| 120 |
+
|
| 121 |
+
image = Image.open("face_image.jpg")- **Group 0**: Youth (0-20 years)
|
| 122 |
+
|
| 123 |
+
results = classifier(image)- **Group 1**: Young Adult (21-40 years)
|
| 124 |
+
|
| 125 |
- **Group 2**: Middle Age (41-60 years)
|
| 126 |
+
|
| 127 |
+
print(f"Predicted age group: {results[0]['label']}")- **Group 3**: Senior (61-80 years)
|
| 128 |
+
|
| 129 |
+
print(f"Confidence: {results[0]['score']:.2%}")- **Group 4**: Elderly (81-100 years)
|
| 130 |
+
|
| 131 |
+
```
|
| 132 |
|
| 133 |
### Performance
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
+
### Using TensorFlow Directly- **Validation Accuracy**: 75.5%
|
| 136 |
|
| 137 |
+
```python- **Training Accuracy**: 79.1%
|
|
|
|
|
|
|
|
|
|
|
|
|
| 138 |
|
| 139 |
+
import tensorflow as tf- **Generalization Gap**: 3.6% (healthy)
|
|
|
|
|
|
|
|
|
|
| 140 |
|
| 141 |
+
import numpy as np- **Training Epochs**: 13 (with early stopping)
|
| 142 |
|
|
|
|
|
|
|
|
|
|
| 143 |
from PIL import Image
|
| 144 |
|
| 145 |
+
from huggingface_hub import hf_hub_download## Problem Solved
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
# Download and load model### Original Issue
|
| 150 |
+
|
| 151 |
+
model_path = hf_hub_download(Traditional age regression models often exhibit severe bias:
|
| 152 |
+
|
| 153 |
+
repo_id="Sharris/age-group-classifier",- 70-year-old faces predicted as 30-year-olds
|
| 154 |
+
|
| 155 |
+
filename="resnet50v2_age_classifier_best.h5"- Inconsistent predictions across age ranges
|
| 156 |
+
|
| 157 |
+
)- Poor handling of seniors and elderly individuals
|
| 158 |
+
|
| 159 |
+
model = tf.keras.models.load_model(model_path)
|
| 160 |
+
|
| 161 |
+
### Our Solution
|
| 162 |
+
|
| 163 |
+
# Preprocess image- **Age Group Classification**: More robust than exact age regression
|
| 164 |
+
|
| 165 |
+
image = Image.open("face_image.jpg").convert("RGB")- **Balanced Training**: Proper representation across all age groups
|
| 166 |
+
|
| 167 |
+
image = image.resize((224, 224))- **Transfer Learning**: Leverages ResNet50V2 features optimized for facial analysis
|
| 168 |
+
|
| 169 |
+
image_array = np.array(image, dtype=np.float32) / 255.0
|
| 170 |
+
|
| 171 |
+
image_array = np.expand_dims(image_array, axis=0)## Usage
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
# Predict```python
|
| 176 |
+
|
| 177 |
+
predictions = model.predict(image_array)[0]from transformers import pipeline
|
| 178 |
+
|
| 179 |
+
age_groups = ["Youth (0-20)", "Young Adult (21-40)", "Middle Age (41-60)", import numpy as np
|
| 180 |
+
|
| 181 |
+
"Senior (61-80)", "Elderly (81-100)"]from PIL import Image
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
predicted_group = age_groups[np.argmax(predictions)]# Load the model
|
| 186 |
+
|
| 187 |
+
confidence = predictions[np.argmax(predictions)]classifier = pipeline("image-classification",
|
| 188 |
+
|
| 189 |
model="your-username/age-group-classifier")
|
| 190 |
|
| 191 |
+
print(f"Predicted: {predicted_group} ({confidence:.1%} confidence)")
|
| 192 |
+
|
| 193 |
+
```# Classify an image
|
| 194 |
+
|
| 195 |
image = Image.open("face_image.jpg")
|
|
|
|
| 196 |
|
| 197 |
+
## π― Model Overviewresults = classifier(image)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
### The Problem We Solvedprint(f"Predicted age group: {results[0]['label']}")
|
| 202 |
+
|
| 203 |
+
Traditional age regression models suffer from **severe age bias**:print(f"Confidence: {results[0]['score']:.2%}")
|
| 204 |
+
|
| 205 |
+
- 70-year-old faces β Predicted as 30-year-olds β```
|
| 206 |
+
|
| 207 |
+
- Inconsistent predictions across age ranges
|
| 208 |
+
|
| 209 |
+
- Poor handling of seniors and elderly individuals### Example Output
|
| 210 |
+
|
| 211 |
+
- Exact age predictions often inaccurate and not practical```python
|
| 212 |
|
|
|
|
|
|
|
| 213 |
[
|
| 214 |
+
|
| 215 |
+
### Our Solution: Age Group Classification {'label': 'Senior (61-80)', 'score': 0.87},
|
| 216 |
+
|
| 217 |
+
- **5 Age Groups**: More robust than exact age regression β
{'label': 'Middle Age (41-60)', 'score': 0.09},
|
| 218 |
+
|
| 219 |
+
- **Bias-Free**: 75-year-olds correctly classified as "Senior (61-80)" β
{'label': 'Elderly (81-100)', 'score': 0.03},
|
| 220 |
+
|
| 221 |
+
- **Practical**: Returns useful age ranges for real applications β
{'label': 'Young Adult (21-40)', 'score': 0.01},
|
| 222 |
+
|
| 223 |
+
- **Reliable**: 75.5% validation accuracy with stable predictions β
{'label': 'Youth (0-20)', 'score': 0.00}
|
| 224 |
+
|
| 225 |
]
|
|
|
|
| 226 |
|
| 227 |
+
## π Model Performance```
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
| Metric | Value | Description |## Training Details
|
| 232 |
+
|
| 233 |
+
|--------|-------|-------------|
|
| 234 |
+
|
| 235 |
+
| **Validation Accuracy** | **75.5%** | 5-class classification accuracy |### Dataset
|
| 236 |
+
|
| 237 |
+
| **Training Accuracy** | **79.1%** | Training set performance |- **Source**: UTKFace dataset
|
| 238 |
+
|
| 239 |
+
| **Generalization Gap** | **3.6%** | Healthy gap - no overfitting |- **Size**: 23,687 facial images
|
| 240 |
+
|
| 241 |
+
| **Training Epochs** | **13** | Early stopping applied |- **Split**: 80% training, 20% validation
|
| 242 |
+
|
| 243 |
+
| **Parameters** | **23.8M** | ResNet50V2 backbone |- **Preprocessing**: Stratified sampling to ensure balanced age group representation
|
| 244 |
+
|
| 245 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
+
## π·οΈ Age Groups### Training Process
|
| 248 |
+
|
| 249 |
1. **Phase 1**: Frozen ResNet50V2 base, train classification head only
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
| Group ID | Age Range | Label | Description |2. **Phase 2**: Fine-tune top layers with reduced learning rate
|
| 252 |
+
|
| 253 |
+
|----------|-----------|-------|-------------|3. **Early Stopping**: Automatic termination when validation plateaus
|
| 254 |
+
|
| 255 |
+
| 0 | 0-20 years | Youth | Children, teenagers |
|
| 256 |
+
|
| 257 |
+
| 1 | 21-40 years | Young Adult | College age to early career |### Training Configuration
|
| 258 |
+
|
| 259 |
+
| 2 | 41-60 years | Middle Age | Established adults |- **Optimizer**: Adam
|
| 260 |
+
|
| 261 |
+
| 3 | 61-80 years | Senior | Retirement age |- **Learning Rate**: 0.001 β 0.0001 (Phase 2)
|
| 262 |
+
|
| 263 |
+
| 4 | 81-100 years | Elderly | Advanced age |- **Loss Function**: Categorical Crossentropy
|
| 264 |
+
|
| 265 |
- **Batch Size**: 32
|
|
|
|
| 266 |
|
| 267 |
+
## π§ Technical Details- **Callbacks**: Early stopping, model checkpointing, learning rate reduction
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
### Architecture## Bias Validation
|
| 272 |
+
|
| 273 |
+
- **Base Model**: ResNet50V2 (pre-trained on ImageNet)
|
| 274 |
+
|
| 275 |
+
- **Task**: Multi-class classification (5 categories)### Test Cases
|
| 276 |
+
|
| 277 |
+
- **Input**: RGB facial images (224Γ224)| Input Age | Predicted Group | Correct? |
|
| 278 |
+
|
| 279 |
+
- **Output**: Age group probabilities|-----------|----------------|----------|
|
| 280 |
+
|
| 281 |
+
- **Transfer Learning**: 2-phase training (frozen base β fine-tuning)| 25 years | Young Adult (21-40) | β
|
|
| 282 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
| 35 years | Young Adult (21-40) | β
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 284 |
|
| 285 |
+
### Training Configuration| 45 years | Middle Age (41-60) | β
|
|
| 286 |
+
|
| 287 |
+
- **Framework**: TensorFlow/Keras| 55 years | Middle Age (41-60) | β
|
|
| 288 |
+
|
| 289 |
+
- **Optimizer**: Adam (lr: 0.001 β 0.0001)| 65 years | Senior (61-80) | β
|
|
| 290 |
+
|
| 291 |
+
- **Loss Function**: Categorical Crossentropy| 75 years | Senior (61-80) | β
**Fixed!** |
|
| 292 |
+
|
| 293 |
+
- **Batch Size**: 32| 85 years | Elderly (81-100) | β
|
|
| 294 |
+
|
| 295 |
+
- **Data Split**: 80% train, 20% validation (stratified)
|
| 296 |
|
| 297 |
+
- **Early Stopping**: Patience=3 epochs## Limitations
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
### Dataset- Performance may vary with extreme lighting conditions
|
| 302 |
+
|
| 303 |
+
- **Source**: UTKFace dataset- Border cases between age groups (e.g., 40 vs 41) inherently challenging
|
| 304 |
+
|
| 305 |
+
- **Size**: 23,687 facial images- Optimized for front-facing facial images
|
| 306 |
+
|
| 307 |
+
- **Age Distribution**: Balanced across age groups- Cultural and demographic variations may affect accuracy
|
| 308 |
+
|
| 309 |
+
- **Preprocessing**: Stratified sampling for equal representation
|
| 310 |
|
| 311 |
## Ethical Considerations
|
| 312 |
|
| 313 |
+
## π― Bias Validation
|
| 314 |
+
|
| 315 |
- **Bias Mitigation**: Specifically designed to reduce age prediction bias
|
|
|
|
|
|
|
|
|
|
| 316 |
|
| 317 |
+
### Test Results- **Fairness**: Balanced training across age groups
|
| 318 |
|
| 319 |
+
| Input Age | Predicted Group | Status |- **Transparency**: Clear category boundaries rather than black-box exact ages
|
| 320 |
+
|
| 321 |
+
|-----------|----------------|---------|- **Privacy**: Consider consent when processing facial images
|
| 322 |
+
|
| 323 |
+
| 15 years | Youth (0-20) | β
Correct |
|
| 324 |
+
|
| 325 |
+
| 25 years | Young Adult (21-40) | β
Correct |## Citation
|
| 326 |
+
|
| 327 |
+
| 35 years | Young Adult (21-40) | β
Correct |
|
| 328 |
+
|
| 329 |
+
| 45 years | Middle Age (41-60) | β
Correct |If you use this model, please cite:
|
| 330 |
+
|
| 331 |
+
| 55 years | Middle Age (41-60) | β
Correct |
|
| 332 |
+
|
| 333 |
+
| 65 years | Senior (61-80) | β
Correct |```bibtex
|
| 334 |
+
|
| 335 |
+
| **75 years** | **Senior (61-80)** | β
**BIAS FIXED!** |@misc{age-group-classifier-2025,
|
| 336 |
+
|
| 337 |
+
| 85 years | Elderly (81-100) | β
Correct | title={Age Group Classification Model: Bias-Free Facial Age Estimation},
|
| 338 |
|
|
|
|
|
|
|
|
|
|
| 339 |
author={SammyHarris},
|
| 340 |
+
|
| 341 |
+
**Key Achievement**: 70+ year olds are now correctly classified as Senior/Elderly instead of being mispredicted as young adults! year={2025},
|
| 342 |
+
|
| 343 |
publisher={Hugging Face},
|
| 344 |
+
|
| 345 |
+
## π‘ Use Cases howpublished={\url{https://huggingface.co/your-username/age-group-classifier}}
|
| 346 |
+
|
| 347 |
}
|
|
|
|
| 348 |
|
| 349 |
+
### β
Recommended Applications```
|
| 350 |
+
|
| 351 |
+
- **Content Personalization**: Age-appropriate content delivery
|
| 352 |
+
|
| 353 |
+
- **Market Research**: Demographic analysis of audiences## License
|
| 354 |
+
|
| 355 |
+
- **Photo Organization**: Automatic family album categorization
|
| 356 |
+
|
| 357 |
+
- **Social Media**: Age group insights and targetingThis model is released under the MIT License.
|
| 358 |
+
|
| 359 |
+
- **Research**: Age-related studies and analysis
|
| 360 |
+
|
| 361 |
+
- **Accessibility**: Age-aware interface design## Contact
|
| 362 |
+
|
| 363 |
|
|
|
|
| 364 |
|
| 365 |
+
### β LimitationsFor questions or issues, please open a discussion on the model repository.
|
| 366 |
+
|
| 367 |
+
- **Border Cases**: Ages near group boundaries (e.g., 40 vs 41) can be challengingdatasets:
|
| 368 |
+
|
| 369 |
+
- **Image Quality**: Performance varies with lighting and image quality- UTKFace
|
| 370 |
+
|
| 371 |
+
- **Pose Sensitivity**: Works best with frontal face imagesmetrics:
|
| 372 |
+
|
| 373 |
+
- **Demographic Bias**: May vary across different ethnic groups- mae
|
| 374 |
+
|
| 375 |
+
- **Not for Legal Use**: Estimates only, not for official identification- mean_absolute_error
|
| 376 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
model-index:
|
| 378 |
+
|
| 379 |
+
## π¬ Model Files- name: age-detection-resnet50-model
|
| 380 |
+
|
| 381 |
results:
|
| 382 |
+
|
| 383 |
+
- **`resnet50v2_age_classifier_best.h5`**: Complete trained model (98MB) - task:
|
| 384 |
+
|
| 385 |
+
- **`config.json`**: Model configuration and label mappings type: image-regression
|
| 386 |
+
|
| 387 |
+
- **`README.md`**: This comprehensive model card name: Age Estimation from Facial Images
|
| 388 |
+
|
| 389 |
dataset:
|
| 390 |
+
|
| 391 |
+
## π€ Live Demo type: UTKFace
|
| 392 |
+
|
| 393 |
name: UTKFace Dataset
|
| 394 |
+
|
| 395 |
+
Try the model instantly with our Gradio demo: metrics:
|
| 396 |
+
|
| 397 |
+
**[Age Group Classifier Demo](https://huggingface.co/spaces/Sharris/age-group-classifier-demo)** - type: mae
|
| 398 |
+
|
| 399 |
value: 19.96
|
| 400 |
+
|
| 401 |
+
Features: name: Mean Absolute Error
|
| 402 |
+
|
| 403 |
+
- Upload facial images verified: true
|
| 404 |
+
|
| 405 |
+
- Get age group predictionswidget:
|
| 406 |
+
|
| 407 |
+
- View confidence scores for all groups- src: https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/transformers/tasks/image-classification-input.jpg
|
| 408 |
+
|
| 409 |
+
- Compare predictions across different ages example_title: Sample Face Image
|
| 410 |
+
|
| 411 |
pipeline_tag: image-regression
|
| 412 |
+
|
| 413 |
+
## π License & Ethicsbase_model: microsoft/resnet-50
|
| 414 |
+
|
| 415 |
---
|
| 416 |
|
| 417 |
+
### License
|
| 418 |
|
| 419 |
+
- **Model**: MIT License# Age Detection with ResNet50 π―π¨βπ©βπ§βπ¦
|
| 420 |
|
| 421 |
+
- **Code**: MIT License
|
| 422 |
+
|
| 423 |
+
- **Dataset**: UTKFace (academic/research use)A state-of-the-art age estimation model using ResNet50 backbone with advanced bias correction techniques. This model predicts human age from facial images with high accuracy (**9.77 years MAE** - 51% improvement over baseline) and addresses systematic age prediction biases through improved square root sample weighting.
|
| 424 |
+
|
| 425 |
+
|
| 426 |
+
|
| 427 |
+
### Ethical Considerations## π Quick Start
|
| 428 |
+
|
| 429 |
+
- **Bias Mitigation**: Specifically designed to reduce age prediction bias
|
| 430 |
+
|
| 431 |
+
- **Fairness**: Balanced training across all age groups```python
|
| 432 |
+
|
| 433 |
+
- **Transparency**: Clear category boundaries and confidence scoresimport tensorflow as tf
|
| 434 |
+
|
| 435 |
+
- **Privacy**: Consider consent when processing facial imagesimport numpy as np
|
| 436 |
+
|
| 437 |
+
- **Responsible Use**: Avoid high-stakes decisions without human oversightfrom PIL import Image
|
| 438 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
from tensorflow.keras.applications.resnet50 import preprocess_input
|
| 440 |
|
| 441 |
+
## π Citation
|
| 442 |
+
|
| 443 |
# Load the model
|
|
|
|
| 444 |
|
| 445 |
+
If you use this model in your research, please cite:model = tf.keras.models.load_model('best_model.h5')
|
| 446 |
+
|
| 447 |
+
|
| 448 |
+
|
| 449 |
+
```bibtex# Preprocess image
|
| 450 |
+
|
| 451 |
+
@misc{age-group-classifier-2025,img = Image.open('face_image.jpg').convert('RGB').resize((256, 256))
|
| 452 |
+
|
| 453 |
+
title={Age Group Classification: Solving Age Prediction Bias in Facial Analysis},arr = np.array(img, dtype=np.float32)
|
| 454 |
+
|
| 455 |
+
author={Sharris},arr = preprocess_input(arr)
|
| 456 |
+
|
| 457 |
+
year={2025},arr = np.expand_dims(arr, 0)
|
| 458 |
+
|
| 459 |
+
publisher={Hugging Face},
|
| 460 |
+
|
| 461 |
+
url={https://huggingface.co/Sharris/age-group-classifier}# Predict age
|
| 462 |
+
|
| 463 |
+
}predicted_age = model.predict(arr)[0][0]
|
| 464 |
+
|
| 465 |
+
```print(f"Predicted age: {predicted_age:.1f} years")
|
| 466 |
|
|
|
|
|
|
|
|
|
|
| 467 |
```
|
| 468 |
|
| 469 |
+
## π€ Contact & Support
|
| 470 |
+
|
| 471 |
## π― Model Overview
|
| 472 |
|
| 473 |
+
- **Model Repository**: [Sharris/age-group-classifier](https://huggingface.co/Sharris/age-group-classifier)
|
| 474 |
+
|
| 475 |
+
- **Demo Space**: [age-group-classifier-demo](https://huggingface.co/spaces/Sharris/age-group-classifier-demo)This model addresses the critical challenge of age estimation bias commonly found in facial analysis systems. Through sophisticated bias correction techniques and robust training methodologies, it achieves superior performance across diverse age groups.
|
| 476 |
+
|
| 477 |
+
- **Issues**: Use the discussions tab for questions and feedback
|
| 478 |
|
| 479 |
## π Model Performance
|
| 480 |
|
| 481 |
+
---
|
| 482 |
+
|
| 483 |
| Metric | Value | Description |
|
| 484 |
+
|
| 485 |
+
**π Ready to use bias-free age group classification?** Try our [live demo](https://huggingface.co/spaces/Sharris/age-group-classifier-demo) or integrate the model into your applications today!|--------|-------|-------------|
|
| 486 |
| **Mean Absolute Error (MAE)** | **9.77 years** | Average prediction error (51% improvement) |
|
| 487 |
| **Architecture** | ResNet50 | Pre-trained on ImageNet |
|
| 488 |
| **Input Resolution** | 256Γ256Γ3 | RGB facial images |
|