F REE L UNCH FOR F EW - SHOT L EARNING : D ISTRIBUTION C ALIBRATION
A BSTRACT
Learning from a limited number of samples is challenging since the learned model can easily become overﬁtted based on the biased distribution formed by only a few training examples.
In this paper we calibrate the distribution of these few-sample classes by transferring statistics from the classes with sufﬁcient examples, then an adequate number of examples can be sampled from the calibrated distribution to expand the inputs to the classiﬁer.
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 classiﬁcation models without extra parameters.
We show that a simple logistic regression classiﬁer trained using the features sampled from our calibrated distribution can outperform the state-of-theart accuracy on two 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
I NTRODUCTION
[Table]
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.
; 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 insufﬁciency problem.
Ren et al.
(2018) propose to leverage unlabeled data and predict pseudo labels to improve the performance of few-shot 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 overﬁt 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.
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 [Figure] distribution can generalize over a broader range of data from a more accurate distribution rather than only ﬁtting 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.
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.
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 sufﬁcient supervision for training the classiﬁcation model.
In the experiments, we show that a simple logistic regression classiﬁer trained with our strategy can achieve state-of-the-art accuracy on two datasets.
Our distribution calibration strategy can be paired with any classiﬁer 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.
R ELATED W ORKS
Few-shot classiﬁcation 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 classiﬁcation problem, researchers proposed simple but effective algorithms based on metric learning.
MatchingNet (Vinyals et al.
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 classiﬁer is trained in a traditional supervised learning way.
Another line of algorithms is to compensate for the insufﬁcient 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.
; Chen et al.
; Schwartz et al.
; Gao et al.
or features (Xian et al.
; Zhang et al.
(2019)) to augment the training set.
Speciﬁcally, 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., 2019) or encoding the intra-class deformations (Schwartz et al., 2018).
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.
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.
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) tried to augment feature representations by sampling from an estimated variance.
These methods learn to augment from the original samples or their feature representation while we try to estimate the class-level distribution and thus can eliminate the inductive bias from a single sample and provide more diverse generations from the calibrated distribution.
M AIN A PPROACH
In this section, we introduce the few-shot classiﬁcation problem deﬁnition in Section 3.1 and details of our proposed approach in Section 3.2.
3. P ROBLEM D EFINITION
We follow a typical few-shot classiﬁcation setting.
Given a dataset with data-label pairs D = { ( x i , y i ) } where x
i ∈ R
d is the feature vector of a sample and y i ∈ C , where C denotes the set of classes.
This set of classes is divided into base classes C b and novel classes C n , where C b ∩ C n = ∅ and C b ∪ C n = 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 =
{ ( x i , y i ) }
N × K i
=
and the model is evaluated on another query set Q = { ( x i , y i ) }
N × K + N × q i = 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.
3. D ISTRIBUTION C ALIBRATION
As introduced in Section 3.1, the base classes have a sufﬁcient 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 ﬁnetuning.
In our experiments, we use the pretrained WideResNet following previous work (Mangla et al.
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.
Require: Support set features S =
( x i , y ) N
× K i =
Require: Base classes’ statistics { µ i } | C b | i
=1 , { Σ i } | C b | i = 1: Transform ( x i ) N
× K i =1 with Tukey’s Ladder of Powers as Equation 3 2: for ( x i , y i )
∈ S do 3:
Calibrate the mean µ (cid:48) and the covariance Σ (cid:48) for class
y i using x i with Equation4:
Sample features for class y i from the calibrated distribution as Equation 7 5: end for 6: Train a classiﬁer using both support set features and all sampled features as Equation 3.2. S TATISTICS OF THE BASE CLASSES 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:
[Equation]
where x j is a feature vector of the j -th sample from the base class i and n i is the total number of samples in class i .
As the feature vector x j 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:
[Equation]
[Equation]
. C ALIBRATING STATISTICS OF THE NOVEL CLASSES
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 ﬁrst 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:
[Equation]
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 sufﬁcient 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.
Speciﬁcally, we select the top k base classes with the closest distance to the feature of a sample ˜ x
from the support set:
[Equation]
where topk ( · ) is an operator to select the top elements from the input distance set S d .
S N 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:
[Equation]
[Table]
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 speciﬁc 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 ∈ C n , we denote the set of statistics as S y = { ( µ (cid:48) 1 , Σ (cid:48) 1 ) , ..., ( µ (cid:48) K , Σ (cid:48) K ) } , where µ (cid:48)
i , Σ (cid:48)
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.
3.2. H OW TO LEVERAGE THE CALIBRATED DISTRIBUTION ?
With a set of calibrated statistics S y for class y in a target task, we generate a set of feature vectors with label y by sampling from the calibrated Gaussian distributions:
[Equation]
Here, the total number of generated features per class is set as a hyperparameter and they are equally distributed for every calibrated distribution in S y .
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-speciﬁc classiﬁer.
We train the classiﬁer for a task by minimizing the cross-entropy loss over both the features of its support set S and the generated features D y :
[Equation]
where Y T 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 classiﬁer model is parameterized by θ .
E XPERIMENTS
In this section, we answer the following questions:
• How does our distribution calibration strategy perform compared to the state-of-the-art methods?
[Table]
• What does calibrated distribution look like?
Is it an accurate approximation for this class?
• How does Tukey’s Ladder of Power transformation interact with the feature generations?
How important is each in relation to performance?
4. E XPERIMENTAL S ETUP 4.1. D ATASETS
We evaluate our distribution calibration strategy on mini ImageNet (Ravi & Larochelle (2017)), tiered ImageNet (Ren et al.
and CUB (Welinder et al.
[Table]
mini ImageNet and tiered ImageNet have a brand range of classes including various animals and objects while CUB is a more ﬁne-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.
mini ImageNet is derived from ILSVRC-12 dataset (Russakovsky et al., 2014).
It containsdiverse 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,validation classes, and 20 novel classes.
tiered ImageNet 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 ﬁne-grained few-shot classiﬁcation 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., 2019), we split the dataset into 100 base classes, 50 validation classes, and 50 novel classes.
4.1. E VALUATION M ETRIC
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 mini ImageNet, tiered ImageNet and
CUB.
The reported results are the averaged classiﬁcation accuracy over 10,000 tasks.
4.1. I MPLEMENTATION D ETAILS
For feature extractor, we use the WideResNet trained following previous work (Mangla et al.
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 α .
Speciﬁcally, the number of generated features is 750; k = 2 and λ = 0 .
α is 0.21, 0.21 and 0.
[Figure]
[Figure]
for miniImageNet, tieredImageNet and CUB, respectively.
The source code is available at: https: //github.com/ShuoYang-1998/ICLR2021-Oral_Distribution_Calibration
4. C OMPARISION TO S TATE - OF - THE - ART
Table 2 and Table 3 presents the 5way1shot and 5way5shot classiﬁcation results of our method on mini ImageNet, tiered ImageNet 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 classiﬁer, and we use two popular and simple classiﬁers, namely SVM and
LR to prove the effectiveness of our method.
Simple linear classiﬁers equipped with our method perform better than the state-of-the-art few-shot classiﬁcation method and achieve the best performance on 1-shot and 5-shot settings of mini ImageNet, tiered ImageNet 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 classiﬁcation 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 classiﬁer with
DC is much more simple, effective and ﬂexible and can be equipped with any feature extractors and classiﬁer model structures.
Speciﬁcally, 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 classiﬁer based on the calibrated distribution can outperform previous baselines and training a SVM classiﬁer or Logistic Regression classiﬁer using the samples from the calibrated distribution can further improve the performance.
4. V ISUALIZATION OF G ENERATED S AMPLES
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
[Table] [Table]
(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 ﬁxed 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.
4. A PPLICABILITY OF DISTRIBUTION CALIBRATION 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 beneﬁt from training with the features generated by our distribution calibration strategy.
We apply our distribution calibration strategy on two simple few-shot classiﬁcation algorithms, Baseline (Chen et al., 2019) and Baseline++ (Chen et al., 2019).
Table 6 shows that our distribution calibration brings over 10% of accuracy improvement on both.
4. E FFECTS OF FEATURE TRANSFORMATION AND TRAINING WITH GENERATED FEATURES 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 classiﬁer 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 [Table] 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 beneﬁts the classiﬁer 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 beneﬁt from more generated features.
However, when more features are sampled, the performance of the classiﬁer tested on untransformed features begins to decline.
By training with the generated samples, the simple logistic regression classiﬁer has a 12% relative performance improvement in a 1-shot classiﬁcation setting.
4. O THER H YPER - PARAMETERS
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 classiﬁer.
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. mini ImageNet, tiered ImageNet 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 overﬁtting to a speciﬁc set.
[Figure]
[Figure]
C ONCLUSION AND FUTURE WORKS
We propose a simple but effective distribution calibration strategy for few-shot classiﬁcation.
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 mini ImageNet.
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 classiﬁcation, and more methods, such as metric-based meta-learning algorithms.
Training data
[Table]
Support set only
[Table]
Support set + 1 feature from the nearest class
[Table]
Support set + 5 features from the nearest class
[Table]
Support set + 10 features from the nearest class
[Table]
Support set + 100 features from the nearest class
[Table]
Support set + 100 features sampled from calibrated distribution
[Table]
A AUGMENTATION WITH NEAREST CLASS FEATURES
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.
B D ISTRIBUTION C ALIBRATION WITHOUT NOVEL FEATURE
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 µ (cid:48)
= Σ i ∈ S N µ i k .
C T HE EFFECTS OF T UKEY ’ S TRANSFORMATION
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 satisﬁes 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.
[Table]
Distribution Calibration
[Table]
[Table]
D T HE SIMILARITY LEVEL ANALYSIS
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.