TL;DR
This paper introduces Graph Head Attention (GHA), a novel mechanism for Vision Transformers (ViTs) that replaces standard Multi-Head Attention (MHA) with a graph-based approach. GHA effectively captures both local and global image features while significantly reducing computational complexity and parameter count, achieving competitive performance on various datasets without extensive pre-training.
What Problem Does This Paper Address?
Vision Transformers (ViTs) have revolutionized computer vision by applying the transformer architecture, originally for natural language processing, to image tasks. However, standard ViTs suffer from a few key limitations:
- Loss of Locality: The self-attention mechanism in ViTs treats all image patches equally, neglecting the inherent spatial relationships and local structures crucial for image understanding.
- Computational Cost: Processing high-resolution images with ViTs is computationally expensive due to the quadratic complexity of self-attention with respect to the number of patches. This also necessitates large amounts of training data.
- Parameter Inefficiency: While MHA allows for learning diverse attention patterns, not all heads contribute equally, and some may even negatively impact performance. This suggests MHA might be over-parameterized for the task.
Existing approaches to mitigate these issues include reducing training data requirements, optimizing operations, or incorporating locality mechanisms. However, many still rely heavily on MHA or struggle to effectively integrate global and local information.
Methods
The core innovation of this paper is the Graph Head Attention (GHA) mechanism, which aims to address the limitations of MHA in ViTs. Here's how it works:
- Graph Structure Generation: Instead of directly computing attention scores between all patch pairs, GHA first generates a graph representation of the image patches.
- The standard attention matrix ($A_T$) is computed using Query (Q), Key (K), and Value (V) matrices derived from the input patches.
- A "Top-k" function is applied to the attention matrix to select a subset of nodes (patches) with high connectivity, forming a sparse adjacency matrix ($A_D$). This step is crucial for reducing unnecessary computations.
- This sparse matrix is then transformed into an undirected graph, ensuring that relationships between patches are considered symmetrically.
- An optional graph calibration step further refines the graph structure using trainable parameters.
- Graph Attention Network (GAT): The generated graph structure and the patch features (Value matrix V) are then fed into a Graph Attention Network (GAT).
- The GAT assigns different importance weights to neighboring nodes (patches) based on their learned relationships, effectively capturing local context.
- This process allows the model to dynamically consider patch relationships and ensures diversity in attention.
- GHA Encoder Layer: The GHA mechanism replaces the MHA module within the standard ViT encoder layers. The output of the GHA is then processed by a feed-forward network (FFN), similar to standard ViTs.
- Multi-Readout Feature: For the final classification, the paper employs a multi-readout mechanism, combining mean, max, and sequential pooling of the output features to capture diverse information.
Key Novelty: Unlike previous graph-based transformers that often combine graph and attention modules separately, GHA integrates graph generation within the attention mechanism itself, directly replacing MHA with fewer, more efficient graph heads. This avoids the need for a class token in patch embedding, further reducing operations.
Datasets
The proposed GHA-ViT model was evaluated on several standard benchmark datasets:
- Small-sized datasets: CIFAR-10, CIFAR-100, MNIST, and MNIST-Fashion.
- Medium-sized dataset: ImageNet-1K.
The paper focuses on demonstrating performance with scratch training, meaning models were trained from random initialization without pre-training on larger datasets, highlighting the model's ability to learn effectively with less data.
Key Insights and Ideas
- Graph Structure as a Pruning Mechanism: The core idea of using a graph structure derived from the attention matrix to prune less relevant patch connections is highly effective. It allows the model to focus computational effort on meaningful interactions.
- Locality and Globality Synergy: By explicitly modeling patch relationships as a graph, GHA successfully preserves and leverages both local image structures and global context, a balance that standard ViTs struggle with.
- MHA Over-parameterization: The paper's premise that not all MHA heads are equally useful is supported by their findings that fewer GHA heads can achieve comparable or better results, suggesting a more efficient use of parameters.
- Inductive Bias for Smaller Datasets: The graph-based approach inherently introduces inductive bias, making the model more robust and performant on smaller datasets without requiring extensive pre-training, a significant advantage over pure ViTs.
- Flexibility of GHA: The GHA mechanism demonstrates flexibility, showing good performance with different graph convolution types (GCN, GIN, GAT), with GAT yielding the best results due to its ability to assign differential importance to neighbors.
Key Results
- Competitive Accuracy: GHA-ViT achieves competitive Top-1 accuracy on CIFAR-10/100, MNIST, and MNIST-F datasets, often outperforming other state-of-the-art (SoTA) models, especially when trained from scratch.
- ImageNet-1K Performance: On ImageNet-1K, the GHA-B model achieved a Top-1 accuracy of 81.7%, demonstrating strong performance on a medium-sized dataset.
- Parameter and Operation Reduction: GHA-S uses approximately 17-fold fewer parameters and 5.8-fold fewer operations than pure ViT-12/4, while achieving a 4.3% higher accuracy on CIFAR-100.
- Efficiency without Pre-training: The model demonstrates strong performance even with scratch training, a significant advantage over methods that rely heavily on pre-trained weights.
- Graph Generation Effectiveness: Ablation studies show that the proposed "Gall" graph generation method (considering both upper and lower triangular matrices) consistently yields higher accuracy than simpler graph generation approaches.
Limitations and Future Work
- Graph Structure Generation Refinement: The authors suggest future work to improve the mask filter used in graph construction and explore different graph-pooling approaches (e.g., graph U-NET) to further enhance attention output and ViT performance.
- Further Exploration of GHA: While GHA shows promise, further research could explore its application to more complex vision tasks beyond classification and investigate its scalability to even higher resolution images.
- Comparison with Pre-trained Models: While the paper emphasizes scratch training, a direct comparison with GHA-ViT using pre-trained weights against other pre-trained SoTA models could provide further insights into its potential.
Summary updated