Update README.md
Browse files
README.md
CHANGED
|
@@ -10,4 +10,100 @@ tags:
|
|
| 10 |
- text-generation-inference
|
| 11 |
---
|
| 12 |
|
| 13 |
-

|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
- text-generation-inference
|
| 11 |
---
|
| 12 |
|
| 13 |
+

|
| 14 |
+
|
| 15 |
+
# **Face-Confidence-SigLIP2**
|
| 16 |
+
|
| 17 |
+
> **Face-Confidence-SigLIP2** is a vision-language encoder model fine-tuned from **google/siglip2-base-patch16-224** for **binary image classification**. It is trained to distinguish between images of **confident faces** and **unconfident faces** using the **SiglipForImageClassification** architecture.
|
| 18 |
+
|
| 19 |
+
```py
|
| 20 |
+
Classification report:
|
| 21 |
+
|
| 22 |
+
precision recall f1-score support
|
| 23 |
+
|
| 24 |
+
confident 0.8468 0.8179 0.8321 4872
|
| 25 |
+
unconfident 0.8691 0.8909 0.8799 6611
|
| 26 |
+
|
| 27 |
+
accuracy 0.8600 11483
|
| 28 |
+
macro avg 0.8580 0.8544 0.8560 11483
|
| 29 |
+
weighted avg 0.8596 0.8600 0.8596 11483
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+

|
| 33 |
+
|
| 34 |
+
## **Label Space: 2 Classes**
|
| 35 |
+
|
| 36 |
+
The model classifies each image into one of the following categories:
|
| 37 |
+
|
| 38 |
+
```
|
| 39 |
+
Class 0: "confident"
|
| 40 |
+
Class 1: "unconfident"
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
---
|
| 44 |
+
|
| 45 |
+
## **Install Dependencies**
|
| 46 |
+
|
| 47 |
+
```bash
|
| 48 |
+
pip install -q transformers torch pillow gradio
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
---
|
| 52 |
+
|
| 53 |
+
## **Inference Code**
|
| 54 |
+
|
| 55 |
+
```python
|
| 56 |
+
import gradio as gr
|
| 57 |
+
from transformers import AutoImageProcessor, SiglipForImageClassification
|
| 58 |
+
from PIL import Image
|
| 59 |
+
import torch
|
| 60 |
+
|
| 61 |
+
# Load model and processor
|
| 62 |
+
model_name = "prithivMLmods/Face-Confidence-SigLIP2" # Replace with your model path if different
|
| 63 |
+
model = SiglipForImageClassification.from_pretrained(model_name)
|
| 64 |
+
processor = AutoImageProcessor.from_pretrained(model_name)
|
| 65 |
+
|
| 66 |
+
# Label mapping
|
| 67 |
+
id2label = {
|
| 68 |
+
"0": "confident",
|
| 69 |
+
"1": "unconfident"
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
def classify_face_confidence(image):
|
| 73 |
+
image = Image.fromarray(image).convert("RGB")
|
| 74 |
+
inputs = processor(images=image, return_tensors="pt")
|
| 75 |
+
|
| 76 |
+
with torch.no_grad():
|
| 77 |
+
outputs = model(**inputs)
|
| 78 |
+
logits = outputs.logits
|
| 79 |
+
probs = torch.nn.functional.softmax(logits, dim=1).squeeze().tolist()
|
| 80 |
+
|
| 81 |
+
prediction = {
|
| 82 |
+
id2label[str(i)]: round(probs[i], 3) for i in range(len(probs))
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
return prediction
|
| 86 |
+
|
| 87 |
+
# Gradio Interface
|
| 88 |
+
iface = gr.Interface(
|
| 89 |
+
fn=classify_face_confidence,
|
| 90 |
+
inputs=gr.Image(type="numpy"),
|
| 91 |
+
outputs=gr.Label(num_top_classes=2, label="Face Confidence Classification"),
|
| 92 |
+
title="Face-Confidence-SigLIP2",
|
| 93 |
+
description="Upload an image to detect if a face looks confident or unconfident."
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
+
if __name__ == "__main__":
|
| 97 |
+
iface.launch()
|
| 98 |
+
```
|
| 99 |
+
|
| 100 |
+
---
|
| 101 |
+
|
| 102 |
+
## **Intended Use**
|
| 103 |
+
|
| 104 |
+
**Face-Confidence-SigLIP2** can be used for:
|
| 105 |
+
|
| 106 |
+
* **Behavioral Analysis** – Detect confidence levels in facial expressions.
|
| 107 |
+
* **Education & Training** – Assess learner engagement or self-confidence.
|
| 108 |
+
* **HR & Recruitment** – Analyze non-verbal cues during interviews.
|
| 109 |
+
* **Dataset Curation** – Separate confident vs unconfident facial images for training.
|