当前位置: 首页>>代码示例>>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;未经允许,请勿转载。