當前位置: 首頁>>代碼示例>>Python>>正文


Python init.kaiming_uniform_方法代碼示例

本文整理匯總了Python中torch.nn.init.kaiming_uniform_方法的典型用法代碼示例。如果您正苦於以下問題:Python init.kaiming_uniform_方法的具體用法?Python init.kaiming_uniform_怎麽用?Python init.kaiming_uniform_使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在torch.nn.init的用法示例。


在下文中一共展示了init.kaiming_uniform_方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: init_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def init_weights(model):
    if isinstance(model, nn.Linear):
        if model.weight is not None:
            init.kaiming_uniform_(model.weight.data)
        if model.bias is not None:
            init.normal_(model.bias.data)
    elif isinstance(model, nn.BatchNorm1d):
        if model.weight is not None:
            init.normal_(model.weight.data, mean=1, std=0.02)
        if model.bias is not None:
            init.constant_(model.bias.data, 0)
    elif isinstance(model, nn.BatchNorm2d):
        if model.weight is not None:
            init.normal_(model.weight.data, mean=1, std=0.02)
        if model.bias is not None:
            init.constant_(model.bias.data, 0)
    elif isinstance(model, nn.BatchNorm3d):
        if model.weight is not None:
            init.normal_(model.weight.data, mean=1, std=0.02)
        if model.bias is not None:
            init.constant_(model.bias.data, 0)
    else:
        pass 
開發者ID:GitHub-HongweiZhang,項目名稱:prediction-flow,代碼行數:25,代碼來源:utils.py

示例2: reset_parameters

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def reset_parameters(self):
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound) 
開發者ID:rtqichen,項目名稱:residual-flows,代碼行數:8,代碼來源:lipschitz.py

示例3: reset_parameters

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def reset_parameters(self, zero_init=False):
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if zero_init:
            # normalize cannot handle zero weight in some cases.
            self.weight.data.div_(1000)
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound) 
開發者ID:rtqichen,項目名稱:residual-flows,代碼行數:11,代碼來源:mixed_lipschitz.py

示例4: reset_parameters

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def reset_parameters(self):
        n = self.in_channels
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound) 
開發者ID:ruinmessi,項目名稱:ASFF,代碼行數:9,代碼來源:deform_conv2d.py

示例5: __init__

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def __init__(self, a=0, mode='fan_in', nonlinearity='leaky_relu', modules=None,
                 targets=['Conv', 'Linear', 'Bilinear']):
        def initialiser(module):
            init.kaiming_uniform_(module.weight.data, a=a, mode=mode, nonlinearity=nonlinearity)

        super(KaimingUniform, self).__init__(initialiser, modules=modules, targets=targets) 
開發者ID:pytorchbearer,項目名稱:torchbearer,代碼行數:8,代碼來源:init.py

示例6: spectral_init

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def spectral_init(module, gain=1):
    init.kaiming_uniform_(module.weight, gain)
    if module.bias is not None:
        module.bias.data.zero_()

    return spectral_norm(module) 
開發者ID:rosinality,項目名稱:sagan-pytorch,代碼行數:8,代碼來源:model.py

示例7: __init__

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def __init__(self, input_dim, hidden_dim, num_layers):
        super(NICEModel, self).__init__()
        assert (input_dim % 2 == 0), "[NICEModel] only even input dimensions supported for now"
        assert (num_layers > 2), "[NICEModel] num_layers must be at least 3"
        self.input_dim = input_dim
        half_dim = int(input_dim / 2)
        self.layer1 = AdditiveCouplingLayer(input_dim, 'odd', _build_relu_network(half_dim, hidden_dim, num_layers))
        self.layer2 = AdditiveCouplingLayer(input_dim, 'even', _build_relu_network(half_dim, hidden_dim, num_layers))
        self.layer3 = AdditiveCouplingLayer(input_dim, 'odd', _build_relu_network(half_dim, hidden_dim, num_layers))
        self.layer4 = AdditiveCouplingLayer(input_dim, 'even', _build_relu_network(half_dim, hidden_dim, num_layers))
        self.scaling_diag = nn.Parameter(torch.ones(input_dim))

        # randomly initialize weights:
        for p in self.layer1.parameters():
            if len(p.shape) > 1:
                init.kaiming_uniform_(p, nonlinearity='relu')
            else:
                init.normal_(p, mean=0., std=0.001)
        for p in self.layer2.parameters():
            if len(p.shape) > 1:
                init.kaiming_uniform_(p, nonlinearity='relu')
            else:
                init.normal_(p, mean=0., std=0.001)
        for p in self.layer3.parameters():
            if len(p.shape) > 1:
                init.kaiming_uniform_(p, nonlinearity='relu')
            else:
                init.normal_(p, mean=0., std=0.001)
        for p in self.layer4.parameters():
            if len(p.shape) > 1:
                init.kaiming_uniform_(p, nonlinearity='relu')
            else:
                init.normal_(p, mean=0., std=0.001) 
開發者ID:paultsw,項目名稱:nice_pytorch,代碼行數:35,代碼來源:models.py

示例8: _init_params

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def _init_params(self):
        for name, module in self.named_modules():
            if isinstance(module, nn.Conv2d):
                init.kaiming_uniform_(module.weight)
                if module.bias is not None:
                    init.constant_(module.bias, 0) 
開發者ID:osmr,項目名稱:imgclsmob,代碼行數:8,代碼來源:sknet.py

示例9: _init_params

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import kaiming_uniform_ [as 別名]
def _init_params(self):
        for name, module in self.named_modules():
            if isinstance(module, nn.Conv2d):
                if 'final_conv' in name:
                    init.normal_(module.weight, mean=0.0, std=0.01)
                else:
                    init.kaiming_uniform_(module.weight)
                if module.bias is not None:
                    init.constant_(module.bias, 0) 
開發者ID:osmr,項目名稱:imgclsmob,代碼行數:11,代碼來源:squeezenet.py


注:本文中的torch.nn.init.kaiming_uniform_方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。