当前位置: 首页>>代码示例>>Python>>正文


Python init.zeros_方法代码示例

本文整理汇总了Python中torch.nn.init.zeros_方法的典型用法代码示例。如果您正苦于以下问题:Python init.zeros_方法的具体用法?Python init.zeros_怎么用?Python init.zeros_使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在torch.nn.init的用法示例。


在下文中一共展示了init.zeros_方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _initialize_weights_norm

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def _initialize_weights_norm(self):

        # last layer of these block don't have Relu
        for i in range(5):
            init.zeros_(self.gnn_0[i].weight)
            init.zeros_(self.gnn_1[i].weight)
            init.zeros_(self.gnn_2[i].weight)
            init.zeros_(self.gnn_3[i].weight)
            init.zeros_(self.gnn_4[i].weight)
            init.zeros_(self.gnn_5[i].weight)
            init.zeros_(self.gnn_6[i].weight)
            init.zeros_(self.gnn_7[i].weight)
            init.zeros_(self.gnn_8[i].weight)

            init.zeros_(self.gnn_9[i].weight)
            init.zeros_(self.gnn_10[i].weight)
            
            init.zeros_(self.gnn_11[i].weight)
            init.zeros_(self.gnn_12[i].weight)
            init.zeros_(self.gnn_13[i].weight)
            init.zeros_(self.gnn_14[i].weight)
            init.zeros_(self.gnn_15[i].weight)
            init.zeros_(self.gnn_16[i].weight)
            init.zeros_(self.gnn_17[i].weight) 
开发者ID:HaiyangLiu1997,项目名称:Pytorch-Networks,代码行数:26,代码来源:GNNlikeCNN2015.py

示例2: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def __init__(self, features, activation, zero_initialization=True,
                 dropout_probability=0.1, use_batch_norm=True):
        super().__init__()
        self.activation = activation

        self.use_batch_norm = use_batch_norm
        if use_batch_norm:
            self.batch_norm_layers = nn.ModuleList([
                nn.BatchNorm1d(features, eps=1e-3)
                for _ in range(2)
            ])
        self.layers = nn.ModuleList([
            nn.Linear(features, features)
            for _ in range(2)
        ])
        self.dropout = nn.Dropout(p=dropout_probability)
        if zero_initialization:
            init.zeros_(self.layers[-1].weight)
            init.zeros_(self.layers[-1].bias) 
开发者ID:conormdurkan,项目名称:autoregressive-energy-machines,代码行数:21,代码来源:energy.py

示例3: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def __init__(self, features, autoregressive_features, activation=F.relu,
                 zero_initialization=True, dropout_probability=0., use_batch_norm=False):
        super().__init__()
        self.features = features
        self.activation = activation

        self.use_batch_norm = use_batch_norm
        if use_batch_norm:
            self.batch_norm_layers = nn.ModuleList([
                nn.BatchNorm1d(features, eps=1e-3)
                for _ in range(2)
            ])
        self.layers = nn.ModuleList([
            MaskedLinear(features, features, autoregressive_features)
            for _ in range(2)
        ])
        self.dropout = nn.Dropout(p=dropout_probability)
        if zero_initialization:
            init.zeros_(self.layers[-1].weight)
            init.zeros_(self.layers[-1].bias) 
开发者ID:conormdurkan,项目名称:autoregressive-energy-machines,代码行数:22,代码来源:made.py

示例4: _initialize

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def _initialize(self, identity_init):
        init.zeros_(self.bias)

        if identity_init:
            init.zeros_(self.lower_entries)
            init.zeros_(self.upper_entries)
            constant = np.log(np.exp(1 - self.eps) - 1)
            init.constant_(self.unconstrained_upper_diag, constant)
        else:
            stdv = 1.0 / np.sqrt(self.features)
            init.uniform_(self.lower_entries, -stdv, stdv)
            init.uniform_(self.upper_entries, -stdv, stdv)
            init.uniform_(self.unconstrained_upper_diag, -stdv, stdv) 
开发者ID:bayesiains,项目名称:nsf,代码行数:15,代码来源:lu.py

示例5: _initialize

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def _initialize(self):
        init.ones_(self.weights.weight.data)
        init.zeros_(self.biases.weight.data) 
开发者ID:crcrpar,项目名称:pytorch.sngan_projection,代码行数:5,代码来源:conditional_batchnorm.py

示例6: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        """Reinitialize learnable parameters."""
        gain = init.calculate_gain('relu')
        init.xavier_normal_(self.fc.weight, gain=gain)
        if isinstance(self.res_fc, nn.Linear):
            init.xavier_normal_(self.res_fc.weight, gain=gain)
        init.normal_(self.mu.data, 0, 0.1)
        init.constant_(self.inv_sigma.data, 1)
        if self.bias is not None:
            init.zeros_(self.bias.data) 
开发者ID:dmlc,项目名称:dgl,代码行数:12,代码来源:gmmconv.py

示例7: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        """Reinitialize learnable parameters."""
        gain = init.calculate_gain('relu')
        self.gru.reset_parameters()
        for linear in self.linears:
            init.xavier_normal_(linear.weight, gain=gain)
            init.zeros_(linear.bias) 
开发者ID:dmlc,项目名称:dgl,代码行数:9,代码来源:gatedgraphconv.py

示例8: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        """Reinitialize learnable parameters."""
        if self.bias is not None:
            init.zeros_(self.bias)
        for i in range(self._k):
            init.xavier_normal_(self.W[i], init.calculate_gain('relu')) 
开发者ID:dmlc,项目名称:dgl,代码行数:8,代码来源:densechebconv.py

示例9: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        """Reinitialize learnable parameters."""
        init.xavier_uniform_(self.weight)
        if self.bias is not None:
            init.zeros_(self.bias) 
开发者ID:dmlc,项目名称:dgl,代码行数:7,代码来源:densegraphconv.py

示例10: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        """Reinitialize learnable parameters."""
        if self.weight is not None:
            init.xavier_uniform_(self.weight)
        if self.bias is not None:
            init.zeros_(self.bias) 
开发者ID:dmlc,项目名称:dgl,代码行数:8,代码来源:graphconv.py

示例11: weights_init_kaiming

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def weights_init_kaiming(m):
    classname = m.__class__.__name__
    # print(classname)
    if classname.find('Conv') != -1:
        init.kaiming_normal_(m.weight.data, a=0, mode='fan_in')
    elif classname.find('Linear') != -1:
        init.kaiming_normal_(m.weight.data, a=0, mode='fan_out')
        init.zeros_(m.bias.data)
    elif classname.find('BatchNorm1d') != -1:
        init.normal_(m.weight.data, 1.0, 0.01)
        init.zeros_(m.bias.data) 
开发者ID:mangye16,项目名称:Cross-Modal-Re-ID-baseline,代码行数:13,代码来源:model.py

示例12: weights_init_classifier

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def weights_init_classifier(m):
    classname = m.__class__.__name__
    if classname.find('Linear') != -1:
        init.normal_(m.weight.data, 0, 0.001)
        if m.bias:
            init.zeros_(m.bias.data) 
开发者ID:mangye16,项目名称:Cross-Modal-Re-ID-baseline,代码行数:8,代码来源:model.py

示例13: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        if self.elementwise_affine:
            init.ones_(self.weight)
            init.zeros_(self.bias) 
开发者ID:mlperf,项目名称:training_results_v0.5,代码行数:6,代码来源:fused_layer_norm.py

示例14: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        self.reset_running_stats()
        init.uniform_(self.weight)
        init.zeros_(self.bias) 
开发者ID:ajbrock,项目名称:BigGAN-PyTorch,代码行数:6,代码来源:batchnorm_reimpl.py

示例15: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import zeros_ [as 别名]
def reset_parameters(self):
        self.reset_running_stats()
        if self.affine:
            init.constant_(self.weight[:,:2],1.4142135623730951)
            init.zeros_(self.weight[:,2])
            init.zeros_(self.bias) 
开发者ID:wavefrontshaping,项目名称:complexPyTorch,代码行数:8,代码来源:complexLayers.py


注:本文中的torch.nn.init.zeros_方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。