コード例 #1
0
ファイル: base.py プロジェクト: jabooth/menpofit
    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)
コード例 #2
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)
コード例 #3
0
ファイル: base.py プロジェクト: lydonchandra/menpofit
    def __init__(
        self,
        template,
        shapes,
        group=None,
        verbose=False,
        holistic_features=no_op,
        patch_normalisation=no_op,
        diagonal=None,
        scales=(0.5, 1.0),
        patch_shape=(17, 17),
        max_shape_components=None,
        batch_size=None,
    ):
        self.patch_shape = checks.check_patch_shape(patch_shape, len(scales))
        self.patch_normalisation = patch_normalisation

        super(PatchATM, self).__init__(
            template,
            shapes,
            group=group,
            verbose=verbose,
            holistic_features=holistic_features,
            transform=DifferentiableThinPlateSplines,
            diagonal=diagonal,
            scales=scales,
            max_shape_components=max_shape_components,
            batch_size=batch_size,
        )
コード例 #4
0
ファイル: fitter.py プロジェクト: HaoyangWang/menpofit
    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)
コード例 #5
0
ファイル: base.py プロジェクト: jabooth/menpofit
 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)
コード例 #6
0
    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)
コード例 #7
0
ファイル: fitter.py プロジェクト: lydonchandra/menpofit
    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,
        )
コード例 #8
0
ファイル: fitter.py プロジェクト: lydonchandra/menpofit
    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)
コード例 #9
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)
コード例 #10
0
ファイル: base.py プロジェクト: zk496007331/menpofit
 def __init__(self, template, shapes, group=None, holistic_features=no_op,
              reference_shape=None, diagonal=None, scales=(0.5, 1.0),
              patch_shape=(17, 17), max_shape_components=None,
              verbose=False, batch_size=None):
     # Check arguments
     self.patch_shape = checks.check_patch_shape(patch_shape, len(scales))
     # Call superclass
     super(LinearMaskedATM, self).__init__(
             template, shapes, group=group,
             holistic_features=holistic_features,
             reference_shape=reference_shape, diagonal=diagonal,
             scales=scales, transform=DifferentiableThinPlateSplines,
             max_shape_components=max_shape_components, verbose=verbose,
             batch_size=batch_size)
コード例 #11
0
ファイル: base.py プロジェクト: HaoyangWang/menpofit
    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)
コード例 #12
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)
コード例 #13
0
ファイル: base.py プロジェクト: HaoyangWang/menpofit
    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)