Views
No views yet
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.
1Classification Report:
2 precision recall f1-score support
3
4 Child 0-12 0.9744 0.9562 0.9652 2193
5 Teenager 13-20 0.8675 0.7032 0.7768 1779
6 Adult 21-44 0.9053 0.9769 0.9397 9999
7Middle Age 45-64 0.9059 0.8317 0.8672 3785
8 Aged 65+ 0.9144 0.8397 0.8755 1260
9
10 accuracy 0.9109 19016
11 macro avg 0.9135 0.8615 0.8849 19016
12 weighted avg 0.9105 0.9109 0.9087 19016!pip install -q transformers torch pillow gradio1import gradio as gr
2from transformers import AutoImageProcessor
3from transformers import SiglipForImageClassification
4from transformers.image_utils import load_image
5from PIL import Image
6import torch
7
8# Load model and processor
9model_name = "prithivMLmods/Age-Classification-SigLIP2"
10model = SiglipForImageClassification.from_pretrained(model_name)
11processor = AutoImageProcessor.from_pretrained(model_name)
12
13def age_classification(image):
14 """Predicts the age group of a person from an image."""
15 image = Image.fromarray(image).convert("RGB")
16 inputs = processor(images=image, return_tensors="pt")
17
18 with torch.no_grad():
19 outputs = model(**inputs)
20 logits = outputs.logits
21 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
22
23 labels = {
24 "0": "Child 0-12",
25 "1": "Teenager 13-20",
26 "2": "Adult 21-44",
27 "3": "Middle Age 45-64",
28 "4": "Aged 65+"
29 }
30 predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))}
31
32 return predictions
33
34# Create Gradio interface
35iface = gr.Interface(
36 fn=age_classification,
37 inputs=gr.Image(type="numpy"),
38 outputs=gr.Label(label="Prediction Scores"),
39 title="Age Group Classification",
40 description="Upload an image to predict the person's age group."
41)
42
43# Launch the app
44if __name__ == "__main__":
45 iface.launch()