Views
No views yet

MetaCLIP-2-Age-Range-Estimator is an image classification vision-language encoder model fine-tuned from facebook/metaclip-2-worldwide-s16 for a single-label classification task. It is designed to predict the age range of a person from an image using the MetaClip2ForImageClassification architecture.
[!note] MetaCLIP 2: A Worldwide Scaling Recipe : https://huggingface.co/papers/2507.22062
Classification Report:
precision recall f1-score support
Child 0-12 0.9763 0.9758 0.9761 2193
Teenager 13-20 0.9158 0.8437 0.8783 1779
Adult 21-44 0.9593 0.9779 0.9685 9999
Middle Age 45-64 0.9458 0.9450 0.9454 3785
Aged 65+ 0.9769 0.9381 0.9571 1260
accuracy 0.9559 19016
macro avg 0.9548 0.9361 0.9451 19016
weighted avg 0.9557 0.9559 0.9556 19016
!pip install -q transformers torch pillow gradio1import gradio as gr
2import torch
3from transformers import AutoImageProcessor, AutoModelForImageClassification
4from PIL import Image
5
6# Model name from Hugging Face Hub
7model_name = "prithivMLmods/MetaCLIP-2-Age-Range-Estimator"
8
9# Load processor and model
10processor = AutoImageProcessor.from_pretrained(model_name)
11model = AutoModelForImageClassification.from_pretrained(model_name)
12model.eval()
13
14# Define labels
15LABELS = {
16 0: "Child (0–12)",
17 1: "Teenager (13–20)",
18 2: "Adult (21–44)",
19 3: "Middle Age (45–64)",
20 4: "Aged (65+)"
21}
22
23def age_classification(image):
24 """Predict the age group of a person from an image."""
25 image = Image.fromarray(image).convert("RGB")
26 inputs = processor(images=image, return_tensors="pt")
27
28 with torch.no_grad():
29 outputs = model(**inputs)
30 logits = outputs.logits
31 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
32
33 predictions = {LABELS[i]: round(probs[i], 3) for i in range(len(probs))}
34 return predictions
35
36# Build Gradio interface
37iface = gr.Interface(
38 fn=age_classification,
39 inputs=gr.Image(type="numpy", label="Upload Image"),
40 outputs=gr.Label(label="Predicted Age Group Probabilities"),
41 title="MetaCLIP-2 Age Range Estimator",
42 description="Upload a face image to estimate the person's age group using MetaCLIP-2."
43)
44
45# Launch app
46if __name__ == "__main__":
47 iface.launch()



