CLM

class menpofit.clm.CLM(images, group=None, holistic_features=<function no_op>, reference_shape=None, diagonal=None, scales=(0.5, 1), patch_shape=(17, 17), patch_normalisation=<function no_op>, context_shape=(34, 34), cosine_mask=True, sample_offsets=None, shape_model_cls=<class 'menpofit.modelinstance.OrthoPDM'>, expert_ensemble_cls=<class 'menpofit.clm.expert.ensemble.CorrelationFilterExpertEnsemble'>, max_shape_components=None, verbose=False, batch_size=None)[source]

Bases: object

Class for training a multi-scale holistic Constrained Local Model. Please see the references for a basic list of relevant papers.

Parameters
  • images (list of menpo.image.Image) – The list of training images.

  • group (str or None, optional) – The landmark group that will be used to train the CLM. If None and the images only have a single landmark group, then that is the one that will be used. Note that all the training images need to have the specified landmark group.

  • holistic_features (closure or list of closure, optional) – The features that will be extracted from the training images. If list, then it must define a feature function per scale. Please refer to menpo.feature for a list of potential features.

  • reference_shape (menpo.shape.PointCloud or None, optional) – The reference shape that will be used for building the CLM. The purpose of the reference shape is to normalise the size of the training images. The normalization is performed by rescaling all the training images so that the scale of their ground truth shapes matches the scale of the reference shape. Note that the reference shape is rescaled with respect to the diagonal before performing the normalisation. If None, then the mean shape will be used.

  • diagonal (int or None, optional) – This parameter is used to rescale the reference shape so that the diagonal of its bounding box matches the provided value. In other words, this parameter controls the size of the model at the highest scale. If None, then the reference shape does not get rescaled.

  • scales (float or tuple of float, optional) – The scale value of each scale. They must provided in ascending order, i.e. from lowest to highest scale. If float, then a single scale is assumed.

  • patch_shape ((int, int) or list of (int, int), optional) – The shape of the patches to be extracted. If a list is provided, then it defines a patch shape per scale.

  • patch_normalisation (callable, optional) – The normalisation function to be applied on the extracted patches.

  • context_shape ((int, int) or list of (int, int), optional) – The context shape for the convolution. If a list is provided, then it defines a context shape per scale.

  • cosine_mask (bool, optional) – If True, then a cosine mask (Hanning function) will be applied on the extracted patches.

  • sample_offsets ((n_offsets, n_dims) ndarray or None, optional) – The offsets to sample from within a patch. So (0, 0) is the centre of the patch (no offset) and (1, 0) would be sampling the patch from 1 pixel up the first axis away from the centre. If None, then no offsets are applied.

  • shape_model_cls (subclass of PDM, optional) – The class to be used for building the shape model. The most common choice is OrthoPDM.

  • expert_ensemble_cls (subclass of ExpertEnsemble, optional) – The class to be used for training the ensemble of experts. The most common choice is CorrelationFilterExpertEnsemble.

  • max_shape_components (int, float, list of those or None, optional) – The number of shape components to keep. If int, then it sets the exact number of components. If float, then it defines the variance percentage that will be kept. If list, then it should define a value per scale. If a single number, then this will be applied to all scales. If None, then all the components are kept. Note that the unused components will be permanently trimmed.

  • verbose (bool, optional) – If True, then the progress of building the CLM will be printed.

  • batch_size (int or None, optional) – If an int is provided, then the training is performed in an incremental fashion on image batches of size equal to the provided value. If None, then the training is performed directly on the all the images.

References

1

D. Cristinacce, and T. F. Cootes. “Feature Detection and Tracking with Constrained Local Models”, British Machine Vision Conference (BMVC), 2006.

2

J.M. Saragih, S. Lucey, and J. F. Cohn. “Deformable model fitting by regularized landmark mean-shift”, International Journal of Computer Vision (IJCV), 91(2): 200-215, 2011.

3

T. F. Cootes, C. J. Taylor, D. H. Cooper, and J. Graham. “Active Shape Models - their training and application”, Computer Vision and Image Understanding (CVIU), 61(1): 38-59, 1995.

increment(images, group=None, shape_forgetting_factor=1.0, verbose=False, batch_size=None)[source]

Method to increment the trained CLM with a new set of training images.

Parameters
  • images (list of menpo.image.Image) – The list of training images.

  • group (str or None, optional) – The landmark group that will be used to train the CLM. If None and the images only have a single landmark group, then that is the one that will be used. Note that all the training images need to have the specified landmark group.

  • shape_forgetting_factor ([0.0, 1.0] float, optional) – Forgetting factor that weights the relative contribution of new samples vs old samples for the shape model. If 1.0, all samples are weighted equally and, hence, the result is the exact same as performing batch PCA on the concatenated list of old and new simples. If <1.0, more emphasis is put on the new samples.

  • verbose (bool, optional) – If True, then the progress of building the CLM will be printed.

  • batch_size (int or None, optional) – If an int is provided, then the training is performed in an incremental fashion on image batches of size equal to the provided value. If None, then the training is performed directly on the all the images.

shape_instance(shape_weights=None, scale_index=- 1)[source]

Generates a novel shape instance given a set of shape weights. If no weights are provided, the mean shape is returned.

Parameters
  • shape_weights ((n_weights,) ndarray or list or None, optional) – The weights of the shape model that will be used to create a novel shape instance. If None, the weights are assumed to be zero, thus the mean shape is used.

  • scale_index (int, optional) – The scale to be used.

Returns

instance (menpo.shape.PointCloud) – The shape instance.

property n_scales

Returns the number of scales.

Type

int