Modules
CAREamics PyTorch Lightning modules.
CAREModule
Bases: LightningModule
CAREamics PyTorch Lightning module for CARE algorithm.
Parameters:
-
algorithm_config(CAREAlgorithm, N2NAlgorithm, or dict) –Configuration for the CARE algorithm, either as a CAREAlgorithm/N2NAlgorithm instance or a dictionary.
__init__(algorithm_config)
Instantiate CARE Module.
Parameters:
-
algorithm_config(CAREAlgorithm, N2NAlgorithm, or dict) –Configuration for the CARE algorithm, either as a CAREAlgorithm/N2NAlgorithm instance or a dictionary.
configure_optimizers()
forward(x)
Forward pass.
Parameters:
-
x(Tensor) –Input tensor.
Returns:
-
Tensor–Model output tensor.
on_fit_start()
On fit start hook for CARE module.
Check that training and validation target data have been supplied.
predict_step(batch, batch_idx)
Prediction step for CARE module.
Parameters:
-
batch(ImageRegionData or (ImageRegionData, ImageRegionData)) –A tuple containing the input data and optionally the target data.
-
batch_idx(int) –The index of the current batch in the prediction loop.
Returns:
-
ImageRegionData–The output batch containing the predictions.
training_step(batch, batch_idx)
Training step for CARE module.
Parameters:
-
batch((ImageRegionData, ImageRegionData)) –A tuple containing the input data and the target data.
-
batch_idx(int) –The index of the current batch in the training loop.
Returns:
-
Tensor–The loss value computed for the current batch.
validation_step(batch, batch_idx)
Validation step for CARE module.
Parameters:
-
batch((ImageRegionData, ImageRegionData)) –A tuple containing the input data and the target data.
-
batch_idx(int) –The index of the current batch in the validation loop.
N2VModule
Bases: LightningModule
CAREamics PyTorch Lightning module for N2V algorithm.
Parameters:
-
algorithm_config(N2VAlgorithm or dict) –Configuration for the N2V algorithm, either as an N2VAlgorithm instance or a dictionary.
__init__(algorithm_config)
Instantiate N2VModule.
Parameters:
-
algorithm_config(N2VAlgorithm or dict) –Configuration for the N2V algorithm, either as an N2VAlgorithm instance or a dictionary.
configure_optimizers()
forward(x)
Forward pass.
Parameters:
-
x(Tensor) –Input tensor.
Returns:
-
Tensor–Model output tensor.
on_fit_start()
On fit start hook for N2V module.
predict_step(batch, batch_idx)
Prediction step for N2V model.
Parameters:
-
batch(ImageRegionData or (ImageRegionData, ImageRegionData)) –A tuple containing the input data and optionally the target data.
-
batch_idx(int) –The index of the current batch in the prediction loop.
Returns:
-
ImageRegionData–The output batch containing the predictions.
training_step(batch, batch_idx)
Training step for N2V model.
Parameters:
-
batch(ImageRegionData or (ImageRegionData, ImageRegionData)) –A tuple containing the input data and the target data.
-
batch_idx(int) –The index of the current batch in the training loop.
Returns:
-
Tensor–The loss value for the current training step.
validation_step(batch, batch_idx)
Validation step for N2V model.
Parameters:
-
batch(ImageRegionData or (ImageRegionData, ImageRegionData)) –A tuple containing the input data and the target data.
-
batch_idx(int) –The index of the current batch in the validation loop.
create_module(algorithm_config)
Initialize the correct Lightning module from an algorithm config.
Parameters:
-
algorithm_config(UNetBasedAlgorithm) –The pydantic model with algorithm specific parameters.
Returns:
-
CAREamicsModule–A lightning module for running one of the algorithms supported by CAREamics.
Raises:
-
NotImplementedError–If the chosen algorithm is not yet supported.
get_module_cls(algorithm)
Get the lightning module class for the specified algorithm.
Parameters:
-
algorithm(SupportedAlgorithm) –One of the algorithms supported by CAREamics, e.g.
"n2v".
Returns:
-
CAREamicsModuleCls–A Lightning module class for running the specified
algorithm.
Raises:
-
NotImplementedError–If the chosen algorithm is not get supported.