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
Returns the configured optimizer for training the network
Direct network pass
Loss calculation function.
Returns the network's predictions based on the input data
Network test step
Network training 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:
Anchors. Shape [anchor, 4].
Class predictions. Shape [ts, batch, anchor, num_classes + 1].
Box predictions. Shape [ts, batch, anchor, 4].
- Return type:
- 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:
anchors: Shape [anchor, 4]
cls_preds: Shape [ts, batch, anchor, num_classes + 1]
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:
- 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:
- test_step(batch: tuple[Tensor, Tensor]) Tensor [source]#
Network test step
- Parameters:
batch (Tuple[torch.Tensor, torch.Tensor]) –
Training data. Contains:
Input data
Labels
- Returns:
Value of losses
- Return type:
- training_step(batch: tuple[Tensor, Tensor]) Tensor [source]#
Network training step
- Parameters:
batch (Tuple[torch.Tensor, torch.Tensor]) –
Training data. Contains:
Input data
Labels
- Returns:
Value of losses
- Return type:
- validation_step(batch: tuple[Tensor, Tensor]) Tensor [source]#
Network validation step
- Parameters:
batch (Tuple[torch.Tensor, torch.Tensor]) –
Training data. Contains:
Input data
Labels
- Returns:
Value of losses
- Return type: