{"id":13564729,"url":"https://github.com/luckycallor/InsightFace-tensorflow","last_synced_at":"2025-04-03T21:31:30.471Z","repository":{"id":217501363,"uuid":"166962331","full_name":"luckycallor/InsightFace-tensorflow","owner":"luckycallor","description":"Tensoflow implementation of InsightFace (ArcFace: Additive Angular Margin Loss for Deep Face Recognition).","archived":false,"fork":false,"pushed_at":"2019-05-24T08:15:15.000Z","size":27,"stargazers_count":248,"open_issues_count":43,"forks_count":112,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-11-04T17:48:01.470Z","etag":null,"topics":["face-recognition","python","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luckycallor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-01-22T09:06:52.000Z","updated_at":"2024-06-25T11:58:30.000Z","dependencies_parsed_at":null,"dependency_job_id":"94c9707c-c150-4039-8e2b-56103ef58dbe","html_url":"https://github.com/luckycallor/InsightFace-tensorflow","commit_stats":null,"previous_names":["luckycallor/insightface-tensorflow"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckycallor%2FInsightFace-tensorflow","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckycallor%2FInsightFace-tensorflow/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckycallor%2FInsightFace-tensorflow/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luckycallor%2FInsightFace-tensorflow/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luckycallor","download_url":"https://codeload.github.com/luckycallor/InsightFace-tensorflow/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247083409,"owners_count":20880835,"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":["face-recognition","python","tensorflow"],"created_at":"2024-08-01T13:01:35.120Z","updated_at":"2025-04-03T21:31:30.047Z","avatar_url":"https://github.com/luckycallor.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"# InsightFace-tensorflow\n\nThis is a tensorflow implementation of paper \"[ArcFace: Additive Angular Margin Loss for Deep Face Recognition](https://arxiv.org/abs/1801.07698)\". This implementation aims at making both usage of pretrained model and training of your own model easier. Whether you just want to use pretrained model to do face recognition/verification or you want train/finetune your own model, this project can give you a favor. An introduction on face recognition losses can be found [here](https://luckycallor.xyz/20190123/FaceLosses.html)(in Chinese).\n\nThe implementation referred to [the official implementation in mxnet](https://github.com/deepinsight/insightface) and [the previous third-party implementation in tensorflow](https://github.com/auroua/InsightFace_TF).\n\n- [InsightFace-tensorflow](#insightface-tensorflow)\n  - [TODO List](#todo-list)\n  - [Running Environment](#running-environment)\n  - [Usage of Pretrained Model](#usage-of-pretrained-model)\n    - [Pretrained Model](#pretrained-model)\n    - [Model Evaluation](#model-evaluation)\n    - [Extract Embedding with Pretrained Model](#extract-embedding-with-pretrained-model)\n  - [Train Your Own Model](#train-your-own-model)\n    - [Data Prepare](#data-prepare)\n    - [Train with Softmax](#train-with-softmax)\n    - [Finetune with Softmax](#finetune-with-softmax)\n\n## TODO List\n\n1. *Train with softmax [done!]*\n2. *Model evaluation [done!]*\n3. *Finetune with softmax [done!]*\n4. *Get embedding with pretrained model [done!]*\n5. **Train with triplet loss [todo]**\n6. **Finetune with triplet loss [todo]**\n7. Backbones    \n   7.1 *ResNet [done!]*    \n   7.2 **ResNeXt [todo]**    \n   7.3 **DenseNet [todo]**    \n8. Losses    \n   8.1 *Arcface loss [done!]*    \n   8.2 **Cosface loss [todo]**    \n   8.3 **Sphereface loss [todo]**    \n   8.4 **Triplet loss [todo]**\n9.  **Face detection and alignment [todo]**\n\n## Running Environment\n\n- python 3.6 \n- scipy, numpy (Anaconda 3 recommended)\n- tensorflow 1.7.0\n- mxnet 1.3.1 (only needed when reading mxrec file)\n\n## Usage of Pretrained Model\n\nHere we open our pretrained models for easier application of face recognition or verification. Codes on model evaluation and extracting embedding from face images are supplied.\n\n### Pretrained Model\n\nPretrained models and their accuracies on validation datasets are shown as following:\n\n|config|lfw|calfw|cplfw|agedb_30|cfp_ff|cfp_fp|vgg2_fp|steps|download|\n|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|:----:|\n|[ms1m_100](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/configs/config_ms1m_100.yaml)|99.53%|93.92%|87.85%|94.18%|99.29%|94.73%|93.9%|334k|[baidu](https://pan.baidu.com/s/1Zr91ZYWTXJDlG63XLqNdzQ)|\n|[ms1m_100](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/configs/config_ms1m_100.yaml)|99.53%|94.68%|89.75%|95.20%|99.54%|96.30%|94.84%|1006k|[baidu](https://pan.baidu.com/s/1v1L3c7cEs_GyqPYH9WhNKA), [google](https://drive.google.com/open?id=107Qu56o1IwQxH61Q6smZk-DO2-xU6EwE)|\n|[ms1m_200](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/configs/config_ms1m_200.yaml)|99.43%|94.40%|88.23%|94.58%|99.29%|94.77%|93.9%|200k|[baidu](https://pan.baidu.com/s/1q3kXkhjtclXD-eQgZC5gBA)|\n\n### Model Evaluation\n\nYou can evaluate a pretrained model with [evaluate.py](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/evaluate.py) by specifying the config path and model path, for example:\n\n```\npython evaluate.py \n--config_path=./configs/config_ms1m_100.yaml \n--model_path=$DIRECTORY_TO_PRETRAINED_MODEL$/best-m-150000\n```\n\nThis will evaluate the pretrained model on validation datasets specified in the config file. If you want to evaluate the model on other validation dataset, you can specify it by --val_data as following:\n\n```\npython evaluate.py \n--config_path=./configs/config_ms1m_100.yaml \n--model_path=$DIRECTORY_TO_PRETRAINED_MODEL$/best-m-150000 \n--val_data=$DIRECTORY_TO_VAL_DATA$/xxx.bin\n```\n\n### Extract Embedding with Pretrained Model\n\nYou can extract embedding from face images with [get_embd.py](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/get_embd.py) by the following script:\n\n```\npython get_embd.py \n--config_path=./configs/config_ms1m_100.yaml \n--model_path=$DIRECTORY_TO_PRETRAINED_MODEL$/best-m-150000 \n--read_path=$PATH_TO_FACE_IMAGES$\n--save_path=$SAVING_DIRECTORY$/embd.pkl\n```\n\nwhere config_path and model_path specify the config file and pretrained model respectively. read_path is path to face images, that can be a path to one image or a directory with only images in it. save_path specifies where to save the embedding. The saved file is a dict with image file name as key, the corresponding embedding as value, and can be loaded with pickle in python. Note that face images should be well cropped here.\n\n## Train Your Own Model\n\nIf you want train your own model from scratch, or finetune pretrained model with your own data, here is what you should do.\n\n### Data Prepare\n\nThe official InsightFace project open their training data in the [DataZoo](https://github.com/deepinsight/insightface/wiki/Dataset-Zoo). This data is in mxrec format, you can transform it to tfrecord format with [./data/generateTFRecord.py](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/data/generateTFRecord.py) by the following script:\n\n```\npython generateTFRecord.py \n--mode=mxrec\n--image_size=112\n--read_dir=$DIRECTORY_TO_THE_TRAINING_DATA$\n--save_path=$DIRECTORY_TO_SAVE_TFRECORD_FILE$/xxx.tfrecord\n```\n\nOr, if you want to train the model with your own data, you can prepare the tfrecord file by the following script:\n\n```\npython generateTFRecord.py \n--mode=folders\n--image_size=112\n--read_dir=$DIRECTORY_TO_THE_TRAINING_DATA$\n--save_path=$DIRECTORY_TO_SAVE_TFRECORD_FILE$/xxx.tfrecord\n```\n\nHere, the read_dir should be the directory to your own face images, where images to one person are saved in one folder. The directory should have a structure like this:\n\n```\nread_dir/\n  - id1/\n    -- id1_1.jpg\n    ...\n  - id2/\n    -- id2_1.jpg\n    ...\n  - id3/\n    -- id3_1.jpg\n    -- id3_2.jpg\n    ...\n  ...\n```\n\n### Train with Softmax\n\nTo train your own model with softmax, firstly you should prepare a config file like those in [./configs](https://github.com/luckycallor/InsightFace-tensorflow/tree/master/configs). It is recommended to modify one example config file to your own config. Secondly, the following script starts training:\n\n```\npython train_softmax.py --config_path=./configs/config_ms1m_100.yaml\n```\n\n### Finetune with Softmax\n\nTo finetune a pretrained model with your own data, you should prepare a finetune config file like [./configs/config_finetune.yaml](https://github.com/luckycallor/InsightFace-tensorflow/blob/master/configs/config_finetune.yaml), and start training by the following script:\n\n```\npython finetune_softmax.py --config_path=./configs/config_finetune.yaml\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckycallor%2FInsightFace-tensorflow","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluckycallor%2FInsightFace-tensorflow","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluckycallor%2FInsightFace-tensorflow/lists"}