tSF: Transformer-based Semantic Filter for Few-Shot Learning

Jinxiang Lai, Siqian Yang, Wenlong Liu, Yi Zeng, Zhongyi Huang, Wenlong Wu, Jun Liu, Bin-Bin Gao, Chengjie Wang · DOI

Abstract

Few-Shot Learning (FSL) remains a significant challenge in computer vision due to the "weak representation problem," where limited labeled data makes it difficult for models to extract robust, discriminative features for novel classes. We introduce the Transformer-based Semantic Filter (tSF), a lightweight and universal module designed to enhance feature representations by leveraging global dataset knowledge. By replacing standard self-attention with a learnable semantic filter, tSF achieves consistent performance gains across classification, segmentation, and object detection tasks while maintaining a minimal parameter footprint.

Introduction

The primary goal of Few-Shot Learning is to enable models to recognize new objects using only a handful of examples. While standard deep learning architectures excel with massive datasets, they often struggle in few-shot settings. Transformers, in particular, are prone to overfitting when applied to small support sets because their self-attention mechanisms focus exclusively on correlations within a single image or a tiny sample size.

To address this, the tSF module acts as a "neck" component that can be integrated into various backbones. It shifts the focus from internal image correlations to "dataset-attention," allowing the model to filter input features against a learned memory bank of semantic concepts derived from a large base dataset.

The tSF Architecture

The tSF module is a redesigned Transformer block optimized for efficiency and generalization. Its core innovation lies in the modification of the Query ($Q$), Key ($K$), and Value ($V$) components:

  • Redesigned Attention Mechanism: In standard Transformers, $Q, K,$ and $V$ are all derived from the input feature map. In tSF, only the Query ($Q$) is generated from the input feature ($f$). The Key ($K$) and Value ($V$) are replaced by a learnable weight matrix $\theta$, termed the Semantic Filter.
  • Dataset-Attention: The matrix $\theta$ is learned across the entire base dataset during the training phase. It functions as a repository of semantic groups (e.g., textures, geometric shapes, or common animal features). During inference, the model performs attention between the input image and these pre-learned semantic groups, effectively "filtering" the image to highlight relevant features based on prior knowledge.
  • Lightweight Implementation: By fixing $K$ and $V$ as learnable parameters rather than calculating them dynamically for every input, tSF significantly reduces computational overhead. The module uses fewer than 1 million parameters—roughly half the size of a standard Transformer block.
  • PatchProto Framework: For classification tasks, tSF is integrated into the "PatchProto" framework, which utilizes auxiliary tasks like rotation prediction and global classification to further stabilize the learned embeddings.

Experimental Evaluation

The authors evaluated the tSF module across three major computer vision domains to demonstrate its universality:

1. Few-Shot Classification

On the miniImageNet benchmark (1-shot), tSF achieved a state-of-the-art accuracy of 70.23% using a WRN-28 backbone. This performance surpasses previous leading methods such as FEAT and DeepEMD, proving that the semantic filter effectively mitigates the weak representation problem.

2. Few-Shot Semantic Segmentation

When integrated into the RePRI framework, tSF improved the mean Intersection over Union (mIoU) by 1.2% to 2% across different folds on the PASCAL-$5^i$ and COCO-$20^i$ datasets.

3. Few-Shot Object Detection

Using the DeFRCN detector as a baseline, the addition of tSF provided a consistent boost of approximately 2.6 mAP on the PASCAL VOC dataset, highlighting its utility in localization-heavy tasks.

Discussion and Key Insights

Semantic Transferability

The success of tSF stems from its ability to transfer semantic knowledge. For example, even if a model has never seen a "wolf," it has likely seen "dogs" in the base training set. By embedding dog-like semantic information into the filter $\theta$, the tSF can enhance wolf-like regions in a novel image based on shared traits, providing a more robust representation than self-attention alone.

Overcoming Overfitting

Standard self-attention often leads few-shot models to focus on spurious correlations within a small support set. tSF forces the model to validate input features against the broader context of the entire base dataset. This acts as a "sanity check," ensuring the model focuses on features that are semantically meaningful across the entire data distribution.

Efficiency vs. Performance

Ablation studies revealed that while standard Transformers sometimes degraded performance in few-shot scenarios due to their high capacity and tendency to overfit, tSF consistently provided a 2-3% boost. This demonstrates that for FSL, a specialized, lightweight attention mechanism is often superior to a heavy, general-purpose one.

Conclusion and Future Work

The Transformer-based Semantic Filter (tSF) provides a robust, efficient solution for the weak representation problem in Few-Shot Learning. Its ability to act as a universal module across classification, segmentation, and detection makes it a versatile tool for low-data regimes. Future research may explore optimizing the number of semantic groups ($n$) within the filter and extending the tSF architecture to more complex domains such as few-shot video action recognition or 3D point cloud analysis.

Summary updated

BibTeX
@inproceedings{lai2022tsf,
  author = {Jinxiang Lai and Siqian Yang and Wenlong Liu and Yi Zeng and Zhongyi Huang and Wenlong Wu and Jun Liu and Bin-Bin Gao and Chengjie Wang},
  title = {{tSF: Transformer-based Semantic Filter for Few-Shot Learning}},
  booktitle = {European Conference on Computer Vision},
  year = {2022},
  doi = {10.1007/978-3-031-20044-1\_1},
}
Figure