Sphereface
Implementation for <SphereFace: Deep Hypersphere Embedding for Face Recognition> in CVPR'17.
Install / Use
/learn @wy1iu/SpherefaceREADME
SphereFace: Deep Hypersphere Embedding for Face Recognition
By Weiyang Liu, Yandong Wen, Zhiding Yu, Ming Li, Bhiksha Raj and Le Song
License
SphereFace is released under the MIT License (refer to the LICENSE file for details).
Update
-
2022.4.10: If you are looking for an easy-to-use and well-performing PyTorch implementation of SphereFace, we now have it! Check out our official SphereFace PyTorch re-implementation here.
-
2018.8.14: We recommand an interesting ECCV 2018 paper that comprehensively evaluates SphereFace (A-Softmax) on current widely used face datasets and their proposed noise-controlled IMDb-Face dataset. Interested users can try to train SphereFace on their IMDb-Face dataset. Take a look here.
-
2018.5.23: A new SphereFace+ that explicitly enhances the inter-class separability has been introduced in our technical report. Check it out here. Code is released here.
-
2018.2.1: As requested, the prototxt files for SphereFace-64 are released.
-
2018.1.27: We updated the appendix of our SphereFace paper with useful experiments and analysis. Take a look here. The content contains:
- The intuition of removing the last ReLU;
- Why do we want to normalize the weights other than because we need more geometric interpretation?
- Empirical experiment of zeroing out the biases;
- More 2D visualization of A-Softmax loss on MNIST;
- Angular Fisher score for evaluating the angular feature discriminativeness, which is a new and straightforward evluation metric other than the final accuracy.
- Experiments of SphereFace on MegaFace with different convolutional layers;
- The annealing optimization strategy for A-Softmax loss;
- Details of the 3-patch ensemble strategy in MegaFace challenge;
-
2018.1.20: We updated some resources to summarize the current advances in angular margin learning. Take a look here.
Contents
- Introduction
- Citation
- Requirements
- Installation
- Usage
- Models
- Results
- Video Demo
- Note
- Third-party re-implementation
- Resources for angular margin learning
Introduction
The repository contains the entire pipeline (including all the preprocessings) for deep face recognition with SphereFace. The recognition pipeline contains three major steps: face detection, face alignment and face recognition.
SphereFace is a recently proposed face recognition method. It was initially described in an arXiv technical report and then published in CVPR 2017. The most up-to-date paper with more experiments can be found at arXiv or here. To facilitate the face recognition research, we give an example of training on CAISA-WebFace and testing on LFW using the 20-layer CNN architecture described in the paper (i.e. SphereFace-20).
In SphereFace, our network architecures use residual units as building blocks, but are quite different from the standrad ResNets (e.g., BatchNorm is not used, the prelu replaces the relu, different initializations, etc). We proposed 4-layer, 20-layer, 36-layer and 64-layer architectures for face recognition (details can be found in the paper and prototxt files). We provided the 20-layer architecure as an example here. If our proposed architectures also help your research, please consider to cite our paper.
SphereFace achieves the state-of-the-art verification performance (previously No.1) in MegaFace Challenge under the small training set protocol.
Citation
If you find SphereFace useful in your research, please consider to cite:
@InProceedings{Liu_2017_CVPR,
title = {SphereFace: Deep Hypersphere Embedding for Face Recognition},
author = {Liu, Weiyang and Wen, Yandong and Yu, Zhiding and Li, Ming and Raj, Bhiksha and Song, Le},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2017}
}
Our another closely-related previous work in ICML'16 (more):
@InProceedings{Liu_2016_ICML,
title = {Large-Margin Softmax Loss for Convolutional Neural Networks},
author = {Liu, Weiyang and Wen, Yandong and Yu, Zhiding and Yang, Meng},
booktitle = {Proceedings of The 33rd International Conference on Machine Learning},
year = {2016}
}
Requirements
- Requirements for
Matlab - Requirements for
Caffeandmatcaffe(see: Caffe installation instructions) - Requirements for
MTCNN(see: MTCNN - face detection & alignment) andPdollar toolbox(see: Piotr's Image & Video Matlab Toolbox).
Installation
-
Clone the SphereFace repository. We'll call the directory that you cloned SphereFace as
SPHEREFACE_ROOT.git clone --recursive https://github.com/wy1iu/sphereface.git -
Build Caffe and matcaffe
cd $SPHEREFACE_ROOT/tools/caffe-sphereface # Now follow the Caffe installation instructions here: # http://caffe.berkeleyvision.org/installation.html make all -j8 && make matcaffe
Usage
After successfully completing the installation, you are ready to run all the following experiments.
Part 1: Preprocessing
Note: In this part, we assume you are in the directory $SPHEREFACE_ROOT/preprocess/
-
Download the training set (
CASIA-WebFace) and test set (LFW) and place them indata/.mv /your_path/CASIA_WebFace data/ ./code/get_lfw.sh tar xvf data/lfw.tgz -C data/Please make sure that the directory of
data/contains two datasets. -
Detect faces and facial landmarks in CAISA-WebFace and LFW datasets using
MTCNN(see: MTCNN - face detection & alignment).# In Matlab Command Window run code/face_detect_demo.mThis will create a file
dataList.matin the directory ofresult/. -
Align faces to a canonical pose using similarity transformation.
# In Matlab Command Window run code/face_align_demo.mThis will create two folders (
CASIA-WebFace-112X96/andlfw-112X96/) in the directory ofresult/, containing the aligned face images.
Part 2: Train
Note: In this part, we assume you are in the directory $SPHEREFACE_ROOT/train/
-
Get a list of training images and labels.
mv ../preprocess/result/CASIA-WebFace-112X96 data/ # In Matlab Command Window run code/get_list.mThe aligned face images in folder
CASIA-WebFace-112X96/are moved from preprocess folder to train folder. A listCASIA-WebFace-112X96.txtis created in the directory ofdata/for the subsequent training. -
Train the sphereface model.
./code/sphereface_train.sh 0,1After training, a model
sphereface_model_iter_28000.caffemodeland a corresponding log filesphereface_train.logare placed in the directory ofresult/sphereface/.
Part 3: Test
Note: In this part, we assume you are in the directory $SPHEREFACE_ROOT/test/
-
Get the pair list of LFW (view 2).
mv ../preprocess/result/lfw-112X96 data/ ./code/get_pairs.shMake sure that the LFW dataset and
pairs.txtin the directory ofdata/ -
Extract deep features and test on LFW.
# In Matlab Command Window run code/evaluation.mFinally we have the
sphereface_model.caffemodel, extracted featurespairs.matin folderresult/, and accuracy on LFW like this:fold|1|2|3|4|5|6|7|8|9|10|AVE :---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---:|:---: ACC|99.33%|99.17%|98.83%|99.50%|99.17%|99.83%|99.17%|98.83%|99.83%|99.33%|99.30%
Models
- Visualizations of network architecture (tools from ethereon):
- SphereFace-20: link
- Model file
- SphereFace-20: Google Drive | Baidu
- Third-party SphereFace-4 & SphereFace-6: here by zuoqing1988
Results
-
Following the instruction, we go through the entire pipeline for 5 times. The accuracies on LFW are shown below. Generally, we report the average but we release the model-3 here.
Experiment |#1|#2|#3 (released)|#4|#5 :---:|:---:|:---:|:---:|:---:|:---: ACC|99.24%|99.20%|99.30%|99.27%|99.13%
-
Other intermediate results:
- LFW features: Google Drive | Baidu
- Training log: Google Drive | Baidu
V
Related Skills
best-practices-researcher
The most comprehensive Claude Code skills registry | Web Search: https://skills-registry-web.vercel.app
groundhog
399Groundhog's primary purpose is to teach people how Cursor and all these other coding agents work under the hood. If you understand how these coding assistants work from first principles, then you can drive these tools harder (or perhaps make your own!).
codebase-to-course
Turn any codebase into a beautiful, interactive single-page HTML course that teaches how the code works to non-technical people. Use this skill whenever someone wants to create an interactive course, tutorial, or educational walkthrough from a codebase or project. Also trigger when users mention 'turn this into a course,' 'explain this codebase interactively,' 'teach this code,' 'interactive tutorial from code,' 'codebase walkthrough,' 'learn from this codebase,' or 'make a course from this project.' This skill produces a stunning, self-contained HTML file with scroll-based navigation, animated visualizations, embedded quizzes, and code-with-plain-English side-by-side translations.
academic-pptx
Use this skill whenever the user wants to create or improve a presentation for an academic context — conference papers, seminar talks, thesis defenses, grant briefings, lab meetings, invited lectures, or any presentation where the audience will evaluate reasoning and evidence. Triggers include: 'conference talk', 'seminar slides', 'thesis defense', 'research presentation', 'academic deck', 'academic presentation'. Also triggers when the user asks to 'make slides' in combination with academic content (e.g., 'make slides for my paper on X', 'create a presentation for my dissertation defense', 'build a deck for my grant proposal'). This skill governs CONTENT and STRUCTURE decisions. For the technical work of creating or editing the .pptx file itself, also read the pptx SKILL.md.
