engine.model.Model#

class Model(*args, **kwargs)[source]#

Bases: Module

Class of interface for models

Initialize internal Module state, shared by both nn.Module and ScriptModule.

Methods

configure_optimizers

Returns the configured optimizer for training the network

forward

Direct network pass

load_params

Loads network weights from a file

loss

Loss calculation function

predict

Returns the network's predictions based on the input data

save_params

Saves network weights

test_step

Network test step

training_step

Network training step

validation_step

Network validation step

Attributes

training

configure_optimizers() Optimizer[source]#

Returns the configured optimizer for training the network

forward(X: Tensor) Any[source]#

Direct network pass

This method must be overridden in child classes.

Parameters:

X (torch.Tensor) – Input data

Raises:

NotImplementedError – This method is not implemented.

Returns:

Result of the network operation

Return type:

Any

load_params(name: str) None[source]#

Loads network weights from a file

The file must be in the nets folder and end with .params

Parameters:

name (str) – Parameters file name.

loss(preds: Any, labels: Any) Tensor[source]#

Loss calculation function

This method must be overridden in child classes.

Parameters:
  • preds (Any) – Predictions made by a neural network.

  • labels (Any) – Ground truth.

Raises:

NotImplementedError – This method is not implemented.

Returns:

Value of losses

Return type:

torch.Tensor

predict(X: Tensor) Tensor[source]#

Returns the network’s predictions based on the input data

Parameters:

X (torch.Tensor) – Input data.

Returns:

Network Predictions.

Return type:

torch.Tensor

save_params(name: str) None[source]#

Saves network weights

Parameters:

name (str, optional) – Parameters file name. The file will be saved to the nets folder.

test_step(batch: Tuple[Tensor, Tensor]) Tensor[source]#

Network test step

Parameters:

batch (Tuple[torch.Tensor, torch.Tensor]) –

Training data. Contains:

  1. Input data

  2. Labels

Returns:

Value of losses

Return type:

torch.Tensor

training_step(batch: Tuple[Tensor, Tensor]) Tensor[source]#

Network training step

Parameters:

batch (Tuple[torch.Tensor, torch.Tensor]) –

Training data. Contains:

  1. Input data

  2. Labels

Returns:

Value of losses

Return type:

torch.Tensor

validation_step(batch: Tuple[Tensor, Tensor]) Tensor[source]#

Network validation step

Parameters:

batch (Tuple[torch.Tensor, torch.Tensor]) –

Training data. Contains:

  1. Input data

  2. Labels

Returns:

Value of losses

Return type:

torch.Tensor