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


Python init.constant_方法代码示例

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


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

示例1: _initialize_weights_norm

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

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                init.normal_(m.weight, std=0.01)
                if m.bias is not None:  # mobilenet conv2d doesn't add bias
                    init.constant_(m.bias, 0.0)

        # last layer of these block don't have Relu
        init.normal_(self.model1_1[8].weight, std=0.01)
        init.normal_(self.model1_2[8].weight, std=0.01)

        init.normal_(self.model2_1[12].weight, std=0.01)
        init.normal_(self.model3_1[12].weight, std=0.01)
        init.normal_(self.model4_1[12].weight, std=0.01)
        init.normal_(self.model5_1[12].weight, std=0.01)
        init.normal_(self.model6_1[12].weight, std=0.01)

        init.normal_(self.model2_2[12].weight, std=0.01)
        init.normal_(self.model3_2[12].weight, std=0.01)
        init.normal_(self.model4_2[12].weight, std=0.01)
        init.normal_(self.model5_2[12].weight, std=0.01)
        init.normal_(self.model6_2[12].weight, std=0.01) 
开发者ID:HaiyangLiu1997,项目名称:Pytorch-Networks,代码行数:25,代码来源:GNNlikeCNN2015.py

示例2: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def __init__(self, dim_in):
        super().__init__()
        self.dim_in = dim_in
        self.cls_on = cfg.FAST_RCNN.CLS_ON
        self.reg_on = cfg.FAST_RCNN.REG_ON

        if self.cls_on:
            self.cls_score = nn.Linear(self.dim_in, cfg.MODEL.NUM_CLASSES)
            init.normal_(self.cls_score.weight, std=0.01)
            init.constant_(self.cls_score.bias, 0)
        # self.avgpool = nn.AdaptiveAvgPool2d(1)
        if self.reg_on:
            if cfg.FAST_RCNN.CLS_AGNOSTIC_BBOX_REG:  # bg and fg
                self.bbox_pred = nn.Linear(self.dim_in, 4 * 2)
            else:
                self.bbox_pred = nn.Linear(self.dim_in, 4 * cfg.MODEL.NUM_CLASSES)
            init.normal_(self.bbox_pred.weight, std=0.001)
            init.constant_(self.bbox_pred.bias, 0) 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:20,代码来源:outputs.py

示例3: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def __init__(self, n_head, f_in, f_out, attn_dropout, bias=True):
        super(MultiHeadGraphAttention, self).__init__()
        self.n_head = n_head
        self.w = Parameter(torch.Tensor(n_head, f_in, f_out))
        self.a_src = Parameter(torch.Tensor(n_head, f_out, 1))
        self.a_dst = Parameter(torch.Tensor(n_head, f_out, 1))

        self.leaky_relu = nn.LeakyReLU(negative_slope=0.2)
        self.softmax = nn.Softmax(dim=-1)
        self.dropout = nn.Dropout(attn_dropout)

        if bias:
            self.bias = Parameter(torch.Tensor(f_out))
            init.constant_(self.bias, 0)
        else:
            self.register_parameter('bias', None)

        init.xavier_uniform_(self.w)
        init.xavier_uniform_(self.a_src)
        init.xavier_uniform_(self.a_dst) 
开发者ID:xptree,项目名称:DeepInf,代码行数:22,代码来源:gat_layers.py

示例4: init_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [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

示例5: initialize_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def initialize_weights(net_l, scale=1):
    if not isinstance(net_l, list):
        net_l = [net_l]
    for net in net_l:
        for m in net.modules():
            if isinstance(m, nn.Conv2d):
                init.kaiming_normal_(m.weight, a=0, mode='fan_in')
                m.weight.data *= scale  # for residual block
                if m.bias is not None:
                    m.bias.data.zero_()
            elif isinstance(m, nn.Linear):
                init.kaiming_normal_(m.weight, a=0, mode='fan_in')
                m.weight.data *= scale
                if m.bias is not None:
                    m.bias.data.zero_()
            elif isinstance(m, nn.BatchNorm2d):
                init.constant_(m.weight, 1)
                init.constant_(m.bias.data, 0.0) 
开发者ID:cszn,项目名称:KAIR,代码行数:20,代码来源:network_msrresnet.py

示例6: init_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def init_weights(net, init_type, init_gain):
    def init_func(m):
        classname = m.__class__.__name__
        if hasattr(m, 'weight') and (classname.find('Conv') != -1 or classname.find('Linear') != -1):
            if init_type == 'normal':
                init.normal_(m.weight.data, 0.0, init_gain)
            elif init_type == 'xavier':
                init.xavier_normal_(m.weight.data, gain=init_gain)
            elif init_type == 'kaiming':
                init.kaiming_normal_(m.weight.data, a=0, mode='fan_in')
            elif init_type == 'orthogonal':
                init.orthogonal_(m.weight.data, gain=init_gain)
            else:
                raise NotImplementedError('initialization method [%s] is not implemented' % init_type)
        elif classname.find('BatchNorm2d') != -1:
            init.normal_(m.weight.data, 1.0, init_gain)
            init.constant_(m.bias.data, 0.0)
    net.apply(init_func) 
开发者ID:ranahanocka,项目名称:MeshCNN,代码行数:20,代码来源:networks.py

示例7: init_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def init_weights(net, init_type='normal', gain=0.02):
    def init_func(m):
        # this will apply to each layer
        classname = m.__class__.__name__
        if hasattr(m, 'weight') and (classname.find('conv')!=-1 or classname.find('Linear')!=-1):
            if init_type=='normal':
                init.normal_(m.weight.data, 0.0, gain)
            elif init_type == 'xavier':
                init.xavier_normal_(m.weight.data, gain=gain)
            elif init_type == 'kaiming':
                init.kaiming_normal_(m.weight.data, a=0, mode='fan_in')#good for relu
            elif init_type == 'orthogonal':
                init.orthogonal_(m.weight.data, gain=gain)
            else:
                raise NotImplementedError('initialization method [%s] is not implemented' % init_type)
            
            if hasattr(m, 'bias') and m.bias is not None:
                init.constant_(m.bias.data, 0.0)
        elif classname.find('BatchNorm2d') != -1:
            init.normal_(m.weight.data, 1.0, gain)
            init.constant_(m.bias.data, 0.0)
    #print('initialize network with %s' % init_type)
    net.apply(init_func)


############################################
# save checkpoint and resume
############################################ 
开发者ID:songdejia,项目名称:DeepLab_v3_plus,代码行数:30,代码来源:util.py

示例8: initialize_weight

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def initialize_weight(self):
        for m in self.modules():
            #print('need check init')
            if isinstance(m, nn.Conv2d):
                init.xavier_normal_(m.weight)
                #init.normal_(m.weight, std = 0.01)
                if m.bias is not None:
                    init.constant_(m.bias, 0.0)
            else: 
                try:init.constant_(m.weight,0.0)
                except:pass 
开发者ID:HaiyangLiu1997,项目名称:Pytorch-Networks,代码行数:13,代码来源:OpenPose2017.py

示例9: initi

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def initi(self):
        #init.kaiming_normal_(self.con_layer.weight, a=0, mode='fan_in', nonlinearity='relu')
        init.normal_(self.con_layer.weight, std=0.01)
        if self.con_layer.bias is not None:  
            init.constant_(self.con_layer.bias, 0.0) 
开发者ID:HaiyangLiu1997,项目名称:Pytorch-Networks,代码行数:7,代码来源:OpenPose2015.py

示例10: _initialize_weights_norm

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def _initialize_weights_norm(self):        
       for m in self.modules():
            if isinstance(m, nn.Conv2d):
                init.normal_(m.weight, std=0.01)
                if m.bias is not None:  # mobilenet conv2d doesn't add bias
                    init.constant_(m.bias, 0.0) 
            elif isinstance(m, nn.BatchNorm2d):
                m.weight.data.fill_(1)
                m.bias.data.zero_() 
开发者ID:HaiyangLiu1997,项目名称:Pytorch-Networks,代码行数:11,代码来源:Hourglass2015.py

示例11: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def __init__(self, input_feature_size, embeding_fea_size=1024, dropout=0.5):
        super(self.__class__, self).__init__()

        # embeding
        self.embeding_fea_size = embeding_fea_size
        self.embeding = nn.Linear(input_feature_size, embeding_fea_size)
        self.embeding_bn = nn.BatchNorm1d(embeding_fea_size)
        init.kaiming_normal_(self.embeding.weight, mode='fan_out')
        init.constant_(self.embeding.bias, 0)
        init.constant_(self.embeding_bn.weight, 1)
        init.constant_(self.embeding_bn.bias, 0)
        self.drop = nn.Dropout(dropout) 
开发者ID:gddingcs,项目名称:Dispersion-based-Clustering,代码行数:14,代码来源:end2end.py

示例12: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def reset_parameters(self):
        init.constant_(self.std, 1)
        if self.mu is not None:
            init.constant_(self.mu, 0) 
开发者ID:lukasruff,项目名称:Deep-SAD-PyTorch,代码行数:6,代码来源:standard.py

示例13: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def reset_parameters(self):
        init.constant_(self.weight, self.gamma) 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:4,代码来源:l2norm.py

示例14: _init_modules

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def _init_modules(self, m):
        if isinstance(m, nn.Conv2d):
            init.normal_(m.weight, std=0.01)
            if m.bias is not None:
                init.constant_(m.bias, 0)
        elif isinstance(m, nn.GroupNorm):
            m.weight.data.fill_(1)
            m.bias.data.zero_() 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:10,代码来源:nonlocal2d.py

示例15: _init_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import constant_ [as 别名]
def _init_weights(self):
        init.normal_(self.cls_score.weight, std=0.01)
        init.constant_(self.cls_score.bias, 0)
        init.normal_(self.bbox_pred.weight, std=0.001)
        init.constant_(self.bbox_pred.bias, 0) 
开发者ID:soeaver,项目名称:Parsing-R-CNN,代码行数:7,代码来源:outputs.py


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