Utilities

mi_module_zoo.mlp.construct_mlp(input_dim: int, out_dim: int, hidden_layer_dims: Sequence[int], activation_layer: torch.nn.modules.module.Module = ReLU()) torch.nn.modules.container.Sequential[source]

Construct a multi-linear perceptron (MLP). No non-linearity is applied at the final layer.

Parameters
  • input_dim – the input dimension of the MLP.

  • out_dim – the input dimension of the MLP.

  • hidden_layer_dims – a list of zero or more integers indicating the dimensions of the hidden layers.

  • activation_layer – the activation layer used between the input and hidden layers.

Returns

a nn.Sequential with the constructed MLP.

mi_module_zoo.utils.activation.get_activation_fn(activation: str) Callable[[torch.Tensor], torch.Tensor][source]

Get an activation function by name. :param activation: the name of the activation function.

Parameters

activation – a case-insensitive name of the activation function.

Returns

an activation function