dacapo.experiments.tasks.predictors.distance_predictor
Attributes
Classes
Predict signed distances for a binary segmentation task. |
Module Contents
- dacapo.experiments.tasks.predictors.distance_predictor.logger
- class dacapo.experiments.tasks.predictors.distance_predictor.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.
- channels
The list of class labels.
- Type:
List[str]
- scale_factor
The scale factor for the distance transform.
- Type:
float
- mask_distances
Whether to mask distances.
- Type:
bool
- clipmin
The minimum value to clip the weights to.
- Type:
float
- clipmax
The maximum value to clip the weights to.
- Type:
float
- __init__(self, channels
List[str], scale_factor: float, mask_distances: bool, clipmin: float = 0.05, clipmax: float = 0.95): Initializes the DistancePredictor.
- create_model(self, architecture)
Create the model for the predictor.
- create_target(self, gt)
Create the target array for training.
- create_weight(self, gt, target, mask, moving_class_counts=None)
Create the weight array for training.
- output_array_type()
Get the output array type.
- create_distance_mask(self, distances, mask, voxel_size, normalize=None, normalize_args=None)
Create the distance mask.
- process(self, labels, voxel_size, normalize=None, normalize_args=None)
Process the labels array.
- gt_region_for_roi(self, target_spec)
Get the ground-truth region for the ROI.
- padding(self, gt_voxel_size
Coordinate) -> Coordinate: Get the padding needed for the ground-truth array.
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.
- channels
- norm = 'tanh'
- dt_scale_factor
- mask_distances
- max_distance
- epsilon = 0.05
- threshold = 0.8
- clipmin
- clipmax
- property embedding_dims
- Get the number of embedding dimensions.
- Returns:
The number of embedding dimensions.
- Return type:
int
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> embedding_dims = predictor.embedding_dims
- create_model(architecture)
Create the model for the predictor.
- Parameters:
architecture – The architecture for the model.
- Returns:
The created model.
- Return type:
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> model = predictor.create_model(architecture)
- create_target(gt)
Create the target array for training.
- Parameters:
gt – The ground-truth array.
- Returns:
The created target array.
- Return type:
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> predictor.create_target(gt)
- create_weight(gt, target, mask, moving_class_counts=None)
Create the weight array for training, given a ground-truth and associated target array.
- Parameters:
gt – The ground-truth array.
target – The target array.
mask – The mask array.
moving_class_counts – The moving class counts.
- Returns:
The weight array and the moving class counts.
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> predictor.create_weight(gt, target, mask, moving_class_counts)
- property output_array_type
- Get the output array type.
- Returns:
The output array type.
- Return type:
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> predictor.output_array_type
- create_distance_mask(distances: numpy.ndarray, mask: numpy.ndarray, voxel_size: funlib.geometry.Coordinate, normalize=None, normalize_args=None)
Create a distance mask.
- Parameters:
distances (np.ndarray) – The distances array.
mask (np.ndarray) – The mask array.
voxel_size (Coordinate) – The voxel size.
normalize (str) – The normalization method.
normalize_args – The normalization arguments.
- Returns:
The distance mask.
- Return type:
np.ndarray
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> predictor.create_distance_mask(distances, mask, voxel_size, normalize, normalize_args)
- 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.
- Parameters:
labels (np.ndarray) – The labels array.
voxel_size (Coordinate) – The voxel size.
normalize (str) – The normalization method.
normalize_args – The normalization arguments.
- Returns:
The distances array.
- Return type:
np.ndarray
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> predictor.process(labels, voxel_size, normalize, normalize_args)
- 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.
- Parameters:
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.
Examples
>>> predictor.gt_region_for_roi(target_spec)
- padding(gt_voxel_size: funlib.geometry.Coordinate) funlib.geometry.Coordinate
Return the padding needed for the ground-truth array.
- Parameters:
gt_voxel_size (Coordinate) – The voxel size of the ground-truth array.
- Returns:
The padding needed for the ground-truth array.
- Return type:
Coordinate
- Raises:
NotImplementedError – This method is not implemented.
Examples
>>> predictor.padding(gt_voxel_size)