{"id":13435747,"url":"https://github.com/peteryuX/retinaface-tf2","last_synced_at":"2025-03-18T11:32:13.043Z","repository":{"id":39854685,"uuid":"237585935","full_name":"peteryuX/retinaface-tf2","owner":"peteryuX","description":"RetinaFace (Single-stage Dense Face Localisation in the Wild, 2019) implemented (ResNet50, MobileNetV2 trained on single GPU) in Tensorflow 2.0+. This is an unofficial implementation. With Colab.","archived":false,"fork":false,"pushed_at":"2023-03-24T22:36:41.000Z","size":1336,"stargazers_count":270,"open_issues_count":28,"forks_count":97,"subscribers_count":12,"default_branch":"master","last_synced_at":"2024-10-27T18:59:06.269Z","etag":null,"topics":["colab","colab-notebook","face-detection","facedetection","mobilenetv2","resnet-50","retinaface","retinaface-detector","tensorflow","tensorflow2","tf2"],"latest_commit_sha":null,"homepage":"","language":"Python","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/peteryuX.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-02-01T08:36:01.000Z","updated_at":"2024-08-19T07:58:31.000Z","dependencies_parsed_at":"2024-05-02T04:59:23.067Z","dependency_job_id":"7406ae0e-bd15-47df-a1c7-f8549a1ac934","html_url":"https://github.com/peteryuX/retinaface-tf2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peteryuX%2Fretinaface-tf2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peteryuX%2Fretinaface-tf2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peteryuX%2Fretinaface-tf2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peteryuX%2Fretinaface-tf2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peteryuX","download_url":"https://codeload.github.com/peteryuX/retinaface-tf2/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244211158,"owners_count":20416589,"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":["colab","colab-notebook","face-detection","facedetection","mobilenetv2","resnet-50","retinaface","retinaface-detector","tensorflow","tensorflow2","tf2"],"created_at":"2024-07-31T03:00:38.623Z","updated_at":"2025-03-18T11:32:08.029Z","avatar_url":"https://github.com/peteryuX.png","language":"Python","funding_links":[],"categories":["Sample Codes / Projects \u003ca name=\"sample\" /\u003e ⛏️📐📁"],"sub_categories":["Reinforcement Learning \u003ca name=\"RL\" /\u003e🔮"],"readme":"# [retinaface-tf2](https://github.com/peteryuX/retinaface-tf2)\n\n[![Language grade: Python](https://img.shields.io/lgtm/grade/python/g/peteryuX/retinaface-tf2.svg?logo=lgtm\u0026logoWidth=18)](https://lgtm.com/projects/g/peteryuX/retinaface-tf2/context:python)\n![Star](https://img.shields.io/github/stars/peteryuX/retinaface-tf2)\n![Fork](https://img.shields.io/github/forks/peteryuX/retinaface-tf2)\n![License](https://img.shields.io/github/license/peteryuX/retinaface-tf2)\n\n[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/peteryuX/retinaface-tf2/blob/master/notebooks/colab-github-demo.ipynb)\n\n:fire: RetinaFace (RetinaFace: Single-stage Dense Face Localisation in the Wild, published in 2019) implemented (ResNet50, MobileNetV2 trained on single GPU) in Tensorflow 2.0+. This is an unofficial implementation. :fire:\n\n\u003e RetinaFace presents a robust single-stage face detector, which performs pixel-wise face localisation on various scales of faces by taking advantages of joint extra-supervised and self-supervised multi-task learning(manually annotate five facial landmarks on the WIDER FACE). On the WIDER FACE hard test set, RetinaFace outperforms the state of the art average precision (AP) by 1.1% (achieving AP equal to 91.4%).\n\nOriginal Paper: \u0026nbsp; [Arxiv](https://arxiv.org/abs/1905.00641)\n\nOffical Implementation: \u0026nbsp; [MXNet](https://github.com/deepinsight/insightface/tree/master/RetinaFace)\n\n:: Results from this reporepository. ::\n\u003cimg src=\"photo/0_Parade_marchingband_1_149.jpg\"\u003e\n\n****\n\n## Contents\n:bookmark_tabs:\n\n* [Installation](#Installation)\n* [Data Preparing](#Data-Preparing)\n* [Training and Testing](#Training-and-Testing)\n* [Benchmark](#Benchmark)\n* [Models](#Models)\n* [References](#References)\n\n***\n\n## Installation\n:pizza:\n\nCreate a new python virtual environment by [Anaconda](https://www.anaconda.com/) or just use pip in your python environment and then clone this repository as following.\n\n### Clone this repo\n```bash\ngit clone https://github.com/peteryuX/retinaface-tf2.git\ncd retinaface-tf2\n```\n\n### Conda\n```bash\nconda env create -f environment.yml\nconda activate retinaface-tf2\n```\n\n### Pip\n\n```bash\npip install -r requirements.txt\n```\n\n****\n\n## Data Preparing\n:beer:\n\n**Step 1**: Download the [WIDER FACE](http://shuoyang1213.me/WIDERFACE/index.html) dataset images from the download links bellow.\n\n| Dataset Name | Link |\n|:------------:|:----------:|\n| WIDER Face Training Images | [Google Drive](https://drive.google.com/file/d/0B6eKvaijfFUDQUUwd21EckhUbWs/view?usp=sharing) |\n| WIDER Face Validation Images | [Google Drive](https://drive.google.com/file/d/0B6eKvaijfFUDd3dIRmpvSk8tLUk/view?usp=sharing) |\n\n**Step 2**: Download the [Retinaface official annotations](https://github.com/deepinsight/insightface/tree/master/RetinaFace#Data) (face bounding boxes \u0026 five facial landmarks) from the download links bellow.\n\n| Dataset Name | Link |\n|:------------:|:----------:|\n| Retinaface Annotations | [Google Drive](https://drive.google.com/file/d/1vgCABX1JI3NGBzsHxwBXlmRjaLV3NIsG/view?usp=sharing) / [Dropbox](https://www.dropbox.com/s/7j70r3eeepe4r2g/retinaface_gt_v1.1.zip?dl=0) |\n\n**Step 3**: Extract downloaded files into `./data/widerface/`. The directory structure should be like bellow.\n```\n./data/widerface/\n    train/\n        images/\n        label.txt\n    val/\n        images/\n        label.txt\n```\n\n**Step 4**: Convert the training images and annotations to tfrecord file with the the script bellow.\n```bash\n# Binary Image (recommend): need additional space\npython data/convert_train_tfrecord.py --output_path=\"./data/widerface_train_bin.tfrecord\" --is_binary=True\n# Online Image Loading:\npython data/convert_train_tfrecord.py --output_path=\"./data/widerface_train.tfrecord\" --is_binary=False\n```\n\nNote:\n- You can run `python ./dataset_checker.py` to check if the dataloader work. Please modify the inside setting (in [./dataset_checker.py](https://github.com/peteryuX/retinaface-tf2/blob/master/dataset_checker.py)) for different situations.\n\n****\n\n## Training and Testing\n:lollipop:\n\n### Config File\nYou can modify your own dataset path or other settings of model in [./configs/*.yaml](https://github.com/peteryuX/retinaface-tf2/tree/master/configs) for training and testing, which like below.\n\n```python\n# general setting\nbatch_size: 8\ninput_size: 640\nbackbone_type: 'ResNet50'  # 'ResNet50', 'MobileNetV2'\nsub_name: 'retinaface_res50'\n\n# training dataset\ndataset_path: './data/widerface_train_bin.tfrecord'\ndataset_len: 12880  # number of training samples\nusing_bin: True\nusing_flip: True\nusing_distort: True\n\n# testing dataset\ntesting_dataset_path: './data/widerface/val'\n\n# network\nout_channel: 256\n\n# anchor setting\nmin_sizes: [[16, 32], [64, 128], [256, 512]]\nsteps: [8, 16, 32]\nmatch_thresh: 0.45\nignore_thresh: 0.3\nvariances: [0.1, 0.2]\nclip: False\n\n# training setting\nepoch: 100\ninit_lr: !!float 1e-2\nlr_decay_epoch: [50, 68]\nlr_rate: 0.1\nwarmup_epoch: 5\nmin_lr: !!float 1e-3\n\nweights_decay: !!float 5e-4\nmomentum: 0.9\n\npretrain: True\n\nsave_steps: 2000\n```\n\nNote:\n- The `sub_name` is the name of outputs directory used in checkpoints and logs folder. (make sure of setting it unique to other models)\n- The `using_bin` is used to choose the type of training data, which should be according to the data type you created in the [Data-Preparing](#Data-Preparing).\n- The `save_steps` is the number interval steps of saving checkpoint file.\n\n### Training\n\nTrain the Retinaface model by yourself, or dowload it from [BenchmarkModels](#Models).\n```bash\n# train ResNet50 backbone model\npython train.py --cfg_path=\"./configs/retinaface_res50.yaml\" --gpu=0\n# or train MobileNetV2 backbone model\npython train.py --cfg_path=\"./configs/retinaface_mbv2.yaml\" --gpu=0\n```\n\nNote:\n- The `--gpu` is used to choose the id of your avaliable GPU devices with `CUDA_VISIBLE_DEVICES` system varaible.\n- You can visualize the learning rate scheduling by running \"`python ./modules/lr_scheduler.py`\".\n\n### Testing on [WIDER FACE](http://shuoyang1213.me/WIDERFACE/index.html) Validation Set\n\nYou can download my trained models for testing from [Models](#Models) without training it yourself. And, evaluate the models you got with the corresponding cfg file on the testing dataset.\n\n**Step 1**: Produce txt results and visualizations from model.\n```bash\n# Test ResNet50 backbone model\npython test_widerface.py --cfg_path=\"./configs/retinaface_res50.yaml\" --gpu=0\n# or\n# Test ResNet50 backbone model\npython test_widerface.py --cfg_path=\"./configs/retinaface_mbv2.yaml\" --gpu=0\n```\n\nNote:\n- The visualizations results would be saved into `./results/`.\n\n**Step 2**: Evaluate txt results. (Codes come from [Here](https://github.com/wondervictor/WiderFace-Evaluation))\n```bash\ncd ./widerface_evaluate\npython setup.py build_ext --inplace\npython evaluation.py\n```\n\n### Detect on Input Image\n\nYou can detect on your image by the model. For example, detect on the image from [./data/0_Parade_marchingband_1_149.jpg](https://github.com/peteryuX/retinaface-tf2/blob/master/data/0_Parade_marchingband_1_149.jpg) as following.\n\n```bash\npython test.py --cfg_path=\"./configs/retinaface_res50.yaml\" --img_path=\"./data/0_Parade_marchingband_1_149.jpg\" --down_scale_factor=1.0\n# or\npython test.py --cfg_path=\"./configs/retinaface_mbv2.yaml\" --img_path=\"./data/0_Parade_marchingband_1_149.jpg\" --down_scale_factor=1.0\n```\n\nNote:\n- You can down scale your input by the `--down_scale_factor`.\n\n### Demo on Webcam\n\nDemo face detection on your webcam.\n```bash\npython test.py --cfg_path=\"./configs/retinaface_res50.yaml\" --webcam=True --down_scale_factor=1.0\n# or\npython test.py --cfg_path=\"./configs/retinaface_mbv2.yaml\" --webcam=True --down_scale_factor=1.0\n```\n\n****\n\n## Benchmark\n:coffee:\n\n### WiderFace Validation Set Performance in single scale\n\n| Model Name          | Easy   | Medium | Hard   |\n|---------------------|--------|--------|--------|\n| Tensorflow2 MobileNetV2 | 93.23% | 91.74% | 80.01% |\n| Tensorflow2 ResNet50 | 94.21% | 93.25% | 83.55% |\n| [Pytorch ResNet50](https://github.com/biubug6/Pytorch_Retinaface) | 95.48% | 94.04% | 84.43% |\n| [Mxnet ResNet50 (Official)](https://github.com/deepinsight/insightface/tree/master/RetinaFace) | 94.97% | 93.89% | 82.27% |\n****\n\nNote:\n- Tensorflow2 version (ResNet50/MobileNetV2) in this repository only trained with batch size (8/16) on single GPU.\n- All models evaluate on original image scale.\n\n## Models\n:doughnut:\n\n| Model Name          | Download Link |\n|---------------------|---------------|\n| Retinaface ResNet50 | [GoogleDrive](https://drive.google.com/file/d/1qnuci2BVUNH3fqVqQYCoub4Wd2gShld9/view?usp=sharing) |\n| Retinaface MobileNetV2 | [GoogleDrive](https://drive.google.com/file/d/16HBH2bpSY3TQ_STryWFe72CIcUzp6GRy/view?usp=sharing) |\n\nNote:\n- After dowloading these models, extract them into `./checkpoints` for restoring.\n- All training settings of the models can be found in the corresponding [./configs/*.yaml](https://github.com/peteryuX/retinaface-tf2/tree/master/configs) files.\n- You can see the tensorboard traning logs in [here](https://tensorboard.dev/experiment/2Jr2OUjpS2CWr9SySPK2tQ/#scalars).\n- **Based on the property of the training dataset, all the pre-trained models can only be used for non-commercial applications.**\n\n****\n\n## References\n:hamburger:\n\nThanks for these source codes porviding me with knowledges to complete this repository.\n\n- https://github.com/deepinsight/insightface/tree/master/detection/retinaface (Official)\n    - Face Analysis Project on MXNet http://insightface.ai\n- https://github.com/biubug6/Pytorch_Retinaface\n    - Retinaface get 80.99% in widerface hard val using mobilenet0.25.\n- https://github.com/wondervictor/WiderFace-Evaluation\n    - Python Evaluation Code for Wider Face Dataset\n- https://github.com/zzh8829/yolov3-tf2\n    - YoloV3 Implemented in TensorFlow 2.0\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FpeteryuX%2Fretinaface-tf2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FpeteryuX%2Fretinaface-tf2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FpeteryuX%2Fretinaface-tf2/lists"}