Skip to content

Lightning Module

Source

Deprecated CAREamics Lightning module.

FCNModule

Bases: LightningModule

CAREamics Lightning module.

This class encapsulates the PyTorch model along with the training, validation, and testing logic. It is configured using an AlgorithmModel Pydantic class.

Parameters:

  • algorithm_config (AlgorithmModel or dict) –

    Algorithm configuration.

Attributes:

  • model (Module) –

    PyTorch model.

  • loss_func (Module) –

    Loss function.

  • optimizer_name (str) –

    Optimizer name.

  • optimizer_params (dict) –

    Optimizer parameters.

  • lr_scheduler_name (str) –

    Learning rate scheduler name.

__init__(algorithm_config)

Lightning module for CAREamics.

This class encapsulates the a PyTorch model along with the training, validation, and testing logic. It is configured using an AlgorithmModel Pydantic class.

Parameters:

  • algorithm_config (AlgorithmModel or dict) –

    Algorithm configuration.

configure_optimizers()

Configure optimizers and learning rate schedulers.

Returns:

  • Any

    Optimizer and learning rate scheduler.

forward(x)

Forward pass.

Parameters:

  • x (Any) –

    Input tensor.

Returns:

  • Any

    Output tensor.

predict_step(batch, batch_idx)

Prediction step.

Parameters:

  • batch (Tensor) –

    Input batch.

  • batch_idx (Any) –

    Batch index.

Returns:

  • Any

    Model output.

training_step(batch, batch_idx)

Training step.

Parameters:

  • batch (Tensor) –

    Input batch.

  • batch_idx (Any) –

    Batch index.

Returns:

  • Any

    Loss value.

validation_step(batch, batch_idx)

Validation step.

Parameters:

  • batch (Tensor) –

    Input batch.

  • batch_idx (Any) –

    Batch index.

create_careamics_module(algorithm, loss, architecture, use_n2v2=False, struct_n2v_axis='none', struct_n2v_span=5, model_parameters=None, optimizer='Adam', optimizer_parameters=None, lr_scheduler='ReduceLROnPlateau', lr_scheduler_parameters=None)

Create a CAREamics Lightning module.

This function exposes parameters used to create an AlgorithmModel instance, triggering parameters validation.

Parameters:

  • algorithm (SupportedAlgorithm or str) –

    Algorithm to use for training (see SupportedAlgorithm).

  • loss (SupportedLoss or str) –

    Loss function to use for training (see SupportedLoss).

  • architecture (SupportedArchitecture or str) –

    Model architecture to use for training (see SupportedArchitecture).

  • use_n2v2 (bool, default: False ) –

    Whether to use N2V2 or Noise2Void.

  • struct_n2v_axis ("horizontal", "vertical", or "none", default: "none" ) –

    Axis of the StructN2V mask.

  • struct_n2v_span (int, default: 5 ) –

    Span of the StructN2V mask.

  • model_parameters (dict, default: None ) –

    Model parameters to use for training, by default {}. Model parameters are defined in the relevant torch.nn.Module class, or Pyddantic model (see careamics.config.architectures).

  • optimizer (SupportedOptimizer or str, default: 'Adam' ) –

    Optimizer to use for training, by default "Adam" (see SupportedOptimizer).

  • optimizer_parameters (dict, default: None ) –

    Optimizer parameters to use for training, as defined in torch.optim, by default {}.

  • lr_scheduler (SupportedScheduler or str, default: 'ReduceLROnPlateau' ) –

    Learning rate scheduler to use for training, by default "ReduceLROnPlateau" (see SupportedScheduler).

  • lr_scheduler_parameters (dict, default: None ) –

    Learning rate scheduler parameters to use for training, as defined in torch.optim, by default {}.

Returns:

  • CAREamicsModule

    CAREamics Lightning module.