Sparse spatial transformers for few-shot learning

Haoxing Chen, Huaxiong Li, Yaohui Li, Chunlin Chen

TL;DR

SSFormers (Sparse Spatial Transformers) is a novel architecture for few-shot learning that uses a "mutual feeling" mechanism to align query images with support sets. By selectively focusing on task-relevant image patches and suppressing background noise through sparse attention, the model achieves state-of-the-art accuracy and exceptional robustness against image distortions.

What Problem Does This Paper Address?

Few-shot learning (FSL) aims to recognize new categories from just a handful of labeled examples. This is notoriously difficult because models easily overfit to noise when data is scarce.

The authors identify a "representation gap" in existing methods:

  1. Global Features: Traditional methods compress an image into a single vector, which often loses critical local details.
  2. Deep Descriptors: Newer methods use pixel-level descriptors, but these often lose the spatial context (the "big picture") of the image.
  3. Task-Agnosticism: Many models process each class in a vacuum, failing to use the context of the entire "task" (the full support set) to highlight what makes a specific object unique in that specific scenario.

Methods

The researchers propose a three-stage pipeline to bridge these gaps:

  1. Dense Local Feature Extractor: Instead of a global pool, the model divides images into a pyramid of patches (e.g., $2\times2$ and $4\times4$ grids). This allows the network to capture hierarchical information—both local details and broader context.
  2. Sparse Spatial Transformer Layer (SSTL): This is the core innovation. It uses a Mutual Nearest Neighbor (MNN) logic. A patch in a query image is only considered "task-relevant" if it is the closest match to a patch in the support set and that support patch considers the query patch its closest match. This "mutual feeling" creates a sparse mask that effectively ignores background clutter and focuses only on the object of interest.
  3. Patch-Matching Module (PMM): A non-parametric module that calculates similarity scores between the query patches and the task-specific prototypes generated by the SSTL. It sums the scores of the most similar patches to determine the final classification.

Datasets

The authors evaluated SSFormers on four standard few-shot learning benchmarks:

  • miniImageNet: 100 classes derived from ImageNet.
  • tieredImageNet: A larger, more complex subset of ImageNet with 608 classes grouped into broader categories.
  • CIFAR-FS: A few-shot variant of the CIFAR-100 dataset.
  • FC100: A more challenging version of CIFAR-100 with minimized overlap between training and testing super-classes.

Key Insights and Ideas

  • Bidirectionality Filters Noise: One-way attention often gets distracted by similar-looking backgrounds. By requiring "mutual" matching between the query and support set, the model ensures that only the most discriminative features (like the beak of a bird or the wheel of a car) are used for classification.
  • The Power of Sparsity: Unlike standard Transformers that use "soft" attention (assigning weights to everything), SSFormers uses a "hard" sparse mask. This prevents irrelevant features from "bleeding" into the final representation.
  • Task-Specific Prototypes: Rather than using a static "mean" image for a class, SSFormers generates a prototype that is dynamically aligned to the specific query image it is currently looking at.

Key Results

  • State-of-the-Art Accuracy: On miniImageNet (5-way 5-shot), SSFormers achieved 82.75% accuracy with a ResNet12 backbone, outperforming established models like FEAT and DeepEMD.
  • Superior Robustness: In "stability attacks," SSFormers proved remarkably resilient. When subjected to Gaussian Blur, a leading competitor (Rethink-D) saw accuracy plummet from 82% to 49%, while SSFormers only dropped from 82% to 77%.
  • Efficiency: Despite the complexity of the transformer layer, the model maintains a low computational footprint (0.0041 GFLOPs), making it comparable in speed to much simpler architectures.

Limitations and Future Work

The authors acknowledge that the current patch-dividing strategy is somewhat manual. While the pyramid structure helps, it still relies on predefined grid sizes.

Future Directions: * Pure Vision Transformers (ViT): The authors suggest moving toward a "pure" ViT architecture where the patch-dividing step is handled end-to-end by the network, potentially reducing the time cost and further improving feature extraction. * Cross-Modal Learning: Applying the sparse spatial logic to multi-modal tasks (e.g., matching text descriptions to image patches) could be a promising avenue.

Summary updated

BibTeX
@article{chen2023sparse,
  author = {Haoxing Chen and Huaxiong Li and Yaohui Li and Chunlin Chen},
  title = {{Sparse spatial transformers for few-shot learning}},
  journal = {Science China Information Sciences},
  year = {2023},
  url = {https://openreview.net/forum?id=VZV387o9Tj},
}
Figure