dacapo.experiments.tasks

Submodules

Classes

Task

Helper class that provides a standard way to create an ABC using

TaskConfig

Base class for task configurations. Each subclass of a Task should

DummyTaskConfig

A class for creating a dummy task configuration object.

DummyTask

A dummy task class that initializes all components (predictor, loss,

DistanceTaskConfig

This is a Distance task config used for generating and

DistanceTask

DistanceTask is a subclass of Task for handling tasks associated

OneHotTaskConfig

Class that derives from the TaskConfig to perform one hot prediction tasks.

OneHotTask

A task that uses a one-hot predictor. The model is loaded from a file

PretrainedTaskConfig

Configuration for a task that uses a pretrained model. The model is loaded from a file

PretrainedTask

A task that uses a pretrained model. The model is loaded from a file

AffinitiesTaskConfig

This is a Affinities task config used for generating and

AffinitiesTask

This is a task for generating voxel affinities. It uses an AffinitiesPredictor for prediction,

InnerDistanceTaskConfig

This is a Distance task config used for generating and

InnerDistanceTask

This class extends the Task class for creating tasks related to computing inner distances.

HotDistanceTaskConfig

Class for generating TaskConfigs for the HotDistanceTask, which predicts one hot encodings of classes, as well as signed distance transforms of those classes.

HotDistanceTask

A class to represent a hot distance task that use binary prediction and distance prediction.

Package Contents

class dacapo.experiments.tasks.Task

Helper class that provides a standard way to create an ABC using inheritance.

predictor: dacapo.experiments.tasks.predictors.Predictor
loss: dacapo.experiments.tasks.losses.Loss
evaluator: dacapo.experiments.tasks.evaluators.Evaluator
post_processor: dacapo.experiments.tasks.post_processors.PostProcessor
property parameters: Iterable[dacapo.experiments.tasks.post_processors.PostProcessorParameters]
property evaluation_scores: dacapo.experiments.tasks.evaluators.EvaluationScores
create_model(architecture)
class dacapo.experiments.tasks.TaskConfig

Base class for task configurations. Each subclass of a Task should have a corresponding config class derived from TaskConfig.

name

A unique name for this task. This will be saved so you and others can find and reuse this task. Keep it short and avoid special characters.

verify(self) Tuple[bool, str]

This method verifies the TaskConfig object.

Notes

This is a base class for all task configurations. It is not meant to be used directly.

name: str
verify() Tuple[bool, str]

Check whether this is a valid Task

Returns:

A tuple containing a boolean value indicating whether the TaskConfig object is valid

and a string containing the reason why the object is invalid.

Return type:

Tuple[bool, str]

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> valid, reason = task_config.verify()
class dacapo.experiments.tasks.DummyTaskConfig

A class for creating a dummy task configuration object.

This class extends the TaskConfig class and initializes dummy task configuration with default attributes. It is mainly used for testing aspects of the application without the need of creating real task configurations.

task_type

The type of task. Here, set to DummyTask.

Type:

cls

embedding_dims

A dummy attribute represented as an integer.

Type:

int

detection_threshold

Another dummy attribute represented as a float.

Type:

float

verify(self) Tuple[bool, str]

This method verifies the DummyTaskConfig object.

Note

This is a subclass of TaskConfig.

task_type
embedding_dims: int
detection_threshold: float
verify() Tuple[bool, str]

A method to verify the dummy task configuration.

Whenever called, this method always returns False and a statement showing that the DummyTaskConfig object is never valid.

Returns:

A tuple containing a boolean status and a string message.

Return type:

tuple

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> valid, reason = task_config.verify()
class dacapo.experiments.tasks.DummyTask(task_config)

A dummy task class that initializes all components (predictor, loss, post-processing, and evaluator) for the dummy task. Primarily used for testing purposes. Inherits from the Task class.

predictor

Object Instance of DummyPredictor class.

loss

Object Instance of DummyLoss class.

post_processor

Object Instance of DummyPostProcessor class.

evaluator

Object Instance of DummyEvaluator class.

__init__(self, task_config)

Initializes all components for the dummy task.

Notes

This is a subclass of Task.

predictor
loss
post_processor
evaluator
class dacapo.experiments.tasks.DistanceTaskConfig

This is a Distance task config used for generating and evaluating signed distance transforms as a way of generating segmentations.

The advantage of generating distance transforms over regular affinities is you can get a denser signal, i.e. 1 misclassified pixel in an affinity prediction could merge 2 otherwise very distinct objects, this cannot happen with distances.

channels

A list of channel names.

clip_distance

Maximum distance to consider for false positive/negatives.

tol_distance

Tolerance distance for counting false positives/negatives

scale_factor

The amount by which to scale distances before applying a tanh normalization.

mask_distances

Whether or not to mask out regions where the true distance to object boundary cannot be known. This is anywhere that the distance to crop boundary is less than the distance to object boundary.

clipmin

The minimum value for distance weights.

clipmax

The maximum value for distance weights.

verify(self) Tuple[bool, str]

This method verifies the DistanceTaskConfig object.

Notes

This is a subclass of TaskConfig.

task_type
channels: List[str]
clip_distance: float
tol_distance: float
scale_factor: float
mask_distances: bool
clipmin: float
clipmax: float
class dacapo.experiments.tasks.DistanceTask(task_config)

DistanceTask is a subclass of Task for handling tasks associated with Distance.

DistanceTask uses DistancePredictor for prediction, MSELoss for computing loss, ThresholdPostProcessor for post-processing the prediction, and BinarySegmentationEvaluator for evaluating the prediction.

predictor

DistancePredictor object

loss

MSELoss object

post_processor

ThresholdPostProcessor object

evaluator

BinarySegmentationEvaluator object

__init__(self, task_config)

Initializes attributes of DistanceTask

Notes

This is a subclass of Task.

predictor
loss
post_processor
evaluator
class dacapo.experiments.tasks.OneHotTaskConfig

Class that derives from the TaskConfig to perform one hot prediction tasks.

task_type

the type of task, in this case, OneHotTask.

classes

a List of classes which starts from id 0.

None()

Note

The class of each voxel is simply the argmax over the vector of output probabilities.

task_type
classes: List[str]
kernel_size: int | None
class dacapo.experiments.tasks.OneHotTask(task_config)

A task that uses a one-hot predictor. The model is loaded from a file and the weights are loaded from a file. The loss is a dummy loss and the post processor is an argmax post processor. The evaluator is a dummy evaluator.

weights

The path to the weights file.

Type:

Path

create_model(self, architecture) Model

This method creates a model using the given architecture.

Notes

This is a base class for all tasks that use one-hot predictors.

predictor
loss
post_processor
evaluator
class dacapo.experiments.tasks.PretrainedTaskConfig

Configuration for a task that uses a pretrained model. The model is loaded from a file and the weights are loaded from a file.

sub_task_config

The task to run starting with the provided pretrained weights.

Type:

TaskConfig

weights

A checkpoint containing pretrained model weights.

Type:

Path

verify(self) Tuple[bool, str]

This method verifies the PretrainedTaskConfig object.

Notes

This is a subclass of TaskConfig.

task_type
sub_task_config: dacapo.experiments.tasks.task_config.TaskConfig
weights: upath.UPath
class dacapo.experiments.tasks.PretrainedTask(task_config)

A task that uses a pretrained model. The model is loaded from a file and the weights are loaded from a file.

weights

The path to the weights file.

Type:

Path

create_model(self, architecture) Model

This method creates a model using the given architecture.

Notes

This is a base class for all tasks that use pretrained models.

weights
predictor
loss
post_processor
evaluator
create_model(architecture)

Create a model using the given architecture.

Parameters:

architecture (str) – The architecture of the model.

Returns:

The model created using the given architecture.

Return type:

Model

Raises:

NotImplementedError – This method is not implemented.

Examples

>>> model = task.create_model(architecture)
class dacapo.experiments.tasks.AffinitiesTaskConfig

This is a Affinities task config used for generating and evaluating voxel affinities for instance segmentations.

neighborhood

A list of Coordinate objects.

lsds

Whether or not to train lsds along with your affinities.

num_lsd_voxels

The number of voxels to use for the lsd center of mass calculation.

downsample_lsds

The factor by which to downsample the lsds.

lsds_to_affs_weight_ratio

If training with lsds, set how much they should be weighted compared to affs.

affs_weight_clipmin

The minimum value for affinities weights.

affs_weight_clipmax

The maximum value for affinities weights.

lsd_weight_clipmin

The minimum value for lsds weights.

lsd_weight_clipmax

The maximum value for lsds weights.

background_as_object

Whether to treat the background as a separate object.

verify(self) Tuple[bool, str]

This method verifies the AffinitiesTaskConfig

Notes

This is a subclass of TaskConfig.

task_type
neighborhood: List[funlib.geometry.Coordinate]
lsds: bool
num_lsd_voxels: int
downsample_lsds: int
lsds_to_affs_weight_ratio: float
affs_weight_clipmin: float
affs_weight_clipmax: float
lsd_weight_clipmin: float
lsd_weight_clipmax: float
background_as_object: bool
class dacapo.experiments.tasks.AffinitiesTask(task_config)

This is a task for generating voxel affinities. It uses an AffinitiesPredictor for prediction, an AffinitiesLoss for loss calculation, a WatershedPostProcessor for post-processing, and an InstanceEvaluator for evaluation.

predictor

AffinitiesPredictor object

loss

AffinitiesLoss object

post_processor

WatershedPostProcessor object

evaluator

InstanceEvaluator object

__init__(self, task_config)

Initializes all components for the affinities task.

Notes

This is a subclass of Task.

predictor
loss
post_processor
evaluator
class dacapo.experiments.tasks.InnerDistanceTaskConfig

This is a Distance task config used for generating and evaluating signed distance transforms as a way of generating segmentations.

The advantage of generating distance transforms over regular affinities is you can get a denser signal, i.e. 1 misclassified pixel in an affinity prediction could merge 2 otherwise very distinct objects, this cannot happen with distances.

channels

A list of channel names.

clip_distance

Maximum distance to consider for false positive/negatives.

tol_distance

Tolerance distance for counting false positives/negatives

scale_factor

The amount by which to scale distances before applying a tanh normalization.

Notes

This is a subclass of TaskConfig.

task_type
channels: List[str]
clip_distance: float
tol_distance: float
scale_factor: float
class dacapo.experiments.tasks.InnerDistanceTask(task_config)

This class extends the Task class for creating tasks related to computing inner distances. It provides methods for prediction, loss calculation and post-processing. It includes Binary Segmentation Evaluator for evaluation.

task_config

The configuration for the task.

predictor

Used for predicting the inner distances.

loss

Used for calculating the mean square error loss.

post_processor

Used for applying threshold post-processing.

evaluator

Used for evaluating the results using binary segmentation.

__init__(self, task_config)

Initializes an instance of InnerDistanceTask.

Notes

This is a subclass of Task.

predictor
loss
post_processor
evaluator
class dacapo.experiments.tasks.HotDistanceTaskConfig

Class for generating TaskConfigs for the HotDistanceTask, which predicts one hot encodings of classes, as well as signed distance transforms of those classes.

task_type

A reference to the Hot Distance Task class.

channels

A list of channel names.

Type:

List[str]

clip_distance

Maximum distance to consider for false positive/negatives.

Type:

float

tol_distance

Tolerance distance for counting false positives/negatives.

Type:

float

scale_factor

The amount by which to scale distances before applying a tanh normalization. Defaults to 1.

Type:

float

mask_distances

Whether or not to mask out regions where the true distance to object boundary cannot be known. Defaults to False

Type:

bool

verify(self) Tuple[bool, str]

This method verifies the HotDistanceTaskConfig object.

Note

Generating distance transforms over regular affinities provides you with a denser signal, i.e., one misclassified pixel in an affinity prediction can merge 2 otherwise very distinct objects, a situation that cannot happen with distances.

task_type
channels: List[str]
clip_distance: float
tol_distance: float
scale_factor: float
mask_distances: bool
kernel_size: int | None
class dacapo.experiments.tasks.HotDistanceTask(task_config)

A class to represent a hot distance task that use binary prediction and distance prediction.

Inherits from Task class.

predictor

HotDistancePredictor object.

loss

HotDistanceLoss object.

post_processor

ThresholdPostProcessor object.

evaluator

BinarySegmentationEvaluator object.

__init__(self, task_config)

Constructs all the necessary attributes for the HotDistanceTask object.

Notes

This is a subclass of Task.

predictor
loss
post_processor
evaluator