MiVOLO: Multi-input Transformer for Age and Gender Estimation
repository·main·Indexed 19 days ago
https://github.com/wildchlamydia/mivoloA transformer-based model architecture for high-accuracy age and gender estimation using dual-stream inputs (face and body). The project includes various model types such as volo_d1, mivolo_d1, and mivolov2_d1_384x384, as well as the successor MiVOLO-Next. It supports evaluation on datasets including Lagenda, IMDB-clean, UTK, Adience, FairFace, and AgeDB, and provides TorchScript export for deployment.
What's inside MiVOLO
- MiVOLO is a Multi-input Transformer designed for Age and Gender estimation. It utilizes both face and body information (dual-stream) to improve recognition performance. The project includes several versions, including the successor MiVOLO-Next, which features a dual-stream face + person backbone and achieves high performance (APPA-Real MAE 4.07) with high throughput (28,722 FPS on A100).
MiVOLO Pretrained Models and Checkpoints
mainMiVOLO provides several pretrained models optimized for different tasks and datasets. Models are categorized by their input type (e.g.,
face_onlyorface_body) and the attributes they estimate (age, gender, or both).Available Model Types:
- volo_d1: Typically used for
face_onlyestimation of age and/or gender. - mivolo_d1: A multi-input model using
face_bodystreams for age and gender estimation. - mivolov2_d1_384x384: An improved version (MiVOLO v2) using
face_bodystreams, trained on the Lagenda dataset, offering higher accuracy (Age MAE 3.65, Gender Accuracy 97.99% on Lagenda).
- volo_d1: Typically used for
MiVOLO Dataset Information
mainMiVOLO utilizes several datasets for training and evaluation. If you use this data, please cite the project's papers.
- Lagenda: Includes images and annotations.
- IMDB-clean: Requires following external instructions for images; annotations are provided.
- UTK: Includes original full images and specific annotations/splits.
- Adience: Requires following external instructions for images; annotations are provided. Uses coarse aligned images from the
faces/directory. - FairFace: Requires following external instructions for images; annotations are provided. Uses aligned images from the
fairface-img-margin125-trainval/directory. - AgeDB: Includes images and annotations for ages 1-101.
Run the MiVOLO Demo
mainTo run the demo, you must first download the required model weights and place them in the
models/directory:- Download the body + face detector model to
models/yolov8x_person_face.pt. - Download the MiVOLO checkpoint to
models/mivolo_imbd.pth.tar.
You can then run the demo on a local image or a YouTube video using the
demo.pyscript.# Demo for a local image python3 demo.py \ --input "jennifer_lawrence.jpg" \ --output "output" \ --detector-weights "models/yolov8x_person_face.pt" \ --checkpoint "models/mivolo_imbd.pth.tar" \ --device "cuda:0" \ --with-persons \ --draw # Demo for a YouTube video python3 demo.py \ --input "https://www.youtube.com/shorts/pVh32k0hGEI" \ --output "output" \ --detector-weights "models/yolov8x_person_face.pt" \ --checkpoint "models/mivolo_imbd.pth.tar" \ --device "cuda:0" \ --draw \ --with-persons- Download the body + face detector model to
Validate MiVOLO models
mainTo reproduce validation metrics, download the prepared annotations for your target dataset (imdb-clean, utk, adience, lagenda, or fairface) and the MiVOLO checkpoint. Use
eval_pretrained.pyto run the evaluation.Supported
--dataset_namevalues:utk,imdb,lagenda,fairface,adience.python3 eval_pretrained.py \ --dataset_images /path/to/dataset/utk/images \ --dataset_annotations /path/to/dataset/utk/annotation \ --dataset_name utk \ --split valid \ --batch-size 512 \ --checkpoint models/mivolo_imbd.pth.tar \ --half \ --with-persons \ --device "cuda:0"Export MiVOLO models via TorchScript
mainWhile ONNX export is technically possible, it is not recommended due to poor performance with batch processing. TensorRT and OpenVINO exports are currently not supported because of
col2imlimitations.The recommended method for exporting is using TorchScript, which maintains original speed and results in a single file. Use
torch.jit.traceto perform the export.torch.jit.trace(model)Reproduce MiVOLO Regression Benchmarks
mainTo reproduce the regression benchmark results (Age MAE, Age CS@5, and Gender Accuracy) using the provided checkpoints, use the
valid_age_gender.shscript located in thescripts/directory../scripts/valid_age_gender.shInstall MiVOLO
mainTo install MiVOLO, ensure you have PyTorch 1.13 or newer installed, then install the project dependencies and the package itself using pip.
pip install -r requirements.txt pip install .