Official repository for the paper BECLR: Batch Enhanced Contrastive Unsupervised Few-Shot Learning
See the codeBenchmark • miniImageNet • tieredImageNet • Notes
Learning quickly from very few labeled samples is a fundamental attribute that separates machines and humans in the era of deep representation learning. Unsupervised few-shot learning (U-FSL) aspires to bridge this gap by discarding the reliance on annotations at training time. Intrigued by the success of contrastive learning approaches in the realm of U-FSL, we structurally approach their shortcomings in both pretraining and downstream inference stages. We propose a novel Dynamic Clustered mEmory (DyCE) module to promote a highly separable latent representation space for enhancing positive sampling at the pretraining phase and infusing implicit class-level insights into unsupervised contrastive learning. We then tackle the, somehow overlooked yet critical, issue of sample bias at the few-shot inference stage. We propose an iterative Optimal Transport-based distribution Alignment (OpTA) strategy and demonstrate that it efficiently addresses the problem, especially in low-shot scenarios where FSL approaches suffer the most from sample bias. We later on discuss that DyCE and OpTA are two intertwined pieces of a novel end-to-end approach (we coin as BECLR), constructively magnifying each other's impact. We then present a suite of extensive quantitative and qualitative experimentation to corroborate that BECLR sets a new state-of-the-art across ALL existing U-FSL benchmarks (to the best of our knowledge), and significantly outperforms the best of the current baselines, e.g. by up to $14$% and $12$% in the ($5$-way, $1$-shot) setting on miniImageNet and tieredImageNet, respectively.
Going beyond instance-level contrastive learning. In unsupervised contrastive FSL approaches each image within the batch and its augmentations correspond to a unique class, which is an unrealistic assumption. The pitfall here is that potential positive samples present within the same batch might then be repelled in the representation space, hampering the overall performance. We argue that infusing a semblance of class (or membership)-level insights into the unsupervised contrastive paradigm is essential. Our key idea to address this is extending the concept of memory queues by introducing inherent membership clusters represented by dynamically updated prototypes, while circumventing the need for large batch sizes. The proposed DyCE module facilitates a more meaningful positive sampling strategy by constructing and dynamically updating separable memory clusters.
Addressing inherent sample bias in (U-)FSL. In Few-Shot learning the base (pretraining) and novel (inference) classes are mutually exclusive classes. This distribution shift poses a significant challenge at inference time for the swift adaptation to the novel classes. This is further aggravated due to access to only a few labeled (a.k.a support) samples within the few-shot task since the support samples are typically not representative of the larger unlabeled (a.k.a query) set. We refer to this phenomenon as sample bias, highlighting that it is overlooked by most (U-)FSL baselines. To address this issue, we introduce our OpTA add-on module within the supervised inference step. OpTA imposes no additional learnable parameters, yet efficiently aligns the representations of the labeled support and the unlabeled query sets, right before the final supervised inference step. We demonstrate that these two novel modules (DyCE and OpTA) are actually intertwined and amplify one another. Combining these two key ideas, we propose an end-to-end U-FSL approach coined as Batch-Enhanced Contrastive LeaRning (BECLR).
| Method | Backbone | 1-shot | 5-shot |
|---|---|---|---|
| C3LR | Conv4 | 47.92 ± 1.20 | 64.81 ± 1.15 |
| SAMPTransfer | Conv4b | 61.02 ± 1.05 | 72.52 ± 0.68 |
| LF2CS | RN12 | 47.93 ± 0.19 | 66.44 ± 0.17 |
| CPNWCP | RN18 | 53.14 ± 0.62 | 67.36 ± 0.50 |
| SimCLR | RN18 | 62.58 ± 0.37 | 79.66 ± 0.27 |
| SwAV† | RN18 | 59.84 ± 0.52 | 78.23 ± 0.26 |
| NNCLR† | RN18 | 63.33 ± 0.53 | 80.75 ± 0.25 |
| SimSiam | RN18 | 62.80 ± 0.37 | 79.85 ± 0.27 |
| HMS | RN18 | 58.20 ± 0.23 | 75.77 ± 0.16 |
| Laplacian Eigenmaps | RN18 | 59.47 ± 0.87 | 78.79 ± 0.58 |
| PsCo† | RN18 | 47.24 ± 0.76 | 65.48 ± 0.68 |
| UniSiam + dist | RN18 | 64.10 ± 0.36 | 82.26 ± 0.25 |
| Meta-DM + UniSiam + dist∗ | RN18 | 65.64 ± 0.36 | 83.97 ± 0.25 |
| BECLR (Ours) 🔥 | RN18 | 75.74 ± 0.62 | 84.93 ± 0.33 |
| Deeper Backbone (RN50) | |||
| SwAV† | RN50 | 63.34 ± 0.42 | 82.76 ± 0.24 |
| NNCLR† | RN50 | 65.42 ± 0.44 | 83.31 ± 0.21 |
| TrainProto | RN50 | 58.92 ± 0.91 | 73.94 ± 0.63 |
| UBC-FSL | RN50 | 56.20 ± 0.60 | 75.40 ± 0.40 |
| PDA-Net | RN50 | 63.84 ± 0.91 | 83.11 ± 0.56 |
| UniSiam + dist | RN50 | 65.33 ± 0.36 | 83.22 ± 0.24 |
| Meta-DM + UniSiam + dist∗ | RN50 | 66.68 ± 0.36 | 85.29 ± 0.23 |
| BECLR (Ours) 🔥 | RN50 | 80.57 ± 0.57 | 87.82 ± 0.29 |
| Method | Backbone | 1-shot | 5-shot |
|---|---|---|---|
| C3LR | Conv4 | 42.37 ± 0.77 | 61.77 ± 0.25 |
| SAMPTransfer | Conv4b | 49.10 ± 0.94 | 65.19 ± 0.82 |
| LF2CS | RN12 | 53.16 ± 0.66 | 66.59 ± 0.57 |
| CPNWCP | RN18 | 45.00 ± 0.19 | 62.96 ± 0.19 |
| SimCLR | RN18 | 63.38 ± 0.42 | 79.17 ± 0.34 |
| SwAV† | RN18 | 65.26 ± 0.53 | 81.73 ± 0.24 |
| NNCLR† | RN18 | 65.46 ± 0.55 | 81.40 ± 0.27 |
| SimSiam | RN18 | 64.05 ± 0.40 | 81.40 ± 0.30 |
| HMS | RN18 | 58.42 ± 0.25 | 75.85 ± 0.18 |
| PsCo† | RN18 | 54.33 ± 0.54 | 69.73 ± 0.49 |
| UniSiam + dist | RN18 | 67.01 ± 0.39 | 84.47 ± 0.28 |
| Meta-DM + UniSiam + dist∗ | RN18 | 67.11 ± 0.40 | 84.39 ± 0.28 |
| BECLR (Ours) 🔥 | RN18 | 76.44 ± 0.66 | 84.85 ± 0.37 |
| Deeper Backbone (RN50) | |||
| SwAV† | RN50 | 68.02 ± 0.52 | 85.93 ± 0.33 |
| NNCLR† | RN50 | 69.82 ± 0.54 | 86.41 ± 0.31 |
| UBC-FSL | RN50 | 66.60 ± 0.70 | 83.10 ± 0.50 |
| PDA-Net | RN50 | 69.01 ± 0.93 | 84.20 ± 0.69 |
| UniSiam + dist | RN50 | 69.60 ± 0.38 | 86.51 ± 0.26 |
| Meta-DM + UniSiam + dist∗ | RN50 | 69.61 ± 0.38 | 86.53 ± 0.26 |
| BECLR (Ours) 🔥 | RN50 | 81.69 ± 0.61 | 87.86 ± 0.32 |
python dataset/create_split_miniImageNet.py --data_path "data/miniimagenet/miniimagenet" --split_path "dataset/split" --save_path "data/miniimagenet/miniimagenet_train" --partition "train"
python dataset/create_split_tieredImageNet.py --data_path "data/imagenet/train" --split_path "dataset/split" --save_path "data/imagenet/tieredimagenet_train"
Finally, the data directory should have the following structure:
\data
|___miniimagenet
| |___miniimagenet
| | |___images
| |___miniimagenet_train
| |___0 ...
| |___63
|
|___imagenet
| |___imagenet
| | |___train
| | |___n01440764 ...
| |___tieredimagenet_train
| |___0 ...
| |___350
|
|___FC100
| |___FC100_train.pickle
| |___FC100_test.pickle
| |___FC100_val.pickle
|
|___CIFAR-FS
| |___CIFAR_FS_train.pickle
| |___CIFAR_FS_test.pickle
| |___CIFAR_FS_val.pickle
|
|___CUB_200_2011
| |___CUB_200_2011
| |___images ...
|
|___cdfsl
|___chestX
| |___images ...
|___EuroSAT
| |___2750
|___ISIC
| |___ISIC2018_Task3_Training_GroundTruth
| |___ISIC2018_Task3_Training_Input
|___plant-disease
|___dataset
First create an anaconda environment with all the required libraries, packages and dependencies: conda env create -n beclr_env -f environment.yml. Then use the following commands for running the training and evaluation scripts.
python -m torch.distributed.launch train.py --cnfg_path "PATH_TO_TRAIN_CONFIG.JSON"
python -m torch.distributed.launch evaluate.py --cnfg_path "PATH_TO_EVAL_CONFIG.JSON"
Different configuration json files can be found in the \configs directory.
Corresponding author: Stylianos Poulakakis-Daktylidis (stypoumic@gmail.com)
@inproceedings{
poulakakis-daktylidis2024beclr,
title={{BECLR}: Batch Enhanced Contrastive Unsupervised Few-Shot Learning},
author={Stylianos Poulakakis-Daktylidis and Hadi Jamali-Rad},
booktitle={The Twelfth International Conference on Learning Representations},
year={2024},
url={https://openreview.net/forum?id=k9SVcrmXL8}
}
191 commits
Python
94.1%
HTML
5.2%
Official repository for the paper BECLR: Batch Enhanced Contrastive Unsupervised Few-Shot Learning
See the codeBenchmark • miniImageNet • tieredImageNet • Notes
Learning quickly from very few labeled samples is a fundamental attribute that separates machines and humans in the era of deep representation learning. Unsupervised few-shot learning (U-FSL) aspires to bridge this gap by discarding the reliance on annotations at training time. Intrigued by the success of contrastive learning approaches in the realm of U-FSL, we structurally approach their shortcomings in both pretraining and downstream inference stages. We propose a novel Dynamic Clustered mEmory (DyCE) module to promote a highly separable latent representation space for enhancing positive sampling at the pretraining phase and infusing implicit class-level insights into unsupervised contrastive learning. We then tackle the, somehow overlooked yet critical, issue of sample bias at the few-shot inference stage. We propose an iterative Optimal Transport-based distribution Alignment (OpTA) strategy and demonstrate that it efficiently addresses the problem, especially in low-shot scenarios where FSL approaches suffer the most from sample bias. We later on discuss that DyCE and OpTA are two intertwined pieces of a novel end-to-end approach (we coin as BECLR), constructively magnifying each other's impact. We then present a suite of extensive quantitative and qualitative experimentation to corroborate that BECLR sets a new state-of-the-art across ALL existing U-FSL benchmarks (to the best of our knowledge), and significantly outperforms the best of the current baselines, e.g. by up to $14$% and $12$% in the ($5$-way, $1$-shot) setting on miniImageNet and tieredImageNet, respectively.
Going beyond instance-level contrastive learning. In unsupervised contrastive FSL approaches each image within the batch and its augmentations correspond to a unique class, which is an unrealistic assumption. The pitfall here is that potential positive samples present within the same batch might then be repelled in the representation space, hampering the overall performance. We argue that infusing a semblance of class (or membership)-level insights into the unsupervised contrastive paradigm is essential. Our key idea to address this is extending the concept of memory queues by introducing inherent membership clusters represented by dynamically updated prototypes, while circumventing the need for large batch sizes. The proposed DyCE module facilitates a more meaningful positive sampling strategy by constructing and dynamically updating separable memory clusters.
Addressing inherent sample bias in (U-)FSL. In Few-Shot learning the base (pretraining) and novel (inference) classes are mutually exclusive classes. This distribution shift poses a significant challenge at inference time for the swift adaptation to the novel classes. This is further aggravated due to access to only a few labeled (a.k.a support) samples within the few-shot task since the support samples are typically not representative of the larger unlabeled (a.k.a query) set. We refer to this phenomenon as sample bias, highlighting that it is overlooked by most (U-)FSL baselines. To address this issue, we introduce our OpTA add-on module within the supervised inference step. OpTA imposes no additional learnable parameters, yet efficiently aligns the representations of the labeled support and the unlabeled query sets, right before the final supervised inference step. We demonstrate that these two novel modules (DyCE and OpTA) are actually intertwined and amplify one another. Combining these two key ideas, we propose an end-to-end U-FSL approach coined as Batch-Enhanced Contrastive LeaRning (BECLR).
| Method | Backbone | 1-shot | 5-shot |
|---|---|---|---|
| C3LR | Conv4 | 47.92 ± 1.20 | 64.81 ± 1.15 |
| SAMPTransfer | Conv4b | 61.02 ± 1.05 | 72.52 ± 0.68 |
| LF2CS | RN12 | 47.93 ± 0.19 | 66.44 ± 0.17 |
| CPNWCP | RN18 | 53.14 ± 0.62 | 67.36 ± 0.50 |
| SimCLR | RN18 | 62.58 ± 0.37 | 79.66 ± 0.27 |
| SwAV† | RN18 | 59.84 ± 0.52 | 78.23 ± 0.26 |
| NNCLR† | RN18 | 63.33 ± 0.53 | 80.75 ± 0.25 |
| SimSiam | RN18 | 62.80 ± 0.37 | 79.85 ± 0.27 |
| HMS | RN18 | 58.20 ± 0.23 | 75.77 ± 0.16 |
| Laplacian Eigenmaps | RN18 | 59.47 ± 0.87 | 78.79 ± 0.58 |
| PsCo† | RN18 | 47.24 ± 0.76 | 65.48 ± 0.68 |
| UniSiam + dist | RN18 | 64.10 ± 0.36 | 82.26 ± 0.25 |
| Meta-DM + UniSiam + dist∗ | RN18 | 65.64 ± 0.36 | 83.97 ± 0.25 |
| BECLR (Ours) 🔥 | RN18 | 75.74 ± 0.62 | 84.93 ± 0.33 |
| Deeper Backbone (RN50) | |||
| SwAV† | RN50 | 63.34 ± 0.42 | 82.76 ± 0.24 |
| NNCLR† | RN50 | 65.42 ± 0.44 | 83.31 ± 0.21 |
| TrainProto | RN50 | 58.92 ± 0.91 | 73.94 ± 0.63 |
| UBC-FSL | RN50 | 56.20 ± 0.60 | 75.40 ± 0.40 |
| PDA-Net | RN50 | 63.84 ± 0.91 | 83.11 ± 0.56 |
| UniSiam + dist | RN50 | 65.33 ± 0.36 | 83.22 ± 0.24 |
| Meta-DM + UniSiam + dist∗ | RN50 | 66.68 ± 0.36 | 85.29 ± 0.23 |
| BECLR (Ours) 🔥 | RN50 | 80.57 ± 0.57 | 87.82 ± 0.29 |
| Method | Backbone | 1-shot | 5-shot |
|---|---|---|---|
| C3LR | Conv4 | 42.37 ± 0.77 | 61.77 ± 0.25 |
| SAMPTransfer | Conv4b | 49.10 ± 0.94 | 65.19 ± 0.82 |
| LF2CS | RN12 | 53.16 ± 0.66 | 66.59 ± 0.57 |
| CPNWCP | RN18 | 45.00 ± 0.19 | 62.96 ± 0.19 |
| SimCLR | RN18 | 63.38 ± 0.42 | 79.17 ± 0.34 |
| SwAV† | RN18 | 65.26 ± 0.53 | 81.73 ± 0.24 |
| NNCLR† | RN18 | 65.46 ± 0.55 | 81.40 ± 0.27 |
| SimSiam | RN18 | 64.05 ± 0.40 | 81.40 ± 0.30 |
| HMS | RN18 | 58.42 ± 0.25 | 75.85 ± 0.18 |
| PsCo† | RN18 | 54.33 ± 0.54 | 69.73 ± 0.49 |
| UniSiam + dist | RN18 | 67.01 ± 0.39 | 84.47 ± 0.28 |
| Meta-DM + UniSiam + dist∗ | RN18 | 67.11 ± 0.40 | 84.39 ± 0.28 |
| BECLR (Ours) 🔥 | RN18 | 76.44 ± 0.66 | 84.85 ± 0.37 |
| Deeper Backbone (RN50) | |||
| SwAV† | RN50 | 68.02 ± 0.52 | 85.93 ± 0.33 |
| NNCLR† | RN50 | 69.82 ± 0.54 | 86.41 ± 0.31 |
| UBC-FSL | RN50 | 66.60 ± 0.70 | 83.10 ± 0.50 |
| PDA-Net | RN50 | 69.01 ± 0.93 | 84.20 ± 0.69 |
| UniSiam + dist | RN50 | 69.60 ± 0.38 | 86.51 ± 0.26 |
| Meta-DM + UniSiam + dist∗ | RN50 | 69.61 ± 0.38 | 86.53 ± 0.26 |
| BECLR (Ours) 🔥 | RN50 | 81.69 ± 0.61 | 87.86 ± 0.32 |
python dataset/create_split_miniImageNet.py --data_path "data/miniimagenet/miniimagenet" --split_path "dataset/split" --save_path "data/miniimagenet/miniimagenet_train" --partition "train"
python dataset/create_split_tieredImageNet.py --data_path "data/imagenet/train" --split_path "dataset/split" --save_path "data/imagenet/tieredimagenet_train"
Finally, the data directory should have the following structure:
\data
|___miniimagenet
| |___miniimagenet
| | |___images
| |___miniimagenet_train
| |___0 ...
| |___63
|
|___imagenet
| |___imagenet
| | |___train
| | |___n01440764 ...
| |___tieredimagenet_train
| |___0 ...
| |___350
|
|___FC100
| |___FC100_train.pickle
| |___FC100_test.pickle
| |___FC100_val.pickle
|
|___CIFAR-FS
| |___CIFAR_FS_train.pickle
| |___CIFAR_FS_test.pickle
| |___CIFAR_FS_val.pickle
|
|___CUB_200_2011
| |___CUB_200_2011
| |___images ...
|
|___cdfsl
|___chestX
| |___images ...
|___EuroSAT
| |___2750
|___ISIC
| |___ISIC2018_Task3_Training_GroundTruth
| |___ISIC2018_Task3_Training_Input
|___plant-disease
|___dataset
First create an anaconda environment with all the required libraries, packages and dependencies: conda env create -n beclr_env -f environment.yml. Then use the following commands for running the training and evaluation scripts.
python -m torch.distributed.launch train.py --cnfg_path "PATH_TO_TRAIN_CONFIG.JSON"
python -m torch.distributed.launch evaluate.py --cnfg_path "PATH_TO_EVAL_CONFIG.JSON"
Different configuration json files can be found in the \configs directory.
Corresponding author: Stylianos Poulakakis-Daktylidis (stypoumic@gmail.com)
@inproceedings{
poulakakis-daktylidis2024beclr,
title={{BECLR}: Batch Enhanced Contrastive Unsupervised Few-Shot Learning},
author={Stylianos Poulakakis-Daktylidis and Hadi Jamali-Rad},
booktitle={The Twelfth International Conference on Learning Representations},
year={2024},
url={https://openreview.net/forum?id=k9SVcrmXL8}
}
191 commits
Python
94.1%
HTML
5.2%