Ejemplo n.º 1
0
def test_verbose_mock(mock_stdout):
    sdm = SDMTrainer(regression_type=mlr_svd,
                     regression_features=sparse_hog,
                     patch_shape=(16, 16),
                     features=no_op,
                     normalization_diagonal=150,
                     n_levels=1,
                     downscale=1.3,
                     noise_std=0.04,
                     rotation=False,
                     n_perturbations=2).train(training_images, verbose=True)
Ejemplo n.º 2
0
def sdm_build_benchmark(training_images, training_options=None, verbose=False):
    r"""
    Builds an SDM model.

    Parameters
    ----------
    training_images: list of :class:MaskedImage objects
        A list of the training images.
    training_options: dictionary, optional
        A dictionary with the parameters that will be passed in the AAMBuilder
        (:class:menpo.fitmultilevel.aam.AAMBuilder).
        If None, the default options will be used.
        This is an example of the dictionary with the default options:
            training_options = {'group': 'PTS',
                                'features': 'igo',
                                'transform': PiecewiseAffine,
                                'trilist': None,
                                'normalization_diagonal': None,
                                'n_levels': 3,
                                'downscale': 2,
                                'scaled_shape_models': True,
                                'max_shape_components': None,
                                'max_appearance_components': None,
                                'boundary': 3
                                }
        For an explanation of the options, please refer to the AAMBuilder
        documentation.

        Default: None
    verbose: boolean, optional
        If True, it prints information regarding the AAM training.

        Default: False

    Returns
    -------
    aam: :class:menpo.fitmultilevel.aam.AAM object
        The trained AAM model.
    """
    if verbose:
        print('SDM Training:')

    # parse options
    if training_options is None:
        training_options = {}

    # group option
    group = training_options.pop('group', None)

    # build sdm
    sdm = SDMTrainer(**training_options).train(training_images,
                                               group=group,
                                               verbose=verbose)
    return sdm
Ejemplo n.º 3
0
def train(img_generator):
    # clean up the images with the standard menpo pre-processing
    images = [menpo_img_process(img) for img in img_generator]
    fitter = SDMTrainer(normalization_diagonal=150,
                        downscale=1.1,
                        n_perturbations=15).train(images,
                                                  group='gt',
                                                  verbose=True)

    # return a callable that wraps the menpo fitter in order to integrate with
    # menpobench
    return MenpoFitWrapper(fitter)
Ejemplo n.º 4
0
def test_downscale_exception():
    sdm = SDMTrainer(downscale=0).train(training_images)
Ejemplo n.º 5
0
def test_n_levels_exception():
    sdm = SDMTrainer(n_levels=0).train(training_images)
Ejemplo n.º 6
0
def test_regression_features_sdmtrainer_exception_2():
    sdm = SDMTrainer(n_levels=3, regression_features=[no_op, sparse_hog, 1]).\
        train(training_images)
Ejemplo n.º 7
0
def test_regression_features_sdmtrainer_exception_1():
    sdm = SDMTrainer(n_levels=2, regression_features=[no_op, no_op, no_op]).\
        train(training_images)
Ejemplo n.º 8
0
def test_features_exception():
    sdm = SDMTrainer(features=[igo, sparse_hog],
                     n_levels=3).train(training_images)