nntoolbox.callbacks.mixup module

class nntoolbox.callbacks.mixup.ManifoldMixupCallback(learner, modules: Sequence[nntoolbox.callbacks.mixup.ManifoldMixupModule], alpha: float = 2.0)[source]

Bases: nntoolbox.callbacks.callbacks.Callback

Implement manifold mixup regularization as a callback. Each iteration, pick a random layer and transform its output and label: x = tau x_1 + (1 - tau) x_2 y = tau y_1 + (1 - tau) y_2 Reference: https://arxiv.org/pdf/1806.05236.pdf Based on fastai implementation: https://github.com/fastai/fastai/blob/master/fastai/callbacks/mixup.py

deregister()[source]
get_lambd(batch_size, device)[source]
on_batch_begin(data: Dict[str, Any], train) → Dict[str, Any][source]
on_batch_end(logs: Dict[str, Any])[source]
on_train_end()[source]
transform_input(inputs: torch.Tensor) → Tuple[torch.Tensor, torch.Tensor][source]
transform_labels(labels)[source]
transform_loss(criterion, train)[source]
class nntoolbox.callbacks.mixup.ManifoldMixupModule(base_module: torch.nn.modules.module.Module)[source]

Bases: torch.nn.modules.module.Module

Wrapper module to apply manifold mixup

forward(input)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool