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


Python init.uniform方法代码示例

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


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

示例1: assert_and_infer_cfg

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def assert_and_infer_cfg(make_immutable=True):
    """Call this function in your script after you have finished setting all cfg
    values that are necessary (e.g., merging a config from a file, merging
    command line config options, etc.). By default, this function will also
    mark the global cfg as immutable to prevent changing the global cfg settings
    during script execution (which can lead to hard to debug errors or code
    that's harder to understand than is necessary).
    """
    if __C.MODEL.LOAD_IMAGENET_PRETRAINED_WEIGHTS:
        assert __C.VGG.IMAGENET_PRETRAINED_WEIGHTS, \
            "Path to the weight file must not be empty to load imagenet pertrained resnets."
    if version.parse(torch.__version__) < version.parse('0.4.0'):
        __C.PYTORCH_VERSION_LESS_THAN_040 = True
        # create alias for PyTorch version less than 0.4.0
        init.uniform_ = init.uniform
        init.normal_ = init.normal
        init.constant_ = init.constant
        nn.GroupNorm = mynn.GroupNorm
    if make_immutable:
        cfg.immutable(True) 
开发者ID:ppengtang,项目名称:pcl.pytorch,代码行数:22,代码来源:config.py

示例2: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def __init__(self, input_size, activation=nn.Tanh(),
                 method="dot"):
        super(AttnScore, self).__init__()
        self.activation = activation
        self.input_size = input_size
        self.method = method
        if method == "general":
            self.linear = nn.Linear(input_size, input_size)
            init.uniform(self.linear.weight.data, -0.005, 0.005)
        elif method == "concat":
            self.linear_1 = nn.Linear(input_size*2, input_size)
            self.linear_2 = nn.Linear(input_size, 1)
            init.uniform(self.linear_1.weight.data, -0.005, 0.005)
            init.uniform(self.linear_2.weight.data, -0.005, 0.005)
        elif method == "tri_concat":
            self.linear = nn.Linear(input_size*3, 1)
            init.uniform(self.linear.weight.data, -0.005, 0.005) 
开发者ID:HKUST-KnowComp,项目名称:ASER,代码行数:19,代码来源:layers.py

示例3: forward_test

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def forward_test(self, input_features, adj):
        self.max_num_nodes = 4
        adj_data = torch.zeros(self.max_num_nodes, self.max_num_nodes)
        adj_data[:4, :4] = torch.FloatTensor([[1,1,0,0], [1,1,1,0], [0,1,1,1], [0,0,1,1]])
        adj_features = torch.Tensor([2,3,3,2])

        adj_data1 = torch.zeros(self.max_num_nodes, self.max_num_nodes)
        adj_data1 = torch.FloatTensor([[1,1,1,0], [1,1,0,1], [1,0,1,0], [0,1,0,1]])
        adj_features1 = torch.Tensor([3,3,2,2])
        S = self.edge_similarity_matrix(adj_data, adj_data1, adj_features, adj_features1,
                self.deg_feature_similarity)

        # initialization strategies
        init_corr = 1 / self.max_num_nodes
        init_assignment = torch.ones(self.max_num_nodes, self.max_num_nodes) * init_corr
        #init_assignment = torch.FloatTensor(4, 4)
        #init.uniform(init_assignment)
        assignment = self.mpm(init_assignment, S)
        #print('Assignment: ', assignment)

        # matching
        row_ind, col_ind = scipy.optimize.linear_sum_assignment(-assignment.numpy())
        print('row: ', row_ind)
        print('col: ', col_ind)

        permuted_adj = self.permute_adj(adj_data, row_ind, col_ind)
        print('permuted: ', permuted_adj)

        adj_recon_loss = self.adj_recon_loss(permuted_adj, adj_data1)
        print(adj_data1)
        print('diff: ', adj_recon_loss) 
开发者ID:JiaxuanYou,项目名称:graph-generation,代码行数:33,代码来源:model.py

示例4: weights_init_normal

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def weights_init_normal(m):
    classname = m.__class__.__name__
    # print(classname)
    if classname.find('Conv') != -1:
        init.uniform(m.weight.data, 0.0, 0.02)
    elif classname.find('Linear') != -1:
        init.uniform(m.weight.data, 0.0, 0.02)
    elif classname.find('BatchNorm2d') != -1:
        init.uniform(m.weight.data, 1.0, 0.02)
        init.constant(m.bias.data, 0.0) 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:12,代码来源:networks.py

示例5: weights_init_xavier

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def weights_init_xavier(m):
    classname = m.__class__.__name__
    # print(classname)
    if classname.find('Conv') != -1:
        init.xavier_normal(m.weight.data, gain=1)
    elif classname.find('Linear') != -1:
        init.xavier_normal(m.weight.data, gain=1)
    elif classname.find('BatchNorm2d') != -1:
        init.uniform(m.weight.data, 1.0, 0.02)
        init.constant(m.bias.data, 0.0) 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:12,代码来源:networks.py

示例6: weights_init_kaiming

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [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_in')
    elif classname.find('BatchNorm2d') != -1:
        init.uniform(m.weight.data, 1.0, 0.02)
        init.constant(m.bias.data, 0.0) 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:12,代码来源:networks.py

示例7: weights_init_orthogonal

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def weights_init_orthogonal(m):
    classname = m.__class__.__name__
    print(classname)
    if classname.find('Conv') != -1:
        init.orthogonal(m.weight.data, gain=1)
    elif classname.find('Linear') != -1:
        init.orthogonal(m.weight.data, gain=1)
    elif classname.find('BatchNorm2d') != -1:
        init.uniform(m.weight.data, 1.0, 0.02)
        init.constant(m.bias.data, 0.0) 
开发者ID:arnabgho,项目名称:iSketchNFill,代码行数:12,代码来源:networks.py

示例8: assert_and_infer_cfg

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def assert_and_infer_cfg(make_immutable=True):
    """Call this function in your script after you have finished setting all cfg
    values that are necessary (e.g., merging a config from a file, merging
    command line config options, etc.). By default, this function will also
    mark the global cfg as immutable to prevent changing the global cfg settings
    during script execution (which can lead to hard to debug errors or code
    that's harder to understand than is necessary).
    """
    if __C.MODEL.RPN_ONLY or __C.MODEL.FASTER_RCNN:
        __C.RPN.RPN_ON = True
    if __C.RPN.RPN_ON or __C.RETINANET.RETINANET_ON:
        __C.TEST.PRECOMPUTED_PROPOSALS = False
    if __C.MODEL.LOAD_IMAGENET_PRETRAINED_WEIGHTS:
        assert __C.RESNETS.IMAGENET_PRETRAINED_WEIGHTS, \
            "Path to the weight file must not be empty to load imagenet pertrained resnets."
    if set([__C.MRCNN.ROI_MASK_HEAD, __C.KRCNN.ROI_KEYPOINTS_HEAD]) & _SHARE_RES5_HEADS:
        __C.MODEL.SHARE_RES5 = True
    if version.parse(torch.__version__) < version.parse('0.4.0'):
        __C.PYTORCH_VERSION_LESS_THAN_040 = True
        # create alias for PyTorch version less than 0.4.0
        init.uniform_ = init.uniform
        init.normal_ = init.normal
        init.constant_ = init.constant
        nn.GroupNorm = mynn.GroupNorm
    if make_immutable:
        cfg.immutable(True) 
开发者ID:roytseng-tw,项目名称:Detectron.pytorch,代码行数:28,代码来源:config.py

示例9: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def __init__(self, d_in, d_out, bias=True, out_norm=False):
        super().__init__(d_in, d_out, bias)
        self.out_norm = out_norm
        stdv = 1. / math.sqrt(self.weight.size(1))
        init.uniform(self.weight, -stdv, stdv)
        if bias:
            self.bias.data.zero_() 
开发者ID:nyu-dl,项目名称:dl4mt-nonauto,代码行数:9,代码来源:model.py

示例10: init_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def init_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                if m.bias is not None:
                    init.uniform(m.bias)
                init.xavier_uniform(m.weight)

            if isinstance(m, nn.ConvTranspose2d):
                if m.bias is not None:
                    init.uniform(m.bias)
                init.xavier_uniform(m.weight)
                # init_deconv_bilinear(m.weight) 
开发者ID:anuragranj,项目名称:cc,代码行数:14,代码来源:FlowNetC6.py

示例11: init_weights

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def init_weights(self):
        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                if m.bias is not None:
                    init.uniform(m.bias)
                init.xavier_uniform(m.weight)

            if isinstance(m, nn.ConvTranspose2d):
                if m.bias is not None:
                    init.uniform(m.bias)
                init.xavier_uniform(m.weight) 
开发者ID:anuragranj,项目名称:cc,代码行数:13,代码来源:back2future.py

示例12: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def __init__(self, with_bn=False, fp16=False, rgb_max=255., div_flow=20):
        super(FlowNet2CS, self).__init__()
        self.with_bn = with_bn
        self.fp16 = fp16
        self.rgb_max = rgb_max
        self.div_flow = div_flow

        self.channelnorm = ChannelNorm()

        # First Block (FlowNetC)
        self.flownetc = FlowNetC(with_bn=with_bn, fp16=fp16)
        self.upsample1 = nn.Upsample(scale_factor=4, mode='bilinear')

        self.resample1 = (nn.Sequential(tofp32(), Resample2d(), tofp16())
                          if fp16 else Resample2d())

        # Block (FlowNetS1)
        self.flownets_1 = FlowNetS(with_bn=with_bn)
        self.upsample2 = nn.Upsample(scale_factor=4, mode='bilinear')

        for m in self.modules():
            if isinstance(m, nn.Conv2d):
                if m.bias is not None:
                    nn_init.uniform(m.bias)
                nn_init.xavier_uniform(m.weight)

            if isinstance(m, nn.ConvTranspose2d):
                if m.bias is not None:
                    nn_init.uniform(m.bias)
                nn_init.xavier_uniform(m.weight) 
开发者ID:vt-vl-lab,项目名称:flownet2.pytorch,代码行数:32,代码来源:flownet2.py

示例13: weights_init_normal

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def weights_init_normal(m):
  classname = m.__class__.__name__
  # print(classname)
  if classname.find('Conv') != -1:
    init.uniform(m.weight.data, 0.0, 0.02)
  elif classname.find('Linear') != -1:
    init.uniform(m.weight.data, 0.0, 0.02)
  elif classname.find('BatchNorm2d') != -1:
    init.uniform(m.weight.data, 1.0, 0.02)
    init.constant(m.bias.data, 0.0) 
开发者ID:D-X-Y,项目名称:landmark-detection,代码行数:12,代码来源:initialization.py

示例14: weights_init_xavier

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [as 别名]
def weights_init_xavier(m):
  classname = m.__class__.__name__
  # print(classname)
  if classname.find('Conv') != -1:
    init.xavier_normal(m.weight.data, gain=1)
  elif classname.find('Linear') != -1:
    init.xavier_normal(m.weight.data, gain=1)
  elif classname.find('BatchNorm2d') != -1:
    init.uniform(m.weight.data, 1.0, 0.02)
    init.constant(m.bias.data, 0.0) 
开发者ID:D-X-Y,项目名称:landmark-detection,代码行数:12,代码来源:initialization.py

示例15: weights_init_kaiming

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform [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_in')
  elif classname.find('BatchNorm2d') != -1:
    init.uniform(m.weight.data, 1.0, 0.02)
    init.constant(m.bias.data, 0.0) 
开发者ID:D-X-Y,项目名称:landmark-detection,代码行数:12,代码来源:initialization.py


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