Skip to content

Example

Example of a simple algorithm for image classification.

This can be run from the command-line like so:

python project/main.py algorithm=example

ExampleAlgorithm #

Bases: LightningModule

Example learning algorithm for image classification.

__init__ #

__init__(
    datamodule: ImageClassificationDataModule,
    network: _Config[Module],
    optimizer: _PartialConfig[Optimizer] = AdamConfig(
        lr=0.0003
    ),
    init_seed: int = 42,
)

Create a new instance of the algorithm.

Parameters:

Name Type Description Default
datamodule ImageClassificationDataModule

Object used to load train/val/test data. See the lightning docs for LightningDataModule for more info.

required
network _Config[Module]

The config of the network to instantiate and train.

required
optimizer _PartialConfig[Optimizer]

The config for the Optimizer. Instantiating this will return a function (a functools.partial) that will create the Optimizer given the hyper-parameters.

AdamConfig(lr=0.0003)
init_seed int

The seed to use when initializing the weights of the network.

42

forward #

forward(input: Tensor) -> Tensor

Forward pass of the network.

configure_optimizers #

configure_optimizers()

Creates the optimizers.

See lightning.pytorch.core.LightningModule.configure_optimizers for more information.

configure_callbacks #

configure_callbacks() -> Sequence[Callback] | Callback

Creates callbacks to be used by default during training.