Need help with Additive-Margin-Softmax?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

461 Stars 154 Forks 91 Commits 14 Opened issues


This is the implementation of paper <Additive Margin Softmax for Face Verification>

Services available


Need anything else?

Contributors list

# 51,772
81 commits


This is the implementation of paper <Additive Margin Softmax for Face Verification>

Training logic is highly inspired by Sandberg's Facenet, check it if you are interested.

model structure can be found at ./models/ and loss head can be found at


Step1: Align Dataset

See folder "align", this totally forked from insightface. The default image size is (112,96), in this repository, all trained faces share same size (112,96). Use align code to align your train data and validation data (like lfw) first. You can use to align both training set and lfw, don't worry about others like aligninsight, aligndlib. ``` python --input-dir [train data dir] --output-dir [aligned output dir] ```

Step2: Train AM-softmax

Read parse_arguments() function carefully to confiure parameters. If you are new in face recognition, after aligning dataset, simply run this code, the default settings will help you solve the rest.

python --data_dir [aligned train data] --random_flip --learning_rate -1 --learning_rate_schedule_file ./data/learning_rate_AM_softmax.txt --lfw_dir [aligned lfw data] --keep_probability 0.8 --weight_decay 5e-4
Also watch out that acc on lfw is not from cross validation. Read source code for more detail. Thanks Sandberg again for his extraordinary code.


| Date | Update | |----------|--------| | 2018-02-11 | Currently it only reaches 97.6%. There might be some bugs, or some irregular preprocessings, when it reaches > 99%, detail configuration will be posted here. | | 2018-02-14 | Now acc on lfw reaches 99.3% with only use resface36 and flipped-concatenate validation. | | 2018-02-15 | After fixing bugs in training code, finally resface20 can reach 99.33% which only took 4 hours to converge. Notice:This model is trained on vggface2 without removing overlaps between vggface2 and lfw, so the performance is little higher than reported in orginal paper 98.98%(m=0.35) which trained on casia whose overlaps with lfw are removed.| | 2018-02-17 | Using L-Resnet50E-IR which was proposed in this paper can reach 99.42%. Also I noticed that alignment method is crucial to accuracy. The quality of alignment algorithm might be the bottleneck of modern face recognition system.| | 2018‑02‑28 | Just for fun, I tried m=0.2 with Resface20, acc on lfw reaches 99.47%. All experimens that I've done used AdamOptimizer without weight decay, SGD(with/without momentum) or RMSProp actually performed really bad in my experiments. My assumption is the difference of implementation of optimizer inside different frameworks (e.g. caffe and tf). | | 2018-03-05 | Add training logic and align code.| | 2018-04-17 | Fix bugs in evaluation code. Upload new/deeper model "LRenet50EIR" proposed in insightface which performs better than resface20 and 36.| | 2018-08-29 | Recently I revisiting this code and found that "weightdecay" settings for last fc layer is wrong, which lead to previous weird experiment conclusion. Now it's been fixed. And to follow standard evaluation protocal on lfw, evaluation code has been modified. The latest experiment result is updated here: Resface20(bn) + vggface2 + weightdecay5e-4 + batchsize256 + momentum achieves 0.995+-0.003 on lfw. Further more, with this code, it's easy to use some deeper models to achieve 99.7%+ on lfw. One big problem of this code is that it will load the name list of all images in cache at the begining, which will take very huge memory space. Also current dataset are composed of so small image files which will lead to low efficiency when load and transmit them. Thus tfrecord is recommanded to speed up training process. |

lfw accuracy

Adam w/o weight_decay: img

Momemtum with weightdecay: See ./tfboard/resface20mom_weightdecay.png

My Chinese blog about Face Recognition system
It includes the experimental details of this repo. Welcome and share your precious advice!

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.