Views
No views yet

MetaCLIP-2-Gender-Identifier 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 gender 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
female 0.9815 0.9631 0.9722 1600
male 0.9638 0.9819 0.9728 1600
accuracy 0.9725 3200
macro avg 0.9727 0.9725 0.9725 3200
weighted avg 0.9727 0.9725 0.9725 3200
!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-Gender-Identifier"
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: "female",
17 1: "male"
18}
19
20def age_classification(image):
21 """Predict the age group of a person from an image."""
22 image = Image.fromarray(image).convert("RGB")
23 inputs = processor(images=image, return_tensors="pt")
24
25 with torch.no_grad():
26 outputs = model(**inputs)
27 logits = outputs.logits
28 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
29
30 predictions = {LABELS[i]: round(probs[i], 3) for i in range(len(probs))}
31 return predictions
32
33# Build Gradio interface
34iface = gr.Interface(
35 fn=age_classification,
36 inputs=gr.Image(type="numpy", label="Upload Image"),
37 outputs=gr.Label(label="Predicted Gender"),
38 title="MetaCLIP-2-Gender-Identifier",
39 description="Upload an image to predict the person's gender."
40)
41
42# Launch app
43if __name__ == "__main__":
44 iface.launch()


