Training MCCNN-OCCL-GMM for face PAD

This section describes the multi-channel face PAD network with the new loss function described in the publication. It is strongly recommended to check the publication for better understanding of the described work-flow. For baselines with MCCNN alone, please refer to the older paper package.

Note

For the experiments discussed in this section, the WMCA dataset needs to be downloaded and installed in your system. Please refer to Executing Baseline Algorithms section in the documentation of bob.pad.face package for more details on how to run the face PAD experiments and setup the databases.

For reproducing the experiments with MCCNN-OCCL-GMM. There are mainly four stages. Each of them are described here.

Preprocessing data

The dataloader for training MCCNN assumes the data is already preprocessed. The preprocessing can be done with spoof.py script from bob.pad.face package. The preprocessed files are stored in the location <PREPROCESSED_FOLDER>. Each file in the preprocessed folder contains .hdf5 files which contains a FrameContainer with each frame being a multichannel image with dimensions NUM_CHANNELSxHxW.

./bin/spoof.py \
protocol-grandtest \
mccnn-occl-gmm \
--execute-only preprocessing \
--sub-directory <PIPELINE_FOLDER>
--grid idiap

After this stage, the preprocessed files will be available in <PIPELINE_FOLDER> /preprocessed/, which is notated from here onwards as <PREPROCESSED_FOLDER>. Running the pipeline generates the preprocessed files for other protocols as well since this protocol is a superset of other protocols.

Training MCCNN-OCCL-GMM

Once the preprocessing is done, the next step is to train the MCCNN architecture. All the parameters required to train MCCNN-OCCL-GMM are defined in the configuration file CNN_MCCNN_TRAINER_template.py file. The CNN_MCCNN_TRAINER_template.py file should contain atleast the network definition and the dataset class to be used for training. It can also define the transforms, number of channels in mccnn, training parameters such as number of epochs, learning rate and so on. However, before training set the correct paths in this configuration files.

Once the config file is defined, training the network can be done with the following code:

./bin/train_generic.py \                   # script used for MCCNN training
<PATH_TO_TRAINER_CONFIG>/CNN_MCCNN_TRAINER_template.py \ # configuration file defining the MCCNN network, database, and training parameters
-vv                                      # set verbosity level

People in Idiap can benefit from GPU cluster, running the training as follows:

jman submit --queue gpu \                      # submit to GPU queue (Idiap only)
--name <NAME_OF_EXPERIMENT> \                  # define the name of th job (Idiap only)
--log-dir <FOLDER_TO_SAVE_THE_RESULTS>/logs/ \ # substitute the path to save the logs to (Idiap only)
--environment="PYTHONUNBUFFERED=1" -- \        #
./bin/train_generic.py \                         # script used for MCCNN training
<PATH_TO_TRAINER_CONFIG>/CNN_MCCNN_TRAINER_template.py \       # configuration file defining the MCCNN network, database, and training parameters
--use-gpu \                                    # enable the GPU mode
-vv                                            # set verbosity level

For a more detailed documentation of functionality available in the training script, run the following command:

./bin/train_generic.py --help   # note: remove ./bin/ if buildout is not used

Please inspect the corresponding configuration file, CNN_MCCNN_TRAINER_template.py for example, for more details on how to define the database, network architecture and training parameters.

The protocols, and channels used in the experiments can be easily configured in the configuration file.

Running experiments with the trained model

The trained model file can be used with MCCNNExtractor to run PAD experiments with spoof.py script. A dummy algorithm is added to forward the scalar values computed as the final scores.

For grandtest protocol this can be done as follows.

    ./bin/spoof.py \
    protocol-grandtest \
    mccnn-occl-gmm \
--extractor-file PATH_TO_model0.pth \
    --sub-directory <FOLDER_TO_SAVE_MCCNN_RESULTS>  -vv

Similarly experiments can be repeated for all three protocols.

Evaluating results

To evaluate the models run the following command.

bob pad metrics -c apcer100 -r attack -e path_to_scores/scores-{dev,eval}

Using pretrained models

Warning

The training of models have some randomness associated with even with all the seeds set. The variations could arise from the platforms, versions of pytorch, non-deterministic nature in GPUs and so on. You can go through the follwing link on how to achive best reproducibility in PyTorch PyTorch Reproducibility. If you wish to reproduce the exact same results in the paper, we suggest you to use the pretrained models shipped with the package. The pretrained models can be downloaded from Download Models.