Toward a Deeper Understanding: Retnet Viewed Through Convolution

Chenghao Li, Chaoning Zhang

Abstract

Vision Transformers (ViTs) often struggle on small-scale datasets due to a lack of the inherent inductive biases found in Convolutional Neural Networks (CNNs), such as locality and translation invariance. This paper introduces the Gaussian Mixture Mask (GMM), a lightweight, plug-and-play module designed to inject spatial inductive bias into ViTs. By representing attention masks as a mixture of learnable Gaussian kernels, the GMM significantly enhances performance on small datasets with negligible parameter overhead.

Introduction

For over a decade, Convolutional Neural Networks (CNNs) have been the standard for computer vision, largely due to their inductive biases of locality—where neighboring pixels are considered more related—and translation invariance. In contrast, Vision Transformers (ViTs) employ a global attention mechanism that treats all image patches as equidistant. While this global perspective is advantageous for massive datasets like ImageNet-21k, it becomes a liability when training on smaller datasets, where the model lacks sufficient data to learn spatial relationships from scratch.

Previous attempts to address this, such as Element-wise Learnable Masks (ELM), introduced a learnable weight for every entry in the attention matrix. However, this approach scales poorly, adding $N^2$ parameters relative to the number of patches, which complicates optimization and increases model weight.

Methodology: The Gaussian Mixture Mask

To overcome the limitations of ELM, the authors propose the Gaussian Mixture Mask (GMM), inspired by the RetNet architecture in natural language processing. The GMM replaces the dense $N^2$ grid with a mixture of $K$ Gaussian kernels.

Architecture of the Gaussian Mixture Mask (GMM) integrated into the attention mechanism.

Each kernel in the GMM is defined by two primary learnable parameters:

  • Sigma ($\sigma$): This parameter controls the "locality" or the spatial spread of the attention.
  • Alpha ($\alpha$): This parameter controls "extroversion." A negative alpha value suppresses a patch’s self-attention, encouraging the model to integrate information from surrounding patches more rapidly.

The GMM is multiplied element-wise with the attention scores prior to the softmax operation. This design allows it to be easily integrated into various architectures, including vanilla ViTs, Swin Transformers, and PiT, without altering their fundamental structure.

Experimental Results

The GMM was evaluated on several small-scale benchmarks, including CIFAR-10, CIFAR-100, SVHN, and Tiny-ImageNet. The results demonstrate consistent performance improvements:

  • Accuracy Gains: On CIFAR-10, a GMM-equipped ViT achieved 95.06% accuracy, compared to the 93.65% baseline. On Tiny-ImageNet, performance rose from 59.89% to 62.27%.
  • Parameter Efficiency: A lightweight GMM-ViT with only 2.5 million parameters performed comparably to a Swin Transformer with 7.1 million parameters. The GMM achieves these gains by adding as few as 150 parameters.
  • Model Stability: Standard ViTs often experience performance degradation as depth increases on small datasets. The GMM stabilizes deep models, making 60-layer architectures viable even with limited training data.

Analysis of Learned Biases

The effectiveness of the GMM stems from its ability to model specific spatial behaviors.

Visualization of attention maps for each patch, demonstrating the learned spatial biases and the extroversion effect.

Key insights from the learned masks include:

  • The Extroversion Effect: Successful models often suppress self-attention in certain layers to accelerate information flow across the network.
  • Depth-Dependent Locality: The GMM allows the model to automatically learn that shallow layers require a tight, local focus, while deeper layers benefit from more global correlations.

Conclusion and Future Work

The Gaussian Mixture Mask provides a highly efficient method for introducing necessary inductive biases into Vision Transformers. While highly effective for small-scale datasets, future research is needed to determine its impact on large-scale training and to explore methods for dynamically determining the optimal number of Gaussian kernels.

Summary updated

BibTeX
@article{li2024toward,
  author = {Chenghao Li and Chaoning Zhang},
  title = {{Toward a Deeper Understanding: Retnet Viewed Through Convolution}},
  journal = {Pattern Recognition},
  year = {2024},
  doi = {10.1016/j.patcog.2024.110625},
}
Figure