README.md
| 1 | --- |
| 2 | license: apache-2.0 |
| 3 | language: |
| 4 | - en |
| 5 | base_model: |
| 6 | - google/siglip2-base-patch16-224 |
| 7 | pipeline_tag: image-classification |
| 8 | library_name: transformers |
| 9 | tags: |
| 10 | - gender |
| 11 | - male |
| 12 | - female |
| 13 | - siglip2 |
| 14 | datasets: |
| 15 | - myvision/gender-classification |
| 16 | --- |
| 17 | |
| 18 |  |
| 19 | |
| 20 | # **Gender-Classifier-Mini** |
| 21 | |
| 22 | > **Gender-Classifier-Mini** 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 classify images based on gender using the **SiglipForImageClassification** architecture. |
| 23 | |
| 24 | ```py |
| 25 | Accuracy: 0.9720 |
| 26 | F1 Score: 0.9720 |
| 27 | |
| 28 | Classification Report: |
| 29 | precision recall f1-score support |
| 30 | |
| 31 | Female ♀ 0.9660 0.9796 0.9727 2549 |
| 32 | Male ♂ 0.9785 0.9641 0.9712 2451 |
| 33 | |
| 34 | accuracy 0.9720 5000 |
| 35 | macro avg 0.9722 0.9718 0.9720 5000 |
| 36 | weighted avg 0.9721 0.9720 0.9720 5000 |
| 37 | ``` |
| 38 | |
| 39 |  |
| 40 | |
| 41 | The model categorizes images into two classes: |
| 42 | - **Class 0:** "Female ♀" |
| 43 | - **Class 1:** "Male ♂" |
| 44 | |
| 45 | # **Run with Transformers🤗** |
| 46 | |
| 47 | ```python |
| 48 | !pip install -q transformers torch pillow gradio |
| 49 | ``` |
| 50 | |
| 51 | ```python |
| 52 | import gradio as gr |
| 53 | from transformers import AutoImageProcessor |
| 54 | from transformers import SiglipForImageClassification |
| 55 | from transformers.image_utils import load_image |
| 56 | from PIL import Image |
| 57 | import torch |
| 58 | |
| 59 | # Load model and processor |
| 60 | model_name = "prithivMLmods/Gender-Classifier-Mini" |
| 61 | model = SiglipForImageClassification.from_pretrained(model_name) |
| 62 | processor = AutoImageProcessor.from_pretrained(model_name) |
| 63 | |
| 64 | def gender_classification(image): |
| 65 | """Predicts gender category for an image.""" |
| 66 | image = Image.fromarray(image).convert("RGB") |
| 67 | inputs = processor(images=image, return_tensors="pt") |
| 68 | |
| 69 | with torch.no_grad(): |
| 70 | outputs = model(**inputs) |
| 71 | logits = outputs.logits |
| 72 | probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist() |
| 73 | |
| 74 | labels = {"0": "Female ♀", "1": "Male ♂"} |
| 75 | predictions = {labels[str(i)]: round(probs[i], 3) for i in range(len(probs))} |
| 76 | |
| 77 | return predictions |
| 78 | |
| 79 | # Create Gradio interface |
| 80 | iface = gr.Interface( |
| 81 | fn=gender_classification, |
| 82 | inputs=gr.Image(type="numpy"), |
| 83 | outputs=gr.Label(label="Prediction Scores"), |
| 84 | title="Gender Classification", |
| 85 | description="Upload an image to classify its gender." |
| 86 | ) |
| 87 | |
| 88 | # Launch the app |
| 89 | if __name__ == "__main__": |
| 90 | iface.launch() |
| 91 | ``` |
| 92 | |
| 93 | # **Intended Use:** |
| 94 | |
| 95 | The **Gender-Classifier-Mini** model is designed to classify images into gender categories. Potential use cases include: |
| 96 | |
| 97 | - **Demographic Analysis:** Assisting in understanding gender distribution in datasets. |
| 98 | - **Face Recognition Systems:** Enhancing identity verification processes. |
| 99 | - **Marketing & Advertising:** Personalizing content based on demographic insights. |
| 100 | - **Healthcare & Research:** Supporting gender-based analysis in medical imaging. |