This is a demo code of training and testing Probabilistic Face Embeddings using Tensorflow. Probabilistic Face Embeddgin (PFE) is a method that converts conventional CNN-based face embeddings into probabilistic embeddings by calibrating each feature value with an uncertainty value. The representation of each face will be an Guassian distribution parametrized by (mu, sigma), where mu is the original embedding and sigma is the learned uncertainty. Experiments show that PFE could improve the performance of face recognition by taking uncertainty into account.
Currently this repo is compatible with Python 3 and Tensorflow r1.9.
- 19/04/2019: Initial Upload.
@article{shi2019PFE,
title = {Probabilistic Face Embeddings},
author = {Shi, Yichun and Jain, Anil K. and Kalka, Nathan D.},
booktitle = {arXiv:1904.09658},
year = {2019}
}
Note: In this section, we assume that you are always in the directory $PROJECT_ROOT/
In this demo, we will use CASIA-WebFace, LFW and IJB-A as examples for training and testing PFEs. In this section, we will align these datasets with the landmarks I pre-extracted.
- Download the original images of CASIA-WebFace dataset and align the images with the following command:
python align/align_dataset.py data/ldmark_casia_mtcnncaffe.txt \ data/casia_mtcnncaffe_aligned \ --prefix /path/to/CASIA-Webface/images \ --transpose_input --image_size 96 112
- Download the original images of LFW dataset and align the images with the following command:
python align/align_dataset.py data/ldmark_lfw_mtcnncaffe.txt \ data/lfw_mtcnncaffe_aligned \ --prefix /path/to/LFW/images \ --transpose_input --image_size 96 112
- Download the IJB-A dataset and crop the faces with the following command:
To crop the images, you need to make sure that there are two folders under the given dataset folder:
python align/crop_ijba.py proto/IJB-A/metadata.csv \ /path/to/IJB-A/images/ \ data/ijba_cropped/
img
andframe
. And then align the images with the following command:python align/align_dataset.py data/ldmark_ijba_mtcnncaffe.txt \ data/ijba_mtcnncaffe_aligned \ --prefix data/ijba_cropped \ --transpose_input --image_size 96 112
-
Before training, you need to download the base model. Unzip the files under
pretrained/sphere64_caisa_am/
. -
The configuration files for training are saved under
config/
folder, where you can define the training data, pre-trained model, network definition and other hyper-parameters. -
The uncertainty module that we are going to train is in
models/uncertainty_module.py
. -
Use the following command to run the default training configuration for the example base model:
python train.py config/sphere64_casia.py
The command will create an folder under
log/sphere64_casia_am_PFE/
, which saves all the checkpoints and summaries. The model directory is named as the time you start training.
-
Single Image Comparison We use LFW dataset as an example for single image comparison. Make sure you have aligned LFW images using the previous commands. Then you can test it on the LFW dataset with the following result:
python eval_lfw.py --model_dir /path/to/your/model/directory \ --dataset_path data/lfw_mtcnncaffe_aligned
-
Template Fusion and Comparison We use IJB-A dataset as an example for template face comparison. Make sure you have aligned IJB-A images using the previous commands. Then you can test it on the LFW dataset with the following result:
python eval_ijb.py --model_dir /path/to/your/model/directory \ --dataset_path data/ijba_mtcnncaffe_aligned
-
Note that in the original paper, I used Matlab to normalize the images, but this demo uses pure python implementation. So the performance could slightly different because of alignment. To use Matlab alignment code, you can check
align/face_align_demo.m
.
TODO