{"id":13934676,"url":"https://github.com/yu4u/age-gender-estimation","last_synced_at":"2025-04-08T09:08:57.508Z","repository":{"id":39617612,"uuid":"87724159","full_name":"yu4u/age-gender-estimation","owner":"yu4u","description":"Keras implementation of a CNN network for age and gender estimation","archived":false,"fork":false,"pushed_at":"2021-06-29T19:49:32.000Z","size":3368,"stargazers_count":1484,"open_issues_count":83,"forks_count":505,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-04-01T07:52:23.522Z","etag":null,"topics":["age-estimation","convolutional-neural-networks","deep-learning","gender-estimation","imdb"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yu4u.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-04-09T16:53:46.000Z","updated_at":"2025-03-27T09:31:04.000Z","dependencies_parsed_at":"2022-07-14T22:46:44.067Z","dependency_job_id":null,"html_url":"https://github.com/yu4u/age-gender-estimation","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fage-gender-estimation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fage-gender-estimation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fage-gender-estimation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yu4u%2Fage-gender-estimation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yu4u","download_url":"https://codeload.github.com/yu4u/age-gender-estimation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247809962,"owners_count":20999816,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["age-estimation","convolutional-neural-networks","deep-learning","gender-estimation","imdb"],"created_at":"2024-08-07T23:01:10.075Z","updated_at":"2025-04-08T09:08:57.488Z","avatar_url":"https://github.com/yu4u.png","language":"Jupyter Notebook","funding_links":[],"categories":["Jupyter Notebook"],"sub_categories":[],"readme":"# Age and Gender Estimation\nThis is a Keras implementation of a CNN for estimating age and gender from a face image [1, 2].\nIn training, [the IMDB-WIKI dataset](https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/) is used.\n\n- [Aug. 21, 2020] Refactored; use tensorflow.keras\n- [Jun. 30, 2019] [Another PyTorch-based project](https://github.com/yu4u/age-estimation-pytorch) was released\n- [Nov. 12, 2018] Enable Adam optimizer; seems to be better than momentum SGD\n- [Sep. 23, 2018] Demo from directory\n- [Aug. 11, 2018] Add age estimation sub-project [here](age_estimation)\n- [Jul. 5, 2018] The UTKFace dataset became available for training.\n- [Apr. 10, 2018] Evaluation result on the APPA-REAL dataset was added.\n\n## Dependencies\n- Python3.6+\n\nTested on:\n- Ubuntu 16.04, Python 3.6.9, Tensorflow 2.3.0, CUDA 10.01, cuDNN 7.6\n\n\n## Usage\n\n### Use trained model for demo\nRun the demo script (requires web cam).\nYou can use `--image_dir [IMAGE_DIR]` option to use images in the `[IMAGE_DIR]` directory instead.\n\n```sh\npython demo.py\n```\n\nThe trained model will be automatically downloaded to the `pretrained_models` directory.\n\n### Create training data from the IMDB-WIKI dataset\nFirst, download the dataset.\nThe dataset is downloaded and extracted to the `data` directory by:\n\n```sh\n./download.sh\n```\n\nSecondly, filter out noise data and serialize labels into `.csv` file.\nPlease check [check_dataset.ipynb](check_dataset.ipynb) for the details of the dataset.\nThe training data is created by:\n\n```sh\npython create_db.py --db imdb\n```\n\n```sh\nusage: create_db.py [-h] [--db DB] [--min_score MIN_SCORE]\n\nThis script cleans-up noisy labels and creates database for training.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --db DB               dataset; wiki or imdb (default: imdb)\n  --min_score MIN_SCORE minimum face_score (default: 1.0)\n```\n\nThe resulting files with default parameters are included in this repo (meta/imdb.csv and meta/wiki.csv),\nthus there is no need to run this by yourself.\n\n\n### Create training data from the UTKFace dataset [currently not supported]\nFirstly, download images from [the website of the UTKFace dataset](https://susanqq.github.io/UTKFace/).\n`UTKFace.tar.gz` can be downloaded from `Aligned\u0026Cropped Faces` in Datasets section.\nThen, extract the archive.\n\n```sh\ntar zxf UTKFace.tar.gz UTKFace\n```\n\nFinally, run the following script to create the training data:\n\n```\npython create_db_utkface.py -i UTKFace -o UTKFace.mat\n```\n\n[NOTE]: Because the face images in the UTKFace dataset is tightly cropped (there is no margin around the face region),\nfaces should also be cropped in `demo.py` if weights trained by the UTKFace dataset is used.\nPlease set the margin argument to 0 for tight cropping:\n\n```sh\npython demo.py --weight_file WEIGHT_FILE --margin 0\n```\n\nThe pre-trained weights can be found [here](https://github.com/yu4u/age-gender-estimation/releases/download/v0.5/weights.29-3.76_utk.hdf5).\n\n### Train model\nTrain the model architecture using the training data created above:\n\n```sh\npython train.py\n```\n\nTrained weight files are stored as `checkpoints/*.hdf5` for each epoch if the validation loss becomes minimum over previous epochs.\n\n#### Changing model or the other training parameters\nYou can change [default setting(s)](src/config.yaml) from command line as:\n\n```sh\npython train.py model.model_name=EfficientNetB3 model.batch_size=64\n```\n\nAvailable models can be found [here](https://keras.io/api/applications/).\n\n#### Check training curve\nThe training logs can be easily visualized via [wandb](https://www.wandb.com/) by:\n\n1. create account from [here](https://app.wandb.ai/login?signup=true)\n2. create new project in wandb (e.g. \"age-gender-estimation\")\n3. run `wandb login` on terminal and authorize\n4. run training script with `wandb.project=age-gender-estimation` argument\n5. check dashboard!\n\n### Use the trained model\n\n```sh\npython demo.py\n```\n\n```sh\nusage: demo.py [-h] [--weight_file WEIGHT_FILE] [--margin MARGIN]\n               [--image_dir IMAGE_DIR]\n\nThis script detects faces from web cam input, and estimates age and gender for\nthe detected faces.\n\noptional arguments:\n  -h, --help            show this help message and exit\n  --weight_file WEIGHT_FILE\n                        path to weight file (e.g. weights.28-3.73.hdf5)\n                        (default: None)\n  --margin MARGIN       margin around detected face for age-gender estimation\n                        (default: 0.4)\n  --image_dir IMAGE_DIR\n                        target image directory; if set, images in image_dir\n                        are used instead of webcam (default: None)\n```\n\nPlease use the best model among `checkpoints/*.hdf5` for `WEIGHT_FILE` if you use your own trained models.\n\n\n\n### Estimated results\nTrained on imdb, tested on wiki.\n![](https://github.com/yu4u/age-gender-estimation/wiki/images/result.png)\n\n\n### Evaluation\n\n#### Evaluation on the APPA-REAL dataset\nYou can evaluate a trained model on the APPA-REAL (validation) dataset by:\n\n```bash\npython evaluate_appa_real.py --weight_file WEIGHT_FILE\n```\n\nPlease refer to [here](appa-real) for the details of the APPA-REAL dataset.\n\nThe results of trained model is:\n\n```\nMAE Apparent: 5.33\nMAE Real: 6.22\n```\n\nThe best result reported in [5] is:\n\n```\nMAE Apparent: 4.08\nMAE Real: 5.30\n```\n\nPlease note that the above result was achieved by finetuning the model using the training set of the APPA-REAL dataset.\n\n## License\nThis project is released under the MIT license.\nHowever, [the IMDB-WIKI dataset](https://data.vision.ee.ethz.ch/cvl/rrothe/imdb-wiki/) used in this project is originally provided under the following conditions.\n\n\u003e Please notice that this dataset is made available for academic research purpose only. All the images are collected from the Internet, and the copyright belongs to the original owners. If any of the images belongs to you and you would like it removed, please kindly inform us, we will remove it from our dataset immediately.\n\nTherefore, the pretrained model(s) included in this repository is restricted by these conditions (available for academic research purpose only).\n\n\n## References\n[1] R. Rothe, R. Timofte, and L. V. Gool, \"DEX: Deep EXpectation of apparent age from a single image,\" in Proc. of ICCV, 2015.\n\n[2] R. Rothe, R. Timofte, and L. V. Gool, \"Deep expectation of real and apparent age from a single image\nwithout facial landmarks,\" in IJCV, 2016.\n\n[3] H. Zhang, M. Cisse, Y. N. Dauphin, and D. Lopez-Paz, \"mixup: Beyond Empirical Risk Minimization,\" in arXiv:1710.09412, 2017.\n\n[4] Z. Zhong, L. Zheng, G. Kang, S. Li, and Y. Yang, \"Random Erasing Data Augmentation,\" in arXiv:1708.04896, 2017.\n\n[5] E. Agustsson, R. Timofte, S. Escalera, X. Baro, I. Guyon, and R. Rothe, \"Apparent and real age estimation in still images with deep residual regressors on APPA-REAL database,\" in Proc. of FG, 2017.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyu4u%2Fage-gender-estimation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyu4u%2Fage-gender-estimation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyu4u%2Fage-gender-estimation/lists"}