Skip to main content

age-and-gender

Age and gender estimation from face images.
Pure Python install. No compiler, no model downloads.


Credits

This package uses pretrained models from dlib-models by Davis E. King. The age predictor and gender classifier were contributed to dlib-models by Cydral Technology. We are grateful to them for making these models freely available.

Installation

pip install age-and-gender

Requires Python 3.11+. Pretrained models are bundled with the package.

Quick start

from PIL import Image
from age_and_gender import AgeAndGender

predictor = AgeAndGender()
image = Image.open("photo.jpg").convert("RGB")

print(predictor.predict(image))
[{'gender': {'value': 'female', 'confidence': 100},
  'age': {'value': 26, 'confidence': 84},
  'face': [419, 266, 506, 352]},
 ...]

result

© Bill Gates family

Using any face detector

The built-in detector is optional. Crop faces with any detector (OpenCV, MediaPipe, RetinaFace, face_recognition, etc.) and pass each crop to predict_face():

from PIL import Image
from age_and_gender import AgeAndGender

predictor = AgeAndGender()
image = Image.open("photo.jpg").convert("RGB")

for left, top, right, bottom in detect_faces(image):  # your detector
    face = image.crop((left, top, right, bottom))  # cropped face only
    print(predictor.predict_face(face))
{'gender': {'value': 'female', 'confidence': 100}, 'age': {'value': 25, 'confidence': 80}}

If you only need one attribute, gender() and age() each run a single model:

predictor.gender(face)  # {'value': 'female', 'confidence': 100}
predictor.age(face)     # {'value': 25, 'confidence': 80}

face can also be an RGB NumPy array. Convert OpenCV (BGR) frames first with cv2.cvtColor(frame, cv2.COLOR_BGR2RGB).

API

Method Returns
AgeAndGender() Predictor using the bundled models
predict(image, face_bounding_boxes=None) list of {gender, age, face}, one per detected face
predict_face(face) {gender, age} for one cropped face
gender(face) {value, confidence}
age(face) {value, confidence}
AgeAndGender.from_model_dir(path) Predictor using a custom model bundle (manifest.json + models)
  • image / face: RGB PIL.Image or [H, W, 3] uint8 NumPy array.
  • face_bounding_boxes: optional (top, right, bottom, left) boxes. When given, detection is skipped.
  • face in results: [left, top, right, bottom].
  • confidence: integer percentage.

Models

The pretrained models come from davisking/dlib-models and are bundled with the package, so nothing needs to be downloaded.

Model Description In this package
HOG face detector dlib's built-in frontal face detector. Used only by predict() when no boxes are given. built into dlib
shape_predictor_5_face_landmarks.dat 5-point landmark model (eye corners and bottom of the nose) used to align each face. Trained on 7,198 annotated faces. unchanged
dnn_age_predictor_v1.dat ResNet-10 age predictor trained on about 110k labelled face images. Estimates ages from 0 to 80. age-v1.onnx
dnn_gender_classifier_v1.dat Compact CNN gender classifier trained on about 200k face images. Around 97.3% accuracy on LFW. gender-v1.onnx

dnn_age_predictor_v1.dat and dnn_gender_classifier_v1.dat were converted to ONNX so they run on ONNX Runtime and are easier to use from Python. The weights are unchanged, and the outputs match the original dlib networks.

What's new in 2.0

  • No legacy C++ code. The C++ extension and the vendored dlib sources from 1.x have been removed. Nothing is compiled during installation.
  • ONNX inference. Age and gender run on ONNX Runtime. Face detection and landmarks use the prebuilt dlib-bin wheel.
  • Bundled models. AgeAndGender() works immediately. The load_* calls are no longer needed.
  • Any face detector. predict_face(), gender() and age() accept cropped faces.

License

The package is released under the MIT License. The bundled models are dedicated to the public domain under CC0 1.0.

Metadata

Release files for age-and-gender 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for age-and-gender 2.0.0
File Size Uploaded
age_and_gender-2.0.0.tar.gz 17.8 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for age-and-gender 2.0.0
File Interpreter ABI Platform
age_and_gender-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 34.9 MB

Release files / age_and_gender-2.0.0.tar.gz

Download URL age_and_gender-2.0.0.tar.gz
Size 17.8 MB
Tags Source
SHA-256 checksum
How to use checksums
14db2f0e6d4d51c830a3596740e902a7323569f2c540adb09224f4b2857d19b0
BLAKE2b-256 checksum
How to use checksums
4bac36095c3d1253597d9c70711166b76c90c19c7398e6e8b4d2a711589ebea4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release files / age_and_gender-2.0.0-py3-none-any.whl

Download URL age_and_gender-2.0.0-py3-none-any.whl
Size 17.1 MB
Tags Python 3
SHA-256 checksum
How to use checksums
b1f8b9947b679c234c03e9f74db20df476b1a44696ad85e98764a0dc147a1797
BLAKE2b-256 checksum
How to use checksums
ae1f7efa5e1670ca1e78319642b91db0e5ea544e2242639b4a55c4fddb55fda8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page