Update README.md
Browse files
README.md
CHANGED
|
@@ -11,6 +11,16 @@ tags:
|
|
| 11 |
- Age-Range-Estimator
|
| 12 |
---
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
```
|
| 15 |
Classification Report:
|
| 16 |
precision recall f1-score support
|
|
@@ -26,4 +36,91 @@ Middle Age 45-64 0.9458 0.9450 0.9454 3785
|
|
| 26 |
weighted avg 0.9557 0.9559 0.9556 19016
|
| 27 |
```
|
| 28 |
|
| 29 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
- Age-Range-Estimator
|
| 12 |
---
|
| 13 |
|
| 14 |
+

|
| 15 |
+
|
| 16 |
+
# **MetaCLIP-2-Age-Range-Estimator**
|
| 17 |
+
|
| 18 |
+
> **MetaCLIP-2-Age-Range-Estimator** is an image classification vision-language encoder model fine-tuned from **[facebook/metaclip-2-worldwide-s16](https://huggingface.co/facebook/metaclip-2-worldwide-s16)** for a single-label classification task.
|
| 19 |
+
> It is designed to predict the age range of a person from an image using the **MetaClip2ForImageClassification** architecture.
|
| 20 |
+
|
| 21 |
+
>[!note]
|
| 22 |
+
MetaCLIP 2: A Worldwide Scaling Recipe : https://huggingface.co/papers/2507.22062
|
| 23 |
+
|
| 24 |
```
|
| 25 |
Classification Report:
|
| 26 |
precision recall f1-score support
|
|
|
|
| 36 |
weighted avg 0.9557 0.9559 0.9556 19016
|
| 37 |
```
|
| 38 |
|
| 39 |
+

|
| 40 |
+
|
| 41 |
+
---
|
| 42 |
+
|
| 43 |
+
The model categorizes images into five age ranges:
|
| 44 |
+
|
| 45 |
+
* **Class 0:** "Child 0-12"
|
| 46 |
+
* **Class 1:** "Teenager 13-20"
|
| 47 |
+
* **Class 2:** "Adult 21-44"
|
| 48 |
+
* **Class 3:** "Middle Age 45-64"
|
| 49 |
+
* **Class 4:** "Aged 65+"
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
# **Run with Transformers**
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
!pip install -q transformers torch pillow gradio
|
| 57 |
+
```
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
import gradio as gr
|
| 61 |
+
import torch
|
| 62 |
+
from transformers import AutoImageProcessor, AutoModelForImageClassification
|
| 63 |
+
from PIL import Image
|
| 64 |
+
|
| 65 |
+
# Model name from Hugging Face Hub
|
| 66 |
+
model_name = "prithivMLmods/MetaCLIP-2-Age-Range-Estimator"
|
| 67 |
+
|
| 68 |
+
# Load processor and model
|
| 69 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 70 |
+
model = AutoModelForImageClassification.from_pretrained(model_name)
|
| 71 |
+
model.eval()
|
| 72 |
+
|
| 73 |
+
# Define labels
|
| 74 |
+
LABELS = {
|
| 75 |
+
0: "Child (0–12)",
|
| 76 |
+
1: "Teenager (13–20)",
|
| 77 |
+
2: "Adult (21–44)",
|
| 78 |
+
3: "Middle Age (45–64)",
|
| 79 |
+
4: "Aged (65+)"
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
def age_classification(image):
|
| 83 |
+
"""Predict the age group of a person from an image."""
|
| 84 |
+
image = Image.fromarray(image).convert("RGB")
|
| 85 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 86 |
+
|
| 87 |
+
with torch.no_grad():
|
| 88 |
+
outputs = model(**inputs)
|
| 89 |
+
logits = outputs.logits
|
| 90 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 91 |
+
|
| 92 |
+
predictions = {LABELS[i]: round(probs[i], 3) for i in range(len(probs))}
|
| 93 |
+
return predictions
|
| 94 |
+
|
| 95 |
+
# Build Gradio interface
|
| 96 |
+
iface = gr.Interface(
|
| 97 |
+
fn=age_classification,
|
| 98 |
+
inputs=gr.Image(type="numpy", label="Upload Image"),
|
| 99 |
+
outputs=gr.Label(label="Predicted Age Group Probabilities"),
|
| 100 |
+
title="MetaCLIP-2 Age Range Estimator",
|
| 101 |
+
description="Upload a face image to estimate the person's age group using MetaCLIP-2."
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
# Launch app
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
iface.launch()
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
# **Sample Inference:**
|
| 110 |
+
|
| 111 |
+

|
| 112 |
+

|
| 113 |
+

|
| 114 |
+

|
| 115 |
+

|
| 116 |
+
|
| 117 |
+
# **Intended Use:**
|
| 118 |
+
|
| 119 |
+
The **MetaCLIP-2-Age-Range-Estimator** model is designed to classify images into five age categories.
|
| 120 |
+
Potential use cases include:
|
| 121 |
+
|
| 122 |
+
* **Demographic Analysis:** Supporting research and business insights into age distribution.
|
| 123 |
+
* **Health and Fitness Applications:** Assisting in age-based health recommendations.
|
| 124 |
+
* **Security and Access Control:** Enabling age verification systems.
|
| 125 |
+
* **Retail and Marketing:** Enhancing personalization and customer profiling.
|
| 126 |
+
* **Forensics and Surveillance:** Supporting age estimation in investigative and security contexts.
|