This section gives a brief overview on training the multi-channel CNN framework for PAD.
The framework described here is described in the publication [NGM20]_. It is recommended to check the publication for better understanding of the framework. However, the framework present in this package does not exactly match with the one presented
in the reference paper. The framework presented here is more flexible, can accomodate more channels, can subselect channels
to perform scalability study. The network implemented here replicates the network in multiple channels instead of sharing the common weights, this modification is made to perform experiments with adapting different channels easily (however, both implementations are functionally same). Another difference is the way data balancing is implemented. In the publication [NGM20]_, databalancing is performed in the dataset using undersampling. However, in the current implementation, data imbalance in each mini-batch is handled explicitly by computing the weight for each samples and using it for the loss computation.
Different stages for training MC-CNN are described below.
1. 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``. Please refer to the section entitled **Multi-channel CNN for face PAD ** in the
documentation of ``bob.pad.face`` package, for an explicit example on how to preprocess the data for training MCCNN.
2. Training MCCNN
All the parameters required to train MCCNN are defined in the configuration file ``config.py`` file.
The ``config.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.
Once the config file is defined, training the network can be done with the following code:
.. code-block:: sh
./bin/train_mccnn.py \ # script used for MCCNN training
config.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:
--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_mccnn.py \ # script used for MCCNN training
config.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:
.. code-block:: sh
./bin/train_mccnn.py --help # note: remove ./bin/ if buildout is not used
Please inspect the corresponding configuration file, ``wmca_mccn.py`` for example, for more details on how to define the database, network architecture and training parameters.
3. Running experiments with the trained model
The trained model file can be used with ``MCCNExtractor`` to run PAD experiments with ``spoof.py`` script. A dummy algorithm is
added to forward the scalar values computed as the final scores.
.. [NGM20] *A. George, Z. Mostaani, D. Geissenbuhler, O. Nikisins, A. Anjos, S. Marcel*, **Biometric Face Presentation Attack Detection with Multi-Channel Convolutional Neural Network**,
in: Submitted to: IEEE Transactions on Information Forensics & Security.