One-shot learning

From HandWiki
Short description: Object categorization problem

One-shot learning is an object categorization problem, found mostly in computer vision. Whereas most machine learning-based object categorization algorithms require training on hundreds or thousands of examples, one-shot learning aims to classify objects from one, or only a few, examples. The term few-shot learning is also used for these problems, especially when more than one example is needed.


Motivation

The ability to learn object categories from few examples, and at a rapid pace, has been demonstrated in humans.[1][2] It is estimated that a child learns almost all of the 10 ~ 30 thousand object categories in the world by age six.[3] This is due not only to the human mind's computational power, but also to its ability to synthesize and learn new object categories from existing information about different, previously learned categories. Given two examples from two object categories: one, an unknown object composed of familiar shapes, the second, an unknown, amorphous shape; it is much easier for humans to recognize the former than the latter, suggesting that humans make use of previously learned categories when learning new ones. The key motivation for solving one-shot learning is that systems, like humans, can use knowledge about object categories to classify new objects.[4][5]

Background

As with most classification schemes, one-shot learning involves three main challenges:

  • Representation: How should objects and categories be described?
  • Learning: How can such descriptions be created?
  • Recognition: How can a known object be filtered from enveloping clutter, irrespective of occlusion, viewpoint, and lighting?[6]

One-shot learning differs from single object recognition and standard category recognition algorithms in its emphasis on knowledge transfer, which makes use of previously learned categories.

  • Model parameters: Reuses model parameters, based on the similarity between old and new categories. Categories are first learned on numerous training examples, then new categories are learned using transformations of model parameters from those initial categories or selecting relevant parameters for a classifier.[7]
  • Feature sharing: Shares parts or features of objects across categories. One algorithm extracts "diagnostic information" in patches from already learned categories by maximizing the patches' mutual information, and then applies these features to the learning of a new category. A dog category, for example, may be learned in one shot from previous knowledge of horse and cow categories, because dog objects may contain similar distinguishing patches.[8]
  • Contextual information: Appeals to global knowledge of the scene in which the object appears. Such global information can be used as frequency distributions in a conditional random field framework to recognize objects.[9] Alternatively context can consider camera height and scene geometry.[10] Algorithms of this type have two advantages. First, they learn object categories that are relatively dissimilar; and second, they perform well in ad hoc situations where an image has not been hand-cropped and aligned.[11]

Theory

The Bayesian one-shot learning algorithm represents the foreground and background of images as parametrized by a mixture of constellation models.[12] During the learning phase, the parameters of these models are learned using a conjugate density parameter posterior and Variational Bayesian Expectation-Maximization (VBEM).[13] In this stage the previously learned object categories inform the choice of model parameters via transfer by contextual information. For object recognition on new images, the posterior obtained during the learning phase is used in a Bayesian decision framework to estimate the ratio of p(object | test, train) to p(background clutter | test, train) where p is the probability of the outcome.[14]

Bayesian framework

Given the task of finding a particular object in a query image, the overall objective of the Bayesian one-shot learning algorithm is to compare the probability that object is present vs the probability that only background clutter is present. If the former probability is higher, the algorithm reports the object's presence, otherwise the algorithm reports its absence. To compute these probabilities, the object class must be modeled from a set of (1 ~ 5) training images containing examples.

To formalize these ideas, let [math]\displaystyle{ I }[/math] be the query image, which contains either an example of the foreground category [math]\displaystyle{ O_{fg} }[/math] or only background clutter of a generic background category [math]\displaystyle{ O_{bg} }[/math]. Also let [math]\displaystyle{ I_t }[/math] be the set of training images used as the foreground category. The decision of whether [math]\displaystyle{ I }[/math] contains an object from the foreground category, or only clutter from the background category is:

[math]\displaystyle{ R = \frac{p(O_{fg}|I,I_t)}{p(O_{bg}|I, I_t)} = \frac{p(I|I_t, O_{fg})p(O_{fg})}{p(I|I_t, O_{bg})p(O_{bg})}, }[/math]

where the class posteriors [math]\displaystyle{ p(O_{fg} |I, I_t) }[/math] and [math]\displaystyle{ p(O_{bg}|I, I_t) }[/math] have been expanded by Bayes' Theorem, yielding a ratio of likelihoods and a ratio of object category priors. We decide that the image [math]\displaystyle{ I }[/math] contains an object from the foreground class if [math]\displaystyle{ R }[/math] exceeds a certain threshold [math]\displaystyle{ T }[/math]. We next introduce parametric models for the foreground and background categories with parameters [math]\displaystyle{ \theta }[/math] and [math]\displaystyle{ \theta_{bg} }[/math] respectively. This foreground parametric model is learned during the learning stage from [math]\displaystyle{ I_t }[/math], as well as prior information of learned categories. The background model we assume to be uniform across images. Omitting the constant ratio of category priors, [math]\displaystyle{ \frac{p(O_{fg})}{p(O_{bg})} }[/math], and parametrizing over [math]\displaystyle{ \theta }[/math] and [math]\displaystyle{ \theta_{bg} }[/math] yields

[math]\displaystyle{ R \propto \frac{\int{p(I | \theta, O_{fg}) p(\theta | I_t, O_{fg})} d\theta}{\int{p(I | \theta_{bg}, O_{bg}) p(\theta_{bg} | I_t, O_{bg})} d\theta_{bg}} = \frac{\int{p(I | \theta) p(\theta | I_t, O_{fg})} d\theta}{\int{p(I | \theta_{bg}) p(\theta_{bg} | I_t, O_{bg})} d\theta_{bg}} }[/math], having simplified [math]\displaystyle{ p(I | \theta, O_{fg}) }[/math] and [math]\displaystyle{ p(I | \theta, O_{bg}) }[/math] to [math]\displaystyle{ p(I | \theta_{fg}) }[/math] and [math]\displaystyle{ p(I | \theta_{bg}). }[/math]

The posterior distribution of model parameters given the training images, [math]\displaystyle{ p(\theta | I_t, O_{fg}) }[/math] is estimated in the learning phase. In this estimation, one-shot learning differs sharply from more traditional Bayesian estimation models that approximate the integral as [math]\displaystyle{ \delta(\theta^{ML}) }[/math]. Instead, it uses a variational approach using prior information from previously learned categories. However, the traditional maximum likelihood estimation of the model parameters is used for the background model and the categories learned in advance through training.[15]

Object category model

For each query image [math]\displaystyle{ I }[/math] and training images [math]\displaystyle{ I_t }[/math], a constellation model is used for representation.[12][16][17] To obtain this model for a given image [math]\displaystyle{ I }[/math], first a set of N interesting regions is detected in the image using the Kadir brady saliency detector.[18] Each region selected is represented by a location in the image, [math]\displaystyle{ X_i }[/math] and a description of its appearance, [math]\displaystyle{ A_i }[/math]. Letting [math]\displaystyle{ X = \sum_{i = 1}^N X_i, A = \sum_{i = 1}^N A_i }[/math] and [math]\displaystyle{ X_t }[/math]and [math]\displaystyle{ A_t }[/math] the analogous representations for training images, the expression for R becomes:

[math]\displaystyle{ R \propto \frac{\int{p(X,A | \theta, O_{fg}) p(\theta | X_t, A_t, O_{fg})} d\theta}{\int{p(X,A | \theta_{bg}, O_{bg}) p(\theta_{bg} | X_t, A_t, O_{bg})} d\theta_{bg}} = \frac{\int{p(X,A | \theta) p(\theta | X_t, A_t, O_{fg})} d\theta}{\int{p(X,A | \theta_{bg}) p(\theta_{bg} | X_t, A_t, O_{bg})} \,d\theta_{bg}} }[/math]

The likelihoods [math]\displaystyle{ p(X, A|\theta) }[/math] and [math]\displaystyle{ p(X, A|\theta_{bg}) }[/math] are represented as mixtures of constellation models. A typical constellation model has P(3 ~ 7) parts, with N(~100) interest regions. Thus a P-dimensional vector h assigns one region of interest (out of N regions) to each model part (for P parts). Thus h denotes a hypothesis (an assignment of interest regions to model parts) for the model and a full constellation model is represented by summing over all possible hypotheses h in the hypothesis space [math]\displaystyle{ H }[/math]. Finally the likelihood is written

[math]\displaystyle{ p(X,A|\theta) = \sum_{\omega=1}^{\Omega} \sum_{\textbf{h} \in H} p(X,A,\textbf{h}, \omega | \theta). }[/math]

The different [math]\displaystyle{ \omega }[/math]'s represent different configurations of parts, whereas the different hypotheses h represent different assignations of regions to parts, given a part model [math]\displaystyle{ \omega }[/math]. The assumption that the shape of the model (as represented by [math]\displaystyle{ X }[/math], the collection of part locations) and appearance are independent allows one to consider the likelihood expression [math]\displaystyle{ p(X,A,\textbf{h}, \omega | \theta) }[/math] as two separate likelihoods of appearance and shape.[19]

Appearance

The appearance of each feature is represented by a point in appearance space (discussed below in implementation). "Each part [math]\displaystyle{ p }[/math] in the constellation model has a Gaussian density within this space with mean and precision parameters [math]\displaystyle{ \theta_{p,\omega}^{A} = { \mu_{p,\omega}^{A}, \Gamma_{p,\omega}^{A} } }[/math]." From these the appearance likelihood described above is computed as a product of Gaussians over the model parts for a give hypothesis h and mixture component [math]\displaystyle{ \omega }[/math].[20]

Shape

The shape of the model for a given mixture component [math]\displaystyle{ \omega }[/math] and hypothesis h is represented as a joint Gaussian density of the locations of features. These features are transformed into a scale and translation-invariant space before modelling the relative location of the parts by a 2(P - 1)-dimensional Gaussian. From this, we obtain the shape likelihood, completing our representation of [math]\displaystyle{ p(X,A, \textbf{h}, \omega | \theta) }[/math] . In order to reduce the number of hypotheses in the hypothesis space [math]\displaystyle{ H }[/math], only those hypotheses that satisfy the ordering constraint that the x-coordinate of each part is monotonically increasing are considered. This eliminates [math]\displaystyle{ P! }[/math] hypotheses from [math]\displaystyle{ H }[/math].[20]

Conjugate densities

In order to compute [math]\displaystyle{ R }[/math], the integral [math]\displaystyle{ \int{p(X,A | \theta) p(\theta | X_t, A_t, O_{fg})} d\theta }[/math] must be evaluated, but is analytically intractable. The object category model above gives information about [math]\displaystyle{ p(X,A | \theta) }[/math], so what remains is to examine [math]\displaystyle{ p(\theta| X_t, A_t, O) }[/math], the posterior of [math]\displaystyle{ \theta }[/math], and find a sufficient approximation to render the integral tractable. Previous work approximates the posterior by a [math]\displaystyle{ \delta }[/math]function centered at [math]\displaystyle{ \theta^{*} }[/math], collapsing the integral in question into [math]\displaystyle{ p(X, A|\theta^{*}) }[/math]. This [math]\displaystyle{ \theta^{*} }[/math] is normally estimated using a Maximum Likelihood ([math]\displaystyle{ \theta^{*} = \theta^{ML} }[/math]) or Maximum A Posteriori ([math]\displaystyle{ \theta^{*} = \theta^{MAP} }[/math]) procedure. However, because in one-shot learning, few training examples are used, the distribution will not be well-peaked, as is assumed in a [math]\displaystyle{ \delta }[/math]function approximation. Thus instead of this traditional approximation, the Bayesian one-shot learning algorithm seeks to "find a parametric form of [math]\displaystyle{ p(\theta) }[/math] such that the learning of [math]\displaystyle{ p(\theta| X_t, A_t, O_{fg}) }[/math] is feasible". The algorithm employs a Normal-Wishart distribution as the conjugate prior of [math]\displaystyle{ p(\theta| X_t, A_t, O_{fg}) }[/math], and in the learning phase, variational Bayesian methods with the same computational complexity as maximum likelihood methods are used to learn the hyperparameters of the distribution. Then, since [math]\displaystyle{ p(X,A|\theta) }[/math] is a product of Gaussians, as chosen in the object category model, the integral reduces to a multivariate Student's T distribution, which can be evaluated.[21]

Implementation

Feature detection and representation

To detect features in an image so that it can be represented by a constellation model, the Kadir Brady feature detector is used on grey-scale images, finding salient regions of the image. These regions are then clustered, yielding a number of features (the clusters) and the shape parameter [math]\displaystyle{ X }[/math], composed of the cluster centers. The Kadir Brady detector was chosen because it produces fewer, more salient regions, as opposed to feature detectors like multiscale Harris, which produces numerous, less significant regions.

The regions are then taken from the image and rescaled to a small patch of 11 x 11 pixels, allowing each patch to be represented in 121-dimensional space. This dimensionality is reduced using principal component analysis, and [math]\displaystyle{ A }[/math], the appearance parameter, is then formed from the first 10 principal components of each patch.[22]

Learning

To obtain shape and appearance priors, three categories (spotted cats, faces, and airplanes) are learned using maximum likelihood estimation. These object category model parameters are then used to estimate the hyper-parameters of the desired priors.

Given a set of training examples, the algorithm runs the feature detector on these images, and determines model parameters from the salient regions. The hypothesis index h assigning features to parts prevents a closed-form solution of the linear model, so the posterior [math]\displaystyle{ p(\theta| X_t, A_t, O_{fg}) }[/math] is estimated by variational Bayesian expectation-maximization, which is run until parameter convergence after ~ 100 iterations. Learning a category in this fashion takes under a minute on a 2.8 GHz machine with a 4-part model and < 10 training images.[23]

Experimental results

Motorbike example

To learn the motorbike category:

  • Six training images are selected from the motorbike category of the Caltech 4 Data Set and the Kadir Brady detector is applied, giving [math]\displaystyle{ X_t }[/math] and through PCA, [math]\displaystyle{ A_t }[/math].
  • Next, the prior model parameters are computed from 30 models [math]\displaystyle{ \theta_t }[/math], 10 from each of the three learned categories: spotted cats, faces, and airplanes. This prior encodes the knowledge that "models lacking visual consistency [ie background clutter] occupy a different part of the parameter space [from] coherent models."
  • In learning, which is performed next, the prior biases the posterior [math]\displaystyle{ p(\theta| X_t, A_t, O_{fg}) }[/math] towards parts of the parameter space corresponding to coherent models. Only one mixture component is used, letting [math]\displaystyle{ \Omega = 1 }[/math]. The estimation of the posterior is shown below.
  • Finally, the figures below show the learned motorbike model with shape and appearance of parts, and the corresponding features.
  • For recognition tests, the model above is applied to 50 images which contain motorbikes and 50 which do not. The image below shows an ROC curve, measuring the probability of detection over the probability of false detection, as well as some recognized examples.

Shared densities on transforms

Another algorithm uses knowledge transfer by model parameters to learn a new object category that is similar in appearance to previously learned categories. An image is represented as either a texture and shape, or as a latent image that has been transformed, denoted by [math]\displaystyle{ I = T(I_L) }[/math].

A Siamese neural network works in tandem on two different input vectors to compute comparable output vectors.[24]

Congealing

In this context, congealing is "the simultaneous vectorization of each of a set of images to each other". For a set of training images of a certain category, congealing iteratively transforms each image to minimize the images' joint pixelwise entropies E, where

[math]\displaystyle{ E = \sum_{p=1}^{P}H(\nu(p)), }[/math]

"where [math]\displaystyle{ \nu(p) }[/math] is the binary random variable defined by the values of a particular pixel p across all of the images, [math]\displaystyle{ H( ) }[/math] is the discrete entropy function of that variable, and [math]\displaystyle{ 1\leq p \leq P }[/math] is the set of pixel indices for the image."

The congealing algorithm begins with a set of images [math]\displaystyle{ I_i }[/math] and a corresponding transform matrix [math]\displaystyle{ U_i }[/math], which at the end of the algorithm will represent the transformation of [math]\displaystyle{ I_i }[/math] into its latent [math]\displaystyle{ I_{L_i} }[/math]. These latents [math]\displaystyle{ I_{L_i} }[/math] minimize the joint pixel-wise entropies. Thus the task of the congealing algorithm is to estimate the transformations [math]\displaystyle{ U_i }[/math].

Sketch of algorithm:

  • Initialize [math]\displaystyle{ U_I }[/math]'s to the identity.
  • Compute the joint pixelwise entropies of the current set of images.
  • For each image [math]\displaystyle{ I_i }[/math], iterate through all possible affine transformations [math]\displaystyle{ A }[/math] (rotation, x-translation, y-translation, x-scale, y-scale, x-shear, y-shear) and test if [math]\displaystyle{ AU_i }[/math] decreases the joint pixelwise entropies. If so, set [math]\displaystyle{ U_i = AU_i }[/math].
  • Repeat previous step until convergence.

At the end of the algorithm, [math]\displaystyle{ U_i(I) = I_{L_i} }[/math], and [math]\displaystyle{ T = U_i^{-1} }[/math] transforms the latent image back into the originally observed image.[25]

Classification

To use this model for classification, it must be estimated with the maximum posterior probability given an observed image [math]\displaystyle{ I }[/math]. Applying Bayes' rule to [math]\displaystyle{ P(c_j|I) }[/math] and parametrization by the transformation [math]\displaystyle{ T }[/math] gives a difficult integral that must be approximated, and then the best transform [math]\displaystyle{ T }[/math] (that which maps the test image to its latent image) must be found. Once this transformation is found, the test image can be transformed into its latent, and a nearest neighbor classifier based on Hausdorff distance between images can classify the latent (and thus the test image) as belonging to a particular class [math]\displaystyle{ c_j }[/math].

To find [math]\displaystyle{ T }[/math], the test image I is inserted into the training ensemble for the congealing process. Since the test image is drawn from one of the categories [math]\displaystyle{ c_j }[/math], congealing provides a corresponding [math]\displaystyle{ T_{\text{test}} = U_{\text{test}}^{-1} }[/math] that maps I to its latent. The latent can then be classified.[26]

Single-example classification

Given a set of transformations [math]\displaystyle{ B_i }[/math] obtained from congealing many images of a certain category, the classifier can be extended to the case where only one training [math]\displaystyle{ I_t }[/math] example of a new category [math]\displaystyle{ c }[/math] is allowed. Applying all the transformations [math]\displaystyle{ B_i }[/math] sequentially to [math]\displaystyle{ I_t }[/math] creates an artificial training set for [math]\displaystyle{ c }[/math]. This artificial data set can be made larger by borrowing transformations from many already known categories. Once this data set is obtained, [math]\displaystyle{ I }[/math], a test instance of [math]\displaystyle{ c }[/math], can be classified as in the normal classification procedure. The key assumption is that categories are similar enough that the transforms from one can be applied to another.[27]

In natural language processing

With the introduction of the practice of scaling up language models like OpenAI's GPT-2 and GPT-3, few-shot performance of such models has been shown to achieve competitive results on natural language processing (NLP) tasks, sometimes surpassing prior state-of-the-art fine-tuning approaches. Examples of such NLP tasks are translation, question answering, cloze tasks, unscrambling words, and using a novel word in a sentence.[28] In these cases, one-shot and few-shot learning have been demonstrated purely via text interaction with the model. This is done by prepending examples directly to the prompt that is fed into the model for inference. The creation and optimisation of such prompts is called prompt engineering and is now an active field of study.

See also

Citations

  1. Li, Fergus & Perona 2002.
  2. Thorpe, Fize & Marlot 1996.
  3. Biederman 1987.
  4. Li, Fergus & Perona 2006, Section 1.
  5. Li 2006, Section 1.
  6. Li, Fergus & Perona 2006, Section 2.
  7. Fink 2004.
  8. Bart & Ullman 2005.
  9. Murphy & et al 2004.
  10. Hoiem, Efros & Herbert 2005.
  11. Li 2006, Section 2.
  12. 12.0 12.1 Burl & et al 1996.
  13. Attias 1999.
  14. Li & et al 2006.
  15. Li, Fergus & Perona 2006, Section 3.1.
  16. Weber, Welling & Perona 2000.
  17. Fergus, Perona & Zisserman 2003.
  18. Kadir & Brady 2001.
  19. Li, Fergus & Perona 2006, Section 3.2.
  20. 20.0 20.1 Li, Fergus & Perona 2006, Section 3.2.1.
  21. Li, Fergus & Perona 2006, Section 3.4.3.
  22. Li, Fergus & Perona 2006, Section 5.1.
  23. Li, Fergus & Perona 2006, Sections 4, 5.2.
  24. Few-Shot Learning (2/3): Siamese Networks. YouTube. Archived from the original on 2021-12-10.
  25. Miller et al.
  26. Miller, Matsakis & Viola 2000, Section 4.
  27. Miller, Matsakis & Viola 2000, Section 7.
  28. Brown, Tom B.; Mann, Benjamin; Ryder, Nick; Subbiah, Melanie; Kaplan, Jared; Dhariwal, Prafulla; Neelakantan, Arvind; Shyam, Pranav et al. (22 July 2020). "Language Models are Few-Shot Learners". arXiv:2005.14165 [cs]. doi:10.48550/arXiv.2005.14165. 

References