Python chainer.links 模块,BatchNormalization() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用chainer.links.BatchNormalization()

项目:chainerrl    作者:chainer    | 项目源码 | 文件源码
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():
        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
项目:chainer-cyclegan    作者:Aixile    | 项目源码 | 文件源码
def __init__(self, ch0, ch1, bn=True, sample='down', activation=F.relu, dropout=False, noise=False):
        self.bn = bn
        self.activation = activation
        self.dropout = dropout
        self.sample = sample
        self.noise = noise
        layers = {}
        w = chainer.initializers.Normal(0.02)
        if sample=='down':
            layers['c'] = L.Convolution2D(ch0, ch1, 4, 2, 1, initialW=w)
        elif sample=='none-9':
            layers['c'] = L.Convolution2D(ch0, ch1, 9, 1, 4, initialW=w)
        elif sample=='none-7':
            layers['c'] = L.Convolution2D(ch0, ch1, 7, 1, 3, initialW=w)
        elif sample=='none-5':
            layers['c'] = L.Convolution2D(ch0, ch1, 5, 1, 2, initialW=w)
        else:
            layers['c'] = L.Convolution2D(ch0, ch1, 3, 1, 1, initialW=w)
        if bn:
            if self.noise:
                layers['batchnorm'] = L.BatchNormalization(ch1, use_gamma=False)
            else:
                layers['batchnorm'] = L.BatchNormalization(ch1)
        super(CBR, self).__init__(**layers)
项目:chainer-fast-neuralstyle    作者:yusuketomoto    | 项目源码 | 文件源码
def __init__(self):
        super(FastStyleNet, self).__init__(
            c1=L.Convolution2D(3, 32, 9, stride=1, pad=4),
            c2=L.Convolution2D(32, 64, 4, stride=2, pad=1),
            c3=L.Convolution2D(64, 128, 4,stride=2, pad=1),
            r1=ResidualBlock(128, 128),
            r2=ResidualBlock(128, 128),
            r3=ResidualBlock(128, 128),
            r4=ResidualBlock(128, 128),
            r5=ResidualBlock(128, 128),
            d1=L.Deconvolution2D(128, 64, 4, stride=2, pad=1),
            d2=L.Deconvolution2D(64, 32, 4, stride=2, pad=1),
            d3=L.Deconvolution2D(32, 3, 9, stride=1, pad=4),
            b1=L.BatchNormalization(32),
            b2=L.BatchNormalization(64),
            b3=L.BatchNormalization(128),
            b4=L.BatchNormalization(64),
            b5=L.BatchNormalization(32),
        )
项目:chainer-fcis    作者:knorth55    | 项目源码 | 文件源码
def __init__(self, in_size, out_size, ch, stride=2):
        super(BottleNeckA, self).__init__()
        initialW = chainer.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, eps=self.eps)
            self.conv2 = L.Convolution2D(
                ch, ch, 3, 1, 1, initialW=initialW, nobias=True)
            self.bn2 = L.BatchNormalization(ch, eps=self.eps)
            self.conv3 = L.Convolution2D(
                ch, out_size, 1, 1, 0, initialW=initialW, nobias=True)
            self.bn3 = L.BatchNormalization(out_size, eps=self.eps)

            self.conv4 = L.Convolution2D(
                in_size, out_size, 1, stride, 0,
                initialW=initialW, nobias=True)
            self.bn4 = L.BatchNormalization(out_size)
项目:chainer-fcis    作者:knorth55    | 项目源码 | 文件源码
def __init__(self, in_size, out_size, ch, stride=1):
        super(DilatedBottleNeckA, self).__init__()
        initialW = chainer.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, eps=self.eps)
            self.conv2 = L.DilatedConvolution2D(
                ch, ch, 3, 1, 2, dilate=2,
                initialW=initialW, nobias=True)
            self.bn2 = L.BatchNormalization(ch, eps=self.eps)
            self.conv3 = L.Convolution2D(
                ch, out_size, 1, 1, 0, initialW=initialW, nobias=True)
            self.bn3 = L.BatchNormalization(out_size, eps=self.eps)

            self.conv4 = L.Convolution2D(
                in_size, out_size, 1, stride, 0,
                initialW=initialW, nobias=True)
            self.bn4 = L.BatchNormalization(out_size)
项目:gym-malware    作者:endgameinc    | 项目源码 | 文件源码
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
项目:tensorboard-pytorch    作者:lanpa    | 项目源码 | 文件源码
def __init__(self, n_hidden, bottom_width=4, ch=512, wscale=0.02):
        super(Generator, self).__init__()
        self.n_hidden = n_hidden
        self.ch = ch
        self.bottom_width = bottom_width

        with self.init_scope():
            w = chainer.initializers.Normal(wscale)
            self.l0 = L.Linear(self.n_hidden, bottom_width * bottom_width * ch,
                               initialW=w)
            self.dc1 = L.Deconvolution2D(ch, ch // 2, 4, 2, 1, initialW=w)
            self.dc2 = L.Deconvolution2D(ch // 2, ch // 4, 4, 2, 1, initialW=w)
            self.dc3 = L.Deconvolution2D(ch // 4, ch // 8, 4, 2, 1, initialW=w)
            self.dc4 = L.Deconvolution2D(ch // 8, 3, 3, 1, 1, initialW=w)
            self.bn0 = L.BatchNormalization(bottom_width * bottom_width * ch)
            self.bn1 = L.BatchNormalization(ch // 2)
            self.bn2 = L.BatchNormalization(ch // 4)
            self.bn3 = L.BatchNormalization(ch // 8)
项目:tensorboard-pytorch    作者:lanpa    | 项目源码 | 文件源码
def __init__(self, bottom_width=4, ch=512, wscale=0.02):
        w = chainer.initializers.Normal(wscale)
        super(Discriminator, self).__init__()
        with self.init_scope():
            self.c0_0 = L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w)
            self.c0_1 = L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w)
            self.c1_0 = L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w)
            self.c1_1 = L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w)
            self.c2_0 = L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w)
            self.c2_1 = L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w)
            self.c3_0 = L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w)
            self.l4 = L.Linear(bottom_width * bottom_width * ch, 1, initialW=w)
            self.bn0_1 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_0 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_1 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_0 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_1 = L.BatchNormalization(ch // 1, use_gamma=False)
            self.bn3_0 = L.BatchNormalization(ch // 1, use_gamma=False)
项目:DeepLearning    作者:Wanwannodao    | 项目源码 | 文件源码
def __init__(self, n_actions):
        initializer = chainer.initializers.HeNormal()
        c1 = 32
        c2 = 64
        c3 = 64
        fc_unit = 256

        super(QFunction, self).__init__(
             # the size of the inputs to each layer will be inferred
            conv1=L.Convolution2D(4, c1, 8, stride=4, pad=0),
            conv2=L.Convolution2D(c1, c2, 4, stride=2, pad=0),
            conv3=L.Convolution2D(c2, c3, 3, stride=1, pad=0),
            #conv4=L.Convolution2D(64, c4, 3, stride=1, pad=1),
            fc1=L.Linear(3136, fc_unit, initialW=initializer),
            fc2=L.Linear(fc_unit, n_actions, initialW=initializer),
            #bnorm1=L.BatchNormalization(c1),
            #bnorm2=L.BatchNormalization(c2),
            #bnorm3=L.BatchNormalization(c3),
            #bnorm4=L.BatchNormalization(c4),
        )
项目:self-driving-cars    作者:musyoku    | 项目源码 | 文件源码
def build_network(self, output_dim=1):
        config.check()
        wscale = config.q_wscale

        # Fully connected part of Q-Network
        fc_attributes = {}
        fc_units = [(34 * config.rl_history_length, config.q_fc_hidden_units[0])]
        fc_units += zip(config.q_fc_hidden_units[:-1], config.q_fc_hidden_units[1:])
        fc_units += [(config.q_fc_hidden_units[-1], output_dim)]

        for i, (n_in, n_out) in enumerate(fc_units):
            fc_attributes["layer_%i" % i] = L.Linear(n_in, n_out, wscale=wscale)
            fc_attributes["batchnorm_%i" % i] = L.BatchNormalization(n_out)

        fc = FullyConnectedNetwork(**fc_attributes)
        fc.n_hidden_layers = len(fc_units) - 1
        fc.activation_function = config.q_fc_activation_function
        fc.apply_batchnorm = config.apply_batchnorm
        fc.apply_dropout = config.q_fc_apply_dropout
        fc.apply_batchnorm_to_input = config.q_fc_apply_batchnorm_to_input
        if config.use_gpu:
            fc.to_gpu()
        return fc
项目:stock_dqn_f    作者:wdy06    | 项目源码 | 文件源码
def __init__(self, input_num, hidden_num,num_of_actions):
        self.input_num = input_num
        self.hidden_num = hidden_num
        self.num_of_actions = num_of_actions

        super(Q_DNN, self).__init__(
            fc1=L.Linear(self.input_num, self.hidden_num),
            bn1=L.BatchNormalization(self.hidden_num),
            fc2=L.Linear(self.hidden_num, self.hidden_num),
            bn2=L.BatchNormalization(self.hidden_num),
            fc3=L.Linear(self.hidden_num, self.hidden_num),
            bn3=L.BatchNormalization(self.hidden_num),
            fc4=L.Linear(self.hidden_num, self.hidden_num),
            bn4=L.BatchNormalization(self.hidden_num),
            fc5=L.Linear(self.hidden_num, self.hidden_num),
            bn5=L.BatchNormalization(self.hidden_num),
            q_value=L.Linear(self.hidden_num, self.num_of_actions,
                             initialW=np.zeros((self.num_of_actions, self.hidden_num),
                                               dtype=np.float32))

        )
项目:deep_metric_learning    作者:ronekko    | 项目源码 | 文件源码
def __init__(self, out_dim):
        super(SimpleConvnet, self).__init__(
            conv1=L.Convolution2D(3, 50, 3),
            bn_conv1=L.BatchNormalization(50),
            conv21=L.Convolution2D(50, 100, 3),
            bn_conv21=L.BatchNormalization(100),
            conv22=L.Convolution2D(100, 100, 1),
            bn_conv22=L.BatchNormalization(100),
            conv31=L.Convolution2D(100, 200, 3),
            bn_conv31=L.BatchNormalization(200),
            conv32=L.Convolution2D(200, 200, 3),
            bn_conv32=L.BatchNormalization(200),
            conv41=L.Convolution2D(200, 400, 3),
            bn_conv41=L.BatchNormalization(400),
            conv42=L.Convolution2D(400, 400, 1),
            bn_conv42=L.BatchNormalization(400),
            conv5=L.Convolution2D(400, 400, 1),
            bn_conv5=L.BatchNormalization(400),
            conv6=L.Convolution2D(400, 400, 1),
            bn_conv6=L.BatchNormalization(400),
            linear1=L.Linear(400, 400),
            bn_linear1=L.BatchNormalization(400),
            linear2=L.Linear(400, out_dim)
        )
项目:pyramidal_residual_networks    作者:nutszebra    | 项目源码 | 文件源码
def __init__(self, in_channel, out_channel, filter_sizes=(3, 3), strides=(1, 1), pads=(1, 1)):
        super(BN_Conv_BN_ReLU_Conv_BN, self).__init__()
        modules = []
        modules += [('bn1', L.BatchNormalization(in_channel))]
        modules += [('conv1', L.Convolution2D(in_channel, out_channel, filter_sizes[0], strides[0], pads[0]))]
        modules += [('bn2', L.BatchNormalization(out_channel))]
        modules += [('conv2', L.Convolution2D(out_channel, out_channel, filter_sizes[1], strides[1], pads[1]))]
        modules += [('bn3', L.BatchNormalization(out_channel))]
        # register layers
        [self.add_link(*link) for link in modules]
        self.modules = modules
        self.in_channel = in_channel
        self.out_channel = out_channel
        self.filter_sizes = filter_sizes
        self.strides = strides
        self.pads = pads
项目:TOHO_AI    作者:re53min    | 项目源码 | 文件源码
def __init__(self, n_outputs, train=True):
        super(ImageNet, self).__init__(
            conv1=L.Convolution2D(None, 96, 11, stride=4),
            bn1=L.BatchNormalization(96),
            conv2=L.Convolution2D(None, 128, 5, pad=2),
            bn2=L.BatchNormalization(128),
            conv3=L.Convolution2D(None, 256, 3, pad=1),
            conv4=L.Convolution2D(None, 384, 3, pad=1),

            l5=L.Linear(None, 512),
            l6=L.Linear(512, n_outputs),

        )
        for param in self.params():
            param.data[...] = np.random.uniform(-0.1, 0.1, param.data.shape)
        self.train = train
项目:SketchSimplification    作者:La4La    | 项目源码 | 文件源码
def __init__(self):
        super(DIS, self).__init__(
            c1=L.Convolution2D(1, 16, 5, 2, 2, wscale=0.02*math.sqrt(5*5*1)),
            c2=L.Convolution2D(16, 32, 3, 2, 1, wscale=0.02*math.sqrt(3*3*16)),
            c3=L.Convolution2D(32, 64, 3, 2, 1, wscale=0.02*math.sqrt(3*3*32)),
            c4=L.Convolution2D(64, 128, 3, 2, 1, wscale=0.02*math.sqrt(3*3*64)),
            c5=L.Convolution2D(128, 256, 3, 2, 1, wscale=0.02*math.sqrt(3*3*128)),
            c6=L.Convolution2D(256, 512, 3, 2, 1, wscale=0.02*math.sqrt(3*3*256)),
            c7=L.Linear(4*4*512, 2, wscale=0.02*math.sqrt(4*4*512)),

            bn1=L.BatchNormalization(16),
            bn2=L.BatchNormalization(32),
            bn3=L.BatchNormalization(64),
            bn4=L.BatchNormalization(128),
            bn5=L.BatchNormalization(256),
            bn6=L.BatchNormalization(512)
        )
项目:deel    作者:uei    | 项目源码 | 文件源码
def _setup_batchnorm(self, layer):
        # Get layer parameters.
        blobs = layer.blobs
        param = layer.batch_norm_param
        use_global_stats = param.use_global_stats
        decay = param.moving_average_fraction
        eps = param.eps
        size = int(blobs[0].shape.dim[0])  # Get channel dim from mean blob.

        # Make BatchNormalization link.
        func = links.BatchNormalization(size, decay=decay, eps=eps,
                                        use_gamma=False, use_beta=False)
        func.avg_mean.ravel()[:] = blobs[0].data
        func.avg_var.ravel()[:] = blobs[1].data
        self.add_link(layer.name, func)

        # Add layer.
        fwd = _SingleArgumentFunction(
            _CallChildLink(self, layer.name),
            test=use_global_stats, finetune=False)
        self.forwards[layer.name] = fwd
        self._add_layer(layer)
项目:chainermn    作者:chainer    | 项目源码 | 文件源码
def __init__(self, in_size, ch, out_size, stride=2):
        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)
            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)
项目:chainermn    作者:chainer    | 项目源码 | 文件源码
def __init__(self, n_hidden, bottom_width=4, ch=512, wscale=0.02):
        super(Generator, self).__init__()
        self.n_hidden = n_hidden
        self.ch = ch
        self.bottom_width = bottom_width

        with self.init_scope():
            w = chainer.initializers.Normal(wscale)
            self.l0 = L.Linear(self.n_hidden, bottom_width * bottom_width * ch,
                               initialW=w)
            self.dc1 = L.Deconvolution2D(ch, ch // 2, 4, 2, 1, initialW=w)
            self.dc2 = L.Deconvolution2D(ch // 2, ch // 4, 4, 2, 1, initialW=w)
            self.dc3 = L.Deconvolution2D(ch // 4, ch // 8, 4, 2, 1, initialW=w)
            self.dc4 = L.Deconvolution2D(ch // 8, 3, 3, 1, 1, initialW=w)
            self.bn0 = L.BatchNormalization(bottom_width * bottom_width * ch)
            self.bn1 = L.BatchNormalization(ch // 2)
            self.bn2 = L.BatchNormalization(ch // 4)
            self.bn3 = L.BatchNormalization(ch // 8)
项目:chainermn    作者:chainer    | 项目源码 | 文件源码
def __init__(self, bottom_width=4, ch=512, wscale=0.02):
        w = chainer.initializers.Normal(wscale)
        super(Discriminator, self).__init__()
        with self.init_scope():
            self.c0_0 = L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w)
            self.c0_1 = L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w)
            self.c1_0 = L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w)
            self.c1_1 = L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w)
            self.c2_0 = L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w)
            self.c2_1 = L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w)
            self.c3_0 = L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w)
            self.l4 = L.Linear(bottom_width * bottom_width * ch, 1, initialW=w)
            self.bn0_1 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_0 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_1 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_0 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_1 = L.BatchNormalization(ch // 1, use_gamma=False)
            self.bn3_0 = L.BatchNormalization(ch // 1, use_gamma=False)
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, n_class, in_ch, n_layer=12, growth_rate=12,
                 dropout_ratio=0.2, block=3):
        in_chs = [in_ch + n_layer * growth_rate * i
                  for i in moves.range(block + 1)]
        super(DenseBlock, self).__init__()
        self.add_link(
            'conv1', L.Convolution2D(3, in_ch, 3, 1, 1, wscale=np.sqrt(2))
        )
        for i in moves.range(block):
            self.add_link('dense%d' % (i+2),
                          DenseBlock(in_chs[i], growth_rate, n_layer))
            if not i == block - 1:
                self.add_link('trans%d' % (i+2), Transition(in_chs[i+1]))

        self.add_link(
            'bn%d' % (block+1), L.BatchNormalization(in_chs[block])
        )
        self.add_link('fc%d' % (block+2), L.Linear(in_chs[block], n_class))
        self.train = True
        self.dropout_ratio = dropout_ratio
        self.block = block
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, in_size, ch, out_size, stride=2):
        super(BottleNeckA, self).__init__()
        w = initializers.HeNormal()

        with self.init_scope():
            self.conv1 = L.Convolution2D(in_size, ch, 1, stride, 0,
                                         initialW=w, nobias=True)
            self.conv2 = L.Convolution2D(ch, ch, 3, 1, 1,
                                         initialW=w, nobias=True)
            self.conv3 = L.Convolution2D(ch, out_size, 1, 1, 0,
                                         initialW=w, nobias=True)
            self.conv4 = L.Convolution2D(in_size, out_size, 1, stride, 0,
                                         initialW=w, nobias=True)
            self.bn1 = L.BatchNormalization(ch)
            self.bn2 = L.BatchNormalization(ch)
            self.bn3 = L.BatchNormalization(out_size)
            self.bn4 = L.BatchNormalization(out_size)
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, in_size, ch, out_size, stride=2):
        super(BottleNeckA, self).__init__()
        w = initializers.HeNormal()

        with self.init_scope():
            self.conv1 = L.Convolution2D(in_size, ch, 1, stride, 0,
                                         initialW=w, nobias=True)
            self.conv2 = L.Convolution2D(ch, ch, 3, 1, 1,
                                         initialW=w, nobias=True)
            self.conv3 = L.Convolution2D(ch, out_size, 1, 1, 0,
                                         initialW=w, nobias=True)
            self.conv4 = L.Convolution2D(in_size, out_size, 1, stride, 0,
                                         initialW=2, nobias=True)
            self.bn1 = L.BatchNormalization(ch)
            self.bn2 = L.BatchNormalization(ch)
            self.bn3 = L.BatchNormalization(out_size)
            self.bn4 = L.BatchNormalization(out_size)
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, in_size, ch, out_size, stride=2):
        super(BottleNeckA, self).__init__()
        w = initializers.HeNormal()

        with self.init_scope():
            self.conv1 = L.Convolution2D(in_size, ch, 1, stride, 0,
                                         initialW=w, nobias=True)
            self.conv2 = L.Convolution2D(ch, ch, 3, 1, 1,
                                         initialW=w, nobias=True)
            self.conv3 = L.Convolution2D(ch, out_size, 1, 1, 0,
                                         initialW=w, nobias=True)
            self.conv4 = L.Convolution2D(in_size, out_size, 1, stride, 0,
                                         initialW=w, nobias=True)
            self.bn1 = L.BatchNormalization(ch)
            self.bn2 = L.BatchNormalization(ch)
            self.bn3 = L.BatchNormalization(out_size)
            self.bn4 = L.BatchNormalization(out_size)
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, n_hidden=128, bottom_width=4, ch=512, wscale=0.02):
        super(Generator, self).__init__()
        self.n_hidden = n_hidden
        self.ch = ch
        self.bottom_width = bottom_width

        with self.init_scope():
            w = chainer.initializers.Normal(wscale)
            self.l0 = L.Linear(self.n_hidden, bottom_width*bottom_width*ch,
                               initialW=w)
            self.dc1 = L.Deconvolution2D(ch, ch//2, 4, 2, 1, initialW=w)
            self.dc2 = L.Deconvolution2D(ch//2, ch//4, 4, 2, 1, initialW=w)
            self.dc3 = L.Deconvolution2D(ch//4, ch//8, 4, 2, 1, initialW=w)
            self.dc4 = L.Deconvolution2D(ch//8, 3, 3, 1, 1, initialW=w)
            self.bn0 = L.BatchNormalization(bottom_width*bottom_width*ch)
            self.bn1 = L.BatchNormalization(ch//2)
            self.bn2 = L.BatchNormalization(ch//4)
            self.bn3 = L.BatchNormalization(ch//8)
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, bottom_width=4, ch=512, wscale=0.02):
        w = chainer.initializers.Normal(wscale)
        super(Discriminator, self).__init__()
        with self.init_scope():
            self.c0_0 = L.Convolution2D(3, ch//8, 3, 1, 1, initialW=w)
            self.c0_1 = L.Convolution2D(ch//8, ch//4, 4, 2, 1, initialW=w)
            self.c1_0 = L.Convolution2D(ch//4, ch//4, 3, 1, 1, initialW=w)
            self.c1_1 = L.Convolution2D(ch//4, ch//2, 4, 2, 1, initialW=w)
            self.c2_0 = L.Convolution2D(ch//2, ch//2, 3, 1, 1, initialW=w)
            self.c2_1 = L.Convolution2D(ch//2, ch//1, 4, 2, 1, initialW=w)
            self.c3_0 = L.Convolution2D(ch//1, ch//1, 3, 1, 1, initialW=w)
            self.l4 = L.Linear(bottom_width*bottom_width*ch, 1, initialW=w)
            self.bn0_1 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_0 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_1 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_0 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_1 = L.BatchNormalization(ch // 1, use_gamma=False)
            self.bn3_0 = L.BatchNormalization(ch // 1, use_gamma=False)
项目:chainer-examples    作者:nocotan    | 项目源码 | 文件源码
def __init__(self, n_hidden=128, bottom_width=4, ch=512, wscale=0.02):
        super(Generator, self).__init__()
        self.n_hidden = n_hidden
        self.ch = ch
        self.bottom_width = bottom_width

        with self.init_scope():
            w = chainer.initializers.Normal(wscale)
            self.l0 = L.Linear(self.n_hidden, bottom_width*bottom_width*ch,
                               initialW=w)
            self.dc1 = L.Deconvolution2D(ch, ch//2, 4, 2, 1, initialW=w)
            self.dc2 = L.Deconvolution2D(ch//2, ch//4, 4, 2, 1, initialW=w)
            self.dc3 = L.Deconvolution2D(ch//4, ch//8, 4, 2, 1, initialW=w)
            self.dc4 = L.Deconvolution2D(ch//8, 3, 3, 1, 1, initialW=w)
            self.bn0 = L.BatchNormalization(bottom_width*bottom_width*ch)
            self.bn1 = L.BatchNormalization(ch//2)
            self.bn2 = L.BatchNormalization(ch//4)
            self.bn3 = L.BatchNormalization(ch//8)
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, n_hidden, activate='sigmoid', size=64, ch=512, wscale=0.02):
        assert (size % 16 == 0)
        initial_size = size // 16
        self.n_hidden = n_hidden
        if activate == 'sigmoid':
            self.activate = F.sigmoid
        elif activate == 'tanh':
            self.activate = F.tanh
        else:
            raise ValueError('invalid activate function')
        self.ch = ch
        self.initial_size = initial_size
        w = chainer.initializers.Normal(wscale)
        super(Generator, self).__init__(
            l0=L.Linear(self.n_hidden, initial_size * initial_size * ch, initialW=w),
            dc1=L.Deconvolution2D(ch // 1, ch // 2, 4, 2, 1, initialW=w),
            dc2=L.Deconvolution2D(ch // 2, ch // 4, 4, 2, 1, initialW=w),
            dc3=L.Deconvolution2D(ch // 4, ch // 8, 4, 2, 1, initialW=w),
            dc4=L.Deconvolution2D(ch // 8, 3, 4, 2, 1, initialW=w),
            bn0=L.BatchNormalization(initial_size * initial_size * ch),
            bn1=L.BatchNormalization(ch // 2),
            bn2=L.BatchNormalization(ch // 4),
            bn3=L.BatchNormalization(ch // 8),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, n_hidden, activate='sigmoid', size=64, ch=512, wscale=0.02):
        assert (size % 8 == 0)
        initial_size = size // 8
        self.n_hidden = n_hidden
        self.ch = ch
        self.initial_size = initial_size
        if activate == 'sigmoid':
            self.activate = F.sigmoid
        elif activate == 'tanh':
            self.activate = F.tanh
        else:
            raise ValueError('invalid activate function')
        w = chainer.initializers.Normal(wscale)
        super(Generator2, self).__init__(
            l0=L.Linear(self.n_hidden, initial_size * initial_size * ch, initialW=w),
            dc1=L.Deconvolution2D(ch // 1, ch // 2, 4, 2, 1, initialW=w),
            dc2=L.Deconvolution2D(ch // 2, ch // 4, 4, 2, 1, initialW=w),
            dc3=L.Deconvolution2D(ch // 4, ch // 8, 4, 2, 1, initialW=w),
            dc4=L.Deconvolution2D(ch // 8, 3, 3, 1, 1, initialW=w),
            bn0=L.BatchNormalization(initial_size * initial_size * ch),
            bn1=L.BatchNormalization(ch // 2),
            bn2=L.BatchNormalization(ch // 4),
            bn3=L.BatchNormalization(ch // 8),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, size=64, ch=512, wscale=0.005, use_gamma=True):
        assert (size % 16 == 0)
        initial_size = size // 16
        w = chainer.initializers.Normal(wscale)
        super(Discriminator, self).__init__(
            c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
            c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
            c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
            c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
            c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
            l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
            bn0_1=L.BatchNormalization(ch // 4, use_gamma=use_gamma),
            bn1_1=L.BatchNormalization(ch // 2, use_gamma=use_gamma),
            bn2_1=L.BatchNormalization(ch // 1, use_gamma=use_gamma),
            bn3_0=L.BatchNormalization(ch // 1, use_gamma=use_gamma),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, size=64, ch=512, wscale=0.005):
        assert (size % 16 == 0)
        initial_size = size // 16
        w = chainer.initializers.Normal(wscale)
        super(Discriminator2, self).__init__(
            c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
            c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
            c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
            c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
            c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
            l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
            bn0_1=L.BatchNormalization(ch // 4, use_gamma=False),
            bn1_1=L.BatchNormalization(ch // 2, use_gamma=False),
            bn2_1=L.BatchNormalization(ch // 1, use_gamma=False),
            bn3_0=L.BatchNormalization(ch // 1, use_gamma=False),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, bottom_width=8, ch=512, wscale=0.005):
        w = chainer.initializers.Normal(wscale)
        super(DiscriminatorPFN, self).__init__(
            c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
            c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
            c1_0=L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w),
            c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
            c2_0=L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w),
            c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
            c3_0=L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w),
            l4=L.Linear(bottom_width * bottom_width * ch, 1, initialW=w),
            bn0_1=L.BatchNormalization(ch // 4, use_gamma=False),
            bn1_0=L.BatchNormalization(ch // 4, use_gamma=False),
            bn1_1=L.BatchNormalization(ch // 2, use_gamma=False),
            bn2_0=L.BatchNormalization(ch // 2, use_gamma=False),
            bn2_1=L.BatchNormalization(ch // 1, use_gamma=False),
            bn3_0=L.BatchNormalization(ch // 1, use_gamma=False),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, density=1, size=64, latent_size=128, channel=3):
        assert (size % 16 == 0)
        initial_size = size / 16
        super(Generator, self).__init__(
            g1=L.Linear(latent_size, initial_size * initial_size * 256 * density, wscale=0.02 * math.sqrt(latent_size)),
            norm1=L.BatchNormalization(initial_size * initial_size * 256 * density),
            g2=L.Deconvolution2D(256 * density, 128 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 256 * density)),
            norm2=L.BatchNormalization(128 * density),
            g3=L.Deconvolution2D(128 * density, 64 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
            norm3=L.BatchNormalization(64 * density),
            g4=L.Deconvolution2D(64 * density, 32 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 64 * density)),
            norm4=L.BatchNormalization(32 * density),
            g5=L.Deconvolution2D(32 * density, channel, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 32 * density)),
        )
        self.density = density
        self.latent_size = latent_size
        self.initial_size = initial_size
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, density=1, size=64, channel=3):
        assert (size % 16 == 0)
        initial_size = size / 16
        super(Discriminator, self).__init__(
            dis1=L.Convolution2D(channel, 32 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * channel * density)),
            dis2=L.Convolution2D(32 * density, 64 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 32 * density)),
            norm2=L.BatchNormalization(64 * density),
            dis3=L.Convolution2D(64 * density, 128 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 64 * density)),
            norm3=L.BatchNormalization(128 * density),
            dis4=L.Convolution2D(128 * density, 256 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
            norm4=L.BatchNormalization(256 * density),
            dis5=L.Linear(initial_size * initial_size * 256 * density, 512,
                          wscale=0.02 * math.sqrt(initial_size * initial_size * 256 * density)),
            norm5=L.BatchNormalization(512),
            dis6=L.Linear(512, 2, wscale=0.02 * math.sqrt(512)),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, density=1, size=64, latent_size=100, channel=3):
        assert (size % 16 == 0)
        initial_size = size / 16
        super(Encoder_origin, self).__init__(
            enc1=L.Convolution2D(channel, 32 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * channel * density)),
            enc2=L.Convolution2D(32 * density, 64 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 32 * density)),
            norm2=L.BatchNormalization(64 * density),
            enc3=L.Convolution2D(64 * density, 128 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 64 * density)),
            norm3=L.BatchNormalization(128 * density),
            enc4=L.Convolution2D(128 * density, 256 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
            norm4=L.BatchNormalization(256 * density),
            mean=L.Linear(initial_size * initial_size * 256 * density, latent_size,
                          wscale=0.02 * math.sqrt(initial_size * initial_size * 256 * density)),
            ln_var=L.Linear(initial_size * initial_size * 256 * density, latent_size,
                            wscale=0.02 * math.sqrt(initial_size * initial_size * 256 * density)),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, density=1, size=64, latent_size=100, channel=3):
        assert (size % 16 == 0)
        initial_size = size / 16
        super(Generator_origin, self).__init__(
            g1=L.Linear(latent_size, initial_size * initial_size * 256 * density, wscale=0.02 * math.sqrt(latent_size)),
            norm1=L.BatchNormalization(initial_size * initial_size * 256 * density),
            g2=L.Deconvolution2D(256 * density, 128 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 256 * density)),
            norm2=L.BatchNormalization(128 * density),
            g3=L.Deconvolution2D(128 * density, 64 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
            norm3=L.BatchNormalization(64 * density),
            g4=L.Deconvolution2D(64 * density, 32 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 64 * density)),
            norm4=L.BatchNormalization(32 * density),
            g5=L.Deconvolution2D(32 * density, channel, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 32 * density)),
        )
        self.density = density
        self.latent_size = latent_size
        self.initial_size = initial_size
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, density=1, size=64, channel=3):
        assert (size % 16 == 0)
        initial_size = size / 16
        super(Discriminator_org, self).__init__(
            dis1=L.Convolution2D(channel, 32 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * channel * density)),
            dis2=L.Convolution2D(32 * density, 64 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 32 * density)),
            norm2=L.BatchNormalization(64 * density),
            dis3=L.Convolution2D(64 * density, 128 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 64 * density)),
            norm3=L.BatchNormalization(128 * density),
            dis4=L.Convolution2D(128 * density, 256 * density, 4, stride=2, pad=1,
                                 wscale=0.02 * math.sqrt(4 * 4 * 128 * density)),
            norm4=L.BatchNormalization(256 * density),
            dis5=L.Linear(initial_size * initial_size * 256 * density, 2,
                          wscale=0.02 * math.sqrt(initial_size * initial_size * 256 * density)),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, size=64, ch=512, wscale=0.005):
        assert (size % 16 == 0)
        initial_size = size // 16
        w = chainer.initializers.Normal(wscale)
        super(Discriminator, self).__init__(
            c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
            c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
            c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
            c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
            c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
            l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
            bn0_1=L.BatchNormalization(ch // 4, use_gamma=False),
            bn1_1=L.BatchNormalization(ch // 2, use_gamma=False),
            bn2_1=L.BatchNormalization(ch // 1, use_gamma=False),
            bn3_0=L.BatchNormalization(ch // 1, use_gamma=False),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, size=64, ch=512, wscale=0.005):
        assert (size % 16 == 0)
        initial_size = size // 16
        w = chainer.initializers.Normal(wscale)
        super(Discriminator2, self).__init__(
            c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
            c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
            c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
            c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
            c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
            l4=L.Linear(initial_size * initial_size * ch, 1, initialW=w),
            bn0_1=L.BatchNormalization(ch // 4),
            bn1_1=L.BatchNormalization(ch // 2),
            bn2_1=L.BatchNormalization(ch // 1),
            bn3_0=L.BatchNormalization(ch // 1),
        )
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, size=64, n_hidden=128, ch=512, wscale=0.02):
        assert (size % 16 == 0)
        initial_size = size / 16
        w = chainer.initializers.Normal(wscale)
        super(Encoder, self).__init__(
            c0_0=L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w),
            c0_1=L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w),
            c1_1=L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w),
            c2_1=L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w),
            c3_0=L.Convolution2D(ch // 1, ch // 1, 4, 2, 1, initialW=w),
            mean=L.Linear(initial_size * initial_size * ch, n_hidden, initialW=w),
            ln_var=L.Linear(initial_size * initial_size * ch, n_hidden, initialW=w),
            bn0_1=L.BatchNormalization(ch // 4, use_gamma=False),
            bn1_1=L.BatchNormalization(ch // 2, use_gamma=False),
            bn2_1=L.BatchNormalization(ch // 1, use_gamma=False),
            bn3_0=L.BatchNormalization(ch // 1, use_gamma=False),
        )

    # noinspection PyCallingNonCallable,PyUnresolvedReferences
项目:chainer-image-generation    作者:fukuta0614    | 项目源码 | 文件源码
def __init__(self, ch0, ch1, bn=True, sample='down', activation=F.relu, dropout=False, noise=False):
        self.bn = bn
        self.activation = activation
        self.dropout = dropout
        self.noise = noise
        layers = {}
        w = chainer.initializers.Normal(0.02)
        if sample == 'down':
            layers['c'] = L.Convolution2D(ch0, ch1, 4, 2, 1, initialW=w)
        elif sample == 'up':
            layers['c'] = L.Deconvolution2D(ch0, ch1, 4, 2, 1, initialW=w)
        elif sample == 'c7s1':
            layers['c'] = L.Convolution2D(ch0, ch1, 7, 1, 3, initialW=w)
        if bn:
            if self.noise:
                layers['batchnorm'] = L.BatchNormalization(ch1, use_gamma=False)
            else:
                layers['batchnorm'] = L.BatchNormalization(ch1)
        super(CBR, self).__init__(**layers)
项目:chainer-DPNs    作者:oyam    | 项目源码 | 文件源码
def __init__(self, in_size, ch, out_size, stride=2):
        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)
            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)
项目:cv-api    作者:yasunorikudo    | 项目源码 | 文件源码
def __init__(self):
        super(FastStyleNet, self).__init__(
            c1=L.Convolution2D(3, 32, 9, stride=1, pad=4),
            c2=L.Convolution2D(32, 64, 4, stride=2, pad=1),
            c3=L.Convolution2D(64, 128, 4,stride=2, pad=1),
            r1=ResidualBlock(128, 128),
            r2=ResidualBlock(128, 128),
            r3=ResidualBlock(128, 128),
            r4=ResidualBlock(128, 128),
            r5=ResidualBlock(128, 128),
            d1=L.Deconvolution2D(128, 64, 4, stride=2, pad=1),
            d2=L.Deconvolution2D(64, 32, 4, stride=2, pad=1),
            d3=L.Deconvolution2D(32, 3, 9, stride=1, pad=4),
            b1=L.BatchNormalization(32),
            b2=L.BatchNormalization(64),
            b3=L.BatchNormalization(128),
            b4=L.BatchNormalization(64),
            b5=L.BatchNormalization(32),
        )
项目:chainer-DenseNet    作者:t-hanya    | 项目源码 | 文件源码
def __init__(self, in_channels, n_layers, growth_rate,
                 dropout_ratio=None):

        super(DenseBlock, self).__init__()

        self._layers = []
        sum_channels = in_channels
        for l in range(n_layers):
            W = initializers.HeNormal()
            conv = L.Convolution2D(sum_channels, growth_rate, 3, pad=1,
                                   initialW=W)
            norm = L.BatchNormalization(sum_channels)
            self.add_link('conv{}'.format(l + 1), conv)
            self.add_link('norm{}'.format(l + 1), norm)
            self._layers.append((conv, norm))
            sum_channels += growth_rate

        self.add_persistent('dropout_ratio', dropout_ratio)
项目:chainer-DenseNet    作者:t-hanya    | 项目源码 | 文件源码
def __init__(self, depth=40, growth_rate=12, in_channels=16,
                 dropout_ratio=0.2, n_class=10):

        assert (depth - 4) % 3 == 0
        n_layers = int((depth - 4) / 3)
        n_ch = [in_channels + growth_rate * n_layers * i for i in range(4)]
        dropout_ratio = dropout_ratio if dropout_ratio > 0 else None

        super(DenseNet, self).__init__(
            conv0=L.Convolution2D(3, n_ch[0], 3, pad=1),
            dense1=DenseBlock(
                n_ch[0], n_layers, growth_rate, dropout_ratio),
            trans1=TransitionLayer(n_ch[1], n_ch[1], dropout_ratio),
            dense2=DenseBlock(
                n_ch[1], n_layers, growth_rate, dropout_ratio),
            trans2=TransitionLayer(n_ch[2], n_ch[2], dropout_ratio),
            dense3=DenseBlock(
                n_ch[2], n_layers, growth_rate, dropout_ratio),
            norm4=L.BatchNormalization(n_ch[3]),
            fc4=L.Linear(n_ch[3], n_class),
        )
项目:GAN    作者:lyakaap    | 项目源码 | 文件源码
def __init__(self, n_hidden, bottom_width=4, ch=512, wscale=0.02):
        super(Generator, self).__init__()
        self.n_hidden = n_hidden
        self.ch = ch
        self.bottom_width = bottom_width

        with self.init_scope():
            w = chainer.initializers.Normal(wscale)
            self.l0 = L.Linear(self.n_hidden, bottom_width * bottom_width * ch,
                               initialW=w)
            self.dc1 = L.Deconvolution2D(ch, ch // 2, 4, 2, 1, initialW=w)
            self.dc2 = L.Deconvolution2D(ch // 2, ch // 4, 4, 2, 1, initialW=w)
            self.dc3 = L.Deconvolution2D(ch // 4, ch // 8, 4, 2, 1, initialW=w)
            self.dc4 = L.Deconvolution2D(ch // 8, 3, 3, 1, 1, initialW=w)
            self.bn0 = L.BatchNormalization(bottom_width * bottom_width * ch)
            self.bn1 = L.BatchNormalization(ch // 2)
            self.bn2 = L.BatchNormalization(ch // 4)
            self.bn3 = L.BatchNormalization(ch // 8)
项目:GAN    作者:lyakaap    | 项目源码 | 文件源码
def __init__(self, bottom_width=4, ch=512, wscale=0.02):
        w = chainer.initializers.Normal(wscale)
        super(Discriminator, self).__init__()
        with self.init_scope():
            self.c0_0 = L.Convolution2D(3, ch // 8, 3, 1, 1, initialW=w)
            self.c0_1 = L.Convolution2D(ch // 8, ch // 4, 4, 2, 1, initialW=w)
            self.c1_0 = L.Convolution2D(ch // 4, ch // 4, 3, 1, 1, initialW=w)
            self.c1_1 = L.Convolution2D(ch // 4, ch // 2, 4, 2, 1, initialW=w)
            self.c2_0 = L.Convolution2D(ch // 2, ch // 2, 3, 1, 1, initialW=w)
            self.c2_1 = L.Convolution2D(ch // 2, ch // 1, 4, 2, 1, initialW=w)
            self.c3_0 = L.Convolution2D(ch // 1, ch // 1, 3, 1, 1, initialW=w)
            self.l4 = L.Linear(bottom_width * bottom_width * ch, 1, initialW=w)
            self.bn0_1 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_0 = L.BatchNormalization(ch // 4, use_gamma=False)
            self.bn1_1 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_0 = L.BatchNormalization(ch // 2, use_gamma=False)
            self.bn2_1 = L.BatchNormalization(ch // 1, use_gamma=False)
            self.bn3_0 = L.BatchNormalization(ch // 1, use_gamma=False)
项目:GAN    作者:lyakaap    | 项目源码 | 文件源码
def __init__(self):
        initializer = initializers.HeNormal()
        dis = Discriminator()
        chainer.serializers.load_npz('result/dis_iter_500000.npz', dis)
        super(DiscriminatorClassifier, self).__init__(
            c0 = L.Convolution2D(1, 64, 4, stride=2, pad=1, initialW=dis.c0.W.data, initial_bias=dis.c0.b.data),
            c1 = L.Convolution2D(64, 128, 4, stride=2, pad=1, initialW=dis.c1.W.data, initial_bias=dis.c1.b.data),
            l2 = L.Linear(7*7*128, 10, initialW = initializer),
            bn1 = L.BatchNormalization(128),
        )
        self.c0.disable_update()

#    def __init__(self):
#        initializer = initializers.HeNormal()
#        super(DiscriminatorClassifier, self).__init__(
#            c0 = L.Convolution2D(1, 64, 4, stride=2, pad=1, initialW=initializer),
#            c1 = L.Convolution2D(64, 128, 4, stride=2, pad=1, initialW=initializer),
#            l2 = L.Linear(7*7*128, 10, initialW = initializer),
#            bn1 = L.BatchNormalization(128),
#        )
#
项目:reinforcement-learning    作者:musyoku    | 项目源码 | 文件源码
def build_network(self):
        config.check()
        wscale = config.q_wscale

        # Fully connected part of Q-Network
        fc_attributes = {}
        fc_units = zip(config.q_fc_units[:-1], config.q_fc_units[1:])

        for i, (n_in, n_out) in enumerate(fc_units):
            fc_attributes["layer_%i" % i] = L.Linear(n_in, n_out, wscale=wscale)
            fc_attributes["batchnorm_%i" % i] = BatchNormalization(n_out)

        fc = FullyConnectedNetwork(**fc_attributes)
        fc.n_hidden_layers = len(fc_units) - 1
        fc.activation_function = config.q_fc_activation_function
        fc.apply_batchnorm = config.apply_batchnorm
        fc.apply_dropout = config.q_fc_apply_dropout
        fc.apply_batchnorm_to_input = config.q_fc_apply_batchnorm_to_input
        if config.use_gpu:
            fc.to_gpu()
        return fc
项目:reinforcement-learning    作者:musyoku    | 项目源码 | 文件源码
def build_network(self, units=None):
        if units is None:
            raise Exception()
        config.check()
        wscale = config.q_wscale

        # Fully connected part of Q-Network
        fc_attributes = {}
        units[-1] *= config.q_k_heads
        fc_units = zip(units[:-1], units[1:])

        for i, (n_in, n_out) in enumerate(fc_units):
            fc_attributes["layer_%i" % i] = L.Linear(n_in, n_out, wscale=wscale)
            fc_attributes["batchnorm_%i" % i] = BatchNormalization(n_out)

        fc = FullyConnectedNetwork(**fc_attributes)
        fc.n_hidden_layers = len(fc_units) - 1
        fc.activation_function = config.q_fc_activation_function
        fc.apply_batchnorm = config.apply_batchnorm
        fc.apply_dropout = config.q_fc_apply_dropout
        fc.apply_batchnorm_to_input = config.q_fc_apply_batchnorm_to_input
        if config.use_gpu:
            fc.to_gpu()
        return fc
项目:reinforcement-learning    作者:musyoku    | 项目源码 | 文件源码
def build_head(self, k=0, units=None):
        if units is None:
            raise Exception()
        config.check()
        wscale = config.q_wscale

        # Fully connected part of Q-Network
        fc_attributes = {}
        fc_units = zip(units[:-1], units[1:])

        for i, (n_in, n_out) in enumerate(fc_units):
            fc_attributes["layer_%i" % i] = LinearHead(n_in, n_out, config.q_k_heads, wscale=wscale)
            fc_attributes["batchnorm_%i" % i] = BatchNormalization(n_out)

        fc = FullyConnectedNetwork(**fc_attributes)
        fc.n_hidden_layers = len(fc_units) - 1
        fc.activation_function = config.q_fc_activation_function
        fc.apply_dropout = config.q_fc_apply_dropout
        if config.use_gpu:
            fc.to_gpu()
        return fc