State Space Models (SSMs), particularly the Mamba architecture, have taken the AI world by storm. By offering the performance of Transformers with the linear-time efficiency of RNNs, Mamba has become a formidable contender in Natural Language Processing. However, translating that success to Computer Vision hasn't been a straight path. A new paper, V2M: Visual 2-Dimensional Mamba for Image Representation Learning, proposes a fundamental shift in how we apply these models to images.
TL;DR
V2M generalizes the Mamba architecture into a native 2D framework, allowing it to process image tokens directly in spatial dimensions rather than flattening them into 1D sequences. This approach preserves critical spatial locality and structural information, leading to superior performance in classification, detection, and segmentation tasks while maintaining Mamba's signature efficiency.
What Problem Does This Paper Address?
The core challenge lies in the "1D nature" of standard Mamba. In NLP, text is a sequence; one word follows another. Images, however, are inherently 2D. To use Mamba for vision, previous methods (like Vision Mamba or Vim) "patchify" an image and flatten it into a 1D string of tokens.
As shown in the left side of Figure 1, this flattening process is destructive. It breaks the spatial relationships between pixels—neighbors in a 2D grid might end up far apart in a 1D sequence. While researchers have tried to fix this using bidirectional scans or complex "zig-zag" scanning patterns, these are essentially band-aids on a 1D framework. They only approximate 2D modeling and inevitably disrupt the coherence of visual data.
Methods
The authors introduce Visual 2-Dimensional Mamba (V2M), which replaces the 1D recurrence of standard SSMs with a 2D version based on the classical Roesser’s state space model.
1. Native 2D Recurrence
Instead of calculating the next state based only on the previous token ($h_{t-1}$), V2M calculates a state ($h_{i,j}$) by considering its neighbors in both the horizontal and vertical dimensions simultaneously. This ensures that every "step" the model takes is informed by the 2D context of the image.
2. Hardware-Efficient Decomposition
A major hurdle for 2D SSMs is hardware acceleration. The highly optimized CUDA kernels that make Mamba fast are designed for 1D scans. To solve this, the authors mathematically decomposed the 2D SSM into row-wise and column-wise 1D operations that can be recombined. This allows V2M to leverage Mamba’s existing parallel scanning algorithms, keeping the model fast and scalable.
3. Four-Directional Scanning
Since images don't have a natural "start" or "end," V2M performs scans starting from all four corners (upper-left, upper-right, lower-left, and lower-right). These four perspectives are processed in parallel (by concatenating them along the batch dimension) and then aggregated, as illustrated in the overall framework in Figure 3.
Datasets
The model was rigorously tested across three standard benchmarks:
- ImageNet-1K: For large-scale image classification (1.28M training images).
- COCO: For object detection and instance segmentation, using the Mask R-CNN framework.
- ADE20K: For semantic segmentation, using the UPerNet framework.
Key Insights and Ideas
- Locality is King: The primary "aha moment" is that native 2D modeling is fundamentally better than trying to recover spatial information from a 1D sequence. By respecting the 2D grid, the model learns more robust features.
- The "Middle Class Token": In 1D models, you usually just stick a "class token" at the beginning or end. In a 2D grid, where does it go? The authors found that inserting a cross-shaped row and column of class tokens in the middle of the image (Figure 4, option c) provided the best global representation.
- Symmetry and Invariance: By scanning from four corners, the model becomes more robust to orientation and ensures that every pixel can "see" every other pixel efficiently.
Key Results
V2M consistently outperformed its 1D-based Mamba predecessors and showed strong competition against established CNNs and ViTs:
- ImageNet: V2M-T (Tiny) achieved 76.2% top-1 accuracy, a 0.4% improvement over the Vim-T baseline. The pyramid version, V2M-S, reached 82.9%*, outperforming VMamba-T.
- Object Detection (COCO): V2M-S outperformed VMamba-T by 0.3 box AP and 0.2 mask AP* in the 1x schedule.
- Semantic Segmentation (ADE20K): V2M-S achieved 48.2 mIoU*, surpassing the VMamba-T baseline by 0.3.
Limitations and Future Work
The main trade-off for V2M is computational speed. Processing four directions within every block is more intensive than a single 1D scan. While the authors used batch-dimension tricks to keep it parallel, V2M is currently slower than its 1D counterparts.
The authors suggest that future work should focus on developing specialized hardware-level kernels (Triton or CUDA) specifically optimized for 2D spatial scanning to bridge this efficiency gap.
Summary updated