SemiParametricRegressorTrainer¶
- class menpo.fit.regression.trainer.SemiParametricRegressorTrainer(transform, reference_shape, regression_type=<function mlr at 0x7f5c2da62cf8>, regression_features=<function sparse_hog at 0x7f5c2da626e0>, patch_shape=(16, 16), update='compositional', noise_std=0.04, rotation=False, n_perturbations=10)[source]¶
Bases: NonParametricRegressorTrainer
Class for training a Semi-Parametric Regressor.
This means that a parametric shape model and a non-parametric appearance representation are employed.
Parameters: reference_shape : PointCloud
The reference shape that will be used.
regression_type : function, optional
A function that defines the regression technique to be used. Examples of such closures can be found in Functions
regression_features : None or string or function, optional
The features that are used during the regression.
If None, no feature representation will be computed from the original image.
If string or function, the feature representation will be computed in the following way:
If string, the feature representation will be extracted by executing:
feature_image = getattr(image.features, feature_type)()
For this to work properly feature_type needs to be one of Menpo’s standard image feature methods. Note that, in this case, the feature computation will be carried out using its default options.
Non-default feature options and new experimental feature can be used by defining a closure. In this case, the closure must define a function that receives as an input an image and returns a particular feature representation of that image. For example:
def igo_double_from_std_normalized_intensities(image) image = deepcopy(image) image.normalize_std_inplace() return image.feature_type.igo(double_angles=True)
See ImageFeatures for details more details on Menpo’s standard image features and feature options. See Features Functions for non standard features definitions.
patch_shape : tuple, optional
The shape of the patches that will be extracted.
update : ‘compositional’ or ‘additive’
Defines the way to update the warp.
noise_std : float, optional
The standard deviation of the gaussian noise used to produce the training shapes.
rotation : boolean, optional
Specifies whether ground truth in-plane rotation is to be used to produce the training shapes.
n_perturbations : int, optional
Defines the number of perturbations that will be applied to the training shapes.
- delta_ps(gt_shape, perturbed_shape)[source]¶
Method to generate the delta_ps for the regression.
Parameters: gt_shape : PointCloud
The ground truth shape.
perturbed_shape : PointCloud
The perturbed shape.
- features(image, shape)¶
Method that extracts the features for the regression, which in this case are patch based.
Parameters: image : MaskedImage
The current image.
shape : PointCloud
The current shape.
- perturb_shapes(gt_shape)¶
Perturbs the given shapes. The number of perturbations is defined by n_perturbations.
Parameters: gt_shape : PointCloud list
List of the shapes that correspond to the images. will be perturbed.
Returns: perturbed_shapes : PointCloud list
List of the perturbed shapes.
- train(images, shapes, perturbed_shapes=None, verbose=False, **kwargs)¶
Trains a Regressor given a list of landmarked images.
Parameters: images : list of MaskedImage
The set of landmarked images from which to train the regressor.
shapes : PointCloud list
List of the shapes that correspond to the images.
perturbed_shapes : PointCloud list, optional
List of the perturbed shapes used for the regressor training.
verbose : boolean, optional
Flag that controls information and progress printing.
Returns: regressor : :map:`Regressor`
A regressor object.
Raises: ValueError :
The number of shapes must be equal to the number of images.
ValueError :
The number of perturbed shapes must be equal or multiple to the number of images.