当前位置: 首页>>代码示例>>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: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def __init__(self, features, orthogonal_initialization=True, using_cache=False):
        """Constructor.

        Args:
            features: int, number of input features.
            orthogonal_initialization: bool, if True initialize weights to be a random
                orthogonal matrix.

        Raises:
            TypeError: if `features` is not a positive integer.
        """
        super().__init__(features, using_cache)

        if orthogonal_initialization:
            self._weight = nn.Parameter(utils.random_orthogonal(features))
        else:
            self._weight = nn.Parameter(torch.empty(features, features))
            stdv = 1.0 / np.sqrt(features)
            init.uniform_(self._weight, -stdv, stdv) 
开发者ID:bayesiains,项目名称:nsf,代码行数:21,代码来源:linear.py

示例2: 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

示例3: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def __init__(self,
                 features,
                 context_features,
                 activation=F.relu,
                 dropout_probability=0.,
                 use_batch_norm=False,
                 zero_initialization=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)
            ])
        if context_features is not None:
            self.context_layer = nn.Linear(context_features, features)
        self.linear_layers = nn.ModuleList([
            nn.Linear(features, features)
            for _ in range(2)
        ])
        self.dropout = nn.Dropout(p=dropout_probability)
        if zero_initialization:
            init.uniform_(self.linear_layers[-1].weight, -1e-3, 1e-3)
            init.uniform_(self.linear_layers[-1].bias, -1e-3, 1e-3) 
开发者ID:bayesiains,项目名称:nsf,代码行数:28,代码来源:resnet.py

示例4: _initialize

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [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) 
开发者ID:bayesiains,项目名称:nsf,代码行数:15,代码来源:lu.py

示例5: _initialize

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def _initialize(self):
        stdv = 1.0 / np.sqrt(self.features)
        init.uniform_(self.upper_entries, -stdv, stdv)
        init.uniform_(self.log_upper_diag, -stdv, stdv)
        init.constant_(self.bias, 0.0) 
开发者ID:bayesiains,项目名称:nsf,代码行数:7,代码来源:qr.py

示例6: _initialize

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def _initialize(self):
        stdv = 1.0 / np.sqrt(self.features)
        init.uniform_(self.log_diagonal, -stdv, stdv)
        init.constant_(self.bias, 0.0) 
开发者ID:bayesiains,项目名称:nsf,代码行数:6,代码来源:svd.py

示例7: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def reset_parameters(self):
        stdv = 1.0 / math.sqrt(self.hidden_size)
        for weight in self.parameters():
            init.uniform_(weight, -stdv, stdv) 
开发者ID:GitHub-HongweiZhang,项目名称:prediction-flow,代码行数:6,代码来源:rnn.py

示例8: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def reset_parameters(self):
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound) 
开发者ID:rtqichen,项目名称:residual-flows,代码行数:8,代码来源:lipschitz.py

示例9: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def reset_parameters(self, zero_init=False):
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if zero_init:
            # normalize cannot handle zero weight in some cases.
            self.weight.data.div_(1000)
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound) 
开发者ID:rtqichen,项目名称:residual-flows,代码行数:11,代码来源:mixed_lipschitz.py

示例10: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def reset_parameters(self):
        n = self.in_channels
        init.kaiming_uniform_(self.weight, a=math.sqrt(5))
        if self.bias is not None:
            fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
            bound = 1 / math.sqrt(fan_in)
            init.uniform_(self.bias, -bound, bound) 
开发者ID:ruinmessi,项目名称:ASFF,代码行数:9,代码来源:deform_conv2d.py

示例11: __init__

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def __init__(self, emb_size, emb_dimension):
        super(SkipGramModel, self).__init__()
        self.emb_size = emb_size
        self.emb_dimension = emb_dimension
        self.u_embeddings = nn.Embedding(emb_size, emb_dimension, sparse=True)
        self.v_embeddings = nn.Embedding(emb_size, emb_dimension, sparse=True)

        initrange = 1.0 / self.emb_dimension
        init.uniform_(self.u_embeddings.weight.data, -initrange, initrange)
        init.constant_(self.v_embeddings.weight.data, 0) 
开发者ID:dmlc,项目名称:dgl,代码行数:12,代码来源:model.py

示例12: init

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def init(self, emb_init):
        """Initializing the embeddings.

        Parameters
        ----------
        emb_init : float
            The intial embedding range should be [-emb_init, emb_init].
        """
        INIT.uniform_(self.emb, -emb_init, emb_init)
        INIT.zeros_(self.state_sum) 
开发者ID:dmlc,项目名称:dgl,代码行数:12,代码来源:tensor_models.py

示例13: reset_parameters

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def reset_parameters(self):
        """
        This method initializes or reset all the parameters of the cell.
        The paramaters are initiated following a uniform distribution.
        """
        std = 1.0 / np.sqrt(self.hidden_size)
        for w in self.parameters():
            init.uniform_(w, -std, std) 
开发者ID:OpenMined,项目名称:PySyft,代码行数:10,代码来源:rnn.py

示例14: XavierFill

# 需要导入模块: from torch.nn import init [as 别名]
# 或者: from torch.nn.init import uniform_ [as 别名]
def XavierFill(tensor):
    """Caffe2 XavierFill Implementation"""
    size = reduce(operator.mul, tensor.shape, 1)
    fan_in = size / tensor.shape[0]
    scale = math.sqrt(3 / fan_in)
    return init.uniform_(tensor, -scale, scale) 
开发者ID:roytseng-tw,项目名称:Detectron.pytorch,代码行数:8,代码来源:init.py

示例15: 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


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