本文整理汇总了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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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'))
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)