dacapo.experiments.model
Classes
A trainable DaCapo model. Consists of an |
Module Contents
- class dacapo.experiments.model.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
Architectureand 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.
- architecture
The architecture of the model.
- Type:
- prediction_head
The prediction head of the model.
- Type:
torch.nn.Module
- chain
The architecture followed by the prediction head.
- Type:
torch.nn.Sequential
- num_in_channels
The number of input channels.
- Type:
int
- input_shape
The shape of the input tensor.
- Type:
Coordinate
- eval_input_shape
The shape of the input tensor during evaluation.
- Type:
Coordinate
- num_out_channels
The number of output channels.
- Type:
int
- output_shape
The shape of the output
- Type:
Coordinate
- eval_activation
The activation function to apply during evaluation.
- Type:
torch.nn.Module | None
- forward(x
torch.Tensor) -> torch.Tensor: Forward pass of the model.
- compute_output_shape(input_shape
Coordinate) -> Tuple[int, Coordinate]: Compute the spatial shape of this model, when fed a tensor of the given spatial shape as input.
- scale(voxel_size
Coordinate) -> Coordinate: Scale the model by the given voxel size.
Note
The output shape is the spatial shape of the model, i.e., not accounting for channels and batch dimensions.
- num_out_channels: int
- num_in_channels: int
- architecture
- prediction_head
- chain
- input_shape
- eval_input_shape
- eval_activation
- forward(x)
Forward pass of the model.
- Parameters:
x (torch.Tensor) – The input tensor.
- Returns:
The output tensor.
- Return type:
torch.Tensor
Examples
>>> model = Model(architecture, prediction_head) >>> model.forward(x) torch.Tensor
Note
The eval_activation is only applied during evaluation. 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.
- 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.
- Parameters:
input_shape (Coordinate) – The shape of the input tensor.
- Returns:
The number of output channels and the spatial shape of the output.
- Return type:
Tuple[int, Coordinate]
- Raises:
AssertionError – If the input_shape is not a Coordinate.
Examples
>>> model = Model(architecture, prediction_head) >>> model.compute_output_shape(input_shape) (1, Coordinate(1, 1, 1))
Note
The output shape is the spatial shape of the model, i.e., not accounting for channels and batch dimensions.
- scale(voxel_size: funlib.geometry.Coordinate) funlib.geometry.Coordinate
Scale the model by the given voxel size.
- Parameters:
voxel_size (Coordinate) – The voxel size to scale the model by.
- Returns:
The scaled model.
- Return type:
Coordinate
- Raises:
AssertionError – If the voxel_size is not a Coordinate.
Examples
>>> model = Model(architecture, prediction_head) >>> model.scale(voxel_size) Coordinate(1, 1, 1)
Note
The output shape is the spatial shape of the model, i.e., not accounting for channels and batch dimensions.