A Spitting Image: Modular Superpixel Tokenization in Vision Transformers

Marius Aasan, Odd Kolbjørnsen, Anne H. Schistad Solberg, Adín Ramírez RiveraWorkshops @ ECCV 2024 · DOI

TL;DR

This paper introduces a novel "superpixel tokenization" strategy for Vision Transformers (ViTs) that moves beyond fixed grid-based partitioning. By adapting tokenization to image content using superpixels, they achieve more semantically meaningful representations, leading to improved interpretability and better performance on dense prediction tasks, all while maintaining competitive classification accuracy.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have revolutionized computer vision, but their standard tokenization method, which simply divides images into fixed-size square patches, has limitations. This rigid approach ignores the semantic content of an image, leading to potential inefficiencies and a loss of fine-grained detail, especially for tasks requiring pixel-level understanding. The authors argue that tokenization is an overlooked but crucial component that can be made more adaptive and modular, decoupling it from feature extraction to better align with the image's structure.

Methods

The core innovation is a modular superpixel tokenization strategy. Instead of fixed square patches, they use an on-line, content-aware superpixel algorithm to partition images. This algorithm dynamically generates a variable number of superpixels based on image complexity, creating tokens that better align with semantic boundaries.

Key aspects of their approach include:

  • Modular Framework: They propose a generalized ViT architecture where tokenization is a distinct, swappable module. This allows for experimentation with different tokenization strategies without altering the core transformer backbone.
  • Superpixel Generation: They employ a hierarchical superpixel generation method that iteratively merges regions based on edge weights derived from color and texture similarity, with optional regularization for compactness.
  • Scale- and Shape-Invariant Positional Embeddings: To handle the irregular shapes and sizes of superpixels, they introduce a novel positional encoding method that uses joint histograms and Gaussian kernels to capture spatial information.
  • Feature Extraction: They propose a feature extraction method that interpolates superpixel features to a fixed resolution and can optionally incorporate gradient information to capture texture details, which is particularly useful for irregular patches.

Datasets

The paper uses standard datasets for evaluation:

  • ImageNet (IN1K): For general-purpose classification tasks.
  • CIFAR100: For classification.
  • CALTECH256: For classification.
  • INREAL: For validation of classification performance.
  • ECSSD, DUTS, DUT-OMRON: For unsupervised salient segmentation tasks.

Key Insights and Ideas

  • Tokenization is More Than Just Grids: The paper convincingly demonstrates that moving beyond fixed square patches can significantly improve ViT performance, especially in areas like interpretability and dense prediction.
  • Superpixels Align with Semantics: Superpixels naturally group pixels based on visual similarity, leading to tokens that better represent semantic regions within an image. This is crucial for tasks where understanding object boundaries is key.
  • Improved Interpretability: The superpixel tokens lead to more faithful and granular attributions (e.g., using attention flow), providing clearer insights into the model's decision-making process.
  • Gradient Features Compensate for Irregularity: The inclusion of gradient features (texture information) is shown to be particularly beneficial when dealing with irregular superpixel tokens, helping to retain information lost in simpler color-based features.
  • Modularity is Key: The proposed modular framework allows for easy swapping of tokenizers, paving the way for future research into adaptive and efficient vision transformer architectures.

Key Results

  • Classification: SPiT (Superpixel Tokenization) performs comparably to standard ViTs on classification tasks, and in some cases, shows improved robustness to label noise (e.g., on INREAL).
  • Interpretability: SPiT significantly improves the "comprehensiveness" of attributions compared to LIME, meaning the model's explanations are less likely to include irrelevant regions.
  • Unsupervised Segmentation: SPiT achieves competitive results on unsupervised salient segmentation tasks (ECSSD, DUTS, DUT-OMRON) without requiring specialized decoders or post-processing, demonstrating its ability to capture semantic content.
  • Efficiency: The superpixel generation process has a low overhead, and the number of tokens can be dynamically adjusted, potentially leading to comparable or even improved inference times compared to standard ViTs.

Limitations and Future Work

  • Gradient-Based Optimization: The current superpixel framework is not directly optimizable with gradient-based methods. The authors suggest that future work could explore learnable tokenization strategies that are end-to-end trainable, but caution against introducing undue computational overhead.
  • Irregular Tokenization Challenges: While gradient features help, irregular tokenization still presents challenges for feature extraction.
  • Further Optimization: The authors see potential in exploring graph neural networks (GNNs) for tokenization and integrating their approach into self-supervised frameworks (like DINO) or pyramid models. They also suggest exploring coupling mechanisms like gating or merging for improved scalability and learnability.

Summary updated

BibTeX
@inproceedings{aasan2024spitting,
  author = {Marius Aasan and Odd Kolbjørnsen and Anne H. Schistad Solberg and Adín Ramírez Rivera},
  title = {{A Spitting Image: Modular Superpixel Tokenization in Vision Transformers}},
  booktitle = {Workshops @ ECCV},
  year = {2024},
  doi = {10.1007/978-3-031-93806-1\_11},
}
Figure