Sequential

The nnabla.core.sequential.Sequential class represents a construction block of neural network.

Sequential

class nnabla.core.sequential.Sequential(*args, **kwargs)[source]

A sequential block. User may construct their network by a sequential block. Importantly, the component within sequential block must be an instance of nn.Module.

For intuitive understanding, some small examples as follows:

import nnabla as nn
import nnabla.parametric_functions as PF
import nnabla.functions as F

class ConvLayer(nn.Module):
    def __init__(self, outmaps, kernel, stride=1, pad=0):
        self.outmaps = outmaps
        self.kernel = (kernel, kernel)
        self.pad = (pad, pad)
        self.stride = (stride, stride)

    def call(self, x):
        x = PF.convolution(x, outmaps=self.outmaps, kernel=self.kernel, pad=self.pad, stride=self.stride)
        x = F.relu(x)
        return x

# Example of using Sequentional
layer = nn.Sequential(
    ConvLayer(48, kernel=1),
    ConvLayer(64, kernel=3, pad=1)
)

# Example of using Sequentional with a specify name for each layer
layer = nn.Sequential(
    ('conv1', ConvLayer(48, kernel=1)),
    ('conv2', ConvLayer(64, kernel=3, pad=1))
)