dacapo.experiments.tasks.predictors.hot_distance_predictor

Attributes

logger

Classes

HotDistancePredictor

Predict signed distances and one hot embedding (as a proxy task) for a binary segmentation task.

Module Contents

dacapo.experiments.tasks.predictors.hot_distance_predictor.logger
class dacapo.experiments.tasks.predictors.hot_distance_predictor.HotDistancePredictor(channels: List[str], scale_factor: float, mask_distances: bool)

Predict signed distances and one hot embedding (as a proxy task) 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

List of strings, each string is the name of a class that is being segmented.

scale_factor

The scale factor for the distance transform.

mask_distances

Whether to mask distances based on the distance to the boundary.

norm

The normalization function to use for the distance transform.

dt_scale_factor

The scale factor for the distance transform.

max_distance

The maximum distance to consider for the distance transform.

epsilon

The epsilon value to use for the distance transform.

threshold

The threshold value to use for the distance transform.

__init__(self, channels

List[str], scale_factor: float, mask_distances: bool): Initializes the HotDistancePredictor.

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.

create_distance_mask(self, distances, mask, voxel_size, normalize=None, normalize_args=None)

Create the distance mask for training.

process(self, labels, voxel_size, normalize=None, normalize_args=None)

Process the labels array and convert it to one-hot encoding.

gt_region_for_roi(self, target_spec)

Report how much spatial context this predictor needs to generate a target for the given ROI.

padding(self, gt_voxel_size)

Return the padding needed for the ground-truth

Notes

This is a subclass of Predictor.

channels
norm = 'tanh'
dt_scale_factor
mask_distances
max_distance
epsilon = 0.05
threshold = 0.8
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
property classes
Get the number of classes.
Returns:

The number of classes.

Return type:

int

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> classes = predictor.classes
create_model(architecture)

Create the model for the predictor.

Parameters:

architecture – The architecture for the model.

Returns:

The created model.

Return type:

Model

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:

NumpyArray

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> target = 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.

Return type:

Tuple[NumpyArray, np.ndarray]

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:

ProbabilityArray

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> output_array_type = predictor.output_array_type

Notes

Technically this is a probability array + distance array, but it is only ever referenced for interpolatability (which is true for both).

create_distance_mask(distances: numpy.ndarray, mask: numpy.ndarray, voxel_size: funlib.geometry.Coordinate, normalize=None, normalize_args=None)

Create the distance mask for training.

Parameters:
  • distances – The distances array.

  • mask – The mask array.

  • voxel_size – The voxel size.

  • normalize – The normalization function to use.

  • normalize_args – The normalization arguments.

Returns:

The distance mask.

Return type:

np.ndarray

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> distance_mask = self.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 – The labels array.

  • voxel_size – The voxel size.

  • normalize – The normalization function to use.

  • normalize_args – The normalization arguments.

Returns:

The one-hot encoded 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 – 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)