model.generic
Attributes
Classes
Class for creating custom neural network architectures using specified weights, |
Functions
|
Validates and reformats inputs. |
|
Creates linear layers and activation function to be used as inputs for nn.Sequential. |
Module Contents
- model.generic._validate_and_reformat_inputs(weights: torch.Tensor | List[torch.Tensor], biases: torch.Tensor | List[torch.Tensor], act_fns: torch.nn.Module | List[torch.nn.Module]) Tuple
Validates and reformats inputs.
- Parameters:
weights (torch.Tensor | list[torch.Tensor]) – Input weight tensors.
biases (torch.Tensor | list[torch.Tensor] | NoneType) – Input bias tensors.
act_fns (torch.Tensor | list[torch.Tensor] | NoneType) – Activation functions.
- Returns:
Tuple contianing the reformatted weights, biases, and activation functions.
- Return type:
tuple
- Raises:
TypeError – If inputs are not of the expected types.
AssertionError – If dimensions of input tensors are incorrect or mismatched.
- model.generic.generate_layers(weights: torch.Tensor | List[torch.Tensor], biases: torch.Tensor | List[torch.Tensor], act_fns: torch.nn.Module | List[torch.nn.Module]) List[torch.nn.Module]
Creates linear layers and activation function to be used as inputs for nn.Sequential.
- Parameters:
weights (torch.Tensor | list[torch.Tensor]) – Weights for each linear layer.
biases (torch.Tensor | list[torch.Tensor] | NoneType) – Bias for each linear layer. Length of weights and biases must match if list.
act_fns (nn.module.activation | list | NoneType) – Activation for each linear layer. If activation Layer (i.e. not list) act_fns will be repeated for each linear layer. It is recommended to pass in the class rather than instance of activation Layer, as certain FA methods require no duplicate layers in the model.
- class model.generic.GenericNN(weights: torch.Tensor, biases: torch.Tensor | None = None, act_fns: torch.nn.Module | None = None)
Bases:
torch.nn.SequentialClass for creating custom neural network architectures using specified weights, biases, and activation functions.
- Inherits from:
torch.nn.Sequential: Parent class for implementing neural networks with modules defined in a sequential manner.
Initializes a GenericNN object.
- Parameters:
weights (torch.Tensor | list[torch.Tensor]) – Weights for each linear layer.
biases (torch.Tensor | list[torch.Tensor], optional) – Bias for each linear layer. Length of weights and biases must match if list.
act_fns (nn.module.activation | list, optional) – Activation for each linear layer.
- model.generic.w