prithivMLmods/Realistic-Gender-Classification
7848
1---2license: apache-2.03datasets:4- prithivMLmods/Realistic-Portrait-Gender-1024px5language:6- en7base_model:8- google/siglip2-base-patch16-2249pipeline_tag: image-classification10library_name: transformers11tags:12- Gender13- Classification14- art15- realism16- portrait17- Male18- Female19- SigLIP220---21 2223 24# **Realistic-Gender-Classification**25 26> **Realistic-Gender-Classification** is a binary image classification model based on `google/siglip2-base-patch16-224`, designed to classify **gender** from realistic human portrait images. It can be used in **demographic analysis**, **personalization systems**, and **automated tagging** in large-scale image datasets.27 28> [!note]29*SigLIP 2: Multilingual Vision-Language Encoders with Improved Semantic Understanding, Localization, and Dense Features* https://arxiv.org/pdf/2502.1478630 31```py32Classification Report:33 precision recall f1-score support34 35female portrait 0.9754 0.9656 0.9705 160036 male portrait 0.9660 0.9756 0.9708 160037 38 accuracy 0.9706 320039 macro avg 0.9707 0.9706 0.9706 320040 weighted avg 0.9707 0.9706 0.9706 320041```42 4344 45---46 47## **Label Classes**48 49The model distinguishes between the following portrait gender categories:50 51```520: female portrait 531: male portrait54```55 56---57 58## **Installation**59 60```bash61pip install transformers torch pillow gradio62```63 64---65 66## **Example Inference Code**67 68```python69import gradio as gr70from transformers import AutoImageProcessor, SiglipForImageClassification71from PIL import Image72import torch73 74# Load model and processor75model_name = "prithivMLmods/Realistic-Gender-Classification"76model = SiglipForImageClassification.from_pretrained(model_name)77processor = AutoImageProcessor.from_pretrained(model_name)78 79# ID to label mapping80id2label = {81 "0": "female portrait",82 "1": "male portrait"83}84 85def classify_gender(image):86 image = Image.fromarray(image).convert("RGB")87 inputs = processor(images=image, return_tensors="pt")88 89 with torch.no_grad():90 outputs = model(**inputs)91 logits = outputs.logits92 probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()93 94 prediction = {id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))}95 return prediction96 97# Gradio Interface98iface = gr.Interface(99 fn=classify_gender,100 inputs=gr.Image(type="numpy"),101 outputs=gr.Label(num_top_classes=2, label="Gender Classification"),102 title="Realistic-Gender-Classification",103 description="Upload a realistic portrait image to classify it as 'female portrait' or 'male portrait'."104)105 106if __name__ == "__main__":107 iface.launch()108```109 110---111 112## Demo Inference113 114> [!note]115female portrait116 117118119 120> [!note]121male portrait122 123124125 126## **Applications**127 128* **Demographic Insights in Visual Data**129* **Dataset Curation & Tagging**130* **Media Analytics**131* **Audience Profiling for Marketing** 