Composite Layers#

Classes#

class Branch(net_check, branches, shapes, *, checkpoint=True, dim=0, channels=None, root='', method='concat', shape=None, defaults=None, **kwargs)[source]

Bases: BaseLayer

Creates a branching layer that processes the input through multiple branches and combines the outputs.

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

brancheslist[BaseLayer]

List of subnetworks for each branch

headConcatenate | Pack | Shortcut

Layer to combine the outputs from each branch, either concatenation, packing or summation

Parameters:
net_checkbool

If layer index should be relative to checkpoint layers

brancheslist[list[dict[str, Any]]]

List of layer configurations for each branch

shapesShapes

Shape of the outputs from each layer

checkpointbool, Optional

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

dimint, Optional

Dimension to concatenate along if method is ‘concat’, default = 0

channelsint, Optional

Number of output channels, won’t be used if shape is provided, if channels and shape aren’t provided, the input dimensions will be preserved

rootstr, Optional

Root directory to prepend to config file path

methodLiteral[‘concat’, ‘pack’, ‘sum’], Optional

Method to combine the outputs from each branch, either concatenation, packing or summation, default = ‘concat’

shapelist[int] | NoneType, Optional

Output shape of the block, will be used if provided; otherwise, channels will be used

defaultsdict[str, Any] | NoneType, Optional

Default values for the parameters for each type of layer

**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, *_, **__)[source]

Forward pass for the Branch layer.

Parameters:
xTensorListT

Input tensor(s) with dtype float32 and shape (N,…), where N is batch size

Returns:
TensorListT

Output tensor(s) from the subnetwork with dtype float32 and shape (N,…)

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

See torch.nn.Module.to().

class Composite(net_check, name, shapes, *, checkpoint=True, channels=None, root='', config_dir='', shape=None, defaults=None, config=None, **kwargs)[source]

Bases: BaseLayer

Creates a subnetwork from a configuration file.

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

netNetwork

Subnetwork for the Composite layer

Parameters:
net_checkbool

If layer index should be relative to checkpoint layers

namestr

Name of the subnetwork

shapesShapes

Shape of the outputs from each layer

checkpointbool, Optional

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

channelsint, Optional

Number of output channels, won’t be used if shape is provided, if channels and shape aren’t provided, the input dimensions will be preserved

rootstr, Optional

Root directory to prepend to config file path

config_dirstr, Optional

Path to the directory with the network configuration file, won’t be used if config is provided

shapelist[int] | NoneType, Optional

Output shape of the block, will be used if provided; otherwise, channels will be used

defaultsdict[str, Any] | NoneType, Optional

Default values for the parameters for each type of layer

configdict[str, Any] | Config | NoneType, Optional

Network configuration dictionary

**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, *_, **__)[source]

Forward pass for the Composite layer.

Parameters:
xTensorListT

Input tensor(s) with dtype float32 and shape (N,…), where N is batch size

Returns:
TensorListT

Output tensor(s) from the subnetwork with dtype float32 and shape (N,…)

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

See torch.nn.Module.to().