Sequencer: Deep LSTM for Image Classification

Yuki Tatsunami, Masato Taki

TL;DR

Sequencer is a novel vision architecture that replaces the self-attention layers of Transformers with a two-dimensional Long Short-Term Memory (LSTM) structure. It achieves competitive performance (84.6% top-1 on ImageNet-1K) while demonstrating superior memory efficiency at high resolutions and remarkable robustness to changes in input resolution compared to Vision Transformers (ViTs) and MLPs.

What Problem Does This Paper Address?

In recent years, the computer vision landscape has been dominated by the Vision Transformer (ViT), which uses self-attention to model long-range dependencies. While powerful, self-attention has a quadratic computational cost relative to the number of image patches, making high-resolution processing expensive.

Alternatives like MLP-Mixer use simple multi-layer perceptrons to mix information, but they suffer from "resolution rigidity"—because their weights are tied to a specific sequence length, they struggle to adapt to different input resolutions without significant fine-tuning. The authors of Sequencer tackle this by asking: Can we use LSTMs—the former kings of sequence modeling in NLP—to create a vision model that is globally aware, memory-efficient, and resolution-flexible?

Methods

The Sequencer architecture adopts the "MetaFormer" macro-structure (patch embedding followed by repeated blocks), but introduces a unique BiLSTM2D layer for token mixing.

Sequencer Macro-architecture and BiLSTM2D block
  1. Spatial Decomposition: Instead of flattening an image into one long 1D sequence, Sequencer treats the image as a 2D grid of patches.
  2. Parallel BiLSTMs: The model processes the grid using two Bidirectional LSTMs in parallel:
  3. A Vertical BiLSTM that processes columns of patches.
  4. A Horizontal BiLSTM that processes rows of patches.
  5. Channel Fusion: The outputs from the vertical and horizontal passes are concatenated and fused through a linear layer.
  6. Macro-Architecture: Like ViTs, these blocks are interleaved with standard MLP layers for channel mixing and use Layer Normalization and residual connections.

By using LSTMs, the model inherently supports variable sequence lengths, allowing it to process images of different sizes more naturally than MLP-based models.

Datasets

The authors evaluated Sequencer across several standard benchmarks:

  • Image Classification: ImageNet-1K (trained from scratch and fine-tuned at higher resolutions).
  • Transfer Learning: CIFAR-10, CIFAR-100, Flowers-102, and Stanford Cars.
  • Semantic Segmentation: ADE20K (using Sequencer as a backbone for a Semantic FPN).

Key Insights and Ideas

  • The "Cruciform" Receptive Field: Analysis of the Effective Receptive Field (ERF) shows that Sequencer looks at the image in a cross-shaped pattern. This allows it to capture long-range dependencies across the entire height and width of the image more effectively than standard CNNs, but with a different inductive bias than the "global" look of self-attention.
  • Resolution Adaptability: This is the paper's "aha moment." When an image's resolution is doubled (e.g., from 224 to 448) during inference without fine-tuning, Sequencer’s accuracy remains much more stable than DeiT (Transformer) or ConvNeXt (CNN). This makes it highly practical for real-world applications where input sizes might vary.
  • Memory Efficiency: At high resolutions, the memory cost of a ViT's attention map grows quadratically ($O(N^2)$). In contrast, the LSTM's internal state grows linearly with the number of patches, making Sequencer more economical for processing very large images.

Key Results

ImageNet-1K Top-1 Accuracy vs. Number of Parameters
  • Top-tier Accuracy: Sequencer2D-L (54M parameters) achieved 84.6% top-1 accuracy on ImageNet-1K, outperforming comparable models like Swin-B and ConvNeXt-B when fine-tuned at 392² resolution.
  • Segmentation Lead: On the ADE20K dataset, Sequencer-based models outperformed PVT and PoolFormer by roughly 6 points in mIoU, suggesting it is a strong backbone for dense prediction tasks.
  • Robustness: In the double-resolution test (224 to 448), Sequencer-S maintained significantly higher relative accuracy than its competitors, proving its flexibility.

Limitations and Future Work

The primary drawback of Sequencer is throughput (speed). Because LSTMs are recursive—meaning the next step depends on the previous one—they cannot be as easily parallelized as CNNs or Transformers on current GPU hardware. The authors note that while Sequencer is memory-efficient, it is slower in terms of images processed per second.

Future work may involve optimizing LSTM kernels for vision tasks or exploring Sequencer's potential in video processing, where the temporal nature of LSTMs could provide an even greater advantage.

Summary updated

BibTeX
@inproceedings{tatsunami2022sequencer,
  author = {Yuki Tatsunami and Masato Taki},
  title = {{Sequencer: Deep LSTM for Image Classification}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2022},
  url = {https://openreview.net/forum?id=wlrYnGZ37Wv},
}
Figure