Test-Time Adaptation for Robust Face Anti-Spoofing
- Publication
- BMVC 2023Conference
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@inproceedings{faceantispoofingthreeatta2023,
title = {{Test-Time Adaptation for Robust Face Anti-Spoofing}},
author = {Pei-Kai Huang and Chen-Yu Lu and Shu-Jung Chang and Jun-Xiong Chong and Chiou-Ting Hsu},
year = {2023},
booktitle = {BMVC},
url = {https://proceedings.bmvc2023.org/379/}
}
You probably don't remember how you learned to distinguish a photo from a face.
Maybe it's the lighting, maybe the reflection, or maybe it's some subtle sense of incongruity.
But for a model, this is never simple. Especially when it has to make the decision on its own, without anyone teaching it.
Defining the Problem
Face Anti-Spoofing (FAS) is a seemingly simple yet tricky problem.
We just need it to determine whether a face is real or fake, but this judgment breaks down under numerous environmental changes, attack types, and device variations.
To address the cross-environment issue, researchers have proposed many seemingly robust learning strategies.
- Domain Generalization (DG) says: Let’s make the model more stable.
- Domain Adaptation (DA) says: Let’s let the model see new data before learning.
- Even Source-Free DA (SFDA) says: It’s fine, we don’t need old data, we can fine-tune.
When the future application scenario is known in advance, these methods can prepare a model for changes during offline training or adaptation.
But the world doesn’t follow the script.
When the model is already deployed, and attackers begin using unfamiliar methods to invade, or when the environment generates variables that the model has never adapted to, can that model—who we thought was trained—still have a second learning opportunity?
The starting point of this paper comes from such a scenario:
When the only opportunity for learning is at the moment of inference, how should the model react?
This is not just a technical issue, but a late-coming memory battle.
We can't predict the attacker’s next move, but we can try to make the model relearn to see at the last moment.
Solving the Problem
The authors propose 3A-TTA, a three-in-one solution, allowing the model to directly rely on the unannotated target data during the "real inference" phase, to make final adaptive adjustments at the last moment.
The entire architecture is divided into three main components:
-
Activation-based Pseudo-Labeling:
With unannotated test data, how should the model learn? If we generate pseudo-labels based on scores, it’s easy to confuse real and fake faces due to their similar appearance.
This part uses Grad-CAM to obtain class activation maps for live and spoof faces, then compares their cosine similarity with the feature to generate "pseudo-labels."
-
Anti-Forgetting Feature Learning:
If the new batch consists of new types of attacks, the model might note them down but may also "forget" old knowledge.
Therefore, the method "filters" reliable samples and stores their features and pseudo-labels in a memory bank. It also considers them during updates to reduce the risk of forgetting.
-
Asymmetric Prototype Contrastive Learning:
New attack types may overlap with old attacks or real faces in feature space. How can the model still distinguish between fake and real faces when it hasn't seen the new attack?
The authors use contrastive learning and apply local aggregation to "spoof" features (finding the K spoof features nearest an attack sample) and global aggregation to "live" features (averaging the live features in memory into one prototype). This uses local similarities between attacks while separating live and spoof faces.
In the authors' setup, every time the model receives a new batch of "unannotated" target data, it immediately performs:
(1) Pseudo-label generation → (2) Reliable sample filtering → (3) Contrastive learning update.
This process happens during the inference phase, with no additional annotations to rely on and no need to return to the source data.
Before predicting each target batch, 3A-TTA updates its parameters using pseudo-labels and contrastive learning on that same batch. The overall benchmark results improve.
If you just want to understand the concept, then you’ve finished reading the paper here.
Next, let’s take a closer look at how each component works. If you're not interested, feel free to skip straight to the conclusion.
Activation-based Pseudo-Labeling
The image above illustrates the operation of this mechanism, which solves the problem of "how to learn without annotations."
Consider an unannotated image . If we rely only on score-based predictions to determine whether it is real or fake, there is a high likelihood of misjudgment due to similar lighting or surface features.
To address this, the authors use Grad-CAM to obtain separate live and spoof activation maps from the classifier, then compare each with the feature.
Next, the authors define cosine similarity :
They then determine the pseudo-label by comparing the activation map similarities of real and fake faces:
This generates a pseudo-label for each image; the experiments still have to test how reliable those labels are.
Finally, they use the liveness loss to ensure the model continues to update during the testing phase:
Anti-Forgetting Feature Learning
Pseudo-labels alone are not enough because some batches might be "all live or all spoof," and could even mix in "unknown new attacks." If we simply update with these batches, the model may "only remember new fake face samples and forget the old knowledge."
To avoid this, the authors select the most reliable features in each batch update using a threshold mechanism and store them in a Memory Bank (MB).
Whenever a new batch arrives, the model also considers the features and pseudo-labels stored from selected samples in earlier target batches. It calculates the Anti-Forgetting Liveness Loss to reduce the risk of shifting entirely toward the current batch. The memory bank does not reuse source data.
Specifically, for each sample with pseudo-label , the following threshold is used to determine if it is reliable:
where , , and .
If , the feature is written into the (using FIFO for updates).
These selected features and pseudo-labels are then considered during subsequent mini-batch updates, and the Anti-Forgetting Liveness Loss is defined as:
The aim is to use both the new batch and selected earlier target batches, reducing forgetting when the current batch is imbalanced.
Asymmetric Prototype Contrastive Learning
However, as the attack patterns increase, even the "memory bank" may not capture all possible variations.
Thus, this phase aims to "increase the distance between live and spoof samples" while "appropriately aggregating commonalities within spoof samples" in the same feature space.
-
Local Aggregation (Local Spoof Prototype)
Suppose a spoof sample is a new attack type.
In the memory bank, some spoof features from earlier target batches may partly resemble it. The authors use Euclidean distance to find the K nearest spoof features and aggregate them into a local spoof prototype as the anchor's positive sample. All live features in memory serve as its negative samples.
-
Global Aggregation (Global Live Prototype)
On the other hand, the authors assume the distribution of live faces varies less across domains. They average all live features in the memory bank into a "global" live prototype as the positive sample; only the K spoof features nearest the live anchor serve as negative samples.
This "asymmetric contrastive learning" aims to separate live from spoof faces while preserving useful local similarities among different spoof types.
Even with pseudo-label learning and anti-forgetting strategies, the model may still lack sufficient discriminative cues when facing unknown attacks. After incorporating positive and negative sample sets, the authors define the Asymmetric Prototype Contrastive Loss :
Here, and represent the negative sample sets of spoof and live anchors, respectively.
Through this contrastive learning, the model can separate real and fake faces in the feature space while retaining subtle similarities between different spoof samples, enhancing its ability to adapt to unknown attacks.
Total Loss Function
Finally, the authors consolidate the three loss components into:
with and .
By integrating pseudo-label learning (Liveness Loss), anti-forgetting (Anti-Forgetting), and contrastive differentiation (Prototype Contrast), the model no longer merely receives input: it can adjust before predicting the target batch. The paper evaluates specified cross-domain and unseen-attack protocols.
Discussion
Comparison with Other Methods
The authors compare 3A-TTA with a model without adaptation, Tent, and OAP with its source samples removed. The Time columns report total running time across the target datasets.
The experimental results are shown in the table above:
- Tent has a higher mean HTER than "No adaptation" under all four protocols in the table. In these FAS tests, this general-purpose TTA method does not necessarily help.
- OAP improves some target domains and worsens others, so its mean gains are limited.
- 3A-TTA has the lowest mean HTER under all four protocols. But its mean AUC of 82.24% for [I,C,M]→[O,D,H] is slightly below "No adaptation" at 82.54%. The paper's prose claims a 12.54% HTER improvement and a 2.11% AUC gain over OAP on average. Calculating directly from the four protocol means in the table instead gives about a 12.68% relative HTER reduction and a 1.80 percentage-point AUC gain. Its total running time is also higher than that of the comparison methods, so the accuracy table alone does not settle deployment cost.
Ablation Study
The authors dissected the three core modules (pseudo-label learning, Anti-Forgetting, Asymmetric Prototype Contrast) and compared the performance of various loss combinations.
Key findings are as follows:
-
Pseudo-labeling Mechanism:
- Compared with score-based and class-prototype-based labeling, Activation-based labeling (the paper's method) gives better downstream HTER and AUC in both Table 3 settings. The table does not directly measure pseudo-label accuracy.
- Figure 3 shows two examples in which activation-based labels correct score-based labels.
-
Anti-Forgetting Feature Learning:
- Compared with M3, which uses only , M4 adds and lowers HTER in both settings, but AUC falls slightly in both. Adding reliable feature selection in M5 then improves both HTER and AUC over M4.
- This supports the benefit of the memory bank and feature selection in these settings.
-
Prototype Contrast vs. General Contrast:
- M6, which uses general supervised contrastive loss , is worse than M5 without that loss on both HTER and AUC in both settings. The authors suggest that globally grouping spoof samples of the same class may overlook differences among attack types.
- Asymmetric Prototype Contrast () in M7 gives the best HTER and AUC under both tested directions, supporting this design in those two settings.
Visualization and Analysis
Finally, the authors conducted a visual analysis of 3A-TTA's results and compared them with other methods, also contrasting with models that were not adapted.
-
t-SNE Feature Distribution:
- In Figure (a), the unadapted model shows overlap between Live and Spoof features for [O,M,I]→[C,D,H].
- In Figure (b), the 3A-TTA features separate more clearly in this t-SNE projection. The visualization helps interpret the result.
-
Activation Maps:
- For the live example, the adapted live activation map ② concentrates more on the face than the unadapted map ①.
- For the spoof example, the adapted live activation map ④ responds less strongly than the unadapted map ③. These are illustrative examples.
Conclusion
Face Anti-Spoofing is no longer just a simple classification task.
In the ever-evolving landscape of generative attacks and increasingly diverse data sources, FAS models need a key ability to survive:
The ability to self-correct their judgment criteria in unforeseen scenarios.
The 3A-TTA method proposed in this paper is, to some extent, an attempt at such "self-correction."
From the results, this method outperforms previous approaches on the TTA-FAS benchmark and demonstrates that Test-Time Adaptation can indeed introduce new adaptability strategies for FAS tasks.
The life cycle of traditional models ends after training and online inference. However, the life cycle of TTA models begins at the moment of inference. This perspective also leads us to reconsider a key question:
If the field is the battleground, how should the model learn to fight back in the field?
Perhaps, in the future, AI models should not only finish the test but also learn to revise their answers after submission.