Run this model with HF Jobs

Run tinylens/gender-classifier-small 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-small. 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-small 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.

tinylens/gender-classifier-small

A tiny 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 2.5M parameters instead of 86M.

Use

from transformers import pipeline

clf = pipeline("image-classification", model="tinylens/gender-classifier-small")
clf("face.jpg")

With timm directly: timm.create_model("hf-hub:tinylens/gender-classifier-small", pretrained=True). ONNX: onnx/model.onnx (fp32, 9.5 MB) and onnx/model_quantized.onnx (int8 weights, 2.5 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 92.7, int8 92.5.

Where this model loses: accuracy vs dima806/fairface_gender_image_detection (92.7 vs 93.5); macro recall vs dima806/fairface_gender_image_detection (92.6 vs 93.4); worst race group accuracy vs dima806/fairface_gender_image_detection (87.6 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 92.6
Indian 94.1
Black 87.6
White 92.3
Middle Eastern 96.3
Latino_Hispanic 94.4
Southeast Asian 92.7

Recall by class:

Class Recall
female 91.5
male 93.8

Training

  • Backbone: MobileNetV4-conv-small (timm mobilenetv4_conv_small.e2400_r224_in1k, Apache-2.0, ImageNet-1k)
  • 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.002, weight decay 0.05, cosine schedule with 1 epoch warm-up, 25 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 (92.7).
  • 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 / Google MobileNetV4, Apache-2.0.

Downloads last month
63
Safetensors
Model size
2.52M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for tinylens/gender-classifier-small

Quantized
(8)
this model

Dataset used to train tinylens/gender-classifier-small

Space using tinylens/gender-classifier-small 1