Run this model with HF Jobs
Run tinylens/gender-classifier-base on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/tinylens/gender-classifier-base. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/tinylens/gender-classifier-base on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use tinylens/gender-classifier-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- timm
How to use tinylens/gender-classifier-base with timm:
import timm model = timm.create_model("hf-hub:tinylens/gender-classifier-base", pretrained=True) - Notebooks
- Google Colab
- Kaggle
tinylens/gender-classifier-base
A compact classifier that predicts perceived binary gender (female / male) from a face crop. Apache-2.0, trained only on FairFace (CC BY 4.0), with ONNX weights for browsers and edge devices. It is a drop-in replacement for the popular ViT-B gender classifiers on the Hub (same labels, same image-classification pipeline) at 21.6M parameters instead of 86M.
- Labels:
female,male - Input: a face crop (FairFace style, the face with some margin), resized to 224x224
- Sibling: tinylens/gender-classifier-small
- Demo (runs in your browser): tinylens/face-attributes
Use
from transformers import pipeline
clf = pipeline("image-classification", model="tinylens/gender-classifier-base")
clf("face.jpg")
With timm directly: timm.create_model("hf-hub:tinylens/gender-classifier-base", pretrained=True). ONNX: onnx/model.onnx (fp32, 82.6 MB) and onnx/model_quantized.onnx (int8 weights, 21.4 MB). The ONNX input is pixel_values (N, 3, 224, 224), RGB, scaled to 0-1 and normalized with mean [0.485, 0.456, 0.406] and std [0.229, 0.224, 0.225].
The model expects one face per image. For photos, detect and crop faces first (the demo uses the MediaPipe face detector and a square crop of 1.6x the face box).
Evaluation
FairFace validation split (padding 0.25, 10,954 images). All models were run by us on the same images, each with its own preprocessing. FairFace validation was never used for training or model selection (we selected on a 5% hold-out of the training split).
| Model | Params | License | Accuracy | Macro recall | Worst race group |
|---|---|---|---|---|---|
| tinylens/gender-classifier-small (this family) | 2.5M | apache-2.0 | 92.7 | 92.6 | 87.6 |
| tinylens/gender-classifier-base (this family) | 21.6M | apache-2.0 | 94.0 | 94.1 | 88.0 |
| rizvandwiki/gender-classification | 85.8M | not stated | 80.2 | 79.2 | 72.4 |
| rizvandwiki/gender-classification-2 | 85.8M | not stated | 82.7 | 83.4 | 76.4 |
| dima806/fairface_gender_image_detection | 85.8M | apache-2.0 | 93.5 | 93.4 | 88.9 |
ONNX on the same split: fp32 94.0, int8 94.0.
Where this model loses: worst race group accuracy vs dima806/fairface_gender_image_detection (88.0 vs 88.9).
Caveats on the comparison: dima806/fairface_gender_image_detection was also fine-tuned on FairFace, so this split is in-domain for it; we do not know whether it used the validation split for training or selection. The rizvandwiki models were trained on other (undocumented) data, so FairFace is out-of-domain for them.
Accuracy by race group (FairFace labels):
| Group | Accuracy |
|---|---|
| East Asian | 94.7 |
| Indian | 95.3 |
| Black | 88.0 |
| White | 94.7 |
| Middle Eastern | 96.8 |
| Latino_Hispanic | 95.9 |
| Southeast Asian | 93.2 |
Recall by class:
| Class | Recall |
|---|---|
| female | 94.8 |
| male | 93.3 |
Training
- Backbone: ViT-S/14 DINOv2 (timm
vit_small_patch14_dinov2.lvd142m, Apache-2.0), at 224 px - Data: FairFace via HuggingFaceM4/FairFace (config
0.25), 86,744 training images, CC BY 4.0. 95% used for training, 5% held out for model selection. - Recipe: AdamW, lr 0.0001, weight decay 0.05, cosine schedule with 1 epoch warm-up, 15 epochs, batch 128, label smoothing 0.1, bf16, random resized crop (0.7-1.0), horizontal flip, color jitter, random erasing. Best epoch by hold-out accuracy (94.1).
- Hardware: one RTX 5070 Ti.
- Code to reproduce training, evaluation and export: https://github.com/DenDen047/agent-earning/tree/main/face_attributes
Limitations and intended use
- Predictions are apparent age and perceived binary gender as labeled by FairFace annotators, not a person's real age or gender identity. Non-binary identities are not represented.
- Accuracy differs across race groups, ages and image conditions (see tables). Age is hard: neighbouring bins are often confused, and the oldest and youngest bins are rare in the data.
- Trained on cropped, mostly frontal faces from Flickr photos. Expect lower accuracy on profile views, heavy occlusion, low light, drawings, or crops that differ from FairFace.
- Do not use this model to make decisions about individuals (hiring, access, law enforcement, age verification for legal purposes, etc.). Suitable uses include aggregate analytics with human review, dataset auditing, and research.
License and attribution
Model weights: Apache-2.0. Training data: FairFace by Kärkkäinen and Joo, CC BY 4.0 ("FairFace: Face Attribute Dataset for Balanced Race, Gender, and Age", WACV 2021). Backbone weights: timm / Meta DINOv2, Apache-2.0.
- Downloads last month
- 110
Model tree for tinylens/gender-classifier-base
Base model
timm/vit_small_patch14_dinov2.lvd142m