Cross Modal Focal Loss for RGBD Face Anti-Spoofing

Automatic methods for detecting presentation attacks are essential to ensure the reliable use of facial recognition technology. Most of the methods available in the literature for presentation attack detection (PAD) fails in generalizing to unseen attacks. In recent years, multi-channel methods have been proposed to improve the robustness of PAD systems. Often, only a limited amount of data is available for additional channels, which limits the effectiveness of these methods. In this work, we present a new framework for PAD that uses RGB and depth channels together with a novel loss function. The new architecture uses complementary information from the two modalities while reducing the impact of overfitting. Essentially, a cross-modal focal loss function is proposed to modulate the loss contribution of each channel as a function of the confidence of individual channels. Extensive evaluations in two publicly available datasets demonstrate the effectiveness of the proposed approach.


Introduction
While face recognition technology has become a ubiquitous method for biometric authentication, the vulnerability to presentation attacks (also known as "spoofing attacks") is a major concern when used in secure scenarios [9], [12]. These attacks can be either impersonation or obfuscation attacks. Impersonation attacks attempt to gain access by masquerading as someone else and obfuscation attacks attempt to evade face recognition systems. While many methods have been suggested in the literature to address this problem, most of these methods fail in generalizing to unseen attacks [10]. In a practical scenario, it is not possible to anticipate all the types of attacks at the time of training a PAD model. Moreover, a PAD system is expected to detect new types of sophisticated attacks. It is therefore important to have unseen attack robustness in PAD models.
The majority of the literature deals with the detection of these attacks with RGB cameras. Over the years, many feature-based methods have been proposed using color, texture, motion, liveliness cues, histogram features [7], local binary pattern [25], [8] and motion patterns [3] for performing PAD. Recently several CNN based methods have also been proposed including 3D-CNN [13], part-based models [22] and so on. Some works have shown that using auxiliary information in the form of binary or depth supervision improves performance [4,14]. However, most of these methods have been designed specifically for 2D attacks and the performance of these methods against challenging 3D and partial attacks is poor [24]. Moreover, these methods suffer from poor unseen attack robustness.
The performance of RGB only models deteriorates with sophisticated attacks such as 3D masks and partial attacks. Due to the limitations of visible spectrum alone, several multi-channel methods have been proposed in literature such as [30], [12], [31], [11], [2], [6], [5], [15][16][17][18] for face PAD. Essentially, it becomes more difficult to fool a multichannel PAD system as it captures complementary informa-tion from different channels. Deceiving different channels at the same time requires considerable effort. Multi-channel methods have proven to be effective, but this comes at the expense of customized and expensive hardware. This could make these systems difficult to deploy widely, even if they are robust. A variety of channels are available for PAD, e.g., RGB, depth, thermal, NIR spectra, SWIR spectra, ultraviolet, light field imagery, etc. Out of these various modalities, we find that RGB-D devices are commercially available and are quite affordable, making it possible to deploy them in real-world scenarios. The Intel RealSense family of devices, Microsoft Kinect, and the OpenCV AI Kit (OAK-D) [1] are examples of standard devices that do not require any additional effort to obtain multi-channel images. Due to the wide availability of these channels in an integrated package, we choose RGB and Depth as the two channels to be used in this work. However, the proposed framework can be trivially extended to any combinations of channels.
Even when using multiple channels, the models tend to overfit to attacks seen in the training set. While the models could perform perfectly in attacks seen in the training set, degradation in performance is often observed when confronted with unseen attacks in real-world scenarios. This is a common phenomenon with most of the machine learning algorithms, and this problem is aggravated in case of a limited amount of training data. The models, in the lack of strong priors, could overfit to the statistical biases of specific datasets it was trained on and could fail in generalizing to unseen samples. Multi-channel methods also suffer from an increased possibility of overfitting as they increase the number of parameters due to the extra channels.
In this work, we address this issue in two different directions. First, we use a multi-head architecture, which follows a late fusion strategy to combine different channels of information. Instead of joining the representations into a joint final node, we keep three different heads separately for the individual branches and the joint branch, this can be viewed as a form of architectural regularization. The proposed architecture can be found in Fig. 1. This enables us a way to supervise individual channels together with the joint representation, ensuring robust representation would be learned in individual as well as joint branches. Secondly, we propose a cross-modal focal loss function to supervise the individual channels that modulate the loss function factoring in the confidence of the channels present.
The main contributions of this work are listed below: • A frame-level RGB-D face PAD method is proposed which operates on synchronously captured RGB-D samples.
• A new loss function called cross-modal focal loss (CMFL ) is proposed, which can be used to supervise individual channels in a multi-stream architecture.
• Though the model is trained for a multi-channel scenario, it can also be deployed with individual channels by just using the score from the head corresponding to the available channel.
• We show the efficacy of the proposed framework in two publicly available datasets consisting of a wide variety of challenging unseen attacks.
Additionally, the source code and protocols to reproduce the results are available publicly * .

Proposed approach
Different stages of the proposed PAD framework are described in this section.

Preprocessing
The PAD pipeline acts on the cropped facial images. For the RGB image, the preprocessing stage consists of face detection and landmark localization using the MTCNN [32] framework, followed by alignment. The detected face is aligned by making the eye centers horizontal followed by resizing them to a resolution of 224 × 224. For the depth image, a normalization method using the median absolute deviation (MAD) [27] is used to normalize the face image to an 8-bit range. The raw images from RGB and depth channels are already spatially registered so that the same transformation can be used to align the face in the depth image.

Network architecture and loss function
This section details the proposed network architecture and loss function.

Architecture
From the prevailing literature, it has been observed that multi-channel methods are robust against a wide range of attacks [15][16][17][18]. Broadly, there are four different strategies to fuse the information from multiple channels, they are 1) early fusion, meaning the channels are stacked at the input level (for example, MC-PixBiS [18]). The second strategy is late fusion, meaning the representations from different networks are combined at a later stage similar to feature fusion (for example MCCNN [17]), a third strategy is score level fusion where individual networks are trained separately for different channels and score level fusion is performed on the scalar scores from each channel. A fourth strategy is a hybrid approach where information from multiple levels is combined as in [28].
Though multiple channels can perform well with a wide variety of attacks, they tend to overfit to known attacks when all channels are used together and trained as a binary classifier. To avoid this, we propose a multi-head architecture that follows a late fusion strategy. The architecture of the proposed network is shown in Fig. 1. Essentially, the architecture consists of a two-stream network with separate branches for the component (RGB and Depth) channels. The embeddings from the two channels are combined to form the third branch. Fully connected layers are added to each of these branches to form the final classification head. These three heads are jointly supervised by a loss function which forces the network to learn discriminative information from individual channels as well as the joint representation, reducing the possibility of overfitting. The multi-head structure also makes it possible to perform scoring even when a channel is missing at test time, meaning that we can do scoring with RGB branch alone (just using the score from the RGB head) even if the network was trained on RGB-D.
The branches are comprised of the first eight blocks from DenseNet architecture (densenet161) proposed by Huang et al. [19]. In the DenseNet architecture, each layer is connected to every other layer, reducing the vanishing gradient problem while reducing the number of parameters. We used pre-trained weights from the Image Net dataset to initialize the individual branches. The number of input channels for the RGB and depth channels has been modified to 3 and 1 for the RGB and depth channels, respectively. For the depth branch, the mean values of three-channel weights are used to initialize the weights of the modified convolutional kernels in the first layer. In each branch, a global average pooling (GAP) layer is added after the dense layers to obtain a 384-dimensional embedding. The RGB and depth embeddings are concatenated to form the joint embedding layer. A fully connected layer, followed by a sigmoid activation is added on top of each of these embeddings to form the different heads in the framework. At training time, each of these heads is supervised by a separate loss function. At test time, the score from the RGB-D branch is used as the PAD score.

Cross Modal Focal Loss function (CMFL )
Having individual heads make it possible to train a multichannel model with the capability to handle missing channels at test time. Now, one naive way to supervise this network would be to supervise the individual branches with binary cross-entropy (BCE).
However, the usage of BCE for individual channels may not be ideal. The issue is illustrated as follows; we can consider different channels as different views of the same sample, and for some attacks, it may not be possible to distinguish it just from one view. It is possible that the images of some attacks would look perfectly like bonafide sam- ples when viewed in just one channel. For example, facial makeup when viewed in depth channel would look exactly like the depth map of a bonafide sample. The naive way of supervising the depth branch with BCE in such cases might lead to overfitting. However, in the same scenario, discriminating makeup would be more obvious in RGB and joint representations. From this example, it can be seen that supervising the individual branches separately might not result in robust decision boundaries. One way to approach this issue is to use the prediction probabilities from the current branch and the other branch to change the loss contributions of samples in each branch. We propose a cross-modal focal loss function to supervise the individual channels, which modulates the loss function based on the confidence of the current and alternate channel present. For each branch, the samples which could be classified correctly should be well separated in the score space. At the same time, we encourage the individual branches to produce unsure scores when there is not enough discriminatory information, rather than overfitting to some statistical bias in the training data. However, this applies only when the other branch can confidently classify the sample correctly.
More formally, consider a binary classification problem where the samples are multi-modal i.e., each sample is a pair of images or features that capture different views with complementary information. Now assume that the classification problem cannot be done with a single channel alone (or is a very hard problem). Combining the features from both the channels and using a learning strategy using the joint features could provide a solution for this. However, this could lead to overfitting and cannot handle missing channels at test time.
If we use BCE on individual branches, the loss will penalize heavily the samples which cannot be classified with the information available with the specific channel. In such a scenario, the model might start to overfit to the biases in the dataset to minimize the loss function, resulting in an over-fitted model.
To avoid this, we propose cross-modal focal loss (CMFL) to supervise the individual channels. The core idea is that, when one of the channels can correctly classify a sample correctly with high confidence, then the loss contribution of the sample in the other branch can be reduced. If a channel can correctly classify a sample confidently, then we don't want the other branch to penalize the model more. CMFL forces each branch to learn robust representations for individual channels, which can then be utilized with the joint branch, effectively acting as an auxiliary loss function.
The idea of relaxing the loss contribution of samples correctly classified is similar to the Focal Loss [23] used in object detection problems. In Focal Loss, a modulating factor is used to reduce the loss contributed by samples that are correctly classified with high confidence. We use this idea by modulating the loss factoring in the confidence of the sample in the current and the alternate branch.
Consider the expression for cross-entropy (CE) in a binary classification problem: Where y ∈ {0, 1} denotes the class label (y:0 attack, y:1 bonafide) and p ∈ [0, 1] is the probability of the class. We follow a similar notation p t as in [23], which is the probability of the target class: and write CE(p, y) = CE(p t ) = − log(p t ).
In the α-balanced form CE loss can be written as: The standard α-balanced focal loss (FL) [23] adds a modulating factor (1 − p t ) γ to the cross entropy loss, with a tunable focusing parameter γ ≥ 0, making the loss formulation as.
Consider the two-stream multi-branch multi-head modal in Fig. 3. X p and X q denotes the image inputs from different modalities, and E p , E q , and E r denotes the corresponding embeddings for the individual and joint representations. In each branch, after the embedding layer, a fully connected layer (followed by a sigmoid layer) is present which provides classification probability. The variables p, q and r denote these probabilities. The proposed Cross Modal Loss Function (CMFL) is given as follows: The function w(p t , q t ), depends on the probabilities given by the channels from two individual branches. This modulating factor should increase as the probability of the other branch increases, and at the same time should be able to prevent very confident mistakes. Hence for this study, we use the harmonic mean of both the branches weighted by the probability of the other branch. This reduces the loss contribution when the other branch is giving confident predictions. And the expression for this function is given as: Note that the function w is assymetric, i.e., the expression for w(q t , p t ) is: Meaning the weight function depends on the probability of the other branch. Now we use the proposed loss function as auxiliary supervision,and the overall loss function to minimize is given as: We have set the value of λ non-optimally as 0.5 for this study. The loss curve for the cross-entropy and the proposed loss is shown in Fig. 2. When the probability of other branch is zero, then the loss is equivalent to standard crossentropy. The loss contribution is reduced when the other branch is able to correctly classify the sample. ie, when an attack example is misclassified by network CN N p , the network CN N p is penalized unless model CN N q can classify the attack sample with high confidence. As the w(p, q) → 1 the modulating factor goes to zero, meaning if one channel is able to classify it perfectly, then the other branch is less penalized. Also, the focussing parameter γ can be adapted to change the behaviour of the loss curve. We used an empirically obtained value of γ = 3 in all our experiments.
Without the loss of generality, the framework can be extended to other multi-channel classification problems as well.

Implementation details
We performed data augmentation during the training phase with random horizontal flips with a probability of 0.5. The combined loss function is minimized with Adam Optimizer [21]. A learning rate of 1 × 10 −4 was used with a weight decay parameter of 1 × 10 −5 . We used a mini-batch size of 64, and the network was trained for 25 epochs on a GPU grid. During the evaluation of the model, the scores from the RGB-D head was used to calculate the final PAD score. The proposed architecture has about 6.39M parameters and about 9.16 GFLOPS. The architecture and the training framework were implemented using the PyTorch [29] library.

Datasets used
We have used two publicly available datasets for the experiments, namely WMCA and HQ-WMCA , which contains a wide variety of 2D, 3D, and partial attacks.

WMCA dataset
The Wide Multi-Channel presentation Attack (WMCA ) [17] database contains a wide variety of 2D and 3D presentation attacks, with a total of 1679 video samples from 72 subjects. Multiple channels collected synchronously, namely color, depth, infrared, and thermal channels, collected using two consumer-grade devices, Intel ® RealSense™SR300 (for color, depth and infrared), and Seek Thermal Com-pactPRO (for the thermal channel) is available with this database. Though four different channels are available in this database, in this work, we focus on the RGB and depth data obtained from the Intel ® RealSense™SR300 device.

HQ-WMCA dataset
The High-Quality Wide Multi-Channel Attack (HQ-WMCA ) [18,26] dataset consists of 2904 short multi-modal video recordings of both bonafide and presentation attacks. This database again consists of a wide variety of attacks including both obfuscation and impersonation attacks. Specifically, the attacks considered are print, replay, rigid mask, paper mask, flexible mask, mannequin, glasses, makeup, tattoo, and wig (Fig. 4). The database consists of recordings from 51 different subjects, with several channels including color, depth, thermal, infrared (spectra), and short-wave infrared (spectra). In this work, we consider the RGB channel captured with Basler acA1921-150uc camera and depth image captured with Intel RealSense D415.

Protocols
Since both of the datasets contains a wide variety of attacks, we have created leave-one-out (LOO) attack protocols individually for both of the datasets. Specifically, one attack is left out in the train and development set and the evaluation set consists of bonafide and the attack which was left out in the train and development set. This constitutes the unseen attack protocols or zero-shot attack protocols. The performance of the PAD methods in these protocols gives a more realistic estimate of their robustness against unseen attacks in real-world scenarios. Further, for cross-dataset experiments, we have created grandtest protocols in both of the datasets which consist of attacks distributed in the train, development, and test sets (with disjoint identities across folds).

Metrics
For the evaluation of the algorithms, we have used the ISO/IEC 30107-3 metrics [20], Attack Presentation Classification Error Rate (APCER), and Bonafide Presentation Classification Error Rate (BPCER) along with the Average Classification Error Rate (ACER) in the eval set. We compute the threshold in the dev set for a BPCER value of 1%.
For cross-database testing, Half Total Error Rate (HTER) is adopted following the convention in [16], which computes the average of False Rejection Rate (FRR) and the False Acceptance Rate (FAR). HTER is computed in the eval set using the threshold computed in the dev set using the equal error rate criterion (EER).

Baseline methods
For a fair comparison with state of the art, we have implemented 3 different multi-channel PAD approaches from literature for the RGB-D channels. Besides, we also introduce the proposed multi-head architecture supervised with BCE alone, as another baseline for comparison. The baselines implemented are listed below. MC-PixBiS: This is a CNN based system [14], extended to multi-channel scenario as described in [18] trained using both binary and pixel-wise binary loss function. This model uses RGB and depth channels stacked together at the input level. MCCNN-OCCL-GMM: This model is the multi-channel CNN system proposed to learn one class model using the one class contrastive loss (OCCL) and Gaussian mixture model as reported in [16]. The model was adapted to accept RGB-D channels as the input. MC-ResNetDLAS: This is the reimplementation of the architecture from [28], which won the first prize in the 'CASIA-SURF' challenge, extending it to RGB-D channels, based on the open-source implementation * . We used the initialization from the best-pretrained model as suggested in [28] followed by retraining in the current protocols using RGB-D channels.

RGBD-MH-BCE:
This uses the newly proposed multi-head architecture shown in Fig.1, where all the branches are supervised by binary cross-entropy (BCE). In essence, this is equivalent to setting the value of γ = 0, in the expression for the cross-modal loss function. This is shown as a baseline to showcase the improvement by the new multi-head architecture alone and to contrast with the performance change with the new loss function.
Proposed: This is our final proposed framework, it uses the multi-head architecture we proposed as shown in Fig.1, together with the newly proposed loss function. More specifically, the individual channel branches are supervised by the newly proposed cross-modal focal loss function (CMFL ). The details of the parameters of the baseline methods can be found in our open-source implementation † .

Experiments
We have conducted experiments in both WMCA and HQ-WMCA datasets, specifically the leave-one-out protocols to evaluate the robustness against unseen attacks. The results are described in the following sections.

Results in WMCA dataset
The performance of the proposed system and baselines in the LOO protocols of WMCA are shown in Table 1. It can be seen that the baselines MCCNN-OCCL-GMM and MC-ResNetDLAS performs poorly in the challenging unseen attack scenarios. Among baselines, the MC-PixBiS model * Available from: https://github.com/ AlexanderParkin/ChaLearn_liveness_challenge † Will be available upon acceptance.
achieves the best performance with an average ACER of 10.5±16.7%. The model with the new architecture, RGBD-MH-BCE achieves reasonable performance as compared to the baselines. However, the proposed method, with the new CMFL loss achieves the best mean accuracy. Also, comparing with RGBD-MH-BCE, the proposed loss function shows a clear improvement in performance achieving an average ACER of 7.6 ± 11.2%.

Results in HQ-WMCA dataset
The HQ-WMCA dataset is consists of more challenging attacks as compared to WMCA . Specifically, there are different types of facial tattoos and partial attacks which occupy only a part of the face. These attacks are much harder to detect when they are not seen in the training set, as they appear very similar to bonafide samples. The experimental results in HQ-WMCA are tabulated in Table 2. Similar, to WMCA database, the baselines MCCNN-OCCL-GMM and MC-ResNetDLAS does not perform well in the LOO protocols of HQ-WMCA database. In addition, the MC-PixBiS method, which achieved reasonable performance in WMCA performs poorly HQ-WMCA dataset. This could be due to the challenging nature of the attacks in the database. It can be seen that the new multi-head architecture proposed, RGBD-MH-BCE, already improves the results as compared to all the baselines with an average ACER of 13.3 ± 16.5. Further, with the addition of the CMFL loss, the ACER further improves to 11.6 ± 14.8%. The results indicate that the proposed architecture already improves the performance in challenging attacks, and the proposed loss further improves the results achieving state of the art results in the HQ-WMCA dataset.
To summarize, the newly proposed multi-head architecture itself improves the performance over other baselines. The addition of the CMFL loss further improves the performance in both WMCA and HQ-WMCA datasets.

Ablation studies
To further analyze the performance, we conduct various ablation studies using the proposed approach. We carry out these experiments in the HQ-WMCA dataset as it contains more challenging attacks.  Table. 3. It can be seen that the optimal value of γ = 3. The model with γ = 0 is equivalent to BCE loss on each of the branches.  Table 4, it can be clearly seen that the performance improves, as compared to using BCE even when using a single channel at the time of deployment. This shows that the performance of the system improves when the loss contributions of samples which are not possible to classify by that modality are reduced. Forcing the individual networks to learn a decision boundary leads to overfitting resulting in poor generalization. In the proposed approach, the network can learn a robust classifier for individual channels as well. This observation opens up the possibility to use multichannel datasets at training time and to deploy the model for the RGB channel only. This could be of practical importance in scenarios where using additional hardware at deployment time is prohibitive, requiring PAD systems to be deployed using legacy RGB cameras.  Here we analyze the score distributions of the proposed model in the grandtest − c protocol of the HQ-WMCA dataset. As opposed to LOO protocols, the grandtest − c consists of different types of attacks roughly equally distributed in the train, development, and evaluationf olds.
The multi-head model provides three different scores from each of the branches, i.e., RGB, depth, and RGB-D branches. Here we show the distribution of scores for different types of attacks in the evaluation set of the HQ-WMCA dataset.
From Fig. 5, it can be seen that the attacks are more compact in RGB head compared to that of depth channel. In depth channel, where classifying attacks are harder, the bonafide distribution is shifted to the left. This can also be seen in the score distribution of attacks in depth channel, i.e., while attack scores are not as low as we desire, still, it is far from bonafide, the loss does not push the depth branch to classify all the attacks correctly, and it performs well on attacks where depth channel contains discriminatory information. Looking at the final 'RGB-D' part, it can be seen the proposed loss function makes the classifications using the joint representations from individual channels robust. To summarize, the proposed framework encourages the individual branches to produce non-confident scores for attacks that are confidently classified by the other branch. The discriminative representation from the joint branch, learned in this fashion, results in a robust PAD system.

Cross database evaluation
To evaluate the robustness in cross-database scenarios we have performed cross-database experiments between models trained in WMCA and HQ-WMCA . This evaluation amounts to both cross sensor and unseen attack at the same time which is much more challenging than typical crossdatabase evaluations. WMCA database uses the Intel Realsense SR300 camera which returns both RGB and depth streams. IntelRealsense SR300 uses dot pattern projection for depth computation. Whereas in HQ-WMCA the RGB channel is acquired using a high-quality Basler acA1921-150uc camera and the depth image was captured with Intel RealSense D415 (which uses stereo for computing depth). The mismatch between the sensors and quality between the sensors used in these datasets makes the performance degrade. The results from the cross-dataset test are tabulated in Table. 5. The models were trained on the grandtest protocol of each dataset and was evaluated on the dev and eval set of the other dataset. We report both the intraand cross-database performance for the sake of completeness. It can be seen that in the intra dataset evaluations, the proposed method achieves good performance in both the datasets. However, in the cross-database evaluations, the performance degrades. The mismatch between the sensors could be one reason for the degradation in performance. Performance is slightly better when the model trained in HQ-WMCA is evaluated on WMCA which could be due to the wider variety of attacks present in the training set. Moreover, it can be seen that methods with better perfor-mance in the target dataset, perform worse in the source dataset.

Discussions
From the experiments in WMCA and HQ-WMCA , it can be seen that the proposed approach outperforms the state of the art methods. We have also shown that the proposed approach is useful in cases where multiple channels are available at training time and when there is a need to deploy with individual channels. Even though the proposed approach works well in intra dataset scenario, cross-database performance needs further improvement. As future work, more preprocessing and data augmentation strategies could be developed to alleviate the discrepancies between datasets to improve the cross-database performance. While we have selected RGB and depth channel for this study, mainly due to the availability of off the shelf devices consisting of these channels, it is trivial to extend this study to other combinations of channels as well, for instance, RGB-Infrared, and RGB-Thermal.

Conclusions
In this work, we proposed a new architecture for RGB-D presentation attack detection, applicable to other multichannel classification problems as well. Also, we proposed a new cross-modal focal loss function which could be useful for two-stream networks. The proposed cross-modal focal loss function modulates the loss contribution of samples based on the confidence of individual channels. The proposed framework can be trivially extended to multiple channels and different classification problems where information from one channel alone is inadequate for classification. This loss forces the network to learn complementary, discriminative, and robust representations for the component channels. The structure of the framework makes it possible to train models using all the available channels and to deploy with a subset of channels. Extensive evaluations in two publicly available datasets demonstrate the effectiveness of the proposed approach.