def aam_build_benchmark(training_images, training_options=None, verbose=False): r""" Builds an AAM 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', 'feature_type': 'igo', 'transform': PiecewiseAffine, 'trilist': None, 'normalization_diagonal': None, 'n_levels': 3, 'downscale': 2, 'scaled_shape_models': True, 'pyramid_on_features': True, 'max_shape_components': None, 'max_appearance_components': None, 'boundary': 3, 'interpolator': 'scipy' } 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('AAM Training:') # parse options if training_options is None: training_options = {} # group option group = training_options.pop('group', None) # trilist option trilist = training_options.pop('trilist', None) if trilist is not None: labeller(training_images[0], 'PTS', trilist) training_options['trilist'] = \ training_images[0].landmarks[trilist.__name__].lms.trilist # build aam aam = AAMBuilder(**training_options).build(training_images, group=group, verbose=verbose) return aam
normalization_diagonal=150, n_levels=2, downscale=1.3, pyramid_on_features=True, noise_std=0.04, rotation=False, n_perturbations=2, interpolator='scipy').train(training_images, group='PTS') aam = AAMBuilder( feature_type=sparse_hog, transform=PiecewiseAffine, trilist=training_images[0].landmarks['ibug_68_trimesh'].lms.trilist, normalization_diagonal=150, n_levels=3, downscale=1.2, scaled_shape_models=False, pyramid_on_features=True, max_shape_components=None, max_appearance_components=3, boundary=3, interpolator='scipy').build(training_images, group='PTS') sdm2 = SDAAMTrainer(aam, regression_type=mlr, regression_features=weights, noise_std=0.04, rotation=False, n_perturbations=1, update='compositional', md_transform=OrthoMDTransform,
def test_n_levels_exception(): aam = AAMBuilder(n_levels=0).build(training_images, group='PTS')
def test_downscale_exception(): aam = AAMBuilder(downscale=1).build(training_images, group='PTS') assert (aam.downscale == 1) aam = AAMBuilder(downscale=0).build(training_images, group='PTS')
def test_verbose_mock(mock_stdout): aam = AAMBuilder().build(training_images, group='PTS', verbose=True)
def test_feature_type_with_pyramid_on_features_exception(): aam = AAMBuilder(feature_type=['igo', sparse_hog]).build(training_images, group='PTS')
def test_boundary_exception(): aam = AAMBuilder(boundary=-1).build(training_images, group='PTS')
def test_max_appearance_components_exception(): aam = AAMBuilder(max_appearance_components=[1, 2]).build(training_images, group='PTS')
def test_max_shape_components_exception(): aam = AAMBuilder(max_shape_components=[1, 0.2, 'a']).build(training_images, group='PTS')
def test_normalization_diagonal_exception(): aam = AAMBuilder(normalization_diagonal=100).build(training_images, group='PTS') assert (aam.appearance_models[0].n_features == 410) aam = AAMBuilder(normalization_diagonal=10).build(training_images, group='PTS')
for i in range(4): im = mio.import_builtin_asset(filenames[i]) im.crop_to_landmarks_proportion_inplace(0.1) labeller(im, 'PTS', ibug_68_trimesh) if im.n_channels == 3: im = im.as_greyscale(mode='luminosity') training_images.append(im) # build aams aam1 = AAMBuilder( feature_type=['igo', sparse_hog, None], transform=PiecewiseAffine, trilist=training_images[0].landmarks['ibug_68_trimesh'].lms.trilist, normalization_diagonal=150, n_levels=3, downscale=2, scaled_shape_models=False, pyramid_on_features=False, max_shape_components=[1, 2, 3], max_appearance_components=[3, 3, 3], boundary=3, interpolator='scipy').build(training_images, group='PTS') aam2 = AAMBuilder(feature_type=None, transform=ThinPlateSplines, trilist=None, normalization_diagonal=None, n_levels=2, downscale=1.2, scaled_shape_models=True, pyramid_on_features=False,