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


Python init.normal_方法代碼示例

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


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

示例1: _initialize_weights_norm

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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 normal_ [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_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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

示例4: init_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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

示例5: weights_init

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def weights_init(m):
    '''
    Code from https://gist.github.com/jeasinema/ed9236ce743c8efaf30fa2ff732749f5
    Usage:
        model = Model()
        model.apply(weight_init)
    '''
    if isinstance(m, nn.Linear):
        init.xavier_normal_(m.weight.data)
        init.normal_(m.bias.data)
    elif isinstance(m, nn.GRUCell):
        for param in m.parameters():
            if len(param.shape) >= 2:
                init.orthogonal_(param.data)
            else:
                init.normal_(param.data) 
開發者ID:dmlc,項目名稱:dgl,代碼行數:18,代碼來源:utils.py

示例6: dgmg_message_weight_init

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def dgmg_message_weight_init(m):
    """
    This is similar as the function above where we initialize linear layers from a normal distribution with std
    1./10 as suggested by the author. This should only be used for the message passing functions, i.e. fe's in the
    paper.
    """
    def _weight_init(m):
        if isinstance(m, nn.Linear):
            init.normal_(m.weight.data, std=1./10)
            init.normal_(m.bias.data, std=1./10)
        else:
            raise ValueError('Expected the input to be of type nn.Linear!')

    if isinstance(m, nn.ModuleList):
        for layer in m:
            layer.apply(_weight_init)
    else:
        m.apply(_weight_init) 
開發者ID:dmlc,項目名稱:dgl,代碼行數:20,代碼來源:utils.py

示例7: init_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def init_weights(m, mode='MSRAFill'):
    import torch.nn as nn
    import torch.nn.init as init
    from torchlab.nnlib.init import XavierFill, MSRAFill
    if isinstance(m, (nn.Conv2d, nn.ConvTranspose2d)):
        if mode == 'GaussianFill':
            init.normal_(m.weight, std=0.001)
        elif mode == 'MSRAFill':
            MSRAFill(m.weight)            
        else:
            raise ValueError
        if m.bias is not None:
            init.constant_(m.bias, 0)
    if isinstance(m, nn.Linear):
        XavierFill(m.weight)
        init.constant_(m.bias, 0) 
開發者ID:liruilong940607,項目名稱:Pose2Seg,代碼行數:18,代碼來源:torch_utils.py

示例8: init_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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) 
開發者ID:songdejia,項目名稱:Siamese-RPN-pytorch,代碼行數:25,代碼來源:train_siamrpn.py

示例9: _weight_init

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def _weight_init(self, m):
        if (m is None) or (not hasattr(m, "weight")):
            return

        if (m.bias is not None) and hasattr(m, "bias"):
            m.bias.data.zero_()

        if isinstance(m, Conv2d):
            self.init_fc(m.weight)
            # m.bias.data.zero_()
        elif isinstance(m, Linear):
            self.init_fc(m.weight)
            # m.bias.data.zero_()
        elif isinstance(m, ConvTranspose2d):
            self.init_fc(m.weight)
            # m.bias.data.zero_()
        elif isinstance(m, InstanceNorm2d):
            init.normal_(m.weight, 1.0, 0.02)
            # m.bias.data.fill_(0)
        elif isinstance(m, BatchNorm2d):
            init.normal_(m.weight, 1.0, 0.02)
            # m.bias.data.fill_(0)
        else:
            pass 
開發者ID:dingguanglei,項目名稱:jdit,代碼行數:26,代碼來源:model.py

示例10: init_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def init_weights(net, init_type='normal', gain=0.02):
    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, 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')
            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) 
開發者ID:Lotayou,項目名稱:densebody_pytorch,代碼行數:24,代碼來源:networks.py

示例11: init_weights

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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

示例12: __init__

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def __init__(self):

        super().__init__()
        self.embed = nn.Parameter(torch.FloatTensor(hp.token_num, hp.E // hp.num_heads))
        d_q = hp.E // 2
        d_k = hp.E // hp.num_heads
        # self.attention = MultiHeadAttention(hp.num_heads, d_model, d_q, d_v)
        self.attention = MultiHeadAttention(query_dim=d_q, key_dim=d_k, num_units=hp.E, num_heads=hp.num_heads)

        init.normal_(self.embed, mean=0, std=0.5) 
開發者ID:KinglittleQ,項目名稱:GST-Tacotron,代碼行數:12,代碼來源:GST.py

示例13: initialize_weight

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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

示例14: initilization

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [as 別名]
def initilization(self):
        for m in self.modules():
            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,代碼行數:12,代碼來源:OpenPose2017.py

示例15: initi

# 需要導入模塊: from torch.nn import init [as 別名]
# 或者: from torch.nn.init import normal_ [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


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