Esempio n. 1
0
    def __init__(self, images, group=None, bounding_box_group_glob=None,
                 reference_shape=None, sd_algorithm_cls=Newton,
                 holistic_features=no_op, patch_features=no_op,
                 patch_shape=(17, 17), diagonal=None, scales=(0.5, 1.0),
                 n_iterations=6, n_perturbations=30,
                 perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
                 batch_size=None, verbose=False):
        # check parameters
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        patch_features = checks.check_features(patch_features, n_scales)
        holistic_features = checks.check_features(holistic_features, n_scales)
        patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        # set parameters
        self.algorithms = []
        self.reference_shape = reference_shape
        self._sd_algorithm_cls = sd_algorithm_cls
        self.holistic_features = holistic_features
        self.patch_features = patch_features
        self.patch_shape = patch_shape
        self.diagonal = diagonal
        self.scales = scales
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box
        # set up algorithms
        self._setup_algorithms()

        # Now, train the model!
        self._train(images,increment=False,  group=group,
                    bounding_box_group_glob=bounding_box_group_glob,
                    verbose=verbose, batch_size=batch_size)
Esempio n. 2
0
    def __init__(self, images, group=None, verbose=False, reference_shape=None,
                 holistic_features=no_op,
                 transform=DifferentiablePiecewiseAffine, diagonal=None,
                 scales=(0.5, 1.0), shape_model_cls=OrthoPDM,
                 max_shape_components=None, max_appearance_components=None,
                 batch_size=None):

        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        holistic_features = checks.check_callable(holistic_features, n_scales)
        shape_model_cls = checks.check_callable(shape_model_cls, n_scales)
        max_shape_components = checks.check_max_components(
            max_shape_components, n_scales, 'max_shape_components')
        max_appearance_components = checks.check_max_components(
            max_appearance_components, n_scales, 'max_appearance_components')

        self.holistic_features = holistic_features
        self.transform = transform
        self.diagonal = diagonal
        self.scales = scales
        self.max_shape_components = max_shape_components
        self.max_appearance_components = max_appearance_components
        self.reference_shape = reference_shape
        self._shape_model_cls = shape_model_cls
        self.shape_models = []
        self.appearance_models = []

        # Train AAM
        self._train(images, increment=False, group=group, verbose=verbose,
                    batch_size=batch_size)
Esempio n. 3
0
    def __init__(self, images, group=None, holistic_features=no_op,
                 reference_shape=None, diagonal=None, scales=(0.5, 1),
                 patch_shape=(17, 17), patch_normalisation=no_op,
                 context_shape=(34, 34), cosine_mask=True, sample_offsets=None,
                 shape_model_cls=OrthoPDM,
                 expert_ensemble_cls=CorrelationFilterExpertEnsemble,
                 max_shape_components=None, verbose=False, batch_size=None):
        self.scales = checks.check_scales(scales)
        n_scales = len(scales)
        self.diagonal = checks.check_diagonal(diagonal)
        self.holistic_features = checks.check_callable(holistic_features,
                                                       n_scales)
        self.expert_ensemble_cls = checks.check_callable(expert_ensemble_cls,
                                                         n_scales)
        self._shape_model_cls = checks.check_callable(shape_model_cls,
                                                      n_scales)
        self.max_shape_components = checks.check_max_components(
            max_shape_components, n_scales, 'max_shape_components')
        self.reference_shape = reference_shape
        self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        self.patch_normalisation = patch_normalisation
        self.context_shape = checks.check_patch_shape(context_shape, n_scales)
        self.cosine_mask = cosine_mask
        self.sample_offsets = sample_offsets
        self.shape_models = []
        self.expert_ensembles = []

        # Train CLM
        self._train(images, increment=False, group=group, verbose=verbose,
                    batch_size=batch_size)
Esempio n. 4
0
    def __init__(
        self,
        template,
        group=None,
        holistic_features=no_op,
        transform_cls=DifferentiableAlignmentAffine,
        diagonal=None,
        scales=(0.5, 1.0),
        algorithm_cls=InverseCompositional,
        residual_cls=SSD,
    ):

        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        holistic_features = checks.check_callable(holistic_features, len(scales))

        self.holistic_features = holistic_features
        self.transform_cls = transform_cls
        self.diagonal = diagonal
        self.scales = list(scales)
        # Make template masked for warping
        template = template.as_masked(copy=False)

        if self.diagonal:
            template = template.rescale_landmarks_to_diagonal_range(self.diagonal, group=group)
        self.reference_shape = template.landmarks[group].lms

        self.templates, self.sources = self._prepare_template(template, group=group)
        self._set_up(algorithm_cls, residual_cls)
Esempio n. 5
0
    def __init__(self, template, shapes, group=None, verbose=False,
                 reference_shape=None, holistic_features=no_op,
                 transform=DifferentiablePiecewiseAffine, diagonal=None,
                 scales=(0.5, 1.0), max_shape_components=None,
                 batch_size=None):

        checks.check_diagonal(diagonal)
        n_scales = len(scales)
        scales = checks.check_scales(scales)
        holistic_features = checks.check_features(holistic_features, n_scales)
        max_shape_components = checks.check_max_components(
            max_shape_components, n_scales, 'max_shape_components')

        self.holistic_features = holistic_features
        self.transform = transform
        self.diagonal = diagonal
        self.scales = scales
        self.max_shape_components = max_shape_components
        self.reference_shape = reference_shape
        self.shape_models = []
        self.warped_templates = []

        # Train ATM
        self._train(template, shapes, increment=False, group=group,
                    verbose=verbose, batch_size=batch_size)
Esempio n. 6
0
    def __init__(self, images, group=None, verbose=False, batch_size=None,
                 diagonal=None, scales=(0.5, 1), holistic_features=no_op,
                 # shape_model_cls=build_normalised_pca_shape_model,
                 expert_ensemble_cls=CorrelationFilterExpertEnsemble,
                 max_shape_components=None, reference_shape=None,
                 shape_forgetting_factor=1.0):
        self.diagonal = checks.check_diagonal(diagonal)
        self.scales = checks.check_scales(scales)
        self.holistic_features = checks.check_features(holistic_features,
                                                       self.n_scales)
        # self.shape_model_cls = checks.check_algorithm_cls(
        #     shape_model_cls, self.n_scales, ShapeModel)
        self.expert_ensemble_cls = checks.check_algorithm_cls(
            expert_ensemble_cls, self.n_scales, ExpertEnsemble)

        self.max_shape_components = checks.check_max_components(
            max_shape_components, self.n_scales, 'max_shape_components')
        self.shape_forgetting_factor = shape_forgetting_factor
        self.reference_shape = reference_shape
        self.shape_models = []
        self.expert_ensembles = []

        # Train CLM
        self._train(images, increment=False, group=group, verbose=verbose,
                    batch_size=batch_size)
Esempio n. 7
0
 def __init__(self, template, shapes, group=None, holistic_features=no_op,
              reference_shape=None, diagonal=None, scales=(0.5, 1.0),
              transform=DifferentiablePiecewiseAffine,
              shape_model_cls=OrthoPDM, max_shape_components=None,
              verbose=False, batch_size=None):
     # Check arguments
     checks.check_diagonal(diagonal)
     n_scales = len(scales)
     scales = checks.check_scales(scales)
     holistic_features = checks.check_callable(holistic_features, n_scales)
     max_shape_components = checks.check_max_components(
         max_shape_components, n_scales, 'max_shape_components')
     shape_model_cls = checks.check_callable(shape_model_cls, n_scales)
     # Assign attributes
     self.holistic_features = holistic_features
     self.transform = transform
     self.diagonal = diagonal
     self.scales = scales
     self.max_shape_components = max_shape_components
     self.reference_shape = reference_shape
     self.shape_models = []
     self.warped_templates = []
     self._shape_model_cls = shape_model_cls
     # Train ATM
     self._train(template, shapes, increment=False, group=group,
                 verbose=verbose, batch_size=batch_size)
Esempio n. 8
0
    def __init__(self, images, group=None, bounding_box_group_glob=None,
                 verbose=False, reference_shape=None, diagonal=None,
                 scales=(0.5, 1.0), n_perturbations=30, n_dlib_perturbations=1,
                 perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
                 n_iterations=10, feature_padding=0, n_pixel_pairs=400,
                 distance_prior_weighting=0.1, regularisation_weight=0.1,
                 n_split_tests=20, n_trees=500, n_tree_levels=5):

        checks.check_diagonal(diagonal)

        self.diagonal = diagonal
        self.scales = checks.check_scales(scales)
        self.holistic_features = checks.check_features(no_op, self.n_scales)
        self.reference_shape = reference_shape
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, self.n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box
        self._setup_dlib_options(feature_padding, n_pixel_pairs,
                                 distance_prior_weighting,
                                 regularisation_weight, n_split_tests, n_trees,
                                 n_dlib_perturbations, n_tree_levels)
        self._setup_algorithms()

        # Train DLIB over multiple scales
        self._train(images, group=group,
                    bounding_box_group_glob=bounding_box_group_glob,
                    verbose=verbose)
Esempio n. 9
0
    def __init__(self,
                 template,
                 group=None,
                 holistic_features=no_op,
                 transform_cls=DifferentiableAlignmentAffine,
                 diagonal=None,
                 scales=(0.5, 1.0),
                 algorithm_cls=InverseCompositional,
                 residual_cls=SSD):

        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        holistic_features = checks.check_callable(holistic_features,
                                                  len(scales))

        self.holistic_features = holistic_features
        self.transform_cls = transform_cls
        self.diagonal = diagonal
        self.scales = list(scales)
        # Make template masked for warping
        template = template.as_masked(copy=False)

        if self.diagonal:
            template = template.rescale_landmarks_to_diagonal_range(
                self.diagonal, group=group)
        self.reference_shape = template.landmarks[group].lms

        self.templates, self.sources = self._prepare_template(template,
                                                              group=group)
        self._set_up(algorithm_cls, residual_cls)
Esempio n. 10
0
    def __init__(self, images, group=None, verbose=False, batch_size=None,
                 diagonal=None, scales=(0.5, 1), holistic_features=no_op,
                 shape_model_cls=OrthoPDM,
                 expert_ensemble_cls=CorrelationFilterExpertEnsemble,
                 max_shape_components=None, reference_shape=None):
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        self.diagonal = checks.check_diagonal(diagonal)
        self.scales = scales
        self.holistic_features = checks.check_callable(holistic_features,
                                                       self.n_scales)
        self.expert_ensemble_cls = checks.check_algorithm_cls(
            expert_ensemble_cls, self.n_scales, ExpertEnsemble)
        shape_model_cls = checks.check_callable(shape_model_cls, n_scales)

        self.max_shape_components = checks.check_max_components(
            max_shape_components, self.n_scales, 'max_shape_components')
        self.reference_shape = reference_shape
        self.shape_models = []
        self._shape_model_cls = shape_model_cls
        self.expert_ensembles = []

        # Train CLM
        self._train(images, increment=False, group=group, verbose=verbose,
                    batch_size=batch_size)
Esempio n. 11
0
    def __init__(self,
                 images,
                 group=None,
                 verbose=False,
                 batch_size=None,
                 diagonal=None,
                 scales=(0.5, 1),
                 holistic_features=no_op,
                 shape_model_cls=OrthoPDM,
                 expert_ensemble_cls=CorrelationFilterExpertEnsemble,
                 max_shape_components=None,
                 reference_shape=None):
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        self.diagonal = checks.check_diagonal(diagonal)
        self.scales = scales
        self.holistic_features = checks.check_callable(holistic_features,
                                                       self.n_scales)
        self.expert_ensemble_cls = checks.check_algorithm_cls(
            expert_ensemble_cls, self.n_scales, ExpertEnsemble)
        shape_model_cls = checks.check_callable(shape_model_cls, n_scales)

        self.max_shape_components = checks.check_max_components(
            max_shape_components, self.n_scales, 'max_shape_components')
        self.reference_shape = reference_shape
        self.shape_models = []
        self._shape_model_cls = shape_model_cls
        self.expert_ensembles = []

        # Train CLM
        self._train(images,
                    increment=False,
                    group=group,
                    verbose=verbose,
                    batch_size=batch_size)
Esempio n. 12
0
    def __init__(self,
                 images,
                 group=None,
                 holistic_features=no_op,
                 reference_shape=None,
                 diagonal=None,
                 scales=(0.5, 1.0),
                 expert_ensemble_cls=CorrelationFilterExpertEnsemble,
                 patch_shape=(17, 17),
                 context_shape=(34, 34),
                 sample_offsets=None,
                 transform=DifferentiablePiecewiseAffine,
                 shape_model_cls=OrthoPDM,
                 max_shape_components=None,
                 max_appearance_components=None,
                 sigma=None,
                 boundary=3,
                 response_covariance=2,
                 patch_normalisation=no_op,
                 cosine_mask=True,
                 verbose=False):
        # Check parameters
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        holistic_features = checks.check_callable(holistic_features, n_scales)
        shape_model_cls = checks.check_callable(shape_model_cls, n_scales)
        max_shape_components = checks.check_max_components(
            max_shape_components, n_scales, 'max_shape_components')
        max_appearance_components = checks.check_max_components(
            max_appearance_components, n_scales, 'max_appearance_components')
        # Assign attributes
        self.expert_ensemble_cls = checks.check_callable(
            expert_ensemble_cls, n_scales)
        self.expert_ensembles = []
        self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        self.context_shape = checks.check_patch_shape(context_shape, n_scales)
        self.holistic_features = holistic_features
        self.transform = transform
        self.diagonal = diagonal
        self.scales = scales
        self.max_shape_components = max_shape_components
        self.max_appearance_components = max_appearance_components
        self.reference_shape = reference_shape
        self.shape_model_cls = shape_model_cls
        self.sigma = sigma
        self.boundary = boundary
        self.sample_offsets = sample_offsets
        self.response_covariance = response_covariance
        self.patch_normalisation = patch_normalisation
        self.cosine_mask = cosine_mask
        self.shape_models = []
        self.appearance_models = []
        self.expert_ensembles = []

        self._train(images=images, group=group, verbose=verbose)
    def __init__(self,
                 images,
                 group=None,
                 bounding_box_group_glob=None,
                 reference_shape=None,
                 diagonal=None,
                 scales=(0.5, 1.0),
                 n_perturbations=30,
                 n_dlib_perturbations=1,
                 perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
                 n_iterations=10,
                 feature_padding=0,
                 n_pixel_pairs=400,
                 distance_prior_weighting=0.1,
                 regularisation_weight=0.1,
                 n_split_tests=20,
                 n_trees=500,
                 n_tree_levels=5,
                 verbose=False):
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        # Dummy option that is required by _prepare_image of MultiFitter.
        holistic_features = checks.check_callable(no_op, n_scales)

        # Call superclass
        super(DlibERT, self).__init__(scales=scales,
                                      reference_shape=reference_shape,
                                      holistic_features=holistic_features,
                                      algorithms=[])

        # Set parameters
        self.diagonal = diagonal
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box

        # DLib options
        self._setup_dlib_options(feature_padding, n_pixel_pairs,
                                 distance_prior_weighting,
                                 regularisation_weight, n_split_tests, n_trees,
                                 n_dlib_perturbations, n_tree_levels)

        # Set-up algorithms
        for j in range(self.n_scales):
            self.algorithms.append(
                DlibAlgorithm(self._dlib_options_templates[j],
                              n_iterations=self.n_iterations[j]))

        # Train DLIB over multiple scales
        self._train(images,
                    group=group,
                    bounding_box_group_glob=bounding_box_group_glob,
                    verbose=verbose)
Esempio n. 14
0
    def __init__(
        self,
        images,
        group=None,
        bounding_box_group_glob=None,
        reference_shape=None,
        sd_algorithm_cls=None,
        holistic_features=no_op,
        patch_features=no_op,
        patch_shape=(17, 17),
        diagonal=None,
        scales=(0.5, 1.0),
        n_iterations=3,
        n_perturbations=30,
        perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
        batch_size=None,
        verbose=False,
    ):

        if batch_size is not None:
            raise NotImplementedError("Training an SDM with a batch size " "(incrementally) is not implemented yet.")
        # check parameters
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        patch_features = checks.check_callable(patch_features, n_scales)
        sd_algorithm_cls = checks.check_callable(sd_algorithm_cls, n_scales)
        holistic_features = checks.check_callable(holistic_features, n_scales)
        patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        # set parameters
        self.algorithms = []
        self.reference_shape = reference_shape
        self._sd_algorithm_cls = sd_algorithm_cls
        self.holistic_features = holistic_features
        self.patch_features = patch_features
        self.patch_shape = patch_shape
        self.diagonal = diagonal
        self.scales = scales
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box
        # set up algorithms
        self._setup_algorithms()

        # Now, train the model!
        self._train(
            images,
            increment=False,
            group=group,
            bounding_box_group_glob=bounding_box_group_glob,
            verbose=verbose,
            batch_size=batch_size,
        )
Esempio n. 15
0
    def __init__(self, images, group=None, appearance_graph=None,
                 shape_graph=None, deformation_graph=None,
                 holistic_features=no_op, reference_shape=None, diagonal=None,
                 scales=(0.5, 1.0), patch_shape=(17, 17),
                 patch_normalisation=no_op, use_procrustes=True,
                 precision_dtype=np.float32, max_shape_components=None,
                 n_appearance_components=None, can_be_incremented=False,
                 verbose=False, batch_size=None):
        # Check parameters
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        holistic_features = checks.check_callable(holistic_features, n_scales)
        patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        patch_normalisation = checks.check_callable(patch_normalisation,
                                                    n_scales)
        max_shape_components = checks.check_max_components(
            max_shape_components, n_scales, 'max_shape_components')
        n_appearance_components = checks.check_max_components(
            n_appearance_components, n_scales, 'n_appearance_components')

        # Assign attributes
        self.diagonal = diagonal
        self.scales = scales
        self.holistic_features = holistic_features
        self.patch_shape = patch_shape
        self.patch_normalisation = patch_normalisation
        self.reference_shape = reference_shape
        self.use_procrustes = use_procrustes
        self.is_incremental = can_be_incremented
        self.precision_dtype = precision_dtype
        self.max_shape_components = max_shape_components
        self.n_appearance_components = n_appearance_components

        # Check provided graphs
        self.appearance_graph = checks.check_graph(
            appearance_graph, UndirectedGraph, 'appearance_graph', n_scales)
        self.shape_graph = checks.check_graph(shape_graph, UndirectedGraph,
                                              'shape_graph', n_scales)
        self.deformation_graph = checks.check_graph(
            deformation_graph, [DirectedGraph, Tree], 'deformation_graph',
            n_scales)

        # Initialize models' lists
        self.shape_models = []
        self.appearance_models = []
        self.deformation_models = []

        # Train APS
        self._train(images, increment=False, group=group, batch_size=batch_size,
                    verbose=verbose)
Esempio n. 16
0
    def __init__(self,
                 images,
                 group=None,
                 bounding_box_group_glob=None,
                 reference_shape=None,
                 sd_algorithm_cls=None,
                 holistic_features=no_op,
                 patch_features=no_op,
                 patch_shape=(17, 17),
                 diagonal=None,
                 scales=(0.5, 1.0),
                 n_iterations=3,
                 n_perturbations=30,
                 perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
                 batch_size=None,
                 verbose=False):

        if batch_size is not None:
            raise NotImplementedError(
                'Training an SDM with a batch size '
                '(incrementally) is not implemented yet.')
        # check parameters
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        patch_features = checks.check_callable(patch_features, n_scales)
        sd_algorithm_cls = checks.check_callable(sd_algorithm_cls, n_scales)
        holistic_features = checks.check_callable(holistic_features, n_scales)
        patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        # set parameters
        self.algorithms = []
        self.reference_shape = reference_shape
        self._sd_algorithm_cls = sd_algorithm_cls
        self.holistic_features = holistic_features
        self.patch_features = patch_features
        self.patch_shape = patch_shape
        self.diagonal = diagonal
        self.scales = scales
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box
        # set up algorithms
        self._setup_algorithms()

        # Now, train the model!
        self._train(images,
                    increment=False,
                    group=group,
                    bounding_box_group_glob=bounding_box_group_glob,
                    verbose=verbose,
                    batch_size=batch_size)
Esempio n. 17
0
    def __init__(self, images, group=None, verbose=False, reference_shape=None,
                 holistic_features=no_op, diagonal=None, scales=(0.5, 1.0),
                 patch_shape=(17, 17), max_shape_components=None,
                 max_appearance_components=None, batch_size=None):
        n_scales = len(checks.check_scales(scales))
        self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)

        super(LinearMaskedAAM, self).__init__(
            images, group=group, verbose=verbose,
            reference_shape=reference_shape,
            holistic_features=holistic_features,
            transform=DifferentiableThinPlateSplines, diagonal=diagonal,
            scales=scales,  max_shape_components=max_shape_components,
            max_appearance_components=max_appearance_components,
            batch_size=batch_size)
Esempio n. 18
0
    def __init__(self, images, group=None, verbose=False, reference_shape=None,
                 holistic_features=no_op, diagonal=None, scales=(0.5, 1.0),
                 patch_shape=(17, 17), max_shape_components=None,
                 max_appearance_components=None,
                 shape_model_cls=OrthoPDM, batch_size=None):
        n_scales = len(checks.check_scales(scales))
        self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)

        super(LinearMaskedAAM, self).__init__(
            images, group=group, verbose=verbose,
            reference_shape=reference_shape,
            holistic_features=holistic_features,
            transform=DifferentiableThinPlateSplines, diagonal=diagonal,
            scales=scales,  max_shape_components=max_shape_components,
            max_appearance_components=max_appearance_components,
            shape_model_cls=shape_model_cls, batch_size=batch_size)
Esempio n. 19
0
    def __init__(self, images, group=None, verbose=False, reference_shape=None,
                 holistic_features=no_op, patch_normalisation=no_op,
                 diagonal=None, scales=(0.5, 1.0), patch_shape=(17, 17),
                 max_shape_components=None, max_appearance_components=None,
                 batch_size=None):
        n_scales = len(checks.check_scales(scales))
        self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        self.patch_normalisation = patch_normalisation

        super(PatchAAM, self).__init__(
            images, group=group, verbose=verbose,
            reference_shape=reference_shape,
            holistic_features=holistic_features, transform=None,
            diagonal=diagonal, scales=scales,
            max_shape_components=max_shape_components,
            max_appearance_components=max_appearance_components,
            batch_size=batch_size)
    def __init__(
            self,
            images,
            group=None,
            holistic_features=no_op,
            reference_shape=None,
            diagonal=None,
            scales=(1, ),  # scales=(0.5, 1)
            patch_shape=(8, 8),
            patch_normalisation=no_op,
            context_shape=(8, 8),
            cosine_mask=True,
            sample_offsets=None,
            shape_model_cls=OrthoPDM,
            expert_ensemble_cls=CorrelationFilterExpertEnsemble,
            max_shape_components=None,
            verbose=False,
            batch_size=None):
        self.scales = checks.check_scales(scales)
        n_scales = len(scales)
        self.diagonal = checks.check_diagonal(diagonal)
        self.holistic_features = checks.check_callable(holistic_features,
                                                       n_scales)
        self.expert_ensemble_cls = checks.check_callable(
            expert_ensemble_cls, n_scales)
        self._shape_model_cls = checks.check_callable(shape_model_cls,
                                                      n_scales)
        self.max_shape_components = checks.check_max_components(
            max_shape_components, n_scales, 'max_shape_components')
        self.reference_shape = reference_shape
        self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)
        self.patch_normalisation = patch_normalisation
        self.context_shape = checks.check_patch_shape(context_shape, n_scales)
        self.cosine_mask = cosine_mask
        self.sample_offsets = sample_offsets
        self.shape_models = []
        self.expert_ensembles = []

        # Train CLM
        self._train(images,
                    increment=False,
                    group=group,
                    verbose=verbose,
                    batch_size=batch_size)
Esempio n. 21
0
 def __init__(self, images, group=None, holistic_features=no_op,
              reference_shape=None, diagonal=None, scales=(0.5, 1.0),
              expert_ensemble_cls=CorrelationFilterExpertEnsemble,
              patch_shape=(17, 17), context_shape=(34, 34),
              sample_offsets=None,  transform=DifferentiablePiecewiseAffine,
              shape_model_cls=OrthoPDM, max_shape_components=None,
              max_appearance_components=None, sigma=None, boundary=3,
              response_covariance=2, patch_normalisation=no_op,
              cosine_mask=True, verbose=False):
     # Check parameters
     checks.check_diagonal(diagonal)
     scales = checks.check_scales(scales)
     n_scales = len(scales)
     holistic_features = checks.check_callable(holistic_features, n_scales)
     shape_model_cls = checks.check_callable(shape_model_cls, n_scales)
     max_shape_components = checks.check_max_components(
         max_shape_components, n_scales, 'max_shape_components')
     max_appearance_components = checks.check_max_components(
         max_appearance_components, n_scales, 'max_appearance_components')
     # Assign attributes
     self.expert_ensemble_cls = checks.check_callable(expert_ensemble_cls,
                                                      n_scales)
     self.expert_ensembles = []
     self.patch_shape = checks.check_patch_shape(patch_shape, n_scales)
     self.context_shape = checks.check_patch_shape(context_shape, n_scales)
     self.holistic_features = holistic_features
     self.transform = transform
     self.diagonal = diagonal
     self.scales = scales
     self.max_shape_components = max_shape_components
     self.max_appearance_components = max_appearance_components
     self.reference_shape = reference_shape
     self.shape_model_cls = shape_model_cls
     self.sigma = sigma
     self.boundary = boundary
     self.sample_offsets = sample_offsets
     self.response_covariance = response_covariance
     self.patch_normalisation = patch_normalisation
     self.cosine_mask = cosine_mask
     self.shape_models = []
     self.appearance_models = []
     self.expert_ensembles = []
     
     self._train(images=images, group=group, verbose=verbose)
Esempio n. 22
0
    def __init__(self,
                 template,
                 group=None,
                 holistic_features=no_op,
                 diagonal=None,
                 transform=DifferentiableAlignmentAffine,
                 scales=(0.5, 1.0),
                 algorithm_cls=InverseCompositional,
                 residual_cls=SSD):
        # Check arguments
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        holistic_features = checks.check_callable(holistic_features,
                                                  len(scales))
        # Assign attributes
        self.transform_cls = transform
        self.diagonal = diagonal

        # Make template masked for warping
        template = template.as_masked(copy=False)

        # Get reference shape
        if self.diagonal:
            template = template.rescale_landmarks_to_diagonal_range(
                self.diagonal, group=group)
        reference_shape = template.landmarks[group]

        # Call superclass
        super(LucasKanadeFitter,
              self).__init__(scales=list(scales),
                             reference_shape=reference_shape,
                             holistic_features=holistic_features,
                             algorithms=[])

        # Create templates
        self.templates, self.sources = self._prepare_template(template,
                                                              group=group)

        # Get list of algorithm objects per scale
        self.algorithms = []
        for j, (t, s) in enumerate(zip(self.templates, self.sources)):
            transform = self.transform_cls(s, s)
            residual = residual_cls()
            self.algorithms.append(algorithm_cls(t, transform, residual))
Esempio n. 23
0
    def __init__(self,
                 images,
                 group=None,
                 bounding_box_group_glob=None,
                 verbose=False,
                 reference_shape=None,
                 diagonal=None,
                 scales=(0.5, 1.0),
                 n_perturbations=30,
                 n_dlib_perturbations=1,
                 perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
                 n_iterations=10,
                 feature_padding=0,
                 n_pixel_pairs=400,
                 distance_prior_weighting=0.1,
                 regularisation_weight=0.1,
                 n_split_tests=20,
                 n_trees=500,
                 n_tree_levels=5):

        checks.check_diagonal(diagonal)

        self.diagonal = diagonal
        self.scales = checks.check_scales(scales)
        self.holistic_features = checks.check_callable(no_op, self.n_scales)
        self.reference_shape = reference_shape
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, self.n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box
        self._setup_dlib_options(feature_padding, n_pixel_pairs,
                                 distance_prior_weighting,
                                 regularisation_weight, n_split_tests, n_trees,
                                 n_dlib_perturbations, n_tree_levels)
        self._setup_algorithms()

        # Train DLIB over multiple scales
        self._train(images,
                    group=group,
                    bounding_box_group_glob=bounding_box_group_glob,
                    verbose=verbose)
Esempio n. 24
0
    def __init__(self, images, group=None, bounding_box_group_glob=None,
                 reference_shape=None, diagonal=None, scales=(0.5, 1.0),
                 n_perturbations=30, n_dlib_perturbations=1,
                 perturb_from_gt_bounding_box=noisy_shape_from_bounding_box,
                 n_iterations=10, feature_padding=0, n_pixel_pairs=400,
                 distance_prior_weighting=0.1, regularisation_weight=0.1,
                 n_split_tests=20, n_trees=500, n_tree_levels=5, verbose=False):
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        n_scales = len(scales)
        # Dummy option that is required by _prepare_image of MultiFitter.
        holistic_features = checks.check_callable(no_op, n_scales)

        # Call superclass
        super(DlibERT, self).__init__(
            scales=scales, reference_shape=reference_shape,
            holistic_features=holistic_features, algorithms=[])

        # Set parameters
        self.diagonal = diagonal
        self.n_perturbations = n_perturbations
        self.n_iterations = checks.check_max_iters(n_iterations, n_scales)
        self._perturb_from_gt_bounding_box = perturb_from_gt_bounding_box

        # DLib options
        self._setup_dlib_options(feature_padding, n_pixel_pairs,
                                 distance_prior_weighting,
                                 regularisation_weight, n_split_tests, n_trees,
                                 n_dlib_perturbations, n_tree_levels)

        # Set-up algorithms
        for j in range(self.n_scales):
            self.algorithms.append(DlibAlgorithm(
                self._dlib_options_templates[j],
                n_iterations=self.n_iterations[j]))

        # Train DLIB over multiple scales
        self._train(images, group=group,
                    bounding_box_group_glob=bounding_box_group_glob,
                    verbose=verbose)
Esempio n. 25
0
    def __init__(self, template, group=None, holistic_features=no_op,
                 diagonal=None, transform=DifferentiableAlignmentAffine,
                 scales=(0.5, 1.0), algorithm_cls=InverseCompositional,
                 residual_cls=SSD):
        # Check arguments
        checks.check_diagonal(diagonal)
        scales = checks.check_scales(scales)
        holistic_features = checks.check_callable(holistic_features,
                                                  len(scales))
        # Assign attributes
        self.transform_cls = transform
        self.diagonal = diagonal

        # Make template masked for warping
        template = template.as_masked(copy=False)

        # Get reference shape
        if self.diagonal:
            template = template.rescale_landmarks_to_diagonal_range(
                self.diagonal, group=group)
        reference_shape = template.landmarks[group]

        # Call superclass
        super(LucasKanadeFitter, self).__init__(
            scales=list(scales), reference_shape=reference_shape,
            holistic_features=holistic_features, algorithms=[])

        # Create templates
        self.templates, self.sources = self._prepare_template(template,
                                                              group=group)

        # Get list of algorithm objects per scale
        self.algorithms = []
        for j, (t, s) in enumerate(zip(self.templates, self.sources)):
            transform = self.transform_cls(s, s)
            residual = residual_cls()
            self.algorithms.append(algorithm_cls(t, transform, residual))