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


Python links.BatchNormalization方法代码示例

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


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

示例1: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self, in_channels, out_channels, ksize=3, pad=1, activation=F.leaky_relu, mode='none', bn=False, dr=None):
        super(ResBlock, self).__init__()
        initializer = chainer.initializers.GlorotUniform()
        initializer_sc = chainer.initializers.GlorotUniform()
        self.activation = activation
        self.mode = _downsample if mode == 'down' else _upsample if mode == 'up' else None
        self.learnable_sc = in_channels != out_channels
        self.dr = dr
        self.bn = bn
        with self.init_scope():
            self.c1 = L.Convolution2D(in_channels,  out_channels, ksize=ksize, pad=pad, initialW=initializer, nobias=bn)
            self.c2 = L.Convolution2D(out_channels, out_channels, ksize=ksize, pad=pad, initialW=initializer, nobias=bn)
            if bn:
                self.b1 = L.BatchNormalization(out_channels)
                self.b2 = L.BatchNormalization(out_channels)
            if self.learnable_sc:
                self.c_sc = L.Convolution2D(in_channels, out_channels, ksize=1, pad=0, initialW=initializer_sc) 
开发者ID:pstuvwx,项目名称:Deep_VoiceChanger,代码行数:19,代码来源:block.py

示例2: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self, in_channels, out_channels, ksize=3, pad=1, activation=F.relu, mode='none', bn=True, dr=None):
        super(ResBlock, self).__init__()
        initializer = chainer.initializers.GlorotUniform()
        initializer_sc = chainer.initializers.GlorotUniform()
        self.activation = activation
        self.mode = _downsample if mode == 'down' else _upsample if mode == 'up' else None
        self.learnable_sc = in_channels != out_channels
        self.dr = dr
        self.bn = bn
        with self.init_scope():
            self.c1 = L.Convolution1D(in_channels,  out_channels, ksize=ksize, pad=pad, initialW=initializer, nobias=bn)
            self.c2 = L.Convolution1D(out_channels, out_channels, ksize=ksize, pad=pad, initialW=initializer, nobias=bn)
            if bn:
                self.b1 = L.BatchNormalization(out_channels)
                self.b2 = L.BatchNormalization(out_channels)
            if self.learnable_sc:
                self.c_sc = L.Convolution2D(in_channels, out_channels, ksize=1, pad=0, initialW=initializer_sc) 
开发者ID:pstuvwx,项目名称:Deep_VoiceChanger,代码行数:19,代码来源:block_1d.py

示例3: copy_param

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def copy_param(target_link, source_link):
    """Copy parameters of a link to another link."""
    target_params = dict(target_link.namedparams())
    for param_name, param in source_link.namedparams():
        if target_params[param_name].array is None:
            raise TypeError(
                'target_link parameter {} is None. Maybe the model params are '
                'not initialized.\nPlease try to forward dummy input '
                'beforehand to determine parameter shape of the model.'.format(
                    param_name))
        target_params[param_name].array[...] = param.array

    # Copy Batch Normalization's statistics
    target_links = dict(target_link.namedlinks())
    for link_name, link in source_link.namedlinks():
        if isinstance(link, L.BatchNormalization):
            target_bn = target_links[link_name]
            target_bn.avg_mean[...] = link.avg_mean
            target_bn.avg_var[...] = link.avg_var 
开发者ID:chainer,项目名称:chainerrl,代码行数:21,代码来源:copy_param.py

示例4: soft_copy_param

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def soft_copy_param(target_link, source_link, tau):
    """Soft-copy parameters of a link to another link."""
    target_params = dict(target_link.namedparams())
    for param_name, param in source_link.namedparams():
        if target_params[param_name].array is None:
            raise TypeError(
                'target_link parameter {} is None. Maybe the model params are '
                'not initialized.\nPlease try to forward dummy input '
                'beforehand to determine parameter shape of the model.'.format(
                    param_name))
        target_params[param_name].array[...] *= (1 - tau)
        target_params[param_name].array[...] += tau * param.array

    # Soft-copy Batch Normalization's statistics
    target_links = dict(target_link.namedlinks())
    for link_name, link in source_link.namedlinks():
        if isinstance(link, L.BatchNormalization):
            target_bn = target_links[link_name]
            target_bn.avg_mean[...] *= (1 - tau)
            target_bn.avg_mean[...] += tau * link.avg_mean
            target_bn.avg_var[...] *= (1 - tau)
            target_bn.avg_var[...] += tau * link.avg_var 
开发者ID:chainer,项目名称:chainerrl,代码行数:24,代码来源:copy_param.py

示例5: soft_copy_param

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def soft_copy_param(target_link, source_link, tau, layers_in_use=None):
    """Soft-copy parameters of a link to another link."""
    target_params = dict(target_link.namedparams())
    for param_name, param in source_link.namedparams():
        if layers_in_use is not None:
            skip = True
            for name in layers_in_use:
                if param_name.startswith(name):
                    skip = False
                    break
            if skip:
                continue
        target_params[param_name].data[:] *= (1 - tau)
        target_params[param_name].data[:] += tau * param.data

   # Soft-copy Batch Normalization's statistics
    target_links = dict(target_link.namedlinks())
    for link_name, link in source_link.namedlinks():
        if isinstance(link, L.BatchNormalization):
            target_bn = target_links[link_name]
            target_bn.avg_mean[:] *= (1 - tau)
            target_bn.avg_mean[:] += tau * link.avg_mean
            target_bn.avg_var[:] *= (1 - tau)
            target_bn.avg_var[:] += tau * link.avg_var 
开发者ID:pfnet-research,项目名称:chainer-stylegan,代码行数:26,代码来源:copy_param.py

示例6: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self, obs_size, n_actions, n_hidden_channels=[1024,256]):
        super(QFunction,self).__init__()
        net = []
        inpdim = obs_size
        for i,n_hid in enumerate(n_hidden_channels):
            net += [ ('l{}'.format(i), L.Linear( inpdim, n_hid ) ) ]
            net += [ ('norm{}'.format(i), L.BatchNormalization( n_hid ) ) ]
            net += [ ('_act{}'.format(i), F.relu ) ]
            inpdim = n_hid

        net += [('output', L.Linear( inpdim, n_actions) )]

        with self.init_scope():
            for n in net:
                if not n[0].startswith('_'):
                    setattr(self, n[0], n[1])

        self.forward = net 
开发者ID:endgameinc,项目名称:gym-malware,代码行数:20,代码来源:train_agent_chainer.py

示例7: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self):
        super(Mix, self).__init__()

        enc_ch = [3, 64, 256, 512, 1024, 2048]
        ins_ch = [6, 128, 384, 640, 2176, 3072]

        self.conv = [None] * 6
        self.bn = [None] * 6
        for i in range(1, 6):
            c = L.Convolution2D(enc_ch[i] + ins_ch[i], enc_ch[i], 1, nobias=True)
            b = L.BatchNormalization(enc_ch[i])

            self.conv[i] = c
            self.bn[i] = b

            self.add_link('c{}'.format(i), c)
            self.add_link('b{}'.format(i), b) 
开发者ID:pfnet-research,项目名称:nips17-adversarial-attack,代码行数:19,代码来源:rec_multibp_resnet.py

示例8: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self, ch):
        super(Link_BatchNormalization, self).__init__(
            L.BatchNormalization(1))

        self.n_out = ch.beta.shape[0]

        self.scale = helper.make_tensor_value_info(
            '/gamma', TensorProto.FLOAT, [self.n_out])
        self.B = helper.make_tensor_value_info(
            '/beta', TensorProto.FLOAT, [self.n_out])
        self.mean = helper.make_tensor_value_info(
            '/avg_mean', TensorProto.FLOAT, [self.n_out])
        self.var = helper.make_tensor_value_info(
            '/avg_var', TensorProto.FLOAT, [self.n_out])

        self.eps = ch.eps
        self.momentum = ch.decay 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:19,代码来源:links.py

示例9: collect_inits

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def collect_inits(lk, pathname):
    res = []
    for na, pa in lk.namedparams():
        if isinstance(pa.data, type(None)):
            continue
        if na.count('/') == 1:
            res.append((pathname + na, pa))

    if isinstance(lk, L.BatchNormalization):
        res.append((pathname + '/avg_mean', lk.avg_mean))
        # TODO(satos) このままだと、nodeのテストは通るがResNetのテストがつらい
        # lk.avg_var = np.ones(lk.avg_var.shape).astype(np.float32) * 4.0
        res.append((pathname + '/avg_var', lk.avg_var))

    elif isinstance(lk, L.NStepLSTM) or isinstance(lk, L.NStepBiLSTM):
        # 先にこちらで集めてしまう
        for i, clk in enumerate(lk.children()):
            for param in clk.params():
                res.append((pathname + '/%d/%s' % (i, param.name), param))
        return res

    for clk in lk.children():
        res += collect_inits(clk, pathname + '/' + clk.name)
    return res 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:26,代码来源:initializer.py

示例10: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self, in_size, ch, out_size, stride=2, groups=1):
        super(BottleNeckA, self).__init__()
        initialW = initializers.HeNormal()

        with self.init_scope():
            self.conv1 = L.Convolution2D(
                in_size, ch, 1, stride, 0, initialW=initialW, nobias=True)
            self.bn1 = L.BatchNormalization(ch)
            self.conv2 = L.Convolution2D(
                ch, ch, 3, 1, 1, initialW=initialW, nobias=True,
                groups=groups)
            self.bn2 = L.BatchNormalization(ch)
            self.conv3 = L.Convolution2D(
                ch, out_size, 1, 1, 0, initialW=initialW, nobias=True)
            self.bn3 = L.BatchNormalization(out_size)

            self.conv4 = L.Convolution2D(
                in_size, out_size, 1, stride, 0,
                initialW=initialW, nobias=True)
            self.bn4 = L.BatchNormalization(out_size) 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:22,代码来源:Resnet_with_loss.py

示例11: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self, in_channels, out_channels, ksize=None,
                 stride=1, pad=0, dilate=1, groups=1, nobias=True,
                 initialW=None, initial_bias=None, activ=relu, bn_kwargs={}):
        if ksize is None:
            out_channels, ksize, in_channels = in_channels, out_channels, None

        self.activ = activ
        super(Conv2DBNActiv, self).__init__()
        with self.init_scope():
            self.conv = Convolution2D(
                in_channels, out_channels, ksize, stride, pad,
                nobias, initialW, initial_bias, dilate=dilate, groups=groups)
            
            if 'comm' in bn_kwargs:
                with flags.ignore_branch(): 
                    self.bn = MultiNodeBatchNormalization(
                        out_channels, **bn_kwargs)
            else:
                self.bn = BatchNormalization(out_channels, **bn_kwargs) 
开发者ID:pfnet-research,项目名称:chainer-compiler,代码行数:21,代码来源:conv_2d_bn_activ.py

示例12: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 ksize,
                 stride,
                 pad,
                 num_blocks):
        super(PolyConv, self).__init__()
        with self.init_scope():
            self.conv = L.Convolution2D(
                in_channels=in_channels,
                out_channels=out_channels,
                ksize=ksize,
                stride=stride,
                pad=pad,
                nobias=True)
            for i in range(num_blocks):
                setattr(self, "bn{}".format(i + 1), L.BatchNormalization(
                    size=out_channels,
                    eps=1e-5))
            self.activ = F.relu 
开发者ID:osmr,项目名称:imgclsmob,代码行数:23,代码来源:polynet.py

示例13: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 ksize,
                 stride,
                 pad,
                 groups):
        super(CondenseSimpleConv, self).__init__()
        with self.init_scope():
            self.bn = L.BatchNormalization(size=in_channels)
            self.activ = F.relu
            self.conv = L.Convolution2D(
                in_channels=in_channels,
                out_channels=out_channels,
                ksize=ksize,
                stride=stride,
                pad=pad,
                nobias=True,
                groups=groups) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:21,代码来源:condensenet.py

示例14: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 ksize,
                 stride,
                 pad):
        super(InceptConv, self).__init__()
        with self.init_scope():
            self.conv = L.Convolution2D(
                in_channels=in_channels,
                out_channels=out_channels,
                ksize=ksize,
                stride=stride,
                pad=pad,
                nobias=True)
            self.bn = L.BatchNormalization(
                size=out_channels,
                decay=0.1,
                eps=1e-3)
            self.activ = F.relu 
开发者ID:osmr,项目名称:imgclsmob,代码行数:22,代码来源:inceptionv4.py

示例15: __init__

# 需要导入模块: from chainer import links [as 别名]
# 或者: from chainer.links import BatchNormalization [as 别名]
def __init__(self,
                 in_channels,
                 out_channels,
                 reduction=16):
        super(PreSEAttBlock, self).__init__()
        mid_cannels = out_channels // reduction

        with self.init_scope():
            self.bn = L.BatchNormalization(
                size=in_channels,
                eps=1e-5)
            self.conv1 = conv1x1(
                in_channels=in_channels,
                out_channels=mid_cannels,
                use_bias=True)
            self.conv2 = conv1x1(
                in_channels=mid_cannels,
                out_channels=out_channels,
                use_bias=True) 
开发者ID:osmr,项目名称:imgclsmob,代码行数:21,代码来源:fishnet.py


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