RepMLP: Re-parameterizing Convolutions into Fully-connected Layers for Image Recognition

Xiaohan Ding, Xiangyu Zhang, Jungong Han, Guiguang DingarXiv 2021

TL;DR

This paper introduces RepMLP, a novel building block for neural networks that re-parameterizes convolutional layers into fully-connected (FC) layers. By cleverly merging convolutional structures into FC layers during training and then simplifying them for inference, RepMLP aims to leverage the global reasoning capabilities of FC layers while retaining the local feature extraction power of convolutions, leading to improved accuracy and speed.

What Problem Does This Paper Address?

Traditional convolutional neural networks (CNNs) excel at image recognition due to their inherent "local prior" – the assumption that nearby pixels are more related than distant ones. This inductive bias is captured by convolutional filters that process small, local receptive fields. However, CNNs can struggle to efficiently model long-range dependencies within an image, a capability that fully-connected (FC) layers, or Multi-Layer Perceptrons (MLPs), are naturally good at. Conversely, pure MLPs, while strong at global reasoning, lack the local prior crucial for image tasks and often suffer from a massive number of parameters. This paper addresses the challenge of combining the strengths of both architectures: the global reasoning and positional perception of FC layers with the local feature extraction of convolutions, without incurring the computational or parameter overhead of traditional methods.

Methods

The core innovation is structural re-parameterization. RepMLP is designed as a training-time block that includes parallel branches for FC layers and convolutional layers (along with Batch Normalization). Crucially, the paper proposes a method to merge these convolutional branches into the FC layers for inference. This process effectively injects the "local prior" into the FC layer, allowing it to learn local patterns while still benefiting from its global reasoning capabilities.

The RepMLP block is further broken down into three components:

  • Global Perceptron: Captures correlations among different spatial partitions of the feature map.
  • Partition Perceptron: Models long-range dependencies using an FC layer.
  • Local Perceptron: Captures local patterns using multiple convolutional layers with different kernel sizes.

The key to their method is a platform-agnostic and differentiable algorithm that converts convolutional kernels into equivalent FC kernels. This allows the entire RepMLP block to be represented by a single, efficient FC layer during inference, eliminating the computational cost of convolutions.

Datasets

The paper evaluates RepMLP on several standard computer vision datasets:

  • CIFAR-10: Used for initial experiments with a pure MLP model.
  • ImageNet: Used for evaluating RepMLP's performance when integrated into ResNet architectures for general image classification.
  • MS1M-V2: A large-scale face dataset used for training face recognition models.
  • MegaFace: Used for evaluating face recognition performance.
  • Cityscapes: Used for evaluating semantic segmentation performance.

Key Insights and Ideas

  • FC layers are powerful for global reasoning and positional perception: The paper argues that FC layers, despite their parameter count, are inherently better at understanding global relationships and specific spatial arrangements (like in face recognition) than standard CNNs.
  • Convolutions can be "unrolled" into FC layers: The core idea of re-parameterization demonstrates that the functionality of a convolution can be mathematically represented as a specific transformation within an FC layer.
  • Structural re-parameterization is key: By designing the network with parallel convolutional and FC branches during training and then merging them, the authors achieve the benefits of both without the inference-time cost.
  • RepMLP offers a flexible building block: The method is shown to be effective when inserted into existing architectures like ResNet, improving performance across various tasks.
  • The "local prior" is not exclusive to convolutions: This work challenges the notion that only convolutions can capture local spatial information, showing that FC layers can be augmented to do so efficiently.

Key Results

  • ImageNet Classification: RepMLP integrated into ResNet-50 improved accuracy by 1.8% compared to the original ResNet-50, with lower FLOPs.
  • Face Recognition: RepMLP-based models achieved 2.9% higher accuracy on ImageNet and outperformed a baseline MobileFaceNet by 4.91% higher accuracy and 8% faster speed on MS1M-V2 and MegaFace.
  • Semantic Segmentation: RepMLP-ResNet-50 achieved 2.21% higher mIoU on Cityscapes compared to the ResNet-50 backbone, with lower FLOPs and faster speed.
  • Pure MLP on CIFAR-10: A pure MLP model using RepMLP achieved performance very close to CNNs, demonstrating the effectiveness of the RepMLP block itself.
  • Speed Improvements: In several scenarios, RepMLP-based models achieved significant speedups (e.g., 55% faster with RepMLP Light Block) while maintaining comparable or improved accuracy.

Limitations and Future Work

  • Parameter Count: While RepMLP aims for efficiency, some configurations (e.g., using RepMLP in all stages of ResNet) can lead to a higher parameter count compared to the original ResNet-50, though often with better accuracy and speed.
  • Groupwise Convolution Efficiency: The paper notes that current groupwise 1x1 convolutions might not be as efficient as expected, suggesting room for further optimization.
  • Optimal Integration: The authors acknowledge that their proposed methods for integrating RepMLP into ResNet are not necessarily optimal and suggest that further research could explore other combinations and architectures.
  • All-MLP Models: The paper mentions that applying RepMLP to existing all-MLP models (like MLP-Mixer) is a promising direction for future work.
  • Understanding Conv as Degraded FC: The theoretical framing of viewing convolutions as a degraded case of FCs opens avenues for deeper theoretical understanding of neural network architectures.

Summary updated

BibTeX
@misc{ding2021repmlp,
  author = {Xiaohan Ding and Xiangyu Zhang and Jungong Han and Guiguang Ding},
  title = {{RepMLP: Re-parameterizing Convolutions into Fully-connected Layers for Image Recognition}},
  year = {2021},
  eprint = {2105.01883},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2105.01883},
}
Figure