InputLayer

class neuralhydrology.modelzoo.inputlayer.InputLayer(cfg: Config, embedding_type: str = 'full_model')

Bases: Module

Input layer to preprocess static and dynamic inputs.

This module provides optional embedding of dynamic and static inputs. If dynamic_embeddings or static_embeddings are specified as dictionaries in the config, a fully-connected embedding network will be prepended to the timeseries model. The dictionaries have the following keys:

  • type (default ‘fc’): Type of the embedding net. Currently, only ‘fc’ for fully-connected net is supported.

  • hiddens: List of integers that define the number of neurons per layer in the fully connected network. The last number is the number of output neurons. Must have at least length one.

  • activation (default ‘tanh’): activation function of the network. Supported values are ‘tanh’, ‘sigmoid’, ‘linear’. The activation function is not applied to the output neurons, which always have a linear activation function. An activation function for the output neurons has to be applied in the main model class.

  • dropout (default 0.0): Dropout rate applied to the embedding network.

Note that this module does not support multi-frequency runs.

Parameters:

cfg (Config) – The run configuration

forward(data: Dict[str, Tensor], concatenate_output: bool = True) Tensor | Tuple[Tensor, Tensor]

Perform a forward pass on the input layer.

Parameters:
  • data (Dict[str, torch.Tensor]) – The input data.

  • concatenate_output (bool, optional) – If True (default), the forward method will concatenate the static inputs to each dynamic time step. If False, the forward method will return a tuple of (dynamic, static) inputs.

Returns:

If concatenate_output is True, a single tensor is returned. Else, a tuple with one tensor of dynamic inputs and one tensor of static inputs.

Return type:

Union[torch.Tensor, Tuple[torch.Tensor, torch.Tensor]]