torchsample.models module#

class torchsample.models.MLP(*layers, activation=None)[source]#

Bases: torch.nn.modules.module.Module

Multi Layer Perceptron.

Applies the MLP to the final dimension of input tensor.

__init__(*layers, activation=None)[source]#

Construct an MLP with specified nodes-per-layer.

Parameters
  • layers (list or tuple) – List of how many nodes each layer should have. Must be at least 2 long.

  • activation (callable) – Activation function applied to all layers except the output layer. Defaults to inplace relu.

forward(x)[source]#

Forward pass through linear and activation layers.

Parameters

x (torch.Tensor) – (…, feat_in) shaped tensor.

Returns

(…, feat_out) shaped tensor.

Return type

torch.Tensor

training: bool#