using of center_loss #5644

Open
wants to merge 8 commits into
from
View
61 LICENSE
@@ -1,44 +1,25 @@
-COPYRIGHT
+Caffe-face
-All contributions by the University of California:
-Copyright (c) 2014, 2015, The Regents of the University of California (Regents)
-All rights reserved.
+Copyright (c) Yandong Wen
-All other contributions:
-Copyright (c) 2014, 2015, the respective contributors
All rights reserved.
-Caffe uses a shared copyright model: each contributor holds copyright over
-their contributions to Caffe. The project versioning records all such
-contribution and copyright details. If a contributor wants to further mark
-their specific copyright on a particular contribution, they should indicate
-their copyright solely in the commit message of the change when it is
-committed.
-
-LICENSE
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice, this
- list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
-ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
-ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-CONTRIBUTION AGREEMENT
-
-By contributing to the BVLC/caffe repository through pull-request, comment,
-or otherwise, the contributor releases their content to the
-license and copyright terms herein.
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
View
@@ -0,0 +1,44 @@
+COPYRIGHT
+
+All contributions by the University of California:
+Copyright (c) 2014, 2015, The Regents of the University of California (Regents)
+All rights reserved.
+
+All other contributions:
+Copyright (c) 2014, 2015, the respective contributors
+All rights reserved.
+
+Caffe uses a shared copyright model: each contributor holds copyright over
+their contributions to Caffe. The project versioning records all such
+contribution and copyright details. If a contributor wants to further mark
+their specific copyright on a particular contribution, they should indicate
+their copyright solely in the commit message of the change when it is
+committed.
+
+LICENSE
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+CONTRIBUTION AGREEMENT
+
+By contributing to the BVLC/caffe repository through pull-request, comment,
+or otherwise, the contributor releases their content to the
+license and copyright terms herein.
View
159 README.md
@@ -1,7 +1,158 @@
-# Caffe
+# Deep Face Recognition with Caffe Implementation
+
+This branch is developed for deep face recognition, the related paper is as follows.
+
+ A Discriminative Feature Learning Approach for Deep Face Recognition[C]
+ Yandong Wen, Kaipeng Zhang, Zhifeng Li*, Yu Qiao
+ European Conference on Computer Vision. Springer International Publishing, 2016: 499-515.
+
+
+* [Updates](#updates)
+* [Files](#files)
+* [Train_Model](#train_model)
+* [Extract_DeepFeature](#extract_deepfeature)
+* [Contact](#contact)
+* [Citation](#citation)
+* [LICENSE](#license)
+* [README_Caffe](#readme_caffe)
+
+### Updates
+- Oct 13, 2016
+ * A demo for extracting deep feature by the given model is provided.
+- Oct 12, 2016
+ * The links of face model and features on LFW are available.
+ **model:** [google drive](https://drive.google.com/open?id=0B_geeR2lTMegUzlSdG5wZ1V5WU0) [baidu skydrive](http://pan.baidu.com/s/1skFoqrr)
+ **feature:** [google drive](https://drive.google.com/open?id=0B_geeR2lTMegLWRuWnZoMVJPZ3c) [baidu skydrive](http://pan.baidu.com/s/1boLM1bh)
+ * The training prototxt of toy example on MNIST are released.
+- Otc 9, 2016
+ * The code and training prototxt for our [ECCV16](http://link.springer.com/chapter/10.1007/978-3-319-46478-7_31) paper are released.
+ * If you train our Network on **CAISA-WebFace**, the expected verification performance of **SINGLE MODEL** on **[LFW](http://vis-www.cs.umass.edu/lfw/)** should be **~99%**.
+
+### Files
+- Original Caffe library
+- Center Loss
+ * src/caffe/proto/caffe.proto
+ * include/caffe/layers/center_loss_layer.hpp
+ * src/caffe/layers/center_loss_layer.cpp
+ * src/caffe/layers/center_loss_layer.cu
+- face_example
+ * face_example/data/
+ * face_example/face_snapshot/
+ * face_example/face_train_test.prototxt
+ * face_example/face_solver.prototxt
+ * face_example/face_deploy.prototxt
+ * face_example/extractDeepFeature.m
+- mnist_example
+ * mnist_example/data/
+ * mnist_example/face_snapshot/
+ * mnist_example/mnist_train_test.prototxt
+ * mnist_example/mnist_solver.prototxt
+ * mnist_example/mnist_deploy.prototxt
+
+### Train_Model
+1. The Installation completely the same as [Caffe](http://caffe.berkeleyvision.org/). Please follow the [installation instructions](http://caffe.berkeleyvision.org/installation.html). Make sure you have correctly installed before using our code.
+2. Download the face dataset for training, e.g. [CAISA-WebFace](http://www.cbsr.ia.ac.cn/english/CASIA-WebFace-Database.html), [VGG-Face](http://www.robots.ox.ac.uk/~vgg/data/vgg_face/), [MS-Celeb-1M](https://www.microsoft.com/en-us/research/project/ms-celeb-1m-challenge-recognizing-one-million-celebrities-real-world/), [MegaFace](http://megaface.cs.washington.edu/).
+3. Preprocess the training face images, including detection, alignment, etc. Here we strongly recommend [MTCNN](https://github.com/kpzhang93/MTCNN_face_detection_alignment), which is an effective and efficient open-source tool for face detection and alignment.
+4. Creat list for training set and validation set. Place them in face_example/data/
+5. Specify your data source for train & val
+
+ layer {
+ name: "data"
+ type: "ImageData"
+ top: "data"
+ top: "label"
+ image_data_param {
+ source: "face_example/data/###your_list###"
+ }
+ }
+
+6. Specify the number of subject in FC6 layer
+
+ layer {
+ name: "fc6"
+ type: "InnerProduct"
+ bottom: "fc5"
+ top: "fc6"
+ inner_product_param {
+ num_output: ##number##
+ }
+ }
+
+7. Specify the loss weight and the number of subject in center loss layer
+
+ layer {
+ name: "center_loss"
+ type: "CenterLoss"
+ bottom: "fc5"
+ bottom: "label"
+ top: "center_loss"
+ loss_weight: ##weight##
+ center_loss_param {
+ num_output: ##number##
+ }
+ }
+
+8. Train model
+
+ cd $CAFFE-FACE_ROOT
+ ./build/tools/caffe train -solver face_example/face_solver.prototxt -gpu X,Y
+
+### Extract_DeepFeature
+1. Compile matcaffe by make matcaffe
+2. Specify the correspinding paths in face_example/extractDeepFeature.m
-[![Build Status](https://travis-ci.org/BVLC/caffe.svg?branch=master)](https://travis-ci.org/BVLC/caffe)
-[![License](https://img.shields.io/badge/license-BSD-blue.svg)](LICENSE)
+ addpath('path_to_matCaffe/matlab');
+ model = 'path_to_deploy/face_deploy.prototxt';
+ weights = 'path_to_model/face_model.caffemodel';
+ image = imread('path_to_image/Jennifer_Aniston_0016.jpg');
+
+3. Run extractDeepFeature.m in Matlab
+
+### Contact
+- [Yandong Wen](http://ydwen.github.io/)
+- [Kaipeng Zhang](http://kpzhang93.github.io/)
+
+### Citation
+You are encouraged to cite the following paper if it helps your research.
+
+ @inproceedings{wen2016discriminative,
+ title={A Discriminative Feature Learning Approach for Deep Face Recognition},
+ author={Wen, Yandong and Zhang, Kaipeng and Li, Zhifeng and Qiao, Yu},
+ booktitle={European Conference on Computer Vision},
+ pages={499--515},
+ year={2016},
+ organization={Springer}
+ }
+
+### License
+Copyright (c) Yandong Wen
+
+All rights reserved.
+
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a
+copy of this software and associated documentation files (the "Software"),
+to deal in the Software without restriction, including without limitation
+the rights to use, copy, modify, merge, publish, distribute, sublicense,
+and/or sell copies of the Software, and to permit persons to whom the
+Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+***
+
+### README_Caffe
+# Caffe
Caffe is a deep learning framework made with expression, speed, and modularity in mind.
It is developed by the Berkeley Vision and Learning Center ([BVLC](http://bvlc.eecs.berkeley.edu)) and community contributors.
@@ -34,4 +185,4 @@ Please cite Caffe in your publications if it helps your research:
Journal = {arXiv preprint arXiv:1408.5093},
Title = {Caffe: Convolutional Architecture for Fast Feature Embedding},
Year = {2014}
- }
+ }
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@@ -0,0 +1,4 @@
+# Ignore everything in this directory
+*
+# Except this file
+!.gitignore
@@ -0,0 +1,44 @@
+clear;clc;
+addpath('path_to_matCaffe/matlab');
+caffe.reset_all();
+
+% load face model and creat network
+caffe.set_device(0);
+caffe.set_mode_gpu();
+model = 'path_to_deploy/face_deploy.prototxt';
+weights = 'path_to_model/face_model.caffemodel';
+net = caffe.Net(model, weights, 'test');
+
+% load face image, and align to 112 X 96
+imgSize = [112, 96];
+coord5points = [30.2946, 65.5318, 48.0252, 33.5493, 62.7299; ...
+ 51.6963, 51.5014, 71.7366, 92.3655, 92.2041];
+
+image = imread('path_to_image/Jennifer_Aniston_0016.jpg');
+facial5points = [105.8306, 147.9323, 121.3533, 106.1169, 144.3622; ...
+ 109.8005, 112.5533, 139.1172, 155.6359, 156.3451];
+
+Tfm = cp2tform(facial5points', coord5points', 'similarity');
+cropImg = imtransform(image, Tfm, 'XData', [1 imgSize(2)],...
+ 'YData', [1 imgSize(1)], 'Size', imgSize);
+
+% transform image, obtaining the original face and the horizontally flipped one
+if size(cropImg, 3) < 3
+ cropImg(:,:,2) = cropImg(:,:,1);
+ cropImg(:,:,3) = cropImg(:,:,1);
+end
+cropImg = single(cropImg);
+cropImg = (cropImg - 127.5)/128;
+cropImg = permute(cropImg, [2,1,3]);
+cropImg = cropImg(:,:,[3,2,1]);
+
+cropImg_(:,:,1) = flipud(cropImg(:,:,1));
+cropImg_(:,:,2) = flipud(cropImg(:,:,2));
+cropImg_(:,:,3) = flipud(cropImg(:,:,3));
+
+% extract deep feature
+res = net.forward({cropImg});
+res_ = net.forward({cropImg_});
+deepfeature = [res{1}; res_{1}];
+
+caffe.reset_all();
Oops, something went wrong.