torch.nn.utils.spectral_norm
function spectral_norm<T extends Module>(module: T, options?: SpectralNormOptions): Tfunction spectral_norm<T extends Module>(module: T, name: string, n_power_iterations: number, eps: number, dim: number, options?: SpectralNormOptions): TApply spectral normalization to a parameter in the given module.
Spectral normalization constrains the Lipschitz constant of the layer by normalizing the weight by its spectral norm (largest singular value). This is commonly used in GANs to stabilize training.
The spectral norm is estimated using power iteration.
Parameters
moduleT- Module containing the parameter
optionsSpectralNormOptionsoptional- Optional settings for spectral normalization
Returns
T– The module with spectral normalization appliedExamples
const conv = new torch.nn.Conv2d(3, 64, 3);
torch.nn.utils.spectral_norm(conv, { name: 'weight' });
// The weight is now normalized by its spectral norm