dacapo.experiments.tasks.predictors.distance_predictor ====================================================== .. py:module:: dacapo.experiments.tasks.predictors.distance_predictor Attributes ---------- .. autoapisummary:: dacapo.experiments.tasks.predictors.distance_predictor.logger Classes ------- .. autoapisummary:: dacapo.experiments.tasks.predictors.distance_predictor.DistancePredictor Module Contents --------------- .. py:data:: logger .. py:class:: DistancePredictor(channels: List[str], scale_factor: float, mask_distances: bool, clipmin: float = 0.05, clipmax: float = 0.95) Predict signed distances for a binary segmentation task. Distances deep within background are pushed to -inf, distances deep within the foreground object are pushed to inf. After distances have been calculated they are passed through a tanh so that distances saturate at +-1. Multiple classes can be predicted via multiple distance channels. The names of each class that is being segmented can be passed in as a list of strings in the channels argument. .. attribute:: channels The list of class labels. :type: List[str] .. attribute:: scale_factor The scale factor for the distance transform. :type: float .. attribute:: mask_distances Whether to mask distances. :type: bool .. attribute:: clipmin The minimum value to clip the weights to. :type: float .. attribute:: clipmax The maximum value to clip the weights to. :type: float .. method:: __init__(self, channels List[str], scale_factor: float, mask_distances: bool, clipmin: float = 0.05, clipmax: float = 0.95): Initializes the DistancePredictor. .. method:: create_model(self, architecture) Create the model for the predictor. .. method:: create_target(self, gt) Create the target array for training. .. method:: create_weight(self, gt, target, mask, moving_class_counts=None) Create the weight array for training. .. method:: output_array_type Get the output array type. .. method:: create_distance_mask(self, distances, mask, voxel_size, normalize=None, normalize_args=None) Create the distance mask. .. method:: process(self, labels, voxel_size, normalize=None, normalize_args=None) Process the labels array. .. method:: gt_region_for_roi(self, target_spec) Get the ground-truth region for the ROI. .. method:: padding(self, gt_voxel_size Coordinate) -> Coordinate: Get the padding needed for the ground-truth array. .. rubric:: Notes The DistancePredictor is used to predict signed distances for a binary segmentation task. The distances are calculated using the distance_transform_edt function from scipy.ndimage.morphology. The distances are then passed through a tanh function to saturate the distances at +-1. The distances are calculated for each class that is being segmented and are stored in separate channels. The names of each class that is being segmented can be passed in as a list of strings in the channels argument. The scale_factor argument is used to scale the distances. The mask_distances argument is used to determine whether to mask distances. The clipmin argument is used to determine the minimum value to clip the weights to. The clipmax argument is used to determine the maximum value to clip the weights to. .. py:attribute:: channels .. py:attribute:: norm :value: 'tanh' .. py:attribute:: dt_scale_factor .. py:attribute:: mask_distances .. py:attribute:: max_distance .. py:attribute:: epsilon :value: 0.05 .. py:attribute:: threshold :value: 0.8 .. py:attribute:: clipmin .. py:attribute:: clipmax .. py:property:: embedding_dims Get the number of embedding dimensions. :returns: The number of embedding dimensions. :rtype: int :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> embedding_dims = predictor.embedding_dims .. py:method:: create_model(architecture) Create the model for the predictor. :param architecture: The architecture for the model. :returns: The created model. :rtype: Model :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> model = predictor.create_model(architecture) .. py:method:: create_target(gt) Create the target array for training. :param gt: The ground-truth array. :returns: The created target array. :rtype: NumpyArray :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.create_target(gt) .. py:method:: create_weight(gt, target, mask, moving_class_counts=None) Create the weight array for training, given a ground-truth and associated target array. :param gt: The ground-truth array. :param target: The target array. :param mask: The mask array. :param moving_class_counts: The moving class counts. :returns: The weight array and the moving class counts. :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.create_weight(gt, target, mask, moving_class_counts) .. py:property:: output_array_type Get the output array type. :returns: The output array type. :rtype: DistanceArray :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.output_array_type .. py:method:: create_distance_mask(distances: numpy.ndarray, mask: numpy.ndarray, voxel_size: funlib.geometry.Coordinate, normalize=None, normalize_args=None) Create a distance mask. :param distances: The distances array. :type distances: np.ndarray :param mask: The mask array. :type mask: np.ndarray :param voxel_size: The voxel size. :type voxel_size: Coordinate :param normalize: The normalization method. :type normalize: str :param normalize_args: The normalization arguments. :returns: The distance mask. :rtype: np.ndarray :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.create_distance_mask(distances, mask, voxel_size, normalize, normalize_args) .. py:method:: process(labels: numpy.ndarray, voxel_size: funlib.geometry.Coordinate, normalize=None, normalize_args=None) Process the labels array and convert it to one-hot encoding. :param labels: The labels array. :type labels: np.ndarray :param voxel_size: The voxel size. :type voxel_size: Coordinate :param normalize: The normalization method. :type normalize: str :param normalize_args: The normalization arguments. :returns: The distances array. :rtype: np.ndarray :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.process(labels, voxel_size, normalize, normalize_args) .. py:method:: gt_region_for_roi(target_spec) Report how much spatial context this predictor needs to generate a target for the given ROI. By default, uses the same ROI. :param target_spec: The ROI for which the target is requested. :returns: The ROI for which the ground-truth is requested. :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.gt_region_for_roi(target_spec) .. py:method:: padding(gt_voxel_size: funlib.geometry.Coordinate) -> funlib.geometry.Coordinate Return the padding needed for the ground-truth array. :param gt_voxel_size: The voxel size of the ground-truth array. :type gt_voxel_size: Coordinate :returns: The padding needed for the ground-truth array. :rtype: Coordinate :raises NotImplementedError: This method is not implemented. .. rubric:: Examples >>> predictor.padding(gt_voxel_size)