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


Python chainer.Parameter方法代码示例

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


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

示例1: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def __init__(self, ch=512, ch_in=512, w_ch=512, upsample=True, enable_blur=False):
        super().__init__()
        self.upsample = upsample
        self.ch = ch
        self.ch_in = ch_in
        self.w_ch = w_ch
        with self.init_scope(): 
            if not upsample:
                self.W = chainer.Parameter(shape=(ch_in, 4, 4))
                self.W.data[:] = 1  # w_data_tmp

            self.b0 = L.Bias(axis=1, shape=(ch,))
            self.b1 = L.Bias(axis=1, shape=(ch,))
            self.n0 = NoiseBlock(ch)
            self.n1 = NoiseBlock(ch)

            self.s0 = StyleBlock(w_ch, ch)
            self.s1 = StyleBlock(w_ch, ch)

            self.c0 = EqualizedConv2d(ch_in, ch, 3, 1, 1, nobias=True)
            self.c1 = EqualizedConv2d(ch, ch, 3, 1, 1, nobias=True)

        self.blur_k = None
        self.enable_blur = enable_blur 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:26,代码来源:net.py

示例2: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def __init__(self, axis=1, W_shape=None, bias_term=False, bias_shape=None, initialW=None, initial_bias=None):
        super(Scale, self).__init__()
        self.axis = axis

        with self.init_scope():
            # Add W parameter and/or bias term.
            if W_shape is not None:
                if initialW is None:
                    initialW = 1
                W_initializer = initializers._get_initializer(initialW)
                self.W = variable.Parameter(W_initializer, W_shape)
                if bias_term:
                    self.bias = Bias(axis, W_shape, initial_bias)
            else:
                if bias_term:
                    if bias_shape is None:
                        raise ValueError(
                            'bias_shape should be given if W is not '
                            'learnt parameter and bias_term is True.')
                    self.bias = Bias(axis, W_shape, initial_bias) 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:22,代码来源:scale.py

示例3: convert_parameter

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def convert_parameter(parameter, name):
    if isinstance(parameter, chainer.Parameter):
        array = parameter.array
    elif isinstance(parameter, chainer.Variable):
        array = parameter.array
    elif isinstance(parameter, np.ndarray):
        array = parameter
    else:
        raise ValueError(
            'The type of parameter is unknown. It should be either Parameter '
            'or Variable or ndarray, but the type was {}.'.format(
                type(parameter)))
    if array.shape == ():
        array = array[None]
    # print('initialize', name, array)
    return tensor_from_array(array, name)

# 入力xから次元を決める
# モデルにxを流して最初の重みを決める 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:21,代码来源:initializer.py

示例4: convert_parameter

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def convert_parameter(parameter, name):
    if isinstance(parameter, chainer.Parameter):
        array = parameter.array
    elif isinstance(parameter, chainer.Variable):
        array = parameter.array
    elif isinstance(parameter, np.ndarray):
        array = parameter
    else:
        raise ValueError(
            'The type of parameter is unknown. It should be either Parameter '
            'or Variable or ndarray, but the type was {}.'.format(
                type(parameter)))
    if array.shape == ():
        array = array[None]
    # print('initialize', name, array)
    return onnx.numpy_helper.from_array(array, name)

# 入力xから次元を決める
# モデルにxを流して最初の重みを決める 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:21,代码来源:initializer.py

示例5: set_name

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def set_name(self, variable, name, pinned=False):
        """Set ONNX node name

        Arguments:
            variable (var): target variable
            name (str): name to be exported as ONNX node name
            pinned (bool): if ``True``, the name will not be overwritten in
                subsequence process.
        """

        str_id = id(variable)
        assert str_id not in self.name_list or not self.name_list[str_id][1]
        self.name_list[str_id] = (name, pinned)
        if isinstance(variable, (chainer.Variable, chainer.Parameter)):
            array_id = id(variable.array)
            self.name_list[array_id] = (name, pinned) 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:context.py

示例6: setUp

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def setUp(self):
        x_shape_0 = 2
        x_shape_1 = numpy.int64(3)
        self.link = chainer.Link(x=((x_shape_0, x_shape_1), 'd'),
                                 u=(None, 'd'))
        with self.link.init_scope():
            self.link.y = chainer.Parameter(shape=(2,))
            self.link.v = chainer.Parameter()
        self.p = numpy.array([1, 2, 3], dtype='f')
        self.link.add_persistent('p', self.p)
        self.link.name = 'a'
        self.link.x.update_rule = chainer.UpdateRule()
        self.link.x.update_rule.enabled = False
        self.link.u.update_rule = chainer.UpdateRule()
        if cuda.available:
            self.current_device_id = cuda.cupy.cuda.get_device_id() 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:test_link.py

示例7: test_serialize

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def test_serialize(self, backend_config):
        call_record = []

        def serializer(key, value):
            call_record.append((key, value))
            return value

        l = chainer.Link()
        with l.init_scope():
            l.x = chainer.Parameter()  # uninitialized
        l.to_device(backend_config.device)

        l.serialize(serializer)

        # Link is kept uninitialized
        self.assertIsNone(l.x.array)

        # Check inputs to the serializer
        self.assertEqual(len(call_record), 1)
        self.assertEqual(call_record[0][0], 'x')
        self.assertIs(call_record[0][1], None) 
开发者ID:chainer,项目名称:chainer,代码行数:23,代码来源:test_link.py

示例8: test_deserialize

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def test_deserialize(self, backend_config):
        # Deserializes uninitialized parameters into uninitialied ones.
        call_record = []

        def serializer(key, value):
            call_record.append((key, value))
            return None  # to be uninitialized

        l = chainer.Link()
        with l.init_scope():
            l.x = chainer.Parameter()  # uninitialized
        l.to_device(backend_config.device)

        l.serialize(serializer)

        # Link is kept uninitialized
        self.assertIsNone(l.x.array)

        # Check inputs to the serializer
        self.assertEqual(len(call_record), 1)
        self.assertEqual(call_record[0][0], 'x')
        self.assertIs(call_record[0][1], None) 
开发者ID:chainer,项目名称:chainer,代码行数:24,代码来源:test_link.py

示例9: test_copyparams

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def test_copyparams(self):
        l1 = chainer.Link()
        with l1.init_scope():
            l1.x = chainer.Parameter(shape=(2, 3))
            l1.y = chainer.Parameter()
        l2 = chainer.Link()
        with l2.init_scope():
            l2.x = chainer.Parameter(shape=2)
        l3 = chainer.Link()
        with l3.init_scope():
            l3.x = chainer.Parameter(shape=3)
        c1 = chainer.ChainList(l1, l2)
        c2 = chainer.ChainList(c1, l3)
        l1.x.data.fill(0)
        l2.x.data.fill(1)
        l3.x.data.fill(2)

        self.c2.copyparams(c2)

        numpy.testing.assert_array_equal(self.l1.x.data, l1.x.data)
        numpy.testing.assert_array_equal(self.l2.x.data, l2.x.data)
        numpy.testing.assert_array_equal(self.l3.x.data, l3.x.data) 
开发者ID:chainer,项目名称:chainer,代码行数:24,代码来源:test_link.py

示例10: test_copydata_to_uninitialized_parameter

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def test_copydata_to_uninitialized_parameter(
            self, src_backend_config, dst_backend_config):
        shape = self.shape
        dtype = np.float32
        src_arr_numpy = np.asarray(np.random.randn(*shape), dtype)
        src_arr = src_backend_config.get_array(src_arr_numpy.copy())
        dst_var = chainer.Parameter()
        dst_var.to_device(dst_backend_config.device)
        src_var = chainer.Parameter(src_arr)
        src_arr_prev = src_var.array

        dst_var.copydata(src_var)

        assert src_var.array is src_arr_prev
        assert src_var.device == src_backend_config.device
        assert dst_var.device == dst_backend_config.device
        np.testing.assert_array_equal(
            _numpy_device.send(dst_var.data), src_arr_numpy) 
开发者ID:chainer,项目名称:chainer,代码行数:20,代码来源:test_variable.py

示例11: _initialize_params

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def _initialize_params(self, in_size):
        super(SNLinear, self)._initialize_params(in_size)
        if self.use_gamma:
            _, s, _ = np.linalg.svd(self.W.data)
            with self.init_scope():
                self.gamma = chainer.Parameter(s[0], (1, 1)) 
开发者ID:pstuvwx,项目名称:Deep_VoiceChanger,代码行数:8,代码来源:sn_linear.py

示例12: _initialize_params

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def _initialize_params(self, in_size):
        super(SNConvolution2D, self)._initialize_params(in_size)
        if self.use_gamma:
            W_mat = self.W.data.reshape(self.W.shape[0], -1)
            _, s, _ = np.linalg.svd(W_mat)
            with self.init_scope():
                self.gamma = chainer.Parameter(s[0], (1, 1, 1, 1)) 
开发者ID:pstuvwx,项目名称:Deep_VoiceChanger,代码行数:9,代码来源:sn_convolution_2d.py

示例13: __init__

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def __init__(self):
        super().__init__()
        with self.init_scope():
            self.bias = chainer.Parameter(0, shape=1) 
开发者ID:chainer,项目名称:chainerrl,代码行数:6,代码来源:train_dqn_batch_ale.py

示例14: create_simple_link

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def create_simple_link():
    link = chainer.Link()
    with link.init_scope():
        link.param = chainer.Parameter(np.zeros(1))
    return link 
开发者ID:chainer,项目名称:chainerrl,代码行数:7,代码来源:test_agent.py

示例15: test_namedpersistent

# 需要导入模块: import chainer [as 别名]
# 或者: from chainer import Parameter [as 别名]
def test_namedpersistent():
    # This test case is adopted from
    # https://github.com/chainer/chainer/pull/6788

    l1 = chainer.Link()
    with l1.init_scope():
        l1.x = chainer.Parameter(shape=(2, 3))

    l2 = chainer.Link()
    with l2.init_scope():
        l2.x = chainer.Parameter(shape=2)
    l2.add_persistent(
        'l2_a', numpy.array([1, 2, 3], dtype=numpy.float32))

    l3 = chainer.Link()
    with l3.init_scope():
        l3.x = chainer.Parameter()
    l3.add_persistent(
        'l3_a', numpy.array([1, 2, 3], dtype=numpy.float32))

    c1 = chainer.Chain()
    with c1.init_scope():
        c1.l1 = l1
    c1.add_link('l2', l2)
    c1.add_persistent(
        'c1_a', numpy.array([1, 2, 3], dtype=numpy.float32))

    c2 = chainer.Chain()
    with c2.init_scope():
        c2.c1 = c1
        c2.l3 = l3
    c2.add_persistent(
        'c2_a', numpy.array([1, 2, 3], dtype=numpy.float32))
    namedpersistent = list(chainerrl.misc.namedpersistent(c2))
    assert (
        [(name, id(p)) for name, p in namedpersistent] ==
        [('/c2_a', id(c2.c2_a)), ('/c1/c1_a', id(c2.c1.c1_a)),
         ('/c1/l2/l2_a', id(c2.c1.l2.l2_a)), ('/l3/l3_a', id(c2.l3.l3_a))]) 
开发者ID:chainer,项目名称:chainerrl,代码行数:40,代码来源:test_namedpersistent.py


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