Skip to content

ocl.neural_networks.wrappers

Wrapper modules with allow the introduction or residuals or the combination of other modules.

Sequential

Bases: nn.Module

Extended sequential module that supports multiple inputs and outputs to layers.

This allows a stack of layers where for example the first layer takes two inputs and only has a single output or where a layer has multiple outputs and the downstream layer takes multiple inputs.

Source code in ocl/neural_networks/wrappers.py
class Sequential(nn.Module):
    """Extended sequential module that supports multiple inputs and outputs to layers.

    This allows a stack of layers where for example the first layer takes two inputs and only has
    a single output or where a layer has multiple outputs and the downstream layer takes multiple
    inputs.
    """

    def __init__(self, *layers):
        super().__init__()
        self.layers = nn.ModuleList(layers)

    def forward(self, *inputs):
        outputs = inputs
        for layer in self.layers:
            if isinstance(outputs, (tuple, list)):
                outputs = layer(*outputs)
            else:
                outputs = layer(outputs)
        return outputs