nntoolbox.vision.components.regularization module

class nntoolbox.vision.components.regularization.ShakeShake(keep: str = 'shake')[source]

Bases: torch.nn.modules.module.Module

Implement shake-shake regularizer:

y = x + sum_i alpha_i branch_i

(alpha_i > 0 are random variables such that sum_i alpha_i = 1)

At test time:

y = x + 1 / n_branch sum_i branch_i

Based on https://arxiv.org/abs/1705.07485

forward(branches: torch.Tensor, training: bool) → torch.Tensor[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