Javier Ródenas
CVPR Workshops 2025 · MetaFood

SPFF: Stochastic-based Patch Filtering for Few-Shot Learning

Javier Ródenas1 Eduardo Aguilar1,2 Petia Radeva1,3
1AIBA, Universitat de Barcelona 2Universidad Católica del Norte 3Institute of Neuroscience, Universitat de Barcelona
SPFF overview: cosine similarity between patches and the class-aware embedding gives a probability distribution from which patches are sampled.
The similarity between each patch and the class-aware embedding becomes a probability distribution over patches. Patches are then sampled from it, so the most relevant ones are likely to be kept but not guaranteed.
TL;DR. Food images are hard for few-shot learning: the same dish looks different on every plate, with different garnishes, lighting and viewpoints. SPFF keeps the patches that look most like the class, but chooses them by random sampling weighted by relevance instead of a fixed top-k. The randomness acts as a regularizer and beats deterministic selection on Food-101, VireoFood-172 and UECFood-256.

Abstract

Food images present unique challenges for few-shot learning models due to their visual complexity and variability. For instance, a pasta dish might appear with various garnishes on different plates and in diverse lighting conditions and camera perspectives. This problem leads to losing focus on the most important elements when comparing the query with support images, resulting in misclassification. To address this issue, we propose Stochastic-based Patch Filtering for Few-Shot Learning (SPFF) to attend to the patch embeddings that show greater correlation with the class representation. The key concept of SPFF involves the stochastic filtering of patch embeddings, where patches less similar to the class-aware embedding are more likely to be discarded. With patch embedding filtered according to the probability of appearance, we use a similarity matrix that quantifies the relationship between the query image and its respective support images. Through a qualitative analysis, we demonstrate that SPFF effectively focuses on patches where class-specific food features are most prominent while successfully filtering out non-relevant patches. We validate our approach through extensive experiments on few-shot classification benchmarks: Food-101, VireoFood-172 and UECFood-256, outperforming the existing SoA methods.

Method

SPFF pipeline for support and query images.
SPFF pipeline. A Vision Transformer produces patch embeddings and a class-aware embedding. Each patch gets a probability from its similarity to the class-aware embedding, patches are sampled from a multinomial distribution, the class-aware embedding is added back, and query and support are compared through a patch-level similarity matrix.

1. Score every patch

Each of the 196 patch embeddings is compared with the class-aware embedding \(C\) by cosine similarity, and the scores are turned into a distribution:

$$p_i = \frac{\exp(S_i)}{\sum_{j=1}^{P}\exp(S_j)}.$$

2. Sample instead of ranking

Rather than taking the top-\(k\) patches, SPFF draws \(k\) indices from a multinomial distribution. Relevant patches are kept most of the time, while the model still sees different subsets across training iterations, which reduces overfitting:

$$\{i_1,\dots,i_k\} \sim \mathrm{Multinomial}(k, p), \qquad \hat P = P_{\text{selected}} + \lambda\, C.$$

3. Match query and support

A dense cosine-similarity matrix between the filtered query and support patches is flattened and scored by an MLP. Scores are summed over the shots of each class and passed through a softmax; training uses cross-entropy on the queries.

Stochastic (blue) versus deterministic (red) patch selection on Food-101 dishes.
Stochastic selection (blue, first row of each pair) covers a broader set of discriminative regions of the dish; deterministic top-k selection (red) is more clustered and sometimes lands on the table or background. Queries on the left, supports on the right.

Results

83.32%
Food-101 5-shot (+2.85 vs. RER)
94.64%
VireoFood-172 5-shot
88.71%
UECFood-256 5-shot

5-way accuracy (%) on food benchmarks

MethodBackboneFood-101 1/5VireoFood-172 1/5UECFood-256 1/5
MVFSL-TCVGG-1655.30 / 68.3075.10 / 83.60–
Fusion LearningEfficientNet-B061.97 / 77.72–54.85 / 69.08
RERResNet-1262.51 / 80.4782.13 / 93.76–
SPFF (ours)ViT-S/1665.07 / 83.3282.31 / 94.6473.82 / 88.71

Does the randomness matter?

Patches kept (K), Food-101 5-shot326498128196 (all)
Deterministic top-K81.4482.8082.8482.0882.14
Stochastic (SPFF)82.3483.2383.3282.8582.14

BibTeX

@inproceedings{rodenas2025spff,
  title     = {Stochastic-based Patch Filtering for Few-Shot Learning},
  author    = {R{\'o}denas Cumplido, Javier and Aguilar, Eduardo and Radeva, Petia},
  booktitle = {Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) Workshops},
  pages     = {440--449},
  year      = {2025}
}