Poly-NL: Linear Complexity Non-local Layers With 3rd Order Polynomials

Francesca Babiloni, Ioannis Marras, Filippos Kokkinos, Jiankang Deng, Grigorios Chrysos, Stefanos Zafeiriou

Abstract

Non-local (NL) layers are effective at capturing long-range spatial dependencies in computer vision tasks but suffer from quadratic computational complexity $O(N^2)$ relative to the number of pixels $N$. This paper introduces Poly-NL, a novel architectural block that reformulates self-attention as a 3rd-order polynomial. By factorizing the interaction using learnable weight matrices and element-wise products, Poly-NL achieves linear complexity $O(N)$ without sacrificing expressiveness. Experimental results on COCO, ImageNet, and WIDER FACE demonstrate that Poly-NL provides state-of-the-art performance with significantly reduced computational overhead and memory usage compared to standard NL blocks.

Introduction: The Computational Tax of Global Context

Convolutional Neural Networks (CNNs) excel at local feature extraction but often fail to capture long-range dependencies—relationships between distant pixels in an image. Non-local (NL) blocks, a form of spatial self-attention, were introduced to address this. However, standard NL blocks compute a similarity score between every pair of pixels, leading to $O(N^2)$ complexity. As image resolutions climb toward 4K and 8K, this quadratic scaling becomes a prohibitive "computational tax." Poly-NL addresses this by providing a theoretically grounded, linear-time alternative.

Methods: Non-local Operations as Polynomials

The core innovation of Poly-NL is treating the non-local operation as a 3rd-order polynomial function. The authors demonstrate that standard self-attention is a specific, sparse instance of such a polynomial.

Instead of constructing a massive $N \times N$ similarity matrix, Poly-NL factorizes the interaction. It employs three learnable weight matrices ($W_1, W_2, W_3$) and element-wise (Hadamard) products. The operation is defined as: $$Y^{Poly-NL} = (\Phi(XW_1 \odot XW_2) \odot X)W_3$$ where $\Phi$ denotes an average pooling and expansion step. By replacing large matrix-matrix multiplications with element-wise operations across the spatial dimension, complexity is reduced from $O(N^2)$ to $O(N)$.

Architecture of the Poly-NL block (a) and its conceptual mapping to a 3rd-order polynomial (b).

Key Insights: The Triplet Connection

A profound insight from this work is the "Triplet" connection: both standard NL blocks and Poly-NL access the same set of "triplets" of input elements. The primary difference lies in how these triplets are weighted and summed. Poly-NL identifies a more efficient computational path to achieve similar or superior global context modeling. Unlike previous "fast" attention methods that rely on low-rank approximations or downsampling, Poly-NL maintains the full expressiveness of the original non-local intent.

Experimental Evaluation

The authors evaluated Poly-NL across three major benchmarks:

  • MS COCO 2017: For object detection and instance segmentation.
  • ImageNet: For large-scale image classification.
  • WIDER FACE: For face detection, focusing on the challenging "Hard" subset.

Key Results: Efficiency and Performance

Poly-NL demonstrates significant advantages in both speed and accuracy. It is approximately 10x faster than high-performing competitors like TESA at standard resolutions. As the number of spatial positions increases, the efficiency gap widens, as Poly-NL's runtime scales linearly while others scale quadratically.

Comparison of GPU run time and memory usage across different non-local variants. Poly-NL (green) shows linear scaling compared to the quadratic growth of standard NL (blue).

In practical tasks:

  • Instance Segmentation: Adding Poly-NL to a Mask R-CNN backbone improved $AP_{box}$ from 37.9 to 39.2, outperforming standard NL blocks.
  • Face Detection: Achieved 92.76% mAP on the WIDER FACE "Hard" set, surpassing other non-local variants.
  • Classification: Boosted ResNet-50 Top-1 accuracy on ImageNet from 75.62% to 76.30% with negligible cost.

Conclusion and Future Directions

Poly-NL proves that explicit similarity matrices are not required for effective global context. While this work focuses on 3rd-order polynomials to match existing NL formulations, future research could explore higher-order polynomials for even more complex interactions. Additionally, the mathematical framework suggests that this polynomial approach could be adapted to Vision Transformers (ViTs) to mitigate their inherent quadratic scaling issues.

Summary updated

BibTeX
@inproceedings{babiloni2021poly,
  author = {Francesca Babiloni and Ioannis Marras and Filippos Kokkinos and Jiankang Deng and Grigorios Chrysos and Stefanos Zafeiriou},
  title = {{Poly-NL: Linear Complexity Non-local Layers With 3rd Order Polynomials}},
  booktitle = {IEEE/CVF International Conference on Computer Vision},
  year = {2021},
  doi = {10.1109/iccv48922.2021.01035},
}
Figure