Base Layers#

Classes#

class BaseLayer(*, idx=0, group=0, version='', description='', **kwargs)[source]#

Bases: Module, ABC

Base layer for other layers to inherit.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks

descriptionstr

Description of the layer

Parameters:
idxint, Optional

Layer number, default = 0

groupint, Optional

Which group the layer belongs to, if 0 it will always be used, else it will only be used if the Network group matches the layer’s group, default = 0

versionstr, Optional

Version of the network, default = netloader.__version__

descriptionstr, Optional

Description of the layer

**kwargs

Leftover parameters for checking if they are valid

abstractmethod forward(x, *_, **__)[source]#

Forward pass for child layer ti implement.

Parameters:
xAny

Layer input

Returns:
Any

Layer output

to(*args, **kwargs)[source]#

See torch.nn.Module.to().

class BaseSingleLayer(**kwargs)[source]#

Bases: BaseLayer

Base layer for layers that only use the previous layer.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Network’s

descriptionstr

Description of the layer

layersSequential

Layers to loop through in the forward pass

Parameters:
**kwargs

Leftover parameters to pass to base layer for checking

forward(x, *_, **__)[source]#

Forward pass for a generic layer.

Parameters:
xTensorListLike

Input with tensors of shape (N,…) and type float, where N is the batch size

Returns:
TensorListLike

Output with tensors of shape (N,…) and type float

class BaseMultiLayer(net_check, layer, shapes, check_shapes, *, checkpoint=False, **kwargs)[source]#

Bases: BaseLayer

Base layer for layers that use earlier layers to inherit.

Attributes:
groupint

Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks

descriptionstr

Description of the layer

Parameters:
net_checkbool

If layer index should be relative to checkpoint layers

layerint | list[int]

Layer index(es) to concatenate the previous layer output with

shapesShapes

Shape of the outputs from each layer

check_shapesShapes

Shape of the outputs from each checkpoint

checkpointbool, Optional

If layer index should be relative to checkpoint layers, default = False

**kwargs

Leftover parameters to pass to base layer for checking

extra_repr()[source]#

Displays layer parameters when printing the network.

Returns:
str

Layer parameters

forward(x, *_, outputs, checkpoints, **__)[source]#

Forward pass to combine outputs from multiple layers.

Parameters:
xTensorListLike

Input with tensors of shape (N,…) and type float, where N is the batch size

outputslist[TensorListLike]

Output from each layer with tensors of shape (N,…) and type float

checkpointslist[TensorListLike]

Output from each checkpoint with tensors of shape (N,…) and type float

Returns:
TensorListLike

Output with tensors of shape (N,…) and type float