ml4gw.nn.autoencoder package

Submodules

ml4gw.nn.autoencoder.base module

class ml4gw.nn.autoencoder.base.Autoencoder(skip_connection=None)

Bases: Module

Base autoencoder class that defines some of the basic methods and functionality. Autoencoders are defined here as a set of sequential blocks that have an encode method, which acts on the input data to the autoencoder, and a decode method, which acts on the encoded vector generated by the encode method. forward just runs these steps one after the other. Although it isn't explicitly enforced, a good rule of thumb is that the ouput of a block's decode method should have the same shape as the _input_ of its encode method.

Accepts a skip_connection argument that defines how to combine information from the input of one block's encode layer with the output to its decode`layer. See `skip_connections.py for more info about what these classes are expected to contain and how they operate.

decode(*X, states=None)
encode(*X, return_states=False)
forward(*X)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ml4gw.nn.autoencoder.convolutional module

class ml4gw.nn.autoencoder.convolutional.ConvBlock(in_channels, encode_channels, kernel_size, stride=1, groups=1, activation=ReLU(), norm=<class 'torch.nn.modules.batchnorm.BatchNorm1d'>, decode_channels=None, output_activation=None, skip_connection=None)

Bases: Autoencoder

decode(X)
encode(X)
class ml4gw.nn.autoencoder.convolutional.ConvolutionalAutoencoder(in_channels, encode_channels, kernel_size, stride=1, groups=1, activation=ReLU(), output_activation=None, norm=<class 'torch.nn.modules.batchnorm.BatchNorm1d'>, decode_channels=None, skip_connection=None)

Bases: Autoencoder

Build a stack of convolutional autoencoder layer blocks. The output of each decoder layer will match the shape of the input to its corresponding encoder layer, except for the last decoder which can have an arbitrary number of channels specified by decode_channels.

All layers also share the same activation except for the last decoder layer, which can have an arbitrary output_activation.

decode(*X, states=None, input_size=None)
forward(X)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

ml4gw.nn.autoencoder.skip_connection module

class ml4gw.nn.autoencoder.skip_connection.AddSkipConnect(*args, **kwargs)

Bases: SkipConnection

forward(X, state)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class ml4gw.nn.autoencoder.skip_connection.ConcatSkipConnect(groups=1)

Bases: SkipConnection

forward(X, state)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_out_channels(in_channels)
class ml4gw.nn.autoencoder.skip_connection.SkipConnection(*args, **kwargs)

Bases: Module

forward(X, state)

Define the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

get_out_channels(in_channels)

ml4gw.nn.autoencoder.utils module

ml4gw.nn.autoencoder.utils.match_size(X, target_size)

Module contents