Attfc: Attention Fully-Connected Layer for Large-Scale Face Recognition with One Gpu

Zhuowen Zheng, Yain‐Whar Si, Xiaochen Yuan, Junwei Duan, Ke Wang, Xiaofan Li, Xinyuan Zhang, Xueyuan GongSSRN 2024

TL;DR

This paper introduces AttFC, a novel attention-based fully-connected layer designed to significantly reduce the computational burden of large-scale face recognition models. By dynamically generating and storing a small subset of class centers using an attention mechanism, AttFC achieves comparable performance to state-of-the-art methods while drastically cutting down memory and time requirements, enabling training on a single GPU.

What Problem Does This Paper Address?

Training deep neural networks for large-scale face recognition (FR) has become computationally demanding. The bottleneck lies in the fully-connected (FC) layer, whose parameter count scales linearly with the number of identities in the dataset. For massive datasets with millions of identities, this leads to enormous memory and time requirements, often exceeding the capacity of a single GPU and necessitating multi-GPU setups. Existing methods to alleviate this issue, like partial FC, require more hardware, while others propose new structures but may not fully capture identity information. This paper aims to address the need for a more efficient FC layer that maintains high performance without requiring extensive computational resources.

Methods

The core innovation is the Attention Fully-Connected (AttFC) layer. Instead of storing all class centers (Learned Class Centers - LCCs) in a traditional FC layer, AttFC uses a Dynamic Class Container (DCC) that stores a much smaller, dynamically updated subset of class centers. These centers are Generative Class Centers (GCCs), created by an attention loader.

Here's a breakdown of the key components:

  • Generative Class Center (GCC): Unlike LCCs that are directly learned from data, GCCs are generated using features from multiple images of the same identity. This approach aims to create a more robust representation of the true class center (TCC).
  • Attention Loader: This module is inspired by attention mechanisms. It takes an identity feature and multiple class features (from different images of the same identity) and calculates "attention weights." These weights determine the contribution of each class feature to the GCC, effectively down-weighting low-quality or noisy images and emphasizing high-quality ones. This ensures the GCC is more closely aligned with the TCC.
  • Dynamic Class Container (DCC): This acts as a replacement for the FC layer. It's a FIFO queue with a fixed capacity (S), storing only S GCCs at any given time. This drastically reduces the number of parameters compared to a traditional FC layer (D x N, where N is the number of identities).
  • Class Encoder: Alongside the standard feature encoder, AttFC uses a class encoder. Both encoders have the same structure. The feature encoder extracts identity features, while the class encoder extracts class features. The class encoder is momentum-updated based on the feature encoder to maintain consistency.
  • Class Center Conflict Handling: To address potential conflicts where multiple GCCs for the same identity might exist in the DCC (due to batch processing), a masking mechanism is employed to ensure each identity feature is associated with only one class center for loss calculation.

Datasets

The paper uses several large-scale face recognition datasets for training and evaluation:

  • MS1MV3: A dataset comprising 93K identities and 5M images.
  • WebFace42M: Including subsets like WebFace21M (1M identities, 21M images), WebFace8M (400K identities), and WebFace4M (200K identities).

Standard benchmarks are used for evaluation:

  • LFW (Labeled Faces in the Wild)
  • CFP-FP (Celebrating Faces in the Wild - Frontal-Profile)
  • AgeDB
  • IJB-B and IJB-C

Key Insights and Ideas

  • Attention for Quality Control: The attention mechanism is crucial for generating high-quality GCCs. By learning to weigh features based on their relevance to the identity, AttFC effectively filters out noise from low-quality images, leading to GCCs that are more representative of the true class center.
  • DCC as a Memory Saver: The Dynamic Class Container is the key to reducing computational resources. By storing only a small subset of class centers, it dramatically shrinks the parameter count of the classification head, making single-GPU training feasible for massive datasets.
  • Trade-off Between Size and Performance: The paper demonstrates that a smaller DCC capacity (size ratio 'r') can still achieve comparable performance to a full FC layer, highlighting that not all class centers are equally important at every training stage.
  • Scalability and Integration: AttFC is designed to replace only the FC layer, making it easily integrable with existing FR architectures and methods.

Key Results

  • Significant Resource Reduction: AttFC reduces the number of parameters in the classification head to approximately 30% of the original FC layer, enabling training on a single GPU even for datasets that cause Out-of-Memory (OOM) errors for standard FC or even Partial FC methods.
  • Comparable Performance: Despite the substantial reduction in parameters, AttFC achieves performance comparable to, and in some cases superior to, traditional FC layers and other state-of-the-art methods on various datasets (e.g., MS1MV3, LFW, CFP, AgeDB). For instance, on MS1MV3, AttFC shows a maximum decrease of less than 1% compared to FC across test sets.
  • Impact of 'k' (Number of Class Images): Increasing the number of class images used to generate GCCs generally improves performance, but the gains diminish significantly after k=3. A default of k=2 is chosen for a balance between performance and computational cost.
  • Attention vs. Constant Weight: AttFC with attention weights outperforms using a constant weight for generating GCCs, underscoring the importance of adaptive feature weighting.

Limitations and Future Work

  • Reliance on Multiple Images: AttFC currently relies on multiple images of the same identity to generate GCCs. The authors suggest that future work could explore methods to generate both features and class centers from a single image, which would further conserve computational resources.
  • Theoretical vs. Empirical: While the paper presents strong empirical results, the theoretical underpinnings of why this specific attention mechanism and DCC approach work so effectively could be further explored.
  • Hyperparameter Tuning: The performance of AttFC, like any deep learning model, is sensitive to hyperparameters such as the DCC capacity (r) and the number of class images (k). Further research into optimal hyperparameter selection strategies could be beneficial.

Summary updated

BibTeX
@misc{zheng2024attfc,
  author = {Zhuowen Zheng and Yain‐Whar Si and Xiaochen Yuan and Junwei Duan and Ke Wang and Xiaofan Li and Xinyuan Zhang and Xueyuan Gong},
  title = {{Attfc: Attention Fully-Connected Layer for Large-Scale Face Recognition with One Gpu}},
  year = {2024},
  eprint = {2503.06839},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2503.06839},
}
Figure