Face Transformer for Recognition

Yaoyao Zhong, Weihong DengarXiv 2021

Abstract

Recently there has been a growing interest in Transformer not only in NLP but also in computer vision. We wonder if transformer can be used in face recognition and whether it is better than CNNs. Therefore, we investigate the performance of Transformer models in face recognition. Considering the original Transformer may neglect the inter-patch information, we modify the patch generation process and make the tokens with sliding patches which overlaps with each others. The models are trained on CASIA-WebFace and MS-Celeb-1M databases, and evaluated on several mainstream benchmarks, including LFW, SLLFW, CALFW, CPLFW, TALFW, CFP-FP, AGEDB and IJB-C databases. We demonstrate that Face Transformer models trained on a large-scale database, MS-Celeb-1M, achieve comparable performance as CNN with similar number of parameters and MACs.

Introduction

For years, face recognition (FR) has been dominated by Convolutional Neural Network (CNN) architectures like ResNet and VGGNet, paired with specialized loss functions such as ArcFace or CosFace. While Transformers have revolutionized Natural Language Processing and general computer vision via Vision Transformers (ViT), their feasibility for the highly specific task of face recognition remained under-explored.

A key challenge in applying standard ViT to faces is the "patchification" process. Standard ViT divides an image into non-overlapping squares. In face recognition, critical features—like the corner of an eye or the curve of a lip—might be split across these rigid boundaries, potentially losing local discriminative information. This study investigates whether a modified Transformer can match CNN performance and whether it offers unique advantages, such as better robustness to occlusions.

Methods

The proposed Face Transformer (ViT) largely follows the original ViT architecture but introduces a crucial modification in the input stage to preserve local context.

The Face Transformer architecture featuring sliding patches and a standard Transformer encoder.

Sliding Patches

Instead of standard non-overlapping patches, the authors use a sliding window approach. By using a patch size larger than the stride (e.g., a $12 \times 12$ patch with a stride of 8), overlapping tokens are created. This ensures that inter-patch information is preserved, allowing the model to better capture features that straddle patch boundaries.

Training Pipeline and Loss

The model utilizes a standard Transformer encoder consisting of Multi-Head Self-Attention and MLP blocks. For the final face embedding, the "class token" ($z_0^L$) output is used. To ensure high discriminative power, the model is trained using CosFace, a large-margin cosine loss function. Interestingly, standard SGD failed to converge; the authors successfully employed AdamW with a cosine learning rate decay.

Results and Key Insights

The models were trained on CASIA-WebFace (~0.49M images) and the large-scale MS-Celeb-1M (~5.3M images), then evaluated on benchmarks like LFW, IJB-C, and others.

Data Hunger and Inductive Bias

On the smaller CASIA-WebFace dataset, Transformers performed significantly worse than ResNet-100. However, on MS-Celeb-1M, the gap closed. Trained on this large-scale data, the ViT-P12S8 achieved 99.80% accuracy on LFW and 96.31% TAR@FAR=1e-4 on IJB-C, nearly matching ResNet-100's performance. This suggests Transformers lack the "inductive bias" of CNNs and require massive data to learn spatial relationships.

Attention Visualization

Using "Attention Rollout" techniques, the authors visualized the model's focus. The Face Transformer naturally learns to attend to central facial features (eyes, nose, mouth) without explicit guidance.

Attention Rollout visualization showing the model's focus on discriminative facial regions.

Architectural Components

The "sliding patch" models consistently outperformed non-overlapping versions, proving the importance of local context. Furthermore, the authors found that removing the MLP blocks significantly degraded accuracy, confirming the MLP's essential role in feature transformation. In terms of speed, ViT models showed comparable inference speeds to ResNet-100 on a Tesla V100 GPU (approx. 42-44 images/sec).

Conclusion

Face Transformers can achieve state-of-the-art performance in face recognition when trained on sufficiently large datasets. While they do not inherently handle occlusions better than CNNs and require more data to generalize, they represent a powerful alternative to traditional convolutional architectures. Future work will explore more efficient Transformer variants and deeper investigations into why Transformers do not inherently handle occlusions better than convolutions.

Summary updated

BibTeX
@misc{zhong2021face,
  author = {Yaoyao Zhong and Weihong Deng},
  title = {{Face Transformer for Recognition}},
  year = {2021},
  eprint = {2103.14803},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2103.14803},
}
Figure