用法:
torch.nn.utils.spectral_norm(module, name='weight', n_power_iterations=1, eps=1e-12, dim=None)
module(torch.nn.Module) -包含模块
name(str,可选的) -权重参数名称
n_power_iterations(int,可选的) -计算频谱范数的幂迭代次数
eps(float,可选的) -epsilon 用于计算范数时的数值稳定性
dim(int,可选的) -与输出数量对应的维度,默认为
0
,但作为 ConvTranspose{1,2,3}d 实例的模块除外,当它为1
带有频谱规范钩子的原始模块
将频谱归一化应用于给定模块中的参数。
谱归一化通过使用幂迭代方法计算的权重矩阵的谱范数
forward()
调用之前计算谱范数并重新调整权重。 重新缩放权重张量,稳定了生成对抗网络 (GAN) 中鉴别器(批评者)的训练。如果权重张量的维数大于 2,则在幂迭代法中将其重塑为 2D 以获得谱范数。这是通过一个钩子实现的,该钩子在每次参看生成对抗网络的频谱归一化.
注意
此函数已使用
torch.nn.utils.parametrize.register_parametrization()
torch.nn.utils.parametrizations.spectral_norm()
例子:
>>> m = spectral_norm(nn.Linear(20, 40)) >>> m Linear(in_features=20, out_features=40, bias=True) >>> m.weight_u.size() torch.Size([40])
参数:
返回:
相关用法
- Python torch.nn.utils.skip_init用法及代码示例
- Python torch.nn.utils.prune.custom_from_mask用法及代码示例
- Python torch.nn.utils.rnn.pad_sequence用法及代码示例
- Python torch.nn.utils.remove_spectral_norm用法及代码示例
- Python torch.nn.utils.prune.random_structured用法及代码示例
- Python torch.nn.utils.parametrize.register_parametrization用法及代码示例
- Python torch.nn.utils.parametrizations.orthogonal用法及代码示例
- Python torch.nn.utils.rnn.pad_packed_sequence用法及代码示例
- Python torch.nn.utils.prune.is_pruned用法及代码示例
- Python torch.nn.utils.prune.random_unstructured用法及代码示例
- Python torch.nn.utils.prune.global_unstructured用法及代码示例
- Python torch.nn.utils.rnn.pack_sequence用法及代码示例
- Python torch.nn.utils.prune.l1_unstructured用法及代码示例
- Python torch.nn.utils.parametrize.cached用法及代码示例
- Python torch.nn.utils.prune.identity用法及代码示例
- Python torch.nn.utils.prune.remove用法及代码示例
- Python torch.nn.utils.parametrizations.spectral_norm用法及代码示例
- Python torch.nn.utils.remove_weight_norm用法及代码示例
- Python torch.nn.utils.weight_norm用法及代码示例
- Python torch.nn.utils.prune.ln_structured用法及代码示例
- Python torch.nn.InstanceNorm3d用法及代码示例
- Python torch.nn.quantized.dynamic.LSTM用法及代码示例
- Python torch.nn.EmbeddingBag用法及代码示例
- Python torch.nn.Module.register_forward_hook用法及代码示例
- Python torch.nn.AvgPool2d用法及代码示例
注:本文由纯净天空筛选整理自pytorch.org大神的英文原创作品 torch.nn.utils.spectral_norm。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。