def __init__(self, data, **kwargs): from menpofit.transform import DifferentiableAlignmentSimilarity aligned_shapes = align_shapes(data) self.mean = mean_pointcloud(aligned_shapes) # Default target is the mean self._target = self.mean self.transform = DifferentiableAlignmentSimilarity( self.target, self.target)
def __init__(self, data, **kwargs): from menpofit.transform import DifferentiableAlignmentSimilarity aligned_shapes = align_shapes(data) self.mean = mean_pointcloud(aligned_shapes) # Default target is the mean self._target = self.mean self.transform = DifferentiableAlignmentSimilarity(self.target, self.target)
class GlobalSimilarityModel(Targetable, Vectorizable): r""" Class for creating a model that represents a global similarity transform (in-plane rotation, scaling, translation). Parameters ---------- data : `list` of `menpo.shape.PointCloud` The `list` of shapes to use as training data. """ def __init__(self, data, **kwargs): from menpofit.transform import DifferentiableAlignmentSimilarity aligned_shapes = align_shapes(data) self.mean = mean_pointcloud(aligned_shapes) # Default target is the mean self._target = self.mean self.transform = DifferentiableAlignmentSimilarity( self.target, self.target) @property def n_weights(self): r""" The number of parameters in the linear model. :type: `int` """ return 4 @property def weights(self): r""" The weights of the model. :type: ``(n_weights,)`` `ndarray` """ return self.transform.as_vector() @property def target(self): r""" The current `menpo.shape.PointCloud` that this object produces. :type: `menpo.shape.PointCloud` """ return self._target def set_target(self, new_target): r""" Update this object so that it attempts to recreate the ``new_target``. Parameters ---------- new_target : `menpo.shape.PointCloud` The new target that this object should try and regenerate. """ self.transform.set_target(new_target) self._target = self.transform.apply(self.mean) return self def _as_vector(self): r""" Return the current parameters of this transform - this is the just the linear model's weights Returns ------- params : (`n_parameters`,) ndarray The vector of parameters """ return self.transform.as_vector() def _from_vector_inplace(self, vector): self.transform._from_vector_inplace(vector) self._target = self.transform.apply(self.mean) @property def n_dims(self): r""" The number of dimensions of the spatial instance of the model. :type: `int` """ return self.mean.n_dims def d_dp(self, _): r""" Returns the Jacobian of the similarity model reshaped in order to have the standard Jacobian shape, i.e. ``(n_points, n_weights, n_dims)`` which maps to ``(n_features, n_components, n_dims)`` on the linear model. Returns ------- jacobian : ``(n_features, n_components, n_dims)`` `ndarray` The Jacobian of the model in the standard Jacobian shape. """ # Always evaluated at the mean shape return self.transform.d_dp(self.mean.points)
class GlobalSimilarityModel(Targetable, Vectorizable): def __init__(self, data, **kwargs): from menpofit.transform import DifferentiableAlignmentSimilarity aligned_shapes = align_shapes(data) self.mean = mean_pointcloud(aligned_shapes) # Default target is the mean self._target = self.mean self.transform = DifferentiableAlignmentSimilarity( self.target, self.target) @property def n_weights(self): r""" The number of parameters in the linear model. :type: int """ return 4 @property def weights(self): r""" In this simple :map:`ModelInstance` the weights are just the weights of the model. """ return self.transform.as_vector() @property def target(self): return self._target def set_target(self, new_target): self.transform.set_target(new_target) self._target = self.transform.apply(self.mean) return self def _as_vector(self): r""" Return the current parameters of this transform - this is the just the linear model's weights Returns ------- params : (`n_parameters`,) ndarray The vector of parameters """ return self.transform.as_vector() def _from_vector_inplace(self, vector): self.transform._from_vector_inplace(vector) self._target = self.transform.apply(self.mean) @property def n_dims(self): r""" The number of dimensions of the spatial instance of the model :type: int """ return self.mean.n_dims def d_dp(self, _): """ Returns the Jacobian of the similarity model reshaped to have the standard Jacobian shape: n_points x n_params x n_dims which maps to n_features x n_components x n_dims on the linear model Returns ------- jacobian : (n_features, n_components, n_dims) ndarray The Jacobian of the model in the standard Jacobian shape. """ # Always evaluated at the mean shape return self.transform.d_dp(self.mean.points)
class GlobalSimilarityModel(Targetable, Vectorizable): def __init__(self, data, **kwargs): from menpofit.transform import DifferentiableAlignmentSimilarity aligned_shapes = align_shapes(data) self.mean = mean_pointcloud(aligned_shapes) # Default target is the mean self._target = self.mean self.transform = DifferentiableAlignmentSimilarity(self.target, self.target) @property def n_weights(self): r""" The number of parameters in the linear model. :type: int """ return 4 @property def weights(self): r""" In this simple :map:`ModelInstance` the weights are just the weights of the model. """ return self.transform.as_vector() @property def target(self): return self._target def set_target(self, new_target): self.transform.set_target(new_target) self._target = self.transform.apply(self.mean) return self def _as_vector(self): r""" Return the current parameters of this transform - this is the just the linear model's weights Returns ------- params : (`n_parameters`,) ndarray The vector of parameters """ return self.transform.as_vector() def _from_vector_inplace(self, vector): self.transform._from_vector_inplace(vector) self._target = self.transform.apply(self.mean) @property def n_dims(self): r""" The number of dimensions of the spatial instance of the model :type: int """ return self.mean.n_dims def d_dp(self, _): """ Returns the Jacobian of the similarity model reshaped to have the standard Jacobian shape: n_points x n_params x n_dims which maps to n_features x n_components x n_dims on the linear model Returns ------- jacobian : (n_features, n_components, n_dims) ndarray The Jacobian of the model in the standard Jacobian shape. """ # Always evaluated at the mean shape return self.transform.d_dp(self.mean.points)
class GlobalSimilarityModel(Targetable, Vectorizable): r""" Class for creating a model that represents a global similarity transform (in-plane rotation, scaling, translation). Parameters ---------- data : `list` of `menpo.shape.PointCloud` The `list` of shapes to use as training data. """ def __init__(self, data, **kwargs): from menpofit.transform import DifferentiableAlignmentSimilarity aligned_shapes = align_shapes(data) self.mean = mean_pointcloud(aligned_shapes) # Default target is the mean self._target = self.mean self.transform = DifferentiableAlignmentSimilarity(self.target, self.target) @property def n_weights(self): r""" The number of parameters in the linear model. :type: `int` """ return 4 @property def weights(self): r""" The weights of the model. :type: ``(n_weights,)`` `ndarray` """ return self.transform.as_vector() @property def target(self): r""" The current `menpo.shape.PointCloud` that this object produces. :type: `menpo.shape.PointCloud` """ return self._target def set_target(self, new_target): r""" Update this object so that it attempts to recreate the ``new_target``. Parameters ---------- new_target : `menpo.shape.PointCloud` The new target that this object should try and regenerate. """ self.transform.set_target(new_target) self._target = self.transform.apply(self.mean) return self def _as_vector(self): r""" Return the current parameters of this transform - this is the just the linear model's weights Returns ------- params : (`n_parameters`,) ndarray The vector of parameters """ return self.transform.as_vector() def _from_vector_inplace(self, vector): self.transform._from_vector_inplace(vector) self._target = self.transform.apply(self.mean) @property def n_dims(self): r""" The number of dimensions of the spatial instance of the model. :type: `int` """ return self.mean.n_dims def d_dp(self, _): r""" Returns the Jacobian of the similarity model reshaped in order to have the standard Jacobian shape, i.e. ``(n_points, n_weights, n_dims)`` which maps to ``(n_features, n_components, n_dims)`` on the linear model. Returns ------- jacobian : ``(n_features, n_components, n_dims)`` `ndarray` The Jacobian of the model in the standard Jacobian shape. """ # Always evaluated at the mean shape return self.transform.d_dp(self.mean.points)