Shortcuts

torchtraining.functional.inputs module

This module has no object oriented counterpart and should be used in a functional fashion inside forward of torchtraining.steps (as the only one currently).

See examples for specific user cases

torchtraining.functional.inputs.mixup(inputs: torch.Tensor, targets: torch.Tensor, gamma: float) → Tuple[torch.Tensor, torch.Tensor][source]

Perform per-batch mixup on images.

See mixup: Beyond Empirical Risk Minimization. for explanation of the method.

Example:

class TrainStep(tt.steps.Train):
    def forward(self, module, sample):
        images, labels = sample
        images, labels = tt.functional.inputs.mixup(images, labels)
        # Calculate what you want below, say loss
        ...
        return loss


step = TrainStep(criterion, device)

Note

IMPORTANT: Examples are modified in-place!

Parameters
  • inputs (torch.Tensor) – torch.Tensor of shape (N,)(N, *) and numerical dtype.

  • labels (torch.Tensor) – torch.Tensor of shape (N,)(N, *) and numerical dtype.

  • gamma (float) – Level of mixing between inputs and labels. The smaller the value, the more “concrete” examples are (e.g. for 0.1 and cat, dog labels it would be 0.9 cat and 0.1 dog).

Returns

Inputs and labels after mixup (linear mix with gamma strength).

Return type

Tuple(torch.Tensor, torch.Tensor)