nntoolbox.vision.components.normalization module

class nntoolbox.vision.components.normalization.AdaIN[source]

Bases: torch.nn.modules.module.Module

Implement adaptive instance normalization layer

static compute_mean_std(images: torch.Tensor) → Tuple[torch.Tensor, torch.Tensor][source]
Parameters

images – (n_img, C, H, W)

Returns

(n_img, C, H, W)

forward(input: torch.Tensor) → 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.

set_style(style)[source]
training: bool
class nntoolbox.vision.components.normalization.BatchRenorm2D(num_features: int, r_max: float, d_max: float, eps: float = 1e-06, momentum: float = 0.1)[source]

Bases: torch.nn.modules.module.Module

Modified from batch norm implementation in FastAI course 2 v3’s notebook. Works better for smaller batches (UNTESTED)

References:

https://github.com/fastai/course-v3/blob/master/nbs/dl2/07_batchnorm.ipynb

Ioffe, Sergey. “Batch Renormalization: Towards Reducing Minibatch Dependence in Batch-Normalized Models.” https://arxiv.org/pdf/1702.03275.pdf

forward(input: torch.Tensor) → 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
update_stats(input: torch.Tensor) → Tuple[torch.Tensor, torch.Tensor, torch.Tensor, torch.Tensor][source]
class nntoolbox.vision.components.normalization.L2NormalizationLayer[source]

Bases: torch.nn.modules.module.Module

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
class nntoolbox.vision.components.normalization.SelfStabilizer(steepness: float = 4.0)[source]

Bases: torch.nn.modules.module.Module

Self stabilize layer, based on: https://www.cntk.ai/pythondocs/cntk.layers.blocks.html https://www.cntk.ai/pythondocs/_modules/cntk/layers/blocks.html#Stabilizer https://www.cntk.ai/pythondocs/layerref.html#batchnormalization-layernormalization-stabilizer https://www.microsoft.com/en-us/research/wp-content/uploads/2016/11/SelfLR.pdf

forward(input: torch.Tensor) → 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