{"id":13443918,"url":"https://github.com/ternaus/retinaface","last_synced_at":"2025-04-12T18:49:28.564Z","repository":{"id":44683059,"uuid":"280950959","full_name":"ternaus/retinaface","owner":"ternaus","description":"The remake of the https://github.com/biubug6/Pytorch_Retinaface","archived":false,"fork":false,"pushed_at":"2023-01-27T01:15:53.000Z","size":325,"stargazers_count":377,"open_issues_count":16,"forks_count":107,"subscribers_count":16,"default_branch":"master","last_synced_at":"2024-05-01T15:48:54.035Z","etag":null,"topics":["deeplearning","face-detection","object-detection","pytorch","retinaface"],"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/ternaus.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":null,"patreon":"ternaus","open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":null}},"created_at":"2020-07-19T21:08:51.000Z","updated_at":"2024-04-15T02:54:04.000Z","dependencies_parsed_at":"2023-02-15T03:47:00.833Z","dependency_job_id":null,"html_url":"https://github.com/ternaus/retinaface","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ternaus%2Fretinaface","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ternaus%2Fretinaface/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ternaus%2Fretinaface/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ternaus%2Fretinaface/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ternaus","download_url":"https://codeload.github.com/ternaus/retinaface/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248618218,"owners_count":21134199,"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":["deeplearning","face-detection","object-detection","pytorch","retinaface"],"created_at":"2024-07-31T03:02:13.879Z","updated_at":"2025-04-12T18:49:28.534Z","avatar_url":"https://github.com/ternaus.png","language":"Python","funding_links":["https://patreon.com/ternaus"],"categories":["Python"],"sub_categories":[],"readme":"# Retinaface\n[![DOI](https://zenodo.org/badge/280950959.svg)](https://zenodo.org/badge/latestdoi/280950959)\n\n![https://habrastorage.org/webt/uj/ff/vx/ujffvxxpzixwlmae8gyh7jylftq.jpeg](https://habrastorage.org/webt/uj/ff/vx/ujffvxxpzixwlmae8gyh7jylftq.jpeg)\n\nThis repo is build on top of [https://github.com/biubug6/Pytorch_Retinaface](https://github.com/biubug6/Pytorch_Retinaface)\n\n## Differences\n\n### Train loop moved to [Pytorch Lightning](https://github.com/PyTorchLightning/pytorch-lightning)\n\nIT added a set of functionality:\n\n * Distributed training\n * fp16\n * Syncronized BatchNorm\n * Support for various loggers like [W\u0026B](https://www.wandb.com/) or [Neptune.ml](https://neptune.ai/)\n\n### Hyperparameters are defined in the config file\n\nHyperparameters that were scattered  across the code moved to the config at [retinadace/config](retinadace/config)\n\n### Augmentations =\u003e [Albumentations](https://albumentations.ai/)\n\nColor that were manually implemented replaced by the Albumentations library.\n\nTodo:\n* Horizontal Flip is not implemented in Albumentations\n* Spatial transforms like rotations or transpose are not implemented yet.\n\nColor transforms defined in the config.\n\n### Added mAP calculation for validation\nIn order to track the progress, mAP metric is calculated on validation.\n\n## Installation\n\n`pip install -U retinaface_pytorch`\n\n## Example inference\n\n```python\nimport cv2\nfrom retinaface.pre_trained_models import get_model\n```\n\n`image = \u003cnumpy array with shape (height, width, 3)\u003e`\n\n```python\nmodel = get_model(\"resnet50_2020-07-20\", max_size=2048)\nmodel.eval()\nannotation = model.predict_jsons(image)\n```\n\n* Jupyter notebook with the example: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1wLXZyoybDRKizfcIzxPwkeYp-XDpTM-K?usp=sharing)\n* Jupyter notebook with the example on how to combine face detector with mask detector: [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/13Ktsrx164eQHfDmYLyMCoI-Kq0gC5Kg1?usp=sharing)\n\n## Data Preparation\n\nThe pipeline expects labels in the format:\n\n```\n[\n  {\n    \"file_name\": \"0--Parade/0_Parade_marchingband_1_849.jpg\",\n    \"annotations\": [\n      {\n        \"bbox\": [\n          449,\n          330,\n          571,\n          720\n        ],\n        \"landmarks\": [\n          [\n            488.906,\n            373.643\n          ],\n          [\n            542.089,\n            376.442\n          ],\n          [\n            515.031,\n            412.83\n          ],\n          [\n            485.174,\n            425.893\n          ],\n          [\n            538.357,\n            431.491\n          ]\n        ]\n      }\n    ]\n  },\n```\n\nYou can convert the default labels of the WiderFaces to the json of the propper format with this [script](https://github.com/ternaus/iglovikov_helper_functions/blob/master/iglovikov_helper_functions/data_processing/wider_face/prepare_data.py).\n\n\n## Training\n### Install dependencies\n```\npip install -r requirements.txt\npip install -r requirements_dev.txt\n```\n\n### Define config\nExample configs could be found at [retinaface/configs](retinaface/configs)\n\n### Define environmental variables\n\n```bash\nexport TRAIN_IMAGE_PATH=\u003cpath to train images\u003e\nexport VAL_IMAGE_PATH=\u003cpath to validation images\u003e\nexport TRAIN_LABEL_PATH=\u003cpath to train annotations\u003e\nexport VAL_LABEL_PATH=\u003cpath to validation annotations\u003e\n```\n\n### Run training script\n\n```\npython retinaface/train.py -h\nusage: train.py [-h] -c CONFIG_PATH\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -c CONFIG_PATH, --config_path CONFIG_PATH\n                        Path to the config.\n\n```\n\n## Inference\n\n```\npython retinaface/inference.py -h\nusage: inference.py [-h] -i INPUT_PATH -c CONFIG_PATH -o OUTPUT_PATH [-v]\n                    [-g NUM_GPUS] [-m MAX_SIZE] [-b BATCH_SIZE]\n                    [-j NUM_WORKERS]\n                    [--confidence_threshold CONFIDENCE_THRESHOLD]\n                    [--nms_threshold NMS_THRESHOLD] -w WEIGHT_PATH\n                    [--keep_top_k KEEP_TOP_K] [--world_size WORLD_SIZE]\n                    [--local_rank LOCAL_RANK] [--fp16]\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i INPUT_PATH, --input_path INPUT_PATH\n                        Path with images.\n  -c CONFIG_PATH, --config_path CONFIG_PATH\n                        Path to config.\n  -o OUTPUT_PATH, --output_path OUTPUT_PATH\n                        Path to save jsons.\n  -v, --visualize       Visualize predictions\n  -g NUM_GPUS, --num_gpus NUM_GPUS\n                        The number of GPUs to use.\n  -m MAX_SIZE, --max_size MAX_SIZE\n                        Resize the largest side to this number\n  -b BATCH_SIZE, --batch_size BATCH_SIZE\n                        batch_size\n  -j NUM_WORKERS, --num_workers NUM_WORKERS\n                        num_workers\n  --confidence_threshold CONFIDENCE_THRESHOLD\n                        confidence_threshold\n  --nms_threshold NMS_THRESHOLD\n                        nms_threshold\n  -w WEIGHT_PATH, --weight_path WEIGHT_PATH\n                        Path to weights.\n  --keep_top_k KEEP_TOP_K\n                        keep_top_k\n  --world_size WORLD_SIZE\n                        number of nodes for distributed training\n  --local_rank LOCAL_RANK\n                        node rank for distributed training\n  --fp16                Use fp6\n```\n\n```\npython -m torch.distributed.launch --nproc_per_node=\u003cnum_gpus\u003e retinaface/inference.py \u003cparameters\u003e\n```\n\n*  [Weights](https://drive.google.com/drive/folders/1DuiwlTd1BbZ0ZzafrV7qMncko1Z5a412?usp=sharing) for the model with [config](retinaface/configs/2020-07-19.yaml).\n*  [Weights](https://drive.google.com/file/d/1slNNW1bntYqDKpvi2r1QfcQAwnhsVw9n/view?usp=sharing) for the model with [config](retinaface/configs/2020-07-20.yaml).\n\n# Web app\nhttps://retinaface.herokuapp.com/\n\nCode for the web app: https://github.com/ternaus/retinaface_demo\n\n### Converting to ONNX\nThe inference could be sped up on CPU by converting the model to ONNX.\n\n```\nEx: python -m converters.to_onnx -m 1280 -o retinaface1280.onnx\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fternaus%2Fretinaface","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fternaus%2Fretinaface","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fternaus%2Fretinaface/lists"}