models.soda.SODa#

class SODa(backbone: BackboneGen, neck: NeckGen, head: Head, loss_ratio: int, time_window: int = 0)[source]#

Bases: Model

Basic object detector class

Implements the basic functions for calculating losses, training the network and generating predictions. The network model is passed as a parameter when initializing.

Parameters:
  • backbone (BackboneGen) – Main network.

  • neck (NeckGen) – Feature Map Extraction Network.

  • head (Head) – Network for transforming feature maps into predictions.

  • loss_ratio (int) – The ratio of the loss for non-detection to the loss for false positives. The higher this parameter, the more guesses the network generates. This is necessary to keep the network active.

  • time_window (int, optional) – The size of the time window at the beginning of the sequence, which can be truncated to a random length. This ensures randomization of the length of training sequences and the ability of the network to work with streaming information. Defaults to 0.

Methods

configure_optimizers

Returns the configured optimizer for training the network

forward

Direct network pass

loss

Loss calculation function.

predict

Returns the network's predictions based on the input data

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) tuple[Tensor, Tensor, Tensor][source]#

Direct network pass

Parameters:

X (torch.Tensor) – Input data.

Returns:

List of three tensors:

  1. Anchors. Shape [anchor, 4].

  2. Class predictions. Shape [ts, batch, anchor, num_classes + 1].

  3. Box predictions. Shape [ts, batch, anchor, 4].

Return type:

tuple[torch.Tensor, torch.Tensor, torch.Tensor]

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

Loss calculation function.

Parameters:
  • preds (Tuple[torch.Tensor, torch.Tensor, torch.Tensor]) –

    Predictions made by a neural network. Contains three tensors:

    1. anchors: Shape [anchor, 4]

    2. cls_preds: Shape [ts, batch, anchor, num_classes + 1]

    3. bbox_preds: Shape [ts, batch, anchor, 4]

  • labels (torch.Tensor) –

    Tensor shape [num_labels, 5].

    One label contains: class id, xlu, ylu, xrd, yrd.

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.

Shape [ts, batch, anchors, 6].

One label contains (class, iou, luw, luh, rdw, rdh)

Return type:

torch.Tensor

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