Catalog PyPI
PACKAGE EXPLORERView in registry

age-and-gender

PyPI

Age and gender estimation from face images, with no compiler required.

agedlibfacegenderonnx
Versions collected1
Direct dependencies8From release 2.0.0
Last observed20 Oct, 21:21 UTC

README

Version 2.0.0 documentation

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

MethodReturns
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.

ModelDescriptionIn this package
HOG face detectordlib's built-in frontal face detector. Used only by predict() when no boxes are given.built into dlib
shape_predictor_5_face_landmarks.dat5-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.datResNet-10 age predictor trained on about 110k labelled face images. Estimates ages from 0 to 80.age-v1.onnx
dnn_gender_classifier_v1.datCompact 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.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
2.0.024 Sept 20268

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
mowshon/age-and-gender

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 21:21 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:75b24e31cda20acb96aa1342d70543139e3d2ea54f33bf8e99d052d81e3be660