FREE LUNCH FOR FEW-SHOT LEARNING: DISTRIBUTION CALIBRATION
Year: 2021

Abstract:
Learning from a limited number of samples is challenging since the learned model can easily become overfitted based on the biased distribution formed by only a few training examples. In this paper, we calibrate the distribution of these fewsample classes by transferring statistics from the classes with sufficient examples. Then an adequate number of examples can be sampled from the calibrated distribution to expand the inputs to the classifier. We assume every dimension in the feature representation follows a Gaussian distribution so that the mean and the variance of the distribution can borrow from that of similar classes whose statistics are better estimated with an adequate number of samples. Our method can be built on top of off-the-shelf pretrained feature extractors and classification models without extra parameters. We show that a simple logistic regression classifier trained using the features sampled from our calibrated distribution can outperform the state-of-the-art accuracy on three datasets (5% improvement on miniImageNet compared to the next best). The visualization of these generated features demonstrates that our calibrated distribution is an accurate estimation. The code is available at: https://github.com/ShuoYang-1998/Few_ Shot_Distribution_Calibration

text: 1 INTRODUCTION
Table 1: The class mean similarity (“mean sim”) and class variance similarity (“var sim”) between Arctic fox and different classes.
Arctic fox mean sim var sim
white wolf 97% 97% malamute 85% 78%
lion 81% 70% meerkat 78% 70% jellyfish 46% 26% orange 40% 19% beer bottle 34% 11%
Learning from a limited number of training samples has drawn increasing attention due to the high cost of collecting and annotating a large amount of data. Researchers have developed algorithms to improve the performance of models that have been trained with very few data. Finn et al. (2017); Snell et al. (2017) train models in a meta-learning fashion so that the model can adapt quickly on tasks with only a few training samples available. Hariharan & Girshick (2017); Wang et al. (2018) try to synthesize data or features by learning a generative model to alleviate the data insufficiency problem. Ren et al. (2018) propose to leverage unlabeled data and predict pseudo labels to improve the performance of fewshot learning.
While most previous works focus on developing stronger models, scant attention has been paid to the property of the data itself. It is natural that when the number of data grows, the ground truth distribution can be more accurately uncovered. Models trained with a wide coverage of data can generalize well during evaluation. On the other hand, when training a model with only a few training data, the model tends to overfit on these few samples by minimizing the training loss over these samples. These phenomena are illustrated in Figure 1. This biased distribution based on a few examples can damage the generalization ability of the model since it is far from mirroring the ground truth distribution from which test cases are sampled during evaluation.
∗Corresponding author.
Here, we consider calibrating this biased distribution into a more accurate approximation of the ground truth distribution. In this way, a model trained with inputs sampled from the calibrated distribution can generalize over a broader range of data from a more accurate distribution rather than only fitting itself to those few samples. Instead of calibrating the distribution of the original data space, we try to calibrate the distribution in the feature space, which has much lower dimensions and is easier to calibrate (Xian et al. (2018)). We assume every dimension in the feature vectors follows a Gaussian distribution and observe that similar classes usually have similar mean and variance of the feature representations, as shown in Table 1. Thus, the mean and variance of the Gaussian distribution can be transferred across similar classes (Salakhutdinov et al. (2012)). Meanwhile, the statistics can be estimated more accurately when there are adequate samples for this class. Based on these observations, we reuse the statistics from many-shot classes and transfer them to better estimate the distribution of the few-shot classes according to their class similarity. More samples can be generated according to the estimated distribution which provides sufficient supervision for training the classification model.
In the experiments, we show that a simple logistic regression classifier trained with our strategy can achieve state-of-the-art accuracy on three datasets. Our distribution calibration strategy can be paired with any classifier and feature extractor with no extra learnable parameters. Training with samples selected from the calibrated distribution can achieve 12% accuracy gain compared to the baseline which is only trained with the few samples given in a 5way1shot task. We also visualize the calibrated distribution and show that it is an accurate approximation of the ground truth that can better cover the test cases.

heading: 2 RELATED WORKS
text: Few-shot classification is a challenging machine learning problem and researchers have explored the idea of learning to learn or meta-learning to improve the quick adaptation ability to alleviate the few-shot challenge. One of the most general algorithms for meta-learning is the optimizationbased algorithm. Finn et al. (2017) and Li et al. (2017) proposed to learn how to optimize the gradient descent procedure so that the learner can have a good initialization, update direction, and learning rate. For the classification problem, researchers proposed simple but effective algorithms based on metric learning. MatchingNet (Vinyals et al., 2016) and ProtoNet (Snell et al., 2017) learned to classify samples by comparing the distance to the representatives of each class. Our distribution calibration and feature sampling procedure does not include any learnable parameters and the classifier is trained in a traditional supervised learning way.
Another line of algorithms is to compensate for the insufficient number of available samples by generation. Most methods use the idea of Generative Adversarial Networks (GANs) (Goodfellow et al., 2014) or autoencoder (Rumelhart et al., 1986) to generate samples (Zhang et al. (2018); Chen et al. (2019b); Schwartz et al. (2018); Gao et al. (2018)) or features (Xian et al. (2018); Zhang et al. (2019)) to augment the training set. Specifically, Zhang et al. (2018) and Xian et al. (2018) proposed to synthesize data by introducing an adversarial generator conditioned on tasks. Zhang et al. (2019) tried to learn a variational autoencoder to approximate the distribution and predict labels based on the estimated statistics. The autoencoder can also augment samples by projecting between the visual
space and the semantic space (Chen et al., 2019b) or encoding the intra-class deformations (Schwartz et al., 2018). Liu et al. (2019b) and Liu et al. (2019a) propose to generate features through the class hierarchy. While these methods can generate extra samples or features for training, they require the design of a complex model and loss function to learn how to generate. However, our distribution calibration strategy is simple and does not need extra learnable parameters.
Data augmentation is a traditional and effective way of increasing the number of training samples. Qin et al. (2020) and Antoniou & Storkey (2019) proposed the used of the traditional data augmentation technique to construct pretext tasks for unsupervised few-shot learning. Wang et al. (2018) and Hariharan & Girshick (2017) leveraged the general idea of data augmentation, they designed a hallucination model to generate the augmented version of the image with different choices for the model’s input, i.e., an image and a noise (Wang et al., 2018) or the concatenation of multiple features (Hariharan & Girshick, 2017). Park et al. (2020); Wang et al. (2019); Liu et al. (2020b) tried to augment feature representations by leveraging intra-class variance. These methods learn to augment from the original samples or their feature representation while we try to estimate the classlevel distribution and thus can eliminate the inductive bias from a single sample and provide more diverse generations from the calibrated distribution.

heading: 3 MAIN APPROACH
text: In this section, we introduce the few-shot classification problem definition in Section 3.1 and details of our proposed approach in Section 3.2.

heading: 3.1 PROBLEM DEFINITION
text: We follow a typical few-shot classification setting. Given a dataset with data-label pairs D = {(xi, yi)} where xi ∈ Rd is the feature vector of a sample and yi ∈ C, where C denotes the set of classes. This set of classes is divided into base classes Cb and novel classes Cn, where Cb∩Cn = ∅ and Cb ∪ Cn = C. The goal is to train a model on the data from the base classes so that the model can generalize well on tasks sampled from the novel classes. In order to evaluate the fast adaptation ability or the generalization ability of the model, there are only a few available labeled samples for each task T . The most common way to build a task is called an N-way-K-shot task (Vinyals et al. (2016)), where N classes are sampled from the novel set and only K (e.g., 1 or 5) labeled samples are provided for each class. The few available labeled data are called support set S = {(xi, yi)}N×Ki=1 and the model is evaluated on another query setQ = {(xi, yi)}N×K+N×qi=N×K+1 , where every class in the task has q test cases. Thus, the performance of a model is evaluated as the averaged accuracy on (the query set of) multiple tasks sampled from the novel classes.

heading: 3.2 DISTRIBUTION CALIBRATION
text: As introduced in Section 3.1, the base classes have a sufficient amount of data while the evaluation tasks sampled from the novel classes only have a limited number of labeled samples. The statistics of the distribution for the base class can be estimated more accurately compared to the estimation based on few-shot samples, which is an ill-posed problem. As shown in Table 1, we observe that if we assume the feature distribution is Gaussian, the mean and variance with respect to each class are correlated to the semantic similarity of each class. With this in mind, the statistics can be transferred from the base classes to the novel classes if we learn how similar the two classes are. In the following sections, we discuss how we calibrate the distribution estimation of the classes with only a few samples (Section 3.2.2) with the help of the statistics of the base classes (Section 3.2.1). We will also elaborate on how do we leverage the calibrated distribution to improve the performance of few-shot learning (Section 3.2.3).
Note that our distribution calibration strategy is over the feature-level and is agnostic to any feature extractor. Thus, it can be built on top of any pretrained feature extractors without further costly finetuning. In our experiments, we use the pretrained WideResNet Zagoruyko & Komodakis (2016) following previous work (Mangla et al. (2020)). The WideResNet is trained to classify the base classes, along with a self-supervised pretext task to learn the general-purpose representations suitable for image understanding tasks. Please refer to their paper for more details on training the feature extractor.
Algorithm 1 Training procedure for an N-way-K-shot task
Require: Support set features S = (xi, y)N×Ki=1 Require: Base classes’ statistics {µi}|Cb|i=1 , {Σi} |Cb| i=1
1: Transform (xi)N×Ki=1 with Tukey’s Ladder of Powers as Equation 3 2: for (xi, yi) ∈ S do 3: Calibrate the mean µ′ and the covariance Σ′ for class yi using xi with Equation 6 4: Sample features for class yi from the calibrated distribution as Equation 7 5: end for 6: Train a classifier using both support set features and all sampled features as Equation 8

heading: 3.2.1 STATISTICS OF THE BASE CLASSES
text: We assume the feature distribution of base classes is Gaussian. The mean of the feature vector from a base class i is calculated as the mean of every single dimension in the vector:
µi =
∑ni j=1 xj
ni , (1)
where xj is a feature vector of the j-th sample from the base class i and ni is the total number of samples in class i. As the feature vector xj is multi-dimensional, we use covariance for a better representation of the variance between any pair of elements in the feature vector. The covariance matrix Σi for the features from class i is calculated as:
Σi = 1
ni − 1 ni∑ j=1 (xj − µi) (xj − µi)T . (2)

heading: 3.2.2 CALIBRATING STATISTICS OF THE NOVEL CLASSES
text: Here, we consider an N-way-K-shot task sampled from the novel classes.
Tukey’s Ladder of Powers Transformation
To make the feature distribution more Gaussian-like, we first transform the features of the support set and query set in the target task using Tukey’s Ladder of Powers transformation (Tukey (1977)). Tukey’s Ladder of Powers transformation is a family of power transformations which can reduce the skewness of distributions and make distributions more Gaussian-like. Tukey’s Ladder of Powers transformation is formulated as:
x̃ = { xλ if λ 6= 0 log(x) if λ = 0 (3)
where λ is a hyper-parameter to adjust how to correct the distribution. The original feature can be recovered by setting λ as 1. Decreasing λ makes the distribution less positively skewed and vice versa.
Calibration through statistics transfer
Using the statistics from the base classes introduced in Section 3.2.1, we transfer the statistics from the base classes which are estimated more accurately on sufficient data to the novel classes. The transfer is based on the Euclidean distance between the feature space of the novel classes and the mean of the features from the base classes µi as computed in Equation 1. Specifically, we select the top k base classes with the closest distance to the feature of a sample x̃ from the support set:
Sd = {−‖µi − x̃‖2 | i ∈ Cb}, (4) SN = {i | − ‖µi − x̃‖2 ∈ topk(Sd)}, (5)
where topk(·) is an operator to select the top elements from the input distance set Sd. SN stores the k nearest base classes with respect to a feature vector x̃. Then, the mean and covariance of the distribution is calibrated by the statistics from the nearest base classes:
µ′ =
∑ i∈SN µi + x̃
k + 1 ,Σ′ =
∑ i∈SN Σi
k + α, (6)
where α is a hyper-parameter that determines the degree of dispersion of features sampled from the calibrated distribution.
For few-shot learning with more than one shot, the aforementioned procedure of the distribution calibration should be undertaken multiple times with each time using one feature vector from the support set. This avoids the bias provided by one specific sample and potentially achieves more diverse and accurate distribution estimation. Thus, for simplicity, we denote the calibrated distribution as a set of statistics. For a class y ∈ Cn, we denote the set of statistics as Sy = {(µ ′ 1,Σ ′ 1), ..., (µ ′ K ,Σ ′
K)}, where µ ′
i, Σ ′
i are the calibrated mean and covariance, respectively, computed based on the i-th feature in the support set of class y. Here, the size of the set is the value of K for an N-way-K-shot task.

heading: 3.2.3 HOW TO LEVERAGE THE CALIBRATED DISTRIBUTION?
text: With a set of calibrated statistics Sy for class y in a target task, we generate a set of feature vectors with label y by sampling from the calibrated Gaussian distributions:
Dy = {(x, y)|x ∼ N (µ,Σ),∀(µ,Σ) ∈ Sy}. (7) Here, the total number of generated features per class is set as a hyperparameter and they are equally distributed for every calibrated distribution in Sy . The generated features along with the original support set features for a few-shot task is then served as the training data for a task-specific classifier. We train the classifier for a task by minimizing the cross-entropy loss over both the features of its support set S and the generated features Dy:
` = ∑
(x,y)∼S̃∪Dy,y∈YT
− log Pr(y|x; θ), (8)
where YT is the set of classes for the task T . S̃ denotes the support set with features transformed by Turkey’s Ladder of Powers transformation and the classifier model is parameterized by θ.

heading: 4 EXPERIMENTS
text: In this section, we answer the following questions:
• How does our distribution calibration strategy perform compared to the state-of-the-art methods?

heading: 4.1 EXPERIMENTAL SETUP

heading: 4.1.1 DATASETS
text: We evaluate our distribution calibration strategy on miniImageNet (Ravi & Larochelle (2017)), tieredImageNet (Ren et al. (2018)) and CUB (Welinder et al. (2010)). miniImageNet and tieredImageNet have a brand range of classes including various animals and objects while CUB is a more fine-grained dataset that includes various species of birds. Datasets with different levels of granularity may have different distributions for their feature space. We want to show the effectiveness and generality of our strategy on all three datasets.
miniImageNet is derived from ILSVRC-12 dataset (Russakovsky et al., 2014). It contains 100 diverse classes with 600 samples per class. The image size is 84 × 84 × 3. We follow the splits used in previous works (Ravi & Larochelle, 2017), which split the dataset into 64 base classes, 16 validation classes, and 20 novel classes.
tieredImageNet is a larger subset of ILSVRC-12 dataset (Russakovsky et al., 2014), which contains 608 classes sampled from hierarchical category structure. Each class belongs to one of 34 higherlevel categories sampled from the high-level nodes in the ImageNet. The average number of images in each class is 1281. We use 351, 97, and 160 classes for training, validation, and test, respectively.
CUB is a fine-grained few-shot classification benchmark. It contains 200 different classes of birds with a total of 11,788 images of size 84 × 84 × 3. Following previous works (Chen et al., 2019a), we split the dataset into 100 base classes, 50 validation classes, and 50 novel classes.

heading: 4.1.2 EVALUATION METRIC
text: We use the top-1 accuracy as the evaluation metric to measure the performance of our method. We report the accuracy on 5way1shot and 5way5shot settings for miniImageNet, tieredImageNet and CUB. The reported results are the averaged classification accuracy over 10,000 tasks.

heading: 4.1.3 IMPLEMENTATION DETAILS
text: For feature extractor, we use the WideResNet (Zagoruyko & Komodakis, 2016) trained following previous work (Mangla et al. (2020)). For each dataset, we train the feature extractor with base classes and test the performance using novel classes. Note that the feature representation is extracted from the penultimate layer (with a ReLU activation function) from the feature extractor, thus the values are all non-negative so that the inputs to Tukey’s Ladder of Powers transformation in Equation 3 are valid. At the distribution calibration stage, we compute the base class statistics and transfer them to calibrate novel class distribution for each dataset. We use the LR and SVM implementation of scikit-learn (Pedregosa et al. (2011)) with the default settings. We use the same hyperparameter value for all datasets except for α. Specifically, the number of generated features
is 750; k = 2 and λ = 0.5. α is 0.21, 0.21 and 0.3 for miniImageNet, tieredImageNet and CUB, respectively.

heading: 4.2 COMPARISION TO STATE-OF-THE-ART
text: Table 2 and Table 3 presents the 5way1shot and 5way5shot classification results of our method on miniImageNet, tieredImageNet and CUB. We compare our method with the three groups of the fewshot learning method, optimization-based, metric-based, and generation-based. Our method can be built on top of any classifier, and we use two popular and simple classifiers, namely SVM and LR to prove the effectiveness of our method. Simple linear classifiers equipped with our method perform better than the state-of-the-art few-shot classification method and achieve the best performance on 1-shot and 5-shot settings of miniImageNet, tieredImageNet and CUB. The performance of our distribution calibration surpasses the state-of-the-art generation-based method by 10% for the 5way1shot setting, which proves that our method can handle extremely low-shot classification tasks better. Compared to other generation-based methods, which require the design of a generative model with extra training costs on the learnable parameters, simple machine learning classifier with DC is much more simple, effective and flexible and can be equipped with any feature extractors and classifier model structures. Specifically, we show three variants, i.e, Maximum likelihood with DC, SVM with DC, Logistic Regression with DC in Table 2 and Table 3. A simple maximum likelihood classifier based on the calibrated distribution can outperform previous baselines and training a SVM classifier or Logistic Regression classifier using the samples from the calibrated distribution can further improve the performance.

heading: 4.3 VISUALIZATION OF GENERATED SAMPLES
text: We show what the calibrated distribution looks like by visualizing the generated features sampled from the distribution. In Figure 2, we show the t-SNE representation (van der Maaten & Hinton
(2008)) of the original support set (a), the generated features (b,c) as well as the query set (d). Based on the calibrated distribution, the sampled features form a Gaussian distribution and more samples (c) can have a more comprehensive representation of the distribution. Due to the limited number of examples in the support set, only 1 in this case, the samples from the query set usually cover a greater area and are a mismatch with the support set. This mismatch can be fixed to some extent by the generated features, i.e., the generated features in (c) can overlap areas of the query set. Thus, training with these generated features can alleviate the mismatch between the distribution estimated only from the few-shot samples and the ground truth distribution.

heading: 4.4 APPLICABILITY OF DISTRIBUTION CALIBRATION
text: Applying distribution calibration on different backbones
Our distribution calibration strategy is agnostic to backbones / feature extractors. Table 5 shows the consistent performance boost when applying distribution calibration on different feature extractors, i.e, four convolutional layers (conv4), six convolutional layers (conv6), resnet18, WRN28 and WRN28 trained with rotation loss. Distribution calibration achieves around 10% accuracy improvement compared to the backbones trained with different baselines.
Applying distribution calibration on other baselines
A variety of works can benefit from training with the features generated by our distribution calibration strategy. We apply our distribution calibration strategy on two simple few-shot classification algorithms, Baseline (Chen et al., 2019a) and Baseline++ (Chen et al., 2019a). Table 6 shows that our distribution calibration brings over 10% of accuracy improvement on both.

heading: 4.5 EFFECTS OF FEATURE TRANSFORMATION AND TRAINING WITH GENERATED FEATURES
text: Ablation Study
Table 4 shows the performance when our model is trained without Tukey’s Ladder of Powers transformation for the features as in Equation 3 and when it is trained without the generated features as in Equation 7. It is clear that there is a severe decline in performance of over 10% if both are not used in the 5way1shot setting. The ablation of either one results in a performance drop of around 5% in the 5way1shot setting.
Choices of Power for Tukey’s Ladder of Powers Transformation
The left side of Figure 3 shows the 5way1shot accuracy when choosing different powers for the Tukey’s transformation in Equation 3 when training the classifier with the generated features (red) and without (blue). Note that when the power λ equals 1, the transformation keeps the original feature representations. There is a consistent general tendency for training with and without the
generated features and in both cases, we found λ = 0.5 is the optimum choice. With the Tukey’s transformation, the distribution of query set features in target tasks become more aligned to the calibrated Gaussian distribution, thus benefits the classifier which is trained on features sampled from the calibrated distribution.
Number of generated features
The right side of Figure 3 analyzes whether more generated features results in consistent improvement in both cases, namely when the features of support and query set are transformed by Tukey’s transformation (red) and when they are not (blue). We found that when the number of generated features is below 500, both cases can benefit from more generated features. However, when more features are sampled, the performance of the classifier tested on untransformed features begins to decline. By training with the generated samples, the simple logistic regression classifier has a 12% relative performance improvement in a 1-shot classification setting.

heading: 4.6 OTHER HYPER-PARAMETERS
text: We select the hyperparameters based on the performance of the validation set. The k base class statistics to calibrate the novel class distribution in Equation 5 is set to 2. Figure 4 shows the effect of different values of k. The α in Equation 6 is a constant added on each element of the estimated covariance matrix, which can determine the degree of dispersion of features sampled from the calibrated distributions. An appropriate value of α can ensure a good decision boundary for the classifier. Different datasets have different statistics and an appropriate value of α may vary for different datasets. Figure 5 explores the effect of α on all three datasets, i.e. miniImageNet, tieredImageNet and CUB. We observe that in each dataset, the performance of the validation set and the novel (testing) set generally has the same tendency, which indicates that the variance is dataset-dependent and is not overfitting to a specific set.
Ac cu
ra cy
(5 w
ay -1
sh ot
)
Number of retrieved base class statistics k
Figure 4: The effect of different values of k.

heading: 5 CONCLUSION AND FUTURE WORKS
text: We propose a simple but effective distribution calibration strategy for few-shot classification. Without complex generative models, training loss and extra parameters to learn, a simple logistic regression trained with features generated by our strategy outperforms the current state-of-the-art methods by ∼ 5% on miniImageNet. The calibrated distribution is visualized and demonstrates an accurate estimation of the feature distribution. Future works will explore the applicability of distribution calibration on more problem settings, such as multi-domain few-shot classification, and more methods, such as metric-based meta-learning algorithms.

heading: A AUGMENTATION WITH NEAREST CLASS FEATURES
text: Instead of sampling from the calibrated distribution, we can simply retrieve examples from the nearest class to augment the support set. Table 7 shows the comparison of training using samples from the calibrated distribution, the different number of retrieved features from the nearest class, and only using the support set. We found the retrieved features can improve the performance compared to only using the support set but can damage the performance when increasing the number of retrieved features, where the retrieved samples probably serve as noisy data for tasks targeting different classes.

heading: B DISTRIBUTION CALIBRATION WITHOUT NOVEL FEATURE
text: We calibrate the novel class mean by averaging the novel class mean and the retrieved base class means in Equation 6. Table 8 shows the distribution calibration without averaging novel feature, in which the calibrated mean is calculated as µ′ = Σi∈SNµik .

heading: C THE EFFECTS OF TUKEY’S TRANSFORMATION
text: Figure 6 shows the distribution of 5 base classes and 5 novel classes before/after Tukey’s transformation. It is observed that the base class distribution satisfies Gaussian assumption well (left) while the novel class distribution is more skew (middle). The novel class distribution after Tukey’s transformation (right) is more aligned with the Gaussian-like base class distribution.

heading: D THE SIMILARITY LEVEL ANALYSIS
text: We found that the higher similarities between the retrieved base class distribution and the novel class ground-truth distribution, the higher the performance improvement our method will bring as shown in Table 9. The results in the table are under 5-way-1-shot setting.

Review summaries:
The paper proposes a method to calibrate the underlying distribution of a few samples in the few-shot classification scenario. The idea is to estimate a feature distribution of a few samples of a novel class from base class distributions. The authors assume that every dimension in the feature vector follows a Gaussian distribution. Based on the observation that the mean and variance of the distribution with respect to each class are correlated to the semantic similarity of each class, base class distribution can be transferred to the novel class distribution. After distribution calibration, features can be generated from the calibrated distribution and the generated features are used to train classifiers. SVM and logistic regression classifier are used to verify the approach on the mini-imagenet and CUB datasets.

This paper identifies the problem of biased distributions in few-shot learning and proposes to fix it. In few-shot learning, only a few samples per class are available; this makes estimating the class distribution difficult. The paper proposes a distribution calibration algorithm that makes use of the meta-train class distributions to calibrate the few-shot class distributions. Once calibrated, more samples are drawn from this distribution to learn a classifier that generalizes better. This approach does not require additional learnable parameters and can be (potentially) built on-top of any pre-trained feature extractor. Empirical results show that this approach achieves state-of-the-art results on Mini-ImageNet and CUB.