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.Tensorof shape and numericaldtype.labels (torch.Tensor) –
torch.Tensorof shape and numericaldtype.gamma (float) – Level of mixing between inputs and labels. The smaller the value, the more “concrete” examples are (e.g. for
0.1andcat,doglabels it would be0.9cat and0.1dog).
- Returns
Inputs and labels after mixup (linear mix with
gammastrength).- Return type
Tuple(torch.Tensor, torch.Tensor)