SPFF: Stochastic-based Patch Filtering for Few-Shot Learning
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
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.
Results
5-way accuracy (%) on food benchmarks
| Method | Backbone | Food-101 1/5 | VireoFood-172 1/5 | UECFood-256 1/5 |
|---|---|---|---|---|
| MVFSL-TC | VGG-16 | 55.30 / 68.30 | 75.10 / 83.60 | – |
| Fusion Learning | EfficientNet-B0 | 61.97 / 77.72 | – | 54.85 / 69.08 |
| RER | ResNet-12 | 62.51 / 80.47 | 82.13 / 93.76 | – |
| SPFF (ours) | ViT-S/16 | 65.07 / 83.32 | 82.31 / 94.64 | 73.82 / 88.71 |
Does the randomness matter?
| Patches kept (K), Food-101 5-shot | 32 | 64 | 98 | 128 | 196 (all) |
|---|---|---|---|---|---|
| Deterministic top-K | 81.44 | 82.80 | 82.84 | 82.08 | 82.14 |
| Stochastic (SPFF) | 82.34 | 83.23 | 83.32 | 82.85 | 82.14 |
- Stochastic sampling beats deterministic selection at every K below 196, and both beat random selection (82.05% at K = 98).
- Keeping half of the patches (K = 98) is best. Keeping all of them (no filtering) is worse, which confirms that dropping patches helps.
- Mixing deterministic and stochastic selection is worse than fully stochastic selection on both Food-101 and UECFood-256.
- Cosine similarity works better than Manhattan or Euclidean distance for the patch matching (83.32% vs. 82.90% and 82.88%).
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}
}