alpine.models package#

Subpackages#

Submodules#

alpine.models.ffn module#

class alpine.models.ffn.FFN#

Bases: AlpineBaseModule

__init__(in_features, hidden_features, hidden_layers, out_features, outermost_linear=True, positional_encoding='fourier', positional_encoding_kwargs={'mapping_size': 256, 'scale': 10.0})#

Fourier Feature Networks by [Tancik et al., 2020] .

Parameters:
  • in_features (int) – number of input features. For a coordinate based model, input the number of coordinate dims (2 for 2D, 3 for 3D)

  • hidden_features (int) – width of each layer in the INR. Number of neurons per layer.

  • hidden_layers (int) – Total number of hidden layers in the INR.

  • out_features (int) – number of output features. For a scalar or grayscale field, this is 1. For an RGB image, this field is 3.

  • outermost_linear (bool, optional) – Ensures that the last layer is a linear layer with no activation. Defaults to True.

  • positional_encoding (str, optional) – Encoding scheeme. Currently only fourier encoding is supported. Defaults to ‘fourier’.

  • positional_encoding_kwargs (dict, optional) – Parameters for position encoding layer. Defaults to {‘mapping_size’:256, ‘scale’: 10.0}.

Raises:

NotImplementedError – Rasies an exception for custom / non-fourier position encoding.

forward(coords, return_features=False)#

Compute the forward pass of the FFN model.

Parameters:
  • coords (torch.Tensor) – Input coordinates or features to the model of shape \(b \times \cdots \times d\) where b is batch and d is the number of input features.

  • return_features (bool, optional) – Set flag to True to return intermediate layer features along with computed output. Defaults to False.

Returns:

Returns a dict with keys: output, features. The output key contains the output of the model. The features key contains the intermediate features of the model.

Return type:

dict

load_weights(weights)#
class alpine.models.ffn.PosEncoding#

Bases: Module

__init__(in_features, mapping_size, scale)#

Positional encoding module to encode the input coordinates. Adapted from FFN by [Tancik et al., 2020] .

Parameters:
  • in_features (_type_) – Input features to the network such as coordinate dimensions

  • mapping_size (_type_) – dimensions to map input features.

  • scale (_type_) – deviation of distribution for sampling random frequencies.

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.

alpine.models.siren module#

class alpine.models.siren.Siren#

Bases: AlpineBaseModule

__init__(in_features, hidden_features, hidden_layers, out_features, outermost_linear=True, omegas=[30.0], bias=True)#

Implements the Siren INR [Sitzmann et al., 2020] .

Parameters:
  • in_features (int) – number of input features. For a coordinate based model, input the number of coordinate dims (2 for 2D, 3 for 3D)

  • hidden_features (int) – width of each layer in the INR. Number of neurons per layer.

  • hidden_layers (int) – Total number of hidden layers in the INR.

  • out_features (int) – number of output features. For a scalar or grayscale field, this is 1. For an RGB image, this field is 3.

  • outermost_linear (bool, optional) – Ensures that the last layer is a linear layer with no activation. Defaults to True.

  • omegas (list[float], optional) – Controls the bandwidth of each layer of the siren. Defaults to [30.0].

  • bias (bool, optional) – Sets bias for each layer in the INR. Defaults to True.

forward(coords, return_features=False)#

Compute the forward pass of the Siren model.

Parameters:
  • coords (torch.Tensor) – Input coordinates or features to the model of shape \(b \times \cdots \times d\) where b is batch and d is the number of input features.

  • return_features (bool, optional) – Set flag to True to return intermediate layer features along with computed output. Defaults to False.

Returns:

Returns a dict with keys: output, features. The output key contains the output of the model. The features key contains the intermediate features of the model.

Return type:

dict

load_weights(weights)#
alpine.models.siren.get_linear_layer(in_features, out_features, omega=30.0, bias=True, is_first=False, is_last=False)#

alpine.models.strainer module#

class alpine.models.strainer.Strainer#

Bases: AlpineBaseModule

__init__(in_features, hidden_features, hidden_layers, out_features, num_shared_layers, num_decoders, outermost_linear=True, omegas=[30.0], bias=True)#

Implements Strainer INR [Vyas et al., 2024] .

Parameters:
  • in_features (int) – number of input features. For a coordinate based model, input the number of coordinate dims (2 for 2D, 3 for 3D)

  • hidden_features (int) – width of each layer in the INR. Number of neurons per layer.

  • hidden_layers (int) – Total number of hidden layers in the INR.

  • out_features (int) – number of output features. For a scalar or grayscale field, this is 1. For an RGB image, this field is 3.

  • num_shared_layers (int) – Number of layers shared for the encoder layer.

  • num_decoders (int) – Number of decoder heads for strainer. Use 1 for single decoder.

  • outermost_linear (bool, optional) – Ensures that the last layer is a linear layer with no activation. Defaults to True.

  • omegas (list[float], optional) – Controls the bandwidth of each layer of the siren. Defaults to [30.0].

  • bias (bool, optional) – Sets bias for each layer in the INR. Defaults to True.

forward(coords, return_features=False)#

Compute the forward pass of the Strainer model.

Parameters:
  • coords (torch.Tensor) – Input coordinates or features to the model of shape \(b \times \cdots \times d\) where b is batch and d is the number of input features.

  • return_features (bool, optional) – Set flag to True to return intermediate layer features along with computed output. Defaults to False.

Returns:

Returns a dict with keys: output, features. The output key contains the output of the model. The features key contains the intermediate features of the model.

Return type:

dict

load_encoder_weights(weights)#
load_weights(weights)#
alpine.models.strainer.get_linear_layer(in_features, out_features, omega=30.0, bias=True, is_first=False, is_last=False)#

alpine.models.utils module#

alpine.models.utils.get_coords_nd(*args, bounds=(-1, 1))#

Get coordinates for ND grid.

alpine.models.utils.get_coords_spatial(*args, bounds=(-1, 1))#

Get coordinates for ND grid.

alpine.models.wire module#

class alpine.models.wire.Wire#

Bases: AlpineBaseModule

__init__(in_features, hidden_features, hidden_layers, out_features, outermost_linear=True, omegas=[20.0], sigmas=[30.0], bias=True)#

Implements the Wire INR [Saragadam et al., 2022] .

Parameters:
  • in_features (int) – number of input features. For a coordinate based model, input the number of coordinate dims (2 for 2D, 3 for 3D)

  • hidden_features (int) – width of each layer in the INR. Number of neurons per layer.

  • hidden_layers (int) – Total number of hidden layers in the INR.

  • out_features (int) – number of output features. For a scalar or grayscale field, this is 1. For an RGB image, this field is 3.

  • outermost_linear (bool, optional) – Ensures that the last layer is a linear layer with no activation. Defaults to True.

  • omegas (list[float], optional) – Controls the frequency of each layer of Wire’s wavelet nonlinearity. Defaults to [20.0].

  • sigmas (list[float], optional) – Controls the bandwidth of each layer of Wire’s wavelet nonlinearity.. Defaults to [30.0].

  • bias (bool, optional) – Sets bias for each layer in the INR. Defaults to True.

forward(coords, return_features=False)#

Compute the forward pass of the Siren model.

Parameters:
  • coords (torch.Tensor) – Input coordinates or features to the model of shape \(b \times \cdots \times d\) where b is batch and d is the number of input features.

  • return_features (bool, optional) – Set flag to True to return intermediate layer features along with computed output. Defaults to False.

Returns:

Returns a dict with keys: output, features. The output key contains the output of the model. The features key contains the intermediate features of the model.

Return type:

dict

load_weights(weights)#
alpine.models.wire.get_linear_layer(in_features, out_features, bias=True, is_first=False, is_last=False)#

Module contents#