{'fraction_non_alphanumeric': 0.03654390934844193, 'fraction_numerical': 0.010269121813031162, 'mean_word_length': 5.001274968125797, 'pattern_counts': {'":': 0, '<': 0, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Towards Generalizable and Robust Face Manipulation Detection via Bag-of-local-feature

Over the past several years, in order to solve the problem of malicious abuse of facial manipulation technology, face manipulation detection technology has obtained considerable attention and achieved remarkable progress. However, most existing methods have very impoverished generalization ability and robustness. In this paper, we propose a novel method for face manipulation detection, which can improve the generalization ability and robustness by bag-of-local-feature. Specifically, we extend Transformers using bag-of-feature approach to encode inter-patch relationships, allowing it to learn local forgery features without any explicit supervision. Extensive experiments demonstrate that our method can outperform competing state-of-the-art methods on FaceForensics++, Celeb-DF and DeeperForensics-1.0 datasets.


INTRODUCTION
In recent years, lots of advanced face forgery techniques have been created to generate highly realistic fake human faces that can be infeasible even for humans to distinguish whether a face image has been manipulated. While these techniques (e.g. talking face [1]) can be benignly used for entertainment and other applications, the malicious abuse of these generated fake faces is inevitable, which poses huge threats to security and brings serious social risks, e.g. fake news and evidence. Therefore, it is highly desirable to develop powerful face manipulation detection technology.
Many manipulation detection methods have been proposed to tackle the problem of malicious abuse of facial forgery technology. The traditional image forensics [2,3,4,5,6] employ handcrafted features and intrinsic statistics to focus on specific types of forgery and achieve remarkable performance. However, these methods cannot adapt to the evolving manipulation technologies. To effectively and automatically detect the forgery features, more recent works [7,8,9] utilize deep learning models for face manipulation detection. While these methods perform well on hold-out test set for most manipulation detection datasets, the performance drops significantly when the testing set is characterized by the different data distribution from the training set (cross-dataset) or applied unseen perturbations (real-world perturbations). This generalization issue has been concerned in a few studies, ranging from learning local fake features [10,11] to simulating the affine face warping step and using extra simulated data [12,13] or adopting additional mask supervision signal [14,15]. It is worth noting that these methods require complex simulated data and additional mask supervision signal, which is very arduous for most face manipulation detection cases. In fact, most of the current works can not contend with both cross-dataset and real-world perturbations at the same time, thereby a major challenge in face manipulation detection community.
To bridge this challenge, we analyse current face manipulation datasets, such as FaceForensics++ [8] and observe the following two characteristics of the manipulated face images. Firstly, the manipulated images retain most of the regions of the source image. For instance, in Original and Fake rows of Fig. 2, face-swapping manipulations (Deepfakes and FaceSwap columns) tamper facial ID information while leaving the ID-independent background regions unchanged. And face-reenactment manipulations (Face2Face and NeuralTextures columns) only tamper the expression or the lips movements of the person. Secondly, the manipulated regions are so subtle compared to the entire image. In other words, the manipulated regions are local rather than global and troublesome to detect. In sight of these observations, we think that learning local forgery features of manipulated images is the key to face manipulation detection. Some existing methods also support the importance of local patch features. For example, [16] combines the deep neural network with bag-of-feature models to reach high accuracy on ImageNet even if limited to fairly small image patches, which verifies that the local image patches contribute to the final decision of the deep neural network. Besides, by rich experiment and additional visualizations, the authors in [17] find that truncated classifiers performs better on face manipulation detection since they focus on the local patches within the face region, which indicates that the local patch errors of a manipulated face are more stereotyped and generalized features.
In this paper, motivated by aforementioned observations and literature, we propose a novel method for face manipulation detection to improve the generalization ability by learn- ing local forgery features. Specifically, we extend transformers [18] using bag-of-local-feature approach to encode interpatch relationships. The core principle is to split a face image into patches and use self-attention to encode inter-patch relationships. This helps the model learn local forgery features without any supervision signal of the face manipulated regions.
To sum up, the major contributions of this work are as follows: 1) To the best of our knowledge, this is the first work using transformers for face manipulation detection. And we show the effectiveness of transformers on smaller task-specific datasets. 2) We propose a simple end-to-end approach that extends transformers using bag-of-feature models to learn local forgery features without any explicit supervision.
3) The extensive experiments not only demonstrate demonstrates the generalization capability of the proposed method on cross-dataset, but also shows its superior robustness to real-world perturbations.

METHODOLOGY
As shown in Fig. 1, we propose a simple end-to-end approach that extends transformers using bag-of-feature models to learn local forgery features. Firstly, we split a face image into bag-of-patch B and use the convolutional layer to embed each of patches into bag-of-feature B c . Then, the standard learnable 1D position embeddings are added to bagof-feature to retain positional information. Finally, we en-code inter-patch relationships in embedded features z using the transformer unit.

Bag-of-feature
In NLP, the counts of each word in the vocabulary are assembled as one long term vector. This is called the bag-of-words document representation. Likewise, the bag-of-feature representations are based on a vocabulary of visual words which represent clusters of local image features.
In this paper, an input image I ∈ R H×W ×C with width W , height H and channels C is divided into N nonoverlapping patches B = (X 1 , · · · , X N ) ∈ R N ×(P 2 ·C) ,where (P, P ) is the resolution of each image patch, and N = HW/P 2 is the resulting number of patches, B is the bag-ofpatch. Then, we feed patches X N inside bag B to a trainable convolutional layer to produce patch-level representations for bag-of-feature To retain image patches positional information, we add the standard learnable 1D position embeddings E ∈ R (N +1)×D to the bag-of-features B c (Eq. 1). Like in BERT [19], we add a special classification token x class in front of the sequence of embedded features z.

Transformer Unit
The Transformer unit consists of alternating layers of Multiheaded Self-Attention (MSA) and MultiLayer Perceptron (MLP) blocks. The particular attention "Scaled Dot-Product Attention" module has three projection branches that maps the input z ∈ R (N +1)×D to query (q), key (k), and value (v), where N + 1 is the number of inputs and D is the input dimensionality. In practice, we compute the attention function on a set of queries simultaneously, packed together into a matrix q. The keys and values are also packed together into matrices k and v . We compute the matrix of outputs as: Multihead self-attention (MSA) is an extension of SA in which we run k self-attention operations, called "heads", in parallel, and project their concatenated outputs. To keep compute and number of parameters constant when changing k, D h is typically set to D/k. MSA allows the model to jointly attend to information from different representation subspaces at different positions. With a single attention head, averaging inhibits this [18]. As shown in Fig. 1, by conducting the above Convolutional Layer and 1D Position Embedding, we fed z to the transformer unit to encode patch relationships in each bag B. Then we aggregate these patch-level representations to produce image-level representations. The iterative process in transformer unit can be formulated as: where = 1 . . . L and L is the number of transformers units, LN shows that layer normalization [20] applied before every block, and residual connections after every block. MLP head contains two linear layers with a GELU non-linearity and Dropout between them in the standard Transformer [18]. f c is one fully-connected layer for classification and y is the output prediction. Celeb-DF has two versions. The Celeb-DF(V1) [21] includes 408 real videos and 795 synthesized videos generated with DeepFake. The Celeb-DF(V2) [22] is composed of 590 real videos and 5,639 DeepFake videos. We only use their test set to evaluate the generalization ability of the proposed method. DeeperForensics-1.0 (DF-1.0) [23] is a large face forgery detection dataset with 60, 000 videos constituted by a total of 17.6 million frames. And extensive real-world perturbations are applied to obtain a more challenging benchmark of larger scale and higher diversity. We use it to evaluate the robustness of the proposed approach under different distortions.
For face data preprocessing, we follow the setting in [8].

Experiments settings
We adopted the pretrained Vision Transformers [25] to initialize weights of our proposed network. The network was supervised with Cross-Entropy loss. We selected 20 frames/video for the training. The input size is 384×384. In the training phase, we adopted the SGD optimizer with a learning rate of 0.01 and momentum of 0.9 and use a CosineAnnealingLR learning rate scheduler. For the evaluation metric, we selected the area under the receiver operating curve (AUC) score and accuracy (Acc).

Evaluation of FaceForensics++
Evaluation results on FF++ are listed in Tab. 1. This experiment shows a thorough comparison on FF++ [8] with recent works. Generally, the proposed approach performance is higher than the existing work. It should be noted that we sample much less frames from each video as training data than other methods and do not use the temporal information of videos as Two-branch method. Our method uses a transformer-based attention network with bag-of-feature, which can help the model automatically learn discriminative local forgery features without explicit supervision.
To better understand the effectiveness of the proposed methods, we use Attention Rollout [26] to visualize maps of the attention on FF++ testing images in Fig. 2. The model accurately highlights some subtle tampering in facial expressions and the lips movements for face-reenactment manipulations (Face2Face and NeuralTextures) in Fig. 2. And for face-swapping manipulations (Deepfakes and FaceSwap), the model could focus attention on face identity related manipulated regions such as eyes, noses, mouths and beards. The attention maps indicate that our approach focuses on manipulated regions and artifacts rather than background content or unmodified face area by learning local forgery features.

Generalization Evaluation on Cross-dataset
We evaluate the generalization ability of the proposed method on unseen Celeb-DF datasets that is trained on FF++ (C23) with four manipulation types. As shown in Tab. 2, our method is about 2% higher than the Face X-ray on Celeb-DF(V1) and is about 5% higher than the Two-branch on Celeb-DF(V2). Table 3. The comparison results in terms of Acc on real-world perturbations DF-1.0 dataset. "std", "std/sing", "std/rand" and "std/mix3" denote the standard set without distortions, the standard set with single-level distortions, the standard set with random-level distortions, and the standard set with the mixed distortions, respectively.
Model Training set std Test set Acc std/sing std/rand std/mix3 C3D [23] 87 Note that the Face X-ray learns to detect the blending boundary by additional private BI [13] dataset and mask supervision signal and the Two-branch utilizes the temporal information of videos. Neither exploiting any additional dataset and supervision signals, nor using the temporal information, our method can still obtain better performance on unseen Celeb-DF datasets. These results further demonstrate the effectiveness of our method on the generalization ability.

Robustness Evaluation of Real-world Perturbations
We study the effect of perturbations towards the face manipulation detection model performance on DF-1.0 [23] dataset. In this setting, all models are trained on the standard set without distortions and tested on different level perturbation sets (std/sing, std/rand and std/mix3). As shown in Tab. 3, our method achieves remarkable performance and is about 5%, 2% and 5% higher than Xception on std/sing, std/rand and std/mix3 test set, respectively. Compared to the video-level methods, C3D, TSN and I3D, that use the temporal information of videos, our method still obtains superior performance. These results show that the proposed approach is more robust to perturbations than the existing methods.

CONCLUSION
In this paper, we extend bag-of-features models using transformers units to learn local forgery features without explicit supervision signal. Since the manipulated regions are so subtle compared to the entire image in face manipulation detection tasks, we divide manipulated face image into patches and use self-attention to encode local forgery inter-patch representations. The proposed method obtains better performance than the prior methods with additional data and manipulation regions supervision signal on FF++, Celeb-DF and DF-1.0 datasets. Our method also shows the effectiveness of vision transformers on smaller task-specific datasets.