{ } Raw JSON

bundles / skimage latest / skimage / feature / _fisher_vector / learn_gmm

function

skimage.feature._fisher_vector:learn_gmm

source: /dev/scikit-image/src/skimage/feature/_fisher_vector.py :40

Signature

def   learn_gmm ( descriptors * n_modes = 32 gm_args = None )

Summary

Estimate a Gaussian mixture model (GMM) given a set of descriptors and number of modes (i.e. Gaussians). This function is essentially a wrapper around the scikit-learn implementation of GMM, namely the sklearn.mixture.GaussianMixture class.

Extended Summary

Due to the nature of the Fisher vector, the only enforced parameter of the underlying scikit-learn class is the covariance_type, which must be 'diag'.

There is no simple way to know what value to use for n_modes a-priori. Typically, the value is usually one of {16, 32, 64, 128}. One may train a few GMMs and choose the one that maximises the log probability of the GMM, or choose n_modes such that the downstream classifier trained on the resultant Fisher vectors has maximal performance.

Parameters

descriptors : ndarray of shape (N, M) or list of (tuple[int, int])

List of NumPy arrays, or a single NumPy array, of the descriptors used to estimate the GMM. The reason a list of NumPy arrays is permissible is because often when using a Fisher vector encoding, descriptors/vectors are computed separately for each sample/image in the dataset, such as SIFT vectors for each image. If a list if passed in, then each element must be a NumPy array in which the number of rows may differ (e.g. different number of SIFT vector for each image), but the number of columns for each must be the same (i.e. the dimensionality must be the same).

n_modes : int

The number of modes/Gaussians to estimate during the GMM estimate.

gm_args : dict

Keyword arguments that can be passed into the underlying scikit-learn sklearn.mixture.GaussianMixture class.

Returns

gmm : :class:`sklearn.mixture.GaussianMixture`

The estimated GMM object, which contains the necessary parameters needed to compute the Fisher vector.

Examples

from skimage.feature import fisher_vector
rng = np.random.Generator(np.random.PCG64())
sift_for_images = [rng.standard_normal((10, 128)) for _ in range(10)]
num_modes = 16
gmm = learn_gmm(sift_for_images, n_modes=num_modes)

Aliases

  • skimage.feature.learn_gmm