How to use the nnabla.functions.relu function in nnabla

To help you get started, we’ve selected a few nnabla 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 sony / nnabla-examples / GANs / sagan / models.py View on Github external
_, c, _, _ = h.shape
    assert maps // 2 == c or maps == c
    maps1 = c if maps // 2 == c else maps
    maps2 = maps
    with nn.parameter_scope(scopename):
        # LeakyRelu -> Conv
        with nn.parameter_scope("conv1"):
            #h = F.leaky_relu(h, 0.2, False)
            h = F.relu(h, False)
            h = convolution(h, maps1, kernel=kernel, pad=pad, stride=stride,
                            with_bias=True, sn=sn, test=test, init_scale=np.sqrt(2))

        # LeakyRelu -> Conv -> Downsample
        with nn.parameter_scope("conv2"):
            #h = F.leaky_relu(h, 0.2, True)
            h = F.relu(h, True)
            h = convolution(h, maps2, kernel=kernel, pad=pad, stride=stride,
                            with_bias=True, sn=sn, test=test, init_scale=np.sqrt(2))
            if downsample:
                h = F.average_pooling(h, kernel=(2, 2))

        # Shortcut: Conv -> Downsample
        if c != maps2 or downsample:
            with nn.parameter_scope("shortcut"):
                s = convolution(s, maps2, kernel=(1, 1), pad=(0, 0), stride=(1, 1),
                                with_bias=True, sn=sn, test=test)
        if downsample:
            s = F.average_pooling(s, kernel=(2, 2))
    return F.add2(h, s, True)
    # return F.add2(h, s)
github sony / nnabla / examples / vision / cifar10 / multi_device_multi_process_classification.py View on Github external
def res_unit(x, scope_name, rng, dn=False, test=False):
        C = x.shape[1]
        with nn.parameter_scope(scope_name):

            # Conv -> BN -> Relu
            with nn.parameter_scope("conv1"):
                w_init = UniformInitializer(
                    calc_uniform_lim_glorot(C, C / 2, kernel=(1, 1)),
                    rng=rng)
                h = PF.convolution(x, C / 2, kernel=(1, 1), pad=(0, 0),
                                   w_init=w_init, with_bias=False)
                h = PF.batch_normalization(h, batch_stat=not test)
                h = F.relu(h)
            # Conv -> BN -> Relu
            with nn.parameter_scope("conv2"):
                w_init = UniformInitializer(
                    calc_uniform_lim_glorot(C / 2, C / 2, kernel=(3, 3)),
                    rng=rng)
                h = PF.convolution(h, C / 2, kernel=(3, 3), pad=(1, 1),
                                   w_init=w_init, with_bias=False)
                h = PF.batch_normalization(h, batch_stat=not test)
                h = F.relu(h)
            # Conv -> BN
            with nn.parameter_scope("conv3"):
                w_init = UniformInitializer(
                    calc_uniform_lim_glorot(C / 2, C, kernel=(1, 1)),
                    rng=rng)
                h = PF.convolution(h, C, kernel=(1, 1), pad=(0, 0),
                                   w_init=w_init, with_bias=False)
github sony / nnabla / tutorial / finetuning.py View on Github external
def construct_networks(args, images, model, num_class, test):
    try:
        pooled = model(images, force_global_pooling=1,
                       use_up_to="pool", training=not test)
    except:
        pooled = model(images, use_up_to="pool", training=not test)

    with nn.parameter_scope("finetuning"):
        if args.model == "VGG":
            pooled = F.relu(pooled)

            with nn.parameter_scope("additional_fc_1"):
                pooled = PF.affine(pooled, 4096)
            pooled = F.relu(pooled)
            if not test:
                pooled = F.dropout(pooled, 0.5)

            with nn.parameter_scope("additional_fc_2"):
                pooled = PF.affine(pooled, 4096)
            pooled = F.relu(pooled)
            if not test:
                pooled = F.dropout(pooled, 0.5)

        with nn.parameter_scope("last_fc"):
            pred = PF.affine(pooled, num_class)

    return pred
github sony / nnabla-examples / GANs / munit / models.py View on Github external
def mlp(x, maps, num_res=4, num_layers=2, name="mlp"):
    h = x
    with nn.parameter_scope(name):
        h = PF.affine(h, maps, name="affine-first")
        h = F.relu(h, True)
        h = PF.affine(h, maps, name="affine-mid")
        h = F.relu(h, True)
        h = PF.affine(h, 2 * maps * num_res * num_layers, name="affine-last")
    return h
github sony / nnabla / examples / cpp / forward_check / mnist / classification.py View on Github external
def mnist_lenet_prediction(image, test=False):
    """
    Construct LeNet for MNIST.
    """
    image /= 255.0
    c1 = PF.convolution(image, 16, (5, 5), name='conv1')
    c1 = F.relu(F.max_pooling(c1, (2, 2)), inplace=True)
    c2 = PF.convolution(c1, 16, (5, 5), name='conv2')
    c2 = F.relu(F.max_pooling(c2, (2, 2)), inplace=True)
    c3 = F.relu(PF.affine(c2, 50, name='fc3'), inplace=True)
    c4 = PF.affine(c3, 10, name='fc4')
    return c4
github sony / nnabla-examples / GANs / pix2pixHD / models.py View on Github external
def instance_norm_relu(self, x):
        # return F.relu(PF.layer_normalization(x, **self.norm_opts), inplace=True)
        return F.relu(PF.instance_normalization(x, **self.norm_opts), inplace=True)
github sony / nnabla-examples / semantic-segmentation / deeplabv3plus / xception_65.py View on Github external
with nn.parameter_scope("depthwise"):
        if(stride == True):
            h = PF.depthwise_convolution(x, (3, 3), stride=(2, 2), pad=(
                1, 1), with_bias=False, fix_parameters=fix_params)
        elif(aspp == True):
            h = PF.depthwise_convolution(x, (3, 3), pad=(atrous_rate, atrous_rate), stride=(
                1, 1), dilation=(atrous_rate, atrous_rate), with_bias=False, fix_parameters=fix_params)

        else:
            h = PF.depthwise_convolution(x, (3, 3), pad=(
                1, 1), with_bias=False, fix_parameters=fix_params)

        h = PF.batch_normalization(
            h, batch_stat=not test, eps=eps, fix_parameters=fix_params)
        if last_block == True:
            h = F.relu(h)

    with nn.parameter_scope("pointwise"):
        h = PF.convolution(h, f, (1, 1), stride=(
            1, 1), with_bias=False, fix_parameters=fix_params)
        h = PF.batch_normalization(
            h, batch_stat=not test, eps=eps, fix_parameters=fix_params)
        if end_point == True:
            global endpoints
            endpoints['Decoder End Point 1'] = h

        if act_fn == True:
            h = F.relu(h)

    return h
github peisuke / DeepLearningSpeedComparison / nnabla / vgg16 / predict.py View on Github external
h = F.relu(PF.convolution(h, 256, (3, 3), pad=(1, 1), stride=(1, 1), name='conv5'))
    h = F.relu(PF.convolution(h, 256, (3, 3), pad=(1, 1), stride=(1, 1), name='conv6'))
    h = F.relu(PF.convolution(h, 256, (3, 3), pad=(1, 1), stride=(1, 1), name='conv7'))
    h = F.max_pooling(h, (2, 2))
    h = F.relu(PF.convolution(h, 512, (3, 3), pad=(1, 1), stride=(1, 1), name='conv8'))
    h = F.relu(PF.convolution(h, 512, (3, 3), pad=(1, 1), stride=(1, 1), name='conv9'))
    h = F.relu(PF.convolution(h, 512, (3, 3), pad=(1, 1), stride=(1, 1), name='conv10'))
    h = F.max_pooling(h, (2, 2))
    h = F.relu(PF.convolution(h, 512, (3, 3), pad=(1, 1), stride=(1, 1), name='conv11'))
    h = F.relu(PF.convolution(h, 512, (3, 3), pad=(1, 1), stride=(1, 1), name='conv12'))
    h = F.relu(PF.convolution(h, 512, (3, 3), pad=(1, 1), stride=(1, 1), name='conv13'))
    h = F.max_pooling(h, (2, 2))
    h = PF.affine(h, 4096, name='fc1')
    h = F.relu(h)
    h = PF.affine(h, 4096, name='fc2')
    h = F.relu(h)
    h = PF.affine(h, 1000, name='fc3')
    return F.softmax(h)
github sony / nnabla / examples / vision / mnist / classification.py View on Github external
def mnist_lenet_prediction(image, test=False):
    """
    Construct LeNet for MNIST.
    """
    image /= 255.0
    c1 = PF.convolution(image, 16, (5, 5), name='conv1')
    c1 = F.relu(F.max_pooling(c1, (2, 2)), inplace=True)
    c2 = PF.convolution(c1, 16, (5, 5), name='conv2')
    c2 = F.relu(F.max_pooling(c2, (2, 2)), inplace=True)
    c3 = F.relu(PF.affine(c2, 50, name='fc3'), inplace=True)
    c4 = PF.affine(c3, 10, name='fc4')
    return c4