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:
BaseLayerCreates a branching layer that processes the input through multiple branches and combines the outputs.
- Attributes:
- group
int Layer group, if 0 it will always be used, else it will only be used if its group matches the Networks
- description
str Description of the layer
- branches
list[BaseLayer] List of subnetworks for each branch
- head
Concatenate|Pack|Shortcut Layer to combine the outputs from each branch, either concatenation, packing or summation
- group
- Parameters:
- net_checkbool
If layer index should be relative to checkpoint layers
- branches
list[list[dict[str,Any]]] List of layer configurations for each branch
- shapes
Shapes Shape of the outputs from each layer
- checkpointbool,
Optional If layer index should be relative to checkpoint layers, default = True
- dim
int,Optional Dimension to concatenate along if method is ‘concat’, default = 0
- channels
int,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
- root
str,Optional Root directory to prepend to config file path
- method
Literal[‘concat’, ‘pack’, ‘sum’],Optional Method to combine the outputs from each branch, either concatenation, packing or summation, default = ‘concat’
- shape
list[int] |NoneType,Optional Output shape of the block, will be used if provided; otherwise, channels will be used
- defaults
dict[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:
strLayer parameters
- forward(x, *_, **__)[source]
Forward pass for the Branch layer.
- Parameters:
- x
TensorListT Input tensor(s) with dtype float32 and shape (N,…), where N is batch size
- x
- Returns:
TensorListTOutput 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:
BaseLayerCreates a subnetwork from a configuration file.
- Attributes:
- Parameters:
- net_checkbool
If layer index should be relative to checkpoint layers
- name
str Name of the subnetwork
- shapes
Shapes Shape of the outputs from each layer
- checkpointbool,
Optional If layer index should be relative to checkpoint layers, default = True
- channels
int,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
- root
str,Optional Root directory to prepend to config file path
- config_dir
str,Optional Path to the directory with the network configuration file, won’t be used if config is provided
- shape
list[int] |NoneType,Optional Output shape of the block, will be used if provided; otherwise, channels will be used
- defaults
dict[str,Any] |NoneType,Optional Default values for the parameters for each type of layer
- config
dict[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:
strLayer parameters
- forward(x, *_, **__)[source]
Forward pass for the Composite layer.
- Parameters:
- x
TensorListT Input tensor(s) with dtype float32 and shape (N,…), where N is batch size
- x
- Returns:
TensorListTOutput tensor(s) from the subnetwork with dtype float32 and shape (N,…)
- to(*args, **kwargs)[source]
See
torch.nn.Module.to().