Skip to content

Commit

Permalink
New model in test cases. Fixed test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidsandberg committed Apr 10, 2018
1 parent accd688 commit 51fc8cb
Show file tree
Hide file tree
Showing 8 changed files with 283 additions and 103 deletions.
22 changes: 13 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,38 @@
[travis]: http://travis-ci.org/davidsandberg/facenet

This is a TensorFlow implementation of the face recognizer described in the paper
["FaceNet: A Unified Embedding for Face Recognition and Clustering"](http://arxiv.org/abs/1503.03832). The project also uses ideas from the paper ["A Discriminative Feature Learning Approach for Deep Face Recognition"](http://ydwen.github.io/papers/WenECCV16.pdf) as well as the paper ["Deep Face Recognition"](http://www.robots.ox.ac.uk/~vgg/publications/2015/Parkhi15/parkhi15.pdf) from the [Visual Geometry Group](http://www.robots.ox.ac.uk/~vgg/) at Oxford.
["FaceNet: A Unified Embedding for Face Recognition and Clustering"](http://arxiv.org/abs/1503.03832). The project also uses ideas from the paper ["Deep Face Recognition"](http://www.robots.ox.ac.uk/~vgg/publications/2015/Parkhi15/parkhi15.pdf) from the [Visual Geometry Group](http://www.robots.ox.ac.uk/~vgg/) at Oxford.

## Compatibility
The code is tested using Tensorflow r1.2 under Ubuntu 14.04 with Python 2.7 and Python 3.5. The test cases can be found [here](https://github.com/davidsandberg/facenet/tree/master/test) and the results can be found [here](http://travis-ci.org/davidsandberg/facenet).
The code is tested using Tensorflow r1.7 under Ubuntu 14.04 with Python 2.7 and Python 3.5. The test cases can be found [here](https://github.com/davidsandberg/facenet/tree/master/test) and the results can be found [here](http://travis-ci.org/davidsandberg/facenet).

## News
| Date | Update |
|----------|--------|
| 2018-04-10 | Added new models trained on Casia-WebFace and VGGFace2 (see below). Note that the models uses fixed image standardization (see [wiki](Training-using-the-VGGFace2-dataset)). |
| 2018-03-31 | Added a new, more flexible input pipeline as well as a bunch of minor updates. |
| 2017-05-13 | Removed a bunch of older non-slim models. Moved the last bottleneck layer into the respective models. Corrected normalization of Center Loss. |
| 2017-05-06 | Added code to [train a classifier on your own images](https://github.com/davidsandberg/facenet/wiki/Train-a-classifier-on-own-images). Renamed facenet_train.py to train_tripletloss.py and facenet_train_classifier.py to train_softmax.py. |
| 2017-03-02 | Added pretrained models that generate 128-dimensional embeddings.|
| 2017-02-22 | Updated to Tensorflow r1.0. Added Continuous Integration using Travis-CI.|
| 2017-02-03 | Added models where only trainable variables has been stored in the checkpoint. These are therefore significantly smaller. |
| 2017-01-27 | Added a model trained on a subset of the MS-Celeb-1M dataset. The LFW accuracy of this model is around 0.994. |
| 2017‑01‑02 | Updated to code to run with Tensorflow r0.12. Not sure if it runs with older versions of Tensorflow though. |
| 2017‑01‑02 | Updated to run with Tensorflow r0.12. Not sure if it runs with older versions of Tensorflow though. |

## Pre-trained models
| Model name | LFW accuracy | Training dataset | Architecture |
|-----------------|--------------|------------------|-------------|
| [20170511-185253](https://drive.google.com/file/d/0B5MzpY9kBtDVOTVnU3NIaUdySFE) | 0.987 | CASIA-WebFace | [Inception ResNet v1](https://github.com/davidsandberg/facenet/blob/master/src/models/inception_resnet_v1.py) |
| [20170512-110547](https://drive.google.com/file/d/0B5MzpY9kBtDVZ2RpVDYwWmxoSUk) | 0.992 | MS-Celeb-1M | [Inception ResNet v1](https://github.com/davidsandberg/facenet/blob/master/src/models/inception_resnet_v1.py) |
| [20180408-102900](https://drive.google.com/open?id=1R77HmFADxe87GmoLwzfgMu_HY0IhcyBz) | 0.9905 | CASIA-WebFace | [Inception ResNet v1](https://github.com/davidsandberg/facenet/blob/master/src/models/inception_resnet_v1.py) |
| [20180402-114759](https://drive.google.com/open?id=1EXPBSXwTaqrSC0OhUdXNmKSh9qJUQ55-) | 0.9965 | VGGFace2 | [Inception ResNet v1](https://github.com/davidsandberg/facenet/blob/master/src/models/inception_resnet_v1.py) |

NOTE: If you use any of the models, please do not forget to give proper credit to those providing the training dataset as well.

## Inspiration
The code is heavily inspired by the [OpenFace](https://github.com/cmusatyalab/openface) implementation.

## Training data
The [CASIA-WebFace](http://www.cbsr.ia.ac.cn/english/CASIA-WebFace-Database.html) dataset has been used for training. This training set consists of total of 453 453 images over 10 575 identities after face detection. Some performance improvement has been seen if the dataset has been filtered before training. Some more information about how this was done will come later.
The best performing model has been trained on a subset of the [MS-Celeb-1M](https://www.microsoft.com/en-us/research/project/ms-celeb-1m-challenge-recognizing-one-million-celebrities-real-world/) dataset. This dataset is significantly larger but also contains significantly more label noise, and therefore it is crucial to apply dataset filtering on this dataset.
The best performing model has been trained on the [VGGFace2](https://www.robots.ox.ac.uk/~vgg/data/vgg_face2/) dataset consisting of ~3.3M faces and ~9000 classes.

## Pre-processing

Expand All @@ -41,11 +45,11 @@ To solve this, other face landmark detectors has been tested. One face landmark
[Multi-task CNN](https://kpzhang93.github.io/MTCNN_face_detection_alignment/index.html). A Matlab/Caffe implementation can be found [here](https://github.com/kpzhang93/MTCNN_face_detection_alignment) and this has been used for face alignment with very good results. A Python/Tensorflow implementation of MTCNN can be found [here](https://github.com/davidsandberg/facenet/tree/master/src/align). This implementation does not give identical results to the Matlab/Caffe implementation but the performance is very similar.

## Running training
Currently, the best results are achieved by training the model as a classifier with the addition of [Center loss](http://ydwen.github.io/papers/WenECCV16.pdf). Details on how to train a model as a classifier can be found on the page [Classifier training of Inception-ResNet-v1](https://github.com/davidsandberg/facenet/wiki/Classifier-training-of-inception-resnet-v1).
Currently, the best results are achieved by training the model using softmax loss. Details on how to train a model using softmax loss on the CASIA-WebFace dataset can be found on the page [Classifier training of Inception-ResNet-v1](https://github.com/davidsandberg/facenet/wiki/Classifier-training-of-inception-resnet-v1) and .

## Pre-trained model
## Pre-trained models
### Inception-ResNet-v1 model
A couple of pretrained models are provided. They are trained using softmax loss with the Inception-Resnet-v1 model. The datasets has been aligned using [MTCNN](https://github.com/davidsandberg/facenet/tree/master/src/align).

## Performance
The accuracy on LFW for the model [20170512-110547](https://drive.google.com/file/d/0B5MzpY9kBtDVZ2RpVDYwWmxoSUk) is 0.992+-0.003. A description of how to run the test can be found on the page [Validate on LFW](https://github.com/davidsandberg/facenet/wiki/Validate-on-lfw).
The accuracy on LFW for the model [20180402-114759](https://drive.google.com/open?id=1EXPBSXwTaqrSC0OhUdXNmKSh9qJUQ55-) is 0.99650+-0.00252. A description of how to run the test can be found on the page [Validate on LFW](https://github.com/davidsandberg/facenet/wiki/Validate-on-lfw). Note that the input images to the model need to be standardized using fixed image standardization (use the option `--use_fixed_image_standardization` when running e.g. `validate_on_lfw.py`).
8 changes: 4 additions & 4 deletions data/learning_rate_schedule_classifier_casia.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Learning rate schedule
# Maps an epoch number to a learning rate
0: 0.1
65: 0.01
77: 0.001
1000: 0.0001
0: 0.05
60: 0.005
80: 0.0005
91: -1
4 changes: 2 additions & 2 deletions src/align/detect_face.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ def fc(self, inp, num_out, name, relu=True):
"""
@layer
def softmax(self, target, axis, name=None):
max_axis = tf.reduce_max(target, axis, keepdims=True)
max_axis = tf.reduce_max(target, axis, keep_dims=True)
target_exp = tf.exp(target-max_axis)
normalize = tf.reduce_sum(target_exp, axis, keepdims=True)
normalize = tf.reduce_sum(target_exp, axis, keep_dims=True)
softmax = tf.div(target_exp, normalize, name)
return softmax

Expand Down
3 changes: 2 additions & 1 deletion src/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import numpy as np
import sys
import os
import copy
import argparse
import facenet
import align.detect_face
Expand Down Expand Up @@ -88,7 +89,7 @@ def load_and_align_data(image_paths, image_size, margin, gpu_memory_fraction):
with sess.as_default():
pnet, rnet, onet = align.detect_face.create_mtcnn(sess, None)

tmp_image_paths = image_paths.copy()
tmp_image_paths=copy.copy(image_paths)
img_list = []
for image in tmp_image_paths:
img = misc.imread(os.path.expanduser(image), mode='RGB')
Expand Down
3 changes: 2 additions & 1 deletion src/download_and_extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
'lfw-subset': '1B5BQUZuJO-paxdN8UclxeHAR1WnR_Tzi',
'20170131-234652': '0B5MzpY9kBtDVSGM0RmVET2EwVEk',
'20170216-091149': '0B5MzpY9kBtDVTGZjcWkzT3pldDA',
'20170512-110547': '0B5MzpY9kBtDVZ2RpVDYwWmxoSUk'
'20170512-110547': '0B5MzpY9kBtDVZ2RpVDYwWmxoSUk',
'20180402-114759': '1EXPBSXwTaqrSC0OhUdXNmKSh9qJUQ55-'
}

def download_and_extract_file(model_name, data_dir):
Expand Down
3 changes: 2 additions & 1 deletion src/train_tripletloss.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

from tensorflow.python.ops import data_flow_ops

from six.moves import xrange
from six.moves import xrange # @UnresolvedImport

def main(args):

Expand Down Expand Up @@ -246,6 +246,7 @@ def train(args, sess, dataset, epoch, image_paths_placeholder, labels_placeholde
emb_array = np.zeros((nrof_examples, embedding_size))
loss_array = np.zeros((nrof_triplets,))
summary = tf.Summary()
step = 0
while i < nrof_batches:
start_time = time.time()
batch_size = min(nrof_examples-i*args.batch_size, args.batch_size)
Expand Down
5 changes: 3 additions & 2 deletions test/train_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ def setUpClass(self):
create_mock_dataset(self.dataset_dir, 160)
self.lfw_pairs_file = create_mock_lfw_pairs(self.tmp_dir)
print(self.lfw_pairs_file)
self.pretrained_model_name = '20170512-110547'
self.pretrained_model_name = '20180402-114759'
download_and_extract.download_and_extract_file(self.pretrained_model_name, 'data/')
download_and_extract.download_and_extract_file('lfw-subset', 'data/')
self.model_file = os.path.join('data', self.pretrained_model_name, 'model-%s.ckpt-250000' % self.pretrained_model_name)
self.model_file = os.path.join('data', self.pretrained_model_name, 'model-%s.ckpt-275' % self.pretrained_model_name)
self.pretrained_model = os.path.join('data', self.pretrained_model_name)
self.frozen_graph_filename = os.path.join('data', self.pretrained_model_name+'.pb')
print('Memory utilization (SetUpClass): %.3f MB' % memory_usage_psutil())
Expand Down Expand Up @@ -152,6 +152,7 @@ def test_finetune_tripletloss_inception_resnet_v1(self):
'--data_dir', self.dataset_dir,
'--model_def', 'models.inception_resnet_v1',
'--pretrained_model', self.model_file,
'--embedding_size', '512',
'--epoch_size', '1',
'--max_nrof_epochs', '1',
'--batch_size', '6',
Expand Down
Loading

0 comments on commit 51fc8cb

Please sign in to comment.