dacapo.experiments

Subpackages

Submodules

Package Contents

Classes

Model

A trainable DaCapo model. Consists of an Architecture and a

RunConfig

A class to represent a configuration of a run that helps to structure all the tasks,

TrainingIterationStats

A class to represent the training iteration statistics.

TrainingStats

A class used to represent Training Statistics.

ValidationIterationScores

A class used to represent the validation iteration scores in an organized structure.

ValidationScores

class dacapo.experiments.Model(architecture: dacapo.experiments.architectures.architecture.Architecture, prediction_head: torch.nn.Module, eval_activation: torch.nn.Module | None = None)

A trainable DaCapo model. Consists of an Architecture and a prediction head. Models are generated by ``Predictor``s.

May include an optional eval_activation that is only executed when the model is in eval mode. This is particularly useful if you want to train with something like BCELossWithLogits, since you want to avoid applying softmax while training, but apply it during evaluation.

num_out_channels: int
num_in_channels: int
forward(x)
compute_output_shape(input_shape: funlib.geometry.Coordinate) Tuple[int, funlib.geometry.Coordinate]

Compute the spatial shape (i.e., not accounting for channels and batch dimensions) of this model, when fed a tensor of the given spatial shape as input.

scale(voxel_size: funlib.geometry.Coordinate) funlib.geometry.Coordinate
class dacapo.experiments.RunConfig

A class to represent a configuration of a run that helps to structure all the tasks, architecture, training, and datasplit configurations.

Attributes:

task_config: TaskConfig

A config defining the Task to run that includes deciding the output of the model and different methods to achieve the goal.

architecture_config: ArchitectureConfig

A config that defines the backbone architecture of the model. It impacts the model’s performance significantly.

trainer_config: TrainerConfig

Defines how batches are generated and passed for training the model along with defining configurations like batch size, learning rate, number of cpu workers and snapshot logging.

datasplit_config: DataSplitConfig

Configures the data available for the model during training or validation phases.

name: str

A unique name for this run to distinguish it.

repetition: int

The repetition number of this run.

num_iterations: int

The total number of iterations to train for during this run.

validation_interval: int

Specifies how often to perform validation during the run. It defaults to 1000.

start_configOptional[StartConfig]

A starting point for continued training. It is optional and can be left out.

task_config: dacapo.experiments.tasks.TaskConfig
architecture_config: dacapo.experiments.architectures.ArchitectureConfig
trainer_config: dacapo.experiments.trainers.TrainerConfig
datasplit_config: dacapo.experiments.datasplits.DataSplitConfig
name: str
repetition: int
num_iterations: int
validation_interval: int
start_config: dacapo.experiments.starts.StartConfig | None
class dacapo.experiments.TrainingIterationStats

A class to represent the training iteration statistics.

iteration

The iteration that produced these stats.

Type:

int

loss

The loss value of this iteration.

Type:

float

time

The time it took to process this iteration.

Type:

float

iteration: int
loss: float
time: float
class dacapo.experiments.TrainingStats

A class used to represent Training Statistics.

iteration_stats

List[TrainingIterationStats] an ordered list of training stats.

add_iteration_stats(iteration_stats

TrainingIterationStats) -> None: Add a new set of iterations stats to the existing list of iteration stats.

delete_after(iteration

int) -> None: Deletes training stats after a specified iteration number.

trained_until() int

Gets the number of iterations that the model has been trained for.

to_xarray() xr.DataArray

Converts the iteration statistics to a xarray data array.

iteration_stats: List[dacapo.experiments.training_iteration_stats.TrainingIterationStats]
add_iteration_stats(iteration_stats: dacapo.experiments.training_iteration_stats.TrainingIterationStats) None

Add a new iteration stats to the current iteration stats.

Parameters:

iteration_stats (TrainingIterationStats) – a new iteration stats object.

Raises:

assert – if the new iteration stats do not follow the order of existing iteration stats.

delete_after(iteration: int) None

Deletes training stats after a specified iteration.

Parameters:

iteration (int) – the iteration after which the stats are to be deleted.

trained_until() int

The number of iterations trained for (the maximum iteration plus one). Returns zero if no iterations trained yet.

Returns:

number of iterations that the model has been trained for.

Return type:

int

to_xarray() xarray.DataArray

Converts the iteration stats to a data array format easily manipulatable.

Returns:

xarray DataArray of iteration losses.

Return type:

xr.DataArray

class dacapo.experiments.ValidationIterationScores

A class used to represent the validation iteration scores in an organized structure.

iteration

The iteration associated with these validation scores.

Type:

int

scores

A list of scores per dataset, post processor

Type:

List[List[List[float]]]

parameters, and evaluation criterion.
iteration: int
scores: List[List[List[float]]]
class dacapo.experiments.ValidationScores
property criteria: List[str]
property parameter_names: List[str]
parameters: List[dacapo.experiments.tasks.post_processors.PostProcessorParameters]
datasets: List[dacapo.experiments.datasplits.datasets.Dataset]
evaluation_scores: dacapo.experiments.tasks.evaluators.EvaluationScores
scores: List[dacapo.experiments.validation_iteration_scores.ValidationIterationScores]
subscores(iteration_scores: List[dacapo.experiments.validation_iteration_scores.ValidationIterationScores]) ValidationScores
add_iteration_scores(iteration_scores: dacapo.experiments.validation_iteration_scores.ValidationIterationScores) None
delete_after(iteration: int) None
validated_until() int

The number of iterations validated for (the maximum iteration plus one).

compare(existing_iteration_scores: List[dacapo.experiments.validation_iteration_scores.ValidationIterationScores]) Tuple[bool, int]

Compares iteration stats provided from elsewhere to scores we have saved locally. Local scores take priority. If local scores are at a lower iteration than the existing ones, delete the existing ones and replace with local. If local iteration > existing iteration, just update existing scores with the last overhanging local scores.

to_xarray() xarray.DataArray
get_best(data: xarray.DataArray, dim: str) Tuple[xarray.DataArray, xarray.DataArray]

Compute the Best scores along dimension “dim” per criterion. Returns both the index associated with the best value, and the best value in two seperate arrays.