atheless commited on
Commit
62cb8da
·
verified ·
1 Parent(s): 26244ea

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +117 -3
README.md CHANGED
@@ -1,3 +1,117 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ ---
4
+
5
+
6
+
7
+
8
+ Here's a clean and professional **Hugging Face model card description** for your `AgeRaceGenderNet` model:
9
+
10
+ ---
11
+
12
+ ## 🧠 AgeRaceGenderNet
13
+ <img src="https://cdn-uploads.huggingface.co/production/uploads/663a886250daed366b657df4/7-yshHOeyZ4DzEDsjVuMA.png" alt="AgeRaceGenderNet" width="800"/>
14
+
15
+ <!-- ![image/png|](https://cdn-uploads.huggingface.co/production/uploads/663a886250daed366b657df4/7-yshHOeyZ4DzEDsjVuMA.png)
16
+ -->
17
+ **AgeRaceGenderNet** is a lightweight, multi-task face classification model capable of predicting **age**, **gender**, and **race** from facial images. It is built with a **Swin Transformer V2 (Tiny)** backbone and designed for **fast inference** (\~5.94 GFLOPs).
18
+
19
+ ---
20
+
21
+ ### 📊 Tasks & Outputs
22
+
23
+ This model simultaneously predicts:
24
+
25
+ * **\[age]**: Integer from `0` to `116`, representing estimated age.
26
+ * **\[gender]**: `0` for **male**, `1` for **female**.
27
+ * **\[race]**: Integer from `0` to `4` representing:
28
+
29
+ * `0`: White
30
+ * `1`: Black
31
+ * `2`: Asian
32
+ * `3`: Indian
33
+ * `4`: Others (e.g., Hispanic, Latino, Middle Eastern)
34
+
35
+ ---
36
+
37
+ ### Model Architecture
38
+
39
+ * **Backbone**: [Swin V2 Tiny](https://arxiv.org/abs/2111.09883) (pretrained and fine-tuned)
40
+ * **Head**: Multi-task architecture with dedicated classification heads for each demographic task.
41
+ * **Criterion**: Custom `MultiTaskLoss` function
42
+ * **Total Parameters**: **28.4M**
43
+ * **Trainable**: 25.7M
44
+ * **Non-trainable**: 2.7M
45
+ * **Model Size**: \~113.7 MB
46
+ * **Inference Cost**: \~5.94 GFLOPs
47
+
48
+ ---
49
+
50
+ ### Training Dataset
51
+
52
+ The model is trained on **[UTKFace Dataset](https://susanqq.github.io/UTKFace/)**
53
+ ---
54
+
55
+
56
+
57
+ ### Usage example
58
+ ##### NOTE: The input image is assumed to be cropped and aligned to contain only the face
59
+ ```python
60
+ import onnxruntime as ort
61
+ from PIL import Image
62
+ from torchvision import transforms
63
+ import numpy as np
64
+
65
+ # Load ONNX model
66
+ session = ort.InferenceSession("Swin_V2_T.onnx")
67
+
68
+ # Get input and output names
69
+ input_name = session.get_inputs()[0].name
70
+ output_names = [out.name for out in session.get_outputs()]
71
+
72
+ # Preprocessing: Load and transform image
73
+ # NOTE: The input image is assumed to be cropped and aligned to contain only the face
74
+
75
+ transform = transforms.Compose([
76
+ transforms.Resize((256, 256)), # Resize to model input size
77
+ transforms.ToTensor(),
78
+ transforms.Normalize(mean=[0.485, 0.456, 0.406],
79
+ std=[0.229, 0.224, 0.225])
80
+ ])
81
+
82
+ img = Image.open("path_to_image.jpg").convert("RGB")
83
+ img_tensor = transform(img).unsqueeze(0).numpy() # Shape: (1, 3, 256, 256)
84
+
85
+ # Run inference
86
+ age_logits, gender_logits, race_logits = session.run(output_names, {input_name: img_tensor})
87
+
88
+ # Postprocessing: Get predictions
89
+ age_pred = int(np.argmax(age_logits, axis=1)[0])
90
+ gender_pred = int(np.argmax(gender_logits, axis=1)[0])
91
+ race_pred = int(np.argmax(race_logits, axis=1)[0])
92
+
93
+ # Convert predictions to labels
94
+ def get_gender_text(gender_idx):
95
+ return 'Male' if gender_idx == 0 else 'Female'
96
+
97
+ def get_race_text(race_idx):
98
+ race_map = {
99
+ 0: 'White',
100
+ 1: 'Black',
101
+ 2: 'Asian',
102
+ 3: 'Indian',
103
+ 4: 'Other'
104
+ }
105
+ return race_map.get(race_idx, 'Unknown')
106
+
107
+ # Display results
108
+ print(f"Predicted Age: {age_pred}")
109
+ print(f"Predicted Gender: {get_gender_text(gender_pred)}")
110
+ print(f"Predicted Race: {get_race_text(race_pred)}")
111
+
112
+ ```
113
+
114
+
115
+
116
+
117
+