How to use the chainer.links.Convolution2D function in chainer

To help you get started, we’ve selected a few chainer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github chainer / chainer / tests / chainermn_tests / links_tests / test_create_mnbn_model.py View on Github external
def check_create_mnbn_model_chain(self, gpu):
        model = BnChain(3)
        mnbn_model = chainermn.links.create_mnbn_model(model,
                                                       self.communicator)
        self.assertTrue(isinstance(mnbn_model.conv,
                                   chainer.links.Convolution2D))
        self.assertTrue(
            isinstance(mnbn_model.bn,
                       chainermn.links.MultiNodeBatchNormalization))
        if gpu:
            mnbn_model.to_device(cupy.cuda.Device())

        with chainer.using_device(mnbn_model.device):
            x = mnbn_model.xp.zeros((1, 1, 1, 1))
            mnbn_model(x)
github mil-tokyo / FTGAN / src / TextureGAN / net.py View on Github external
def __init__(self, ch0, ch1, bn=True, sample='down', activation=F.leaky_relu, add_noise=False, sigma=0.2):
        self.bn = bn
        self.activation = activation
        self.add_noise = add_noise
        self.sigma = sigma
        self.iteration = 0
        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 == 'same':
            layers['c'] = L.Convolution2D(ch0, ch1, 3, 1, 1, initialW=w)
        if bn:
            layers['batchnorm'] = L.BatchNormalization(ch1)
        super(CBR, self).__init__(**layers)
github corochann / chainer-pointnet / chainer_pointnet / models / pointnet2 / pointnet2_seg_ssg.py View on Github external
self.sam4 = SetAbstractionModule(
                k=16, num_sample_in_region=32, radius=0.8, mlp=[256, 256, 512],
                mlp2=None, use_bn=use_bn, return_distance=True,
                residual=residual)

            self.fpm5 = FeaturePropagationModule(
                mlp=[256, 256], use_bn=use_bn, residual=residual)
            self.fpm6 = FeaturePropagationModule(
                mlp=[256, 256], use_bn=use_bn, residual=residual)
            self.fpm7 = FeaturePropagationModule(
                mlp=[256, 128], use_bn=use_bn, residual=residual)
            self.fpm8 = FeaturePropagationModule(
                mlp=[128, 128, 128], use_bn=use_bn, residual=residual)
            self.conv_block9 = ConvBlock(
                128, 128, ksize=1, use_bn=use_bn, residual=residual)
            self.conv10 = links.Convolution2D(128, out_dim, ksize=1)

        self.compute_accuracy = compute_accuracy
github wkentaro / fcn / fcn / models / fcn8s_atonce.py View on Github external
super(FCN8sAtOnce, self).__init__(
            conv1_1=L.Convolution2D(3, 64, 3, stride=1, pad=100,
                                    initialW=initialW, initial_bias=initialb),
            conv1_2=L.Convolution2D(64, 64, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),

            conv2_1=L.Convolution2D(64, 128, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv2_2=L.Convolution2D(128, 128, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),

            conv3_1=L.Convolution2D(128, 256, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv3_2=L.Convolution2D(256, 256, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv3_3=L.Convolution2D(256, 256, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),

            conv4_1=L.Convolution2D(256, 512, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv4_2=L.Convolution2D(512, 512, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv4_3=L.Convolution2D(512, 512, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),

            conv5_1=L.Convolution2D(512, 512, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv5_2=L.Convolution2D(512, 512, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
            conv5_3=L.Convolution2D(512, 512, 3, stride=1, pad=1,
                                    initialW=initialW, initial_bias=initialb),
github chainer / chainerrl / examples / atari / train_drqn_ale.py View on Github external
F.relu,
            L.Convolution2D(None, 64, 4, stride=2),
            F.relu,
            L.Convolution2D(None, 64, 3, stride=1),
            functools.partial(F.reshape, shape=(-1, 3136)),
            F.relu,
            L.NStepLSTM(1, 3136, 512, 0),
            L.Linear(None, n_actions),
            DiscreteActionValue,
        )
        # Replay buffer that stores whole episodes
        rbuf = replay_buffer.EpisodicReplayBuffer(10 ** 6)
    else:
        # Q-network without LSTM
        q_func = chainer.Sequential(
            L.Convolution2D(None, 32, 8, stride=4),
            F.relu,
            L.Convolution2D(None, 64, 4, stride=2),
            F.relu,
            L.Convolution2D(None, 64, 3, stride=1),
            functools.partial(F.reshape, shape=(-1, 3136)),
            L.Linear(None, 512),
            F.relu,
            L.Linear(None, n_actions),
            DiscreteActionValue,
        )
        # Replay buffer that stores transitions separately
        rbuf = replay_buffer.ReplayBuffer(10 ** 6)

    # Draw the computational graph and save it in the output directory.
    fake_obss = np.zeros(env.observation_space.shape, dtype=np.float32)[None]
    if args.recurrent:
github katotetsuro / FPN-SSD / feature_pyramid_network.py View on Github external
def __init__(self, initialW=None):
        super().__init__()
        with self.init_scope():
            # bottom up
            self.resnet = ResNet50Layers('auto')
            del self.resnet.fc6
            # top layer (reduce channel)
            self.toplayer = L.Convolution2D(
                in_channels=None, out_channels=256, ksize=1, stride=1, pad=0, initialW=initialW)

            # conv layer for top-down pathway
            self.conv_p4 = L.Convolution2D(
                None, 256, ksize=3, stride=1, pad=1, initialW=initialW)
            self.conv_p3 = L.Convolution2D(
                None, 256, ksize=3, stride=1, pad=1, initialW=initialW)
            self.conv_p2 = L.Convolution2D(
                None, 256, ksize=3, stride=1, pad=1, initialW=initialW)

            self.conv_p7 = L.Convolution2D(
                None, 256, ksize=3, stride=1, pad=1, initialW=initialW)

            # lateral connection
            self.lat_p4 = L.Convolution2D(
                in_channels=None, out_channels=256, ksize=1, stride=1, pad=0, initialW=initialW)