Views
No views yet

facial-age-detection is a vision-language encoder model fine-tuned fromgoogle/siglip2-base-patch16-512for multi-class image classification. It is trained to detect and classify human faces into age groups ranging from early childhood to elderly adults. The model uses theSiglipForImageClassificationarchitecture.
[!note] SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features https://arxiv.org/pdf/2502.14786
1Classification Report:
2 precision recall f1-score support
3
4 age 01-10 0.9614 0.9669 0.9641 2474
5 age 11-20 0.8418 0.8467 0.8442 1181
6 age 21-30 0.8118 0.8326 0.8220 1523
7 age 31-40 0.6937 0.6683 0.6808 1010
8 age 41-55 0.7106 0.7528 0.7311 1181
9 age 56-65 0.6878 0.6646 0.6760 799
10 age 66-80 0.7949 0.7596 0.7768 653
11 age 80 + 0.9349 0.8343 0.8817 344
12
13 accuracy 0.8225 9165
14 macro avg 0.8046 0.7907 0.7971 9165
15weighted avg 0.8226 0.8225 0.8223 9165
Class 0: age 01-10
Class 1: age 11-20
Class 2: age 21-30
Class 3: age 31-40
Class 4: age 41-55
Class 5: age 56-65
Class 6: age 66-80
Class 7: age 80 +pip install -q transformers torch pillow gradio hf_xet1import gradio as gr
2from transformers import AutoImageProcessor, SiglipForImageClassification
3from PIL import Image
4import torch
5
6# Load model and processor
7model_name = "prithivMLmods/facial-age-detection" # Update with actual model name on Hugging Face
8model = SiglipForImageClassification.from_pretrained(model_name)
9processor = AutoImageProcessor.from_pretrained(model_name)
10
11# Updated label mapping
12id2label = {
13 "0": "age 01-10",
14 "1": "age 11-20",
15 "2": "age 21-30",
16 "3": "age 31-40",
17 "4": "age 41-55",
18 "5": "age 56-65",
19 "6": "age 66-80",
20 "7": "age 80 +"
21}
22
23def classify_image(image):
24 image = Image.fromarray(image).convert("RGB")
25 inputs = processor(images=image, return_tensors="pt")
26
27 with torch.no_grad():
28 outputs = model(**inputs)
29 logits = outputs.logits
30 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
31
32 prediction = {
33 id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
34 }
35
36 return prediction
37
38# Gradio Interface
39iface = gr.Interface(
40 fn=classify_image,
41 inputs=gr.Image(type="numpy"),
42 outputs=gr.Label(num_top_classes=8, label="Age Group Classification"),
43 title="Facial Age Detection",
44 description="Upload a face image to estimate the age group: 01–10, 11–20, 21–30, 31–40, 41–55, 56–65, 66–80, or 80+."
45)
46
47if __name__ == "__main__":
48 iface.launch()facial-age-detection is designed for: