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