Package: antispoofing.lbptop
This package implements an LBP-TOP based countermeasure to spoofing attacks to face recognition systems as described at the paper LBP-TOP based countermeasure against facial spoofing attacks, International Workshop on Computer Vision With Local Binary Pattern Variants, 2012.If you use this package and/or its results, please cite the following publications:The original paper with the counter-measure explained in details:@inproceedings{Pereira_LBP_2012,
  author = {Pereira, Tiago de Freitas and Anjos, Andr{\'{e}} and De Martino, Jos{\'{e}} Mario and Marcel, S{\'{e}}bastien},
  keywords = {Attack, Countermeasures, Counter-Spoofing, Face Recognition, Liveness Detection, Replay, Spoofing},
  month = nov,
  year = {2012},
  title = {LBP-TOP based countermeasure against facial spoofing attacks},
  journal = {International Workshop on Computer Vision With Local Binary Pattern Variants - ACCV},
}Bob as the core framework used to run the experiments:@inproceedings{Anjos_ACMMM_2012,
  author = {A. Anjos AND L. El Shafey AND R. Wallace AND M. G\"unther AND C. McCool AND S. Marcel},
  title = {Bob: a free signal processing and machine learning toolbox for researchers},
  year = {2012},
  month = oct,
  booktitle = {20th ACM Conference on Multimedia Systems (ACMMM), Nara, Japan},
  publisher = {ACM Press},
}Raw DataThe dataset used in the paper is REPLAY-ATTACK database and it is publicly available. It should be downloaded and
installedpriorto using the programs described in this package. Visitthe REPLAY-ATTACK database pagefor more information.InstallationNoteIf you are reading this page through our GitHub portal and not through PyPI,
notethe development tip of the package may not be stableor become
unstable in a matter of moments.Go tohttp://pypi.python.org/pypi/antispoofing.lbptopto download the latest
stable version of this package.There are 2 options you can follow to get this package installed and
operational on your computer: you can use automatic installers likepip(oreasy_install) or manually download, unpack and
usezc.buildoutto create a
virtual work environment just for this package.Using an automatic installerUsingpipis the easiest (shell commands are marked with a$signal):$ pip install antispoofing.lbptopYou can also do the same witheasy_install:$ easy_install antispoofing.lbptopThis will download and install this package plus any other required
dependencies. It will also verify if the version of Bob you have installed
is compatible.This scheme works well with virtual environments byvirtualenvor if you have root access to your
machine. Otherwise, we recommend you use the next option.Usingzc.buildoutDownload the latest version of this package fromPyPIand unpack it in your
working area. The installation of the toolkit itself usesbuildout. You don’t need to understand its inner workings
to use this package. Here is a recipe to get you started:$ python bootstrap.py
$ ./bin/buildoutThese 2 commands should download and install all non-installed dependencies and
get you a fully operational test and development environment.NoteThe python shell used in the first line of the previous command set
determines the python interpreter that will be used for all scripts developed
inside this package. Because this package makes use ofBob, you must make sure that thebootstrap.pyscript is called with thesameinterpreter used to build Bob, or
unexpected problems might occur.If Bob is installed by the administrator of your system, it is safe to
consider it uses the default python interpreter. In this case, the above 3
command lines should work as expected. If you have Bob installed somewhere
else on a private directory, edit the filebuildout.cfgbeforerunning./bin/buildout. Find the section namedexternaland edit the
lineegg-directoriesto point to thelibdirectory of the Bob
installation you want to use. For example:[external]
recipe = xbob.buildout:external
egg-directories=/Users/crazyfox/work/bob/build/libUser GuideIt is assumed you have followed the installation instructions for the package
and got this package installed and the REPLAY-ATTACK database downloaded and
uncompressed in a directory. You should have all required utilities sitting
inside a binary directory depending on your installation strategy (utilities
will be inside thebinif you used the buildout option). We expect that the
video files downloaded for the REPLAY-ATTACK database are installed in a
sub-directory calleddatabaseat the root of the package.  You can use a
link to the location of the database files, if you don’t want to have the
database installed on the root of this package:$ ln -s /path/where/you/installed/the/replay-attack-database databaseIf you don’t want to create a link, use the--input-dirflag to specify
the root directory containing the database files. That would be the directory
thatcontainsthe sub-directoriestrain,test,develandface-locations.Calculate the multiresolution and single resolution LBP-TOP featuresThe first stage of the process is calculating the feature vectors, which are essentially LBP-TOP histograms (XY, XT and YT directions) for each frame of the video.The program to be used isscript/lbptop_calculate_parameters.py.The resulting histograms will be put in .hdf5 files in the default output directory./lbp_features:$ ./bin/lbptop_calculate_parameters.py replayTo gerate LBP-TOP features following the multiresolution strategy in time domain, it is necessary to set different values for Rt. For example, to generate a multiresolution description in time domain for Rt=[1-4] the code is the follows:$ ./bin/lbptop_calculate_parameters.py -rT 1 2 3 4 replayTo gerate a single resolution strategy in time domain, it is necessary to set only one value for Rt. For example, to generate a single resolution description in time domain for Rt=1 the code is the follows:$ ./bin/lbptop_calculate_parameters.py -rT 1 replayTo see all the options for the scriptslbptop_calculate_parameters.pyjust type–helpat the command line.Classification using Chi-2 DistanceThe clasification using Chi-2 distance consists of two steps. The first one is creating the histogram model (average LBP-TOP histogram for each plane and it combinations of all the real access videos in the training set). The second step is comparison of the features of development and test videos to the model histogram and writing the results.The script to use for creating the histogram model isscript/lbptop_mkhistmodel.py. It expects that the LBP-TOP features of the videos are stored in a folder./lbp_features. The model histogram will be written in the default output folder./res. You can change this default features by setting the input arguments. To execute this script, just run:$ ./bin/lbptop_mkhistmodel.pyThe script for performing Chi-2 histogram comparison isscript/lbptop_cmphistmodels.py, and it assumes that the model histogram has been already created. It makes use of the utility scriptspoof/chi2.pyandml/perf.pyfor writing the results in a file. The default input directory is./lbp_features, while the default input directory for the histogram model as well as default output directory is./res. To execute this script, just run:$ ./bin/lbptop_cmphistmodels.pyThe performance results will be calculated for each LBP-TOP planes and the combinations XT+YT and XY+XT+YT.To see all the options for the scriptslbptop_mkhistmodel.pyandlbptop_cmphistmodels.py, just type–helpat the command line.Classification with Linear Discriminant Analysis (LDA)The classification with LDA is performed using the scriptscript/lbptop_ldatrain.py. It makes use of the scriptsml/lda.py,ml/pca.py(if PCA reduction is performed on the data) andml/norm.py(if the data need to be normalized). The default input and output directories are./lbp_featuresand./res. To execute the script with the default parameters, call:$ ./bin/lbptop_ldatrain.pyThe performance results will be calculated for each LBP-TOP planes and the combinations XT+YT and XY+XT+YT.To see all the options for this script, just type–helpat the command line.Classification with Support Vector Machine (SVM)The classification with SVM is performed using the scriptscript/lbptop_svmtrain.py. It makes use of the scriptsml/pca.py(if PCA reduction is performed on the data) andml/norm.py(if the data need to be normalized). The default input and output directories are./lbp_featuresand./res. To execute the script with the default parameters, call:$ ./bin/lbptop_svmtrain.pyThe performance results will be calculated for each LBP-TOP planes and the combinations XT+YT and XY+XT+YT.To see all the options for this script, just type–helpat the command line.Generating paper resultsThe next code blocks are codes to generate the results from lines 4, 5, 6, 7, 8 of Table 1.Line 4#Extracting the LBP-TOP features
$ ./bin/lbptop_calculate_parameters.py --directory lbptop_features/ --input-dir database/ -rX 1 -rY 1 -rT 1 2 3 4 5 6 -cXY -cXT -cYT --lbptypeXY riu2 --lbptypeXT riu2 --lbptypeYT riu2 replay

#Running the SVM machine
$ ./bin/lbptop_svmtrain.py  -n --input-dir lbptop_features/ --output-dir res/ replay

#Extracting the scores for each plane
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-plane.txt --normalization-file svm_normalization_XY-plane.txt --machine-type SVM --plane XY --output-dir res/scores/scores_XY replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-Plane.txt --normalization-file svm_normalization_XT-Plane.txt --machine-type SVM --plane XT --output-dir res/scores/scores_XT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_YT-Plane.txt --normalization-file svm_normalization_YT-Plane.txt --machine-type SVM --plane YT --output-dir res/scores/scores_YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-YT-Plane.txt --normalization-file svm_normalization_XT-YT-Plane.txt --machine-type SVM --plane XT-YT --output-dir res/scores/scores_XT-YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-XT-YT-plane.txt --normalization-file svm_normalization_XY-XT-YT-plane.txt --machine-type SVM --plane XY-XT-YT --output-dir res/scores/scores_XY-XT-YT replay

#Result Analysis
$./bin/lbptop_result_analysis.py --scores-dir res/scores/ --output-dir res/results/ replayLine 5:#Extracting the LBP-TOP features
$ ./bin/lbptop_calculate_parameters.py --directory lbptop_features/ --input-dir database/ -rX 1 -rY 1 -rT 1 2 3 4 5 6 -cXY -cXT -cYT -nXT 4 -nYT 4 replay

#Running the SVM machine
$ ./bin/lbptop_svmtrain.py  -n --input-dir lbptop_features/ --output-dir res/ replay

#Extracting the scores for each plane
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-plane.txt --normalization-file svm_normalization_XY-plane.txt --machine-type SVM --plane XY --output-dir res/scores/scores_XY replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-Plane.txt --normalization-file svm_normalization_XT-Plane.txt --machine-type SVM --plane XT --output-dir res/scores/scores_XT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_YT-Plane.txt --normalization-file svm_normalization_YT-Plane.txt --machine-type SVM --plane YT --output-dir res/scores/scores_YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-YT-Plane.txt --normalization-file svm_normalization_XT-YT-Plane.txt --machine-type SVM --plane XT-YT --output-dir res/scores/scores_XT-YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-XT-YT-plane.txt --normalization-file svm_normalization_XY-XT-YT-plane.txt --machine-type SVM --plane XY-XT-YT --output-dir res/scores/scores_XY-XT-YT replay

#Result Analysis
$./bin/lbptop_result_analysis.py --scores-dir res/scores/ --output-dir res/results/ replayLine 6:#Extracting the LBP-TOP features
$ ./bin/lbptop_calculate_parameters.py --directory lbptop_features/ --input-dir database/ -rX 1 -rY 1 -rT 1 2 3 4 -cXY -cXT -cYT replay

#Running the SVM machine
$ ./bin/lbptop_svmtrain.py  -n --input-dir lbptop_features/ --output-dir res/ replay

#Extracting the scores for each plane
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-plane.txt --normalization-file svm_normalization_XY-plane.txt --machine-type SVM --plane XY --output-dir res/scores/scores_XY replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-Plane.txt --normalization-file svm_normalization_XT-Plane.txt --machine-type SVM --plane XT --output-dir res/scores/scores_XT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_YT-Plane.txt --normalization-file svm_normalization_YT-Plane.txt --machine-type SVM --plane YT --output-dir res/scores/scores_YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-YT-Plane.txt --normalization-file svm_normalization_XT-YT-Plane.txt --machine-type SVM --plane XT-YT --output-dir res/scores/scores_XT-YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-XT-YT-plane.txt --normalization-file svm_normalization_XY-XT-YT-plane.txt --machine-type SVM --plane XY-XT-YT --output-dir res/scores/scores_XY-XT-YT replay

#Result Analysis
$./bin/lbptop_result_analysis.py --scores-dir res/scores/ --output-dir res/results/ replayLine 7:#Extracting the LBP-TOP features
$ ./bin/lbptop_calculate_parameters.py --directory lbptop_features/ --input-dir database/ -rX 1 -rY 1 -rT 1 2 -cXY -cXT -cYT --lbptypeXY regular --lbptypeXT regular --lbptypeYT regular replay

#Running the SVM machine
$ ./bin/lbptop_svmtrain.py  -n --input-dir lbptop_features/ --output-dir res/ replay

#Extracting the scores for each plane
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-plane.txt --normalization-file svm_normalization_XY-plane.txt --machine-type SVM --plane XY --output-dir res/scores/scores_XY replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-Plane.txt --normalization-file svm_normalization_XT-Plane.txt --machine-type SVM --plane XT --output-dir res/scores/scores_XT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_YT-Plane.txt --normalization-file svm_normalization_YT-Plane.txt --machine-type SVM --plane YT --output-dir res/scores/scores_YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-YT-Plane.txt --normalization-file svm_normalization_XT-YT-Plane.txt --machine-type SVM --plane XT-YT --output-dir res/scores/scores_XT-YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-XT-YT-plane.txt --normalization-file svm_normalization_XY-XT-YT-plane.txt --machine-type SVM --plane XY-XT-YT --output-dir res/scores/scores_XY-XT-YT replay

#Result Analysis
$./bin/lbptop_result_analysis.py --scores-dir res/scores/ --output-dir res/results/ replayLine 8:#Extracting the LBP-TOP features
$ ./bin/lbptop_calculate_parameters.py --directory lbptop_features/ --input-dir database/ -rX 1 -rY 1 -rT 1 2 -cXY -cXT -cYT -nXT 16 -nYT 16 replay

#Running the SVM machine
$ ./bin/lbptop_svmtrain.py  -n --input-dir lbptop_features/ --output-dir res/ replay

#Extracting the scores for each plane
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-plane.txt --normalization-file svm_normalization_XY-plane.txt --machine-type SVM --plane XY --output-dir res/scores/scores_XY replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-Plane.txt --normalization-file svm_normalization_XT-Plane.txt --machine-type SVM --plane XT --output-dir res/scores/scores_XT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_YT-Plane.txt --normalization-file svm_normalization_YT-Plane.txt --machine-type SVM --plane YT --output-dir res/scores/scores_YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XT-YT-Plane.txt --normalization-file svm_normalization_XT-YT-Plane.txt --machine-type SVM --plane XT-YT --output-dir res/scores/scores_XT-YT replay
$ ./bin/lbptop_make_scores.py --features-dir lbptop_features --machine-file svm_machine_XY-XT-YT-plane.txt --normalization-file svm_normalization_XY-XT-YT-plane.txt --machine-type SVM --plane XY-XT-YT --output-dir res/scores/scores_XY-XT-YT replay

#Result Analysis
$./bin/lbptop_result_analysis.py --scores-dir res/scores/ --output-dir res/results/ replayAfter that, it’s recommended to go out for a long coffee. This procedure can take a week.ProblemsIn case of problems, please contact any of the authors of the paper.