本文簡要介紹python語言中 torch.nn.utils.weight_norm
的用法。
用法:
torch.nn.utils.weight_norm(module, name='weight', dim=0)
module(torch.nn.Module) -包含模塊
name(str,可選的) -權重參數名稱
dim(int,可選的) -計算範數的維度
帶有重量標準掛鉤的原始模塊
將權重歸一化應用於給定模塊中的參數。
權重歸一化是將權重張量的大小與其方向解耦的重新參數化。這將
name
指定的參數(例如'weight'
)替換為兩個參數:一個指定幅度(例如'weight_g'
),另一個指定方向(例如'weight_v'
)。權重歸一化是通過一個鉤子實現的,該鉤子在每次forward()
調用之前從大小和方向重新計算權重張量。默認情況下,使用
dim=0
,每個輸出通道/平麵獨立計算範數。要計算整個權重張量的範數,請使用dim=None
。見https://arxiv.org/abs/1602.07868
例子:
>>> m = weight_norm(nn.Linear(20, 40), name='weight') >>> m Linear(in_features=20, out_features=40, bias=True) >>> m.weight_g.size() torch.Size([40, 1]) >>> m.weight_v.size() torch.Size([40, 20])
參數:
返回:
相關用法
- Python PyTorch wrap_torch_function用法及代碼示例
- Python PyTorch wrap用法及代碼示例
- Python PyTorch wav2vec2_model用法及代碼示例
- Python PyTorch where用法及代碼示例
- Python PyTorch frexp用法及代碼示例
- Python PyTorch jvp用法及代碼示例
- Python PyTorch cholesky用法及代碼示例
- Python PyTorch vdot用法及代碼示例
- Python PyTorch ELU用法及代碼示例
- Python PyTorch ScaledDotProduct.__init__用法及代碼示例
- Python PyTorch gumbel_softmax用法及代碼示例
- Python PyTorch get_tokenizer用法及代碼示例
- Python PyTorch saved_tensors_hooks用法及代碼示例
- Python PyTorch positive用法及代碼示例
- Python PyTorch renorm用法及代碼示例
- Python PyTorch AvgPool2d用法及代碼示例
- Python PyTorch MaxUnpool3d用法及代碼示例
- Python PyTorch Bernoulli用法及代碼示例
- Python PyTorch Tensor.unflatten用法及代碼示例
- Python PyTorch Sigmoid用法及代碼示例
- Python PyTorch Tensor.register_hook用法及代碼示例
- Python PyTorch ShardedEmbeddingBagCollection.named_parameters用法及代碼示例
- Python PyTorch sqrt用法及代碼示例
- Python PyTorch PackageImporter.id用法及代碼示例
- Python PyTorch column_stack用法及代碼示例
注:本文由純淨天空篩選整理自pytorch.org大神的英文原創作品 torch.nn.utils.weight_norm。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。