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


Python functions.fixed_batch_normalization方法代码示例

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


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

示例1: check_backward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def check_backward(self, inputs, grad_outputs, backend_config):
        inputs = backend_config.get_array(inputs)
        grad_outputs = backend_config.get_array(grad_outputs)
        if not self.c_contiguous:
            with backend_config:
                inputs = _as_noncontiguous_array(inputs)
                grad_outputs = _as_noncontiguous_array(grad_outputs)

        def f(*inputs):
            y = functions.fixed_batch_normalization(*inputs, eps=self.eps)
            return y,

        with backend_config:
            gradient_check.check_backward(
                f, inputs, grad_outputs,
                **self.check_backward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:18,代码来源:test_batch_normalization.py

示例2: check_double_backward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def check_double_backward(
            self, inputs, grad_outputs, grad_grad_inputs, backend_config):
        inputs = backend_config.get_array(inputs)
        grad_outputs = backend_config.get_array(grad_outputs)
        grad_grad_inputs = backend_config.get_array(grad_grad_inputs)
        if not self.c_contiguous:
            with backend_config:
                inputs = _as_noncontiguous_array(inputs)
                grad_outputs = _as_noncontiguous_array(grad_outputs)
                grad_grad_inputs = _as_noncontiguous_array(grad_grad_inputs)

        def f(*inputs):
            return functions.fixed_batch_normalization(*inputs, eps=self.eps)

        with backend_config:
            gradient_check.check_double_backward(
                f, inputs, grad_outputs, grad_grad_inputs,
                **self.check_double_backward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:20,代码来源:test_batch_normalization.py

示例3: gen_convtranspose_bn

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def gen_convtranspose_bn(test_name):
    gb = onnx_script.GraphBuilder(test_name)
    bsize = 2
    ichan = 3
    ochan = 4
    ksize = 3
    isize = 7

    x = aranges(bsize, ochan, isize, isize)
    w = aranges(ochan, ichan, ksize, ksize) * 0.01
    scale = aranges(ichan) * 0.1 + 1
    bias = aranges(ichan) * 0.1 + 2
    mean = aranges(ichan) * 0.1 + 3
    var = aranges(ichan) * 0.1 + 4

    conv = F.deconvolution_2d(x, w, pad=1, outsize=(isize, isize))
    y = F.fixed_batch_normalization(conv, scale, bias, mean, var)

    x_v = gb.input('x', x)
    w_v = gb.param('w', w)
    scale_v = gb.param('scale', scale)
    bias_v = gb.param('bias', bias)
    mean_v = gb.param('mean', mean)
    var_v = gb.param('var', var)

    conv_v = gb.ConvTranspose([x_v, w_v],
                              kernel_shape=[ksize, ksize],
                              pads=[1, 1, 1, 1],
                              output_shape=[isize, isize])
    y_v = gb.BatchNormalization([conv_v, scale_v, bias_v, mean_v, var_v])

    gb.output(y_v, y)
    gb.gen_test() 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:35,代码来源:gen_extra_test.py

示例4: call_bn

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def call_bn(bn, x, test=False, update_batch_stats=True):
    if test:
        return F.fixed_batch_normalization(x, bn.gamma, bn.beta, bn.avg_mean, bn.avg_var, use_cudnn=False)
    elif not update_batch_stats:
        return F.batch_normalization(x, bn.gamma, bn.beta, use_cudnn=False)
    else:
        return bn(x) 
开发者ID:takerum,项目名称:vat_chainer,代码行数:9,代码来源:misc.py

示例5: _as_noncontiguous_array

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def _as_noncontiguous_array(array):
    # TODO(niboshi): cupy + cudnn test fails in F.fixed_batch_normalization.
    # Fix it and use testing.array._as_noncontiguous_array.
    def as_noncontiguous_array(arr):
        if arr is None:
            return None
        if isinstance(arr, (numpy.ndarray, cuda.ndarray)):
            xp = chainer.backend.get_array_module(arr)
            return xp.asfortranarray(arr)
        return testing.array._as_noncontiguous_array(arr)

    if isinstance(array, (list, tuple)):
        return type(array)([as_noncontiguous_array(arr) for arr in array])
    return as_noncontiguous_array(array) 
开发者ID:chainer,项目名称:chainer,代码行数:16,代码来源:test_batch_normalization.py

示例6: check_forward

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def check_forward(self, inputs, enable_backprop, backend_config):
        y_expected, = self.forward_cpu(inputs)

        inputs = backend_config.get_array(inputs)
        if not self.c_contiguous:
            with backend_config:
                inputs = _as_noncontiguous_array(inputs)

        with chainer.using_config('enable_backprop', enable_backprop):
            with backend_config:
                y = functions.fixed_batch_normalization(*inputs, eps=self.eps)
        assert y.data.dtype == self.dtype

        testing.assert_allclose(
            y_expected, y.data, **self.check_forward_options) 
开发者ID:chainer,项目名称:chainer,代码行数:17,代码来源:test_batch_normalization.py

示例7: test_valid

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def test_valid(self):
        functions.fixed_batch_normalization(*self.args, eps=1e-5) 
开发者ID:chainer,项目名称:chainer,代码行数:4,代码来源:test_batch_normalization.py

示例8: setUp

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def setUp(self):

        class Model(chainer.Chain):

            def __call__(self, x):
                mean = x.array.mean(axis=0)
                var = x.array.var(axis=0)
                gamma = np.ones_like(mean, dtype=x.dtype)
                beta = np.zeros_like(mean, dtype=x.dtype)
                return F.fixed_batch_normalization(x, gamma, beta, mean, var)

        self.model = Model()
        self.x = input_generator.increasing(2, 5) 
开发者ID:chainer,项目名称:chainer,代码行数:15,代码来源:test_normalizations.py

示例9: test_forward1

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def test_forward1(self):
        N, C = 8, 1
        x, gamma, beta, mean, var = get_params(N, C)
        cy = CF.fixed_batch_normalization(x, gamma, beta, mean, var)
        with dezero.test_mode():
            y = F.batch_nrom(x, gamma, beta, mean, var)
        self.assertTrue(array_allclose(y.data, cy.data)) 
开发者ID:oreilly-japan,项目名称:deep-learning-from-scratch-3,代码行数:9,代码来源:test_batchnorm.py

示例10: test_forward2

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def test_forward2(self):
        N, C = 1, 10
        x, gamma, beta, mean, var = get_params(N, C)
        cy = CF.fixed_batch_normalization(x, gamma, beta, mean, var)
        with dezero.test_mode():
            y = F.batch_nrom(x, gamma, beta, mean, var)
        self.assertTrue(array_allclose(y.data, cy.data)) 
开发者ID:oreilly-japan,项目名称:deep-learning-from-scratch-3,代码行数:9,代码来源:test_batchnorm.py

示例11: test_forward3

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def test_forward3(self):
        N, C = 20, 10
        x, gamma, beta, mean, var = get_params(N, C)
        cy = CF.fixed_batch_normalization(x, gamma, beta, mean, var)
        with dezero.test_mode():
            y = F.batch_nrom(x, gamma, beta, mean, var)
        self.assertTrue(array_allclose(y.data, cy.data)) 
开发者ID:oreilly-japan,项目名称:deep-learning-from-scratch-3,代码行数:9,代码来源:test_batchnorm.py

示例12: test_forward4

# 需要导入模块: from chainer import functions [as 别名]
# 或者: from chainer.functions import fixed_batch_normalization [as 别名]
def test_forward4(self):
        N, C, H, W = 20, 10, 5, 5
        x, gamma, beta, mean, var = get_params(N, C, H, W)
        cy = CF.fixed_batch_normalization(x, gamma, beta, mean, var)
        with dezero.test_mode():
            y = F.batch_nrom(x, gamma, beta, mean, var)
        self.assertTrue(array_allclose(y.data, cy.data)) 
开发者ID:oreilly-japan,项目名称:deep-learning-from-scratch-3,代码行数:9,代码来源:test_batchnorm.py


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