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 and numericaldtype
.labels (torch.Tensor) –
torch.Tensor
of 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.1
andcat
,dog
labels it would be0.9
cat and0.1
dog).
- Returns
Inputs and labels after mixup (linear mix with
gamma
strength).- Return type
Tuple(torch.Tensor, torch.Tensor)