• Docs >
  • deel.torchlip.normalizers module
Shortcuts

deel.torchlip.normalizers module

The deel.torchlip.normalizers module contains various functions to normalize weights tensors so that all their singular values equal 1.

Normalizers

This module contains computation functions for Bjorck and spectral normalization. This is most for internal use.

deel.torchlip.normalizers.bjorck_normalization(w: torch.Tensor, niter: int = 15, beta: float = 0.5) torch.Tensor[source]

Apply Bjorck normalization on the kernel as per

W0=WWn+1=(1+β)WnβWnWnTWnW=WN\begin{array}{l} W_0 = W \\ W_{n + 1} = (1 + \beta) W_{n} - \beta W_n W_n^T W_n \\ \overline{W} = W_{N} \end{array}

where WW is the kernel of shape (C,)(C, *), with CC the number of channels.

Parameters
  • w – Weights to normalize. For the normalization to work properly, the greatest eigen value of w must be approximately 1.

  • niter – Number of iterations.

  • beta – Value of β\beta to use.

Returns

The weights W\overline{W} after Bjorck normalization.

deel.torchlip.normalizers.spectral_normalization(kernel: torch.Tensor, u: Optional[torch.Tensor] = None, niter: int = 3) Tuple[torch.Tensor, torch.Tensor, torch.Tensor][source]

Apply spectral normalization on the given kernel WW to set its greatest eigen value to approximately 1.

Note

This function is provided for completeness since torchlip layers use the torch.nn.utils.spectral_norm() hook instead.

Parameters
  • kernel – The kernel to normalize.

  • u – Initialization for the initial singular vector. If None, it will be randomly initialized from a normal distribution and twice as much iterations will be performed.

  • niter – Number of iteration. If u is not specified, we perform twice as much iterations.

Returns

The normalized kernel W\overline{W}, the right singular vector corresponding to the largest singular value, and the largest singular value before normalization.


© Copyright 2020, IRT Antoine de Saint Exupéry - All rights reserved. DEEL is a research program operated by IVADO, IRT Saint Exupéry, CRIAQ and ANITI..

Built with Sphinx using PyTorch's theme provided originally by Read the Docs.