File size: 4,093 Bytes
2ea9ff4
 
93f2d43
b827ae0
93f2d43
 
 
 
 
 
 
 
 
 
 
 
48cd5fd
2ea9ff4
7468ac2
 
cbb5e23
 
 
 
7468ac2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7b7def8
cbb5e23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b41e62c
cbb5e23
b41e62c
 
 
cbb5e23
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
license: apache-2.0
datasets:
- prithivMLmods/Age-Classification-Set
language:
- en
base_model:
- google/siglip2-base-patch16-224
pipeline_tag: image-classification
library_name: transformers
tags:
- Age
- Detection
- Siglip2
- ViT
- AutoImageProcessor
- 0-60+
---
![AAAAAAAA.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/hWrRztXlZ0j87BEajVNtA.png)

# **Age-Classification-SigLIP2**  

> **Age-Classification-SigLIP2** is an image classification vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for a single-label classification task. It is designed to predict the age group of a person from an image using the **SiglipForImageClassification** architecture.  

```py
Classification Report:
                  precision    recall  f1-score   support

      Child 0-12     0.9744    0.9562    0.9652      2193
  Teenager 13-20     0.8675    0.7032    0.7768      1779
     Adult 21-44     0.9053    0.9769    0.9397      9999
Middle Age 45-64     0.9059    0.8317    0.8672      3785
        Aged 65+     0.9144    0.8397    0.8755      1260

        accuracy                         0.9109     19016
       macro avg     0.9135    0.8615    0.8849     19016
    weighted avg     0.9105    0.9109    0.9087     19016
```

![download (1).png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/rgfZs4duAb09vRvFmO3Qy.png)



The model categorizes images into five age groups:  
- **Class 0:** "Child 0-12"  
- **Class 1:** "Teenager 13-20"  
- **Class 2:** "Adult 21-44"  
- **Class 3:** "Middle Age 45-64"  
- **Class 4:** "Aged 65+"  

# **Run with Transformers🤗**  

```python
!pip install -q transformers torch pillow gradio
```  

```python
import gradio as gr
from transformers import AutoImageProcessor
from transformers import SiglipForImageClassification
from transformers.image_utils import load_image
from PIL import Image
import torch

# Load model and processor
model_name = "prithivMLmods/Age-Classification-SigLIP2"
model = SiglipForImageClassification.from_pretrained(model_name)
processor = AutoImageProcessor.from_pretrained(model_name)

def age_classification(image):
    """Predicts the age group of a person from an image."""
    image = Image.fromarray(image).convert("RGB")
    inputs = processor(images=image, return_tensors="pt")
    
    with torch.no_grad():
        outputs = model(**inputs)
        logits = outputs.logits
        probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
    
    labels = {
        "0": "Child 0-12", 
        "1": "Teenager 13-20", 
        "2": "Adult 21-44", 
        "3": "Middle Age 45-64", 
        "4": "Aged 65+"
    }
    predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
    
    return predictions

# Create Gradio interface
iface = gr.Interface(
    fn=age_classification,
    inputs=gr.Image(type="numpy"),
    outputs=gr.Label(label="Prediction Scores"),
    title="Age Group Classification",
    description="Upload an image to predict the person's age group."
)

# Launch the app
if __name__ == "__main__":
    iface.launch()
```
# **Sample Inference:**  

![Screenshot 2025-03-28 at 12-25-46 Age Group Classification.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/ARlNhc-ZxqfBntu-SkIVH.png)

![Screenshot 2025-03-28 at 12-36-49 Age Group Classification.png](https://cdn-uploads.huggingface.co/production/uploads/65bb837dbfb878f46c77de4c/tvZ2VMoaQqNKdIx39DrTe.png)

# **Intended Use:**  

The **Age-Classification-SigLIP2** model is designed to classify images into five age categories. Potential use cases include:  

- **Demographic Analysis:** Helping businesses and researchers analyze age distribution.  
- **Health & Fitness Applications:** Assisting in age-based health recommendations.  
- **Security & Access Control:** Implementing age verification in digital systems.  
- **Retail & Marketing:** Enhancing personalized customer experiences.  
- **Forensics & Surveillance:** Aiding in age estimation for security purposes.