yamle.models.fc module#

class yamle.models.fc.FCModel(hidden_dim, width_multiplier, depth, normalization, activation, *args, **kwargs)[source]#

Bases: BaseModel

This class is used to create a FC model with the given parameters.

Parameters:
  • hidden_dim (int) – The dimensions of the hidden layers.

  • width_multiplier (int) – The width multiplier for the hidden layers. Default: 1.

  • depth (int) – The number of hidden layers.

  • normalization (Optional[str]) – The normalization to use. Either ‘batch’, ‘linear’, ‘instance’ or None.

  • activation (Optional[str]) – The activation to use. Either ‘relu’, ‘linear’ or None.

tasks = ['classification', 'regression']#
forward(x, staged_output=False, input_kwargs={}, output_kwargs={})[source]#

This method is used to perform a forward pass through the model.

The input is expected to be of shape (batch_size, inputs_dim). The output is of shape (batch_size, outputs_dim).

Parameters:
  • x (torch.Tensor) – The input to the model.

  • staged_output (bool) – If True, the output is a tuple of the last layer and the hidden layers.

  • input_kwargs (Dict[str, Any]) – The kwargs for the input layer.

  • output_kwargs (Dict[str, Any]) – The kwargs for the output layer.

Return type:

Union[Tensor, Tuple[Tensor, List[Tensor]]]

final_layer(x, **output_kwargs)[source]#

This function is used to get the final layer output.

Return type:

Tensor

add_method_specific_layers(method, **kwargs)[source]#

This method is used to add method specific layers to the model.

Parameters:

method (str) – The method to use.

Return type:

None

replace_layers_for_quantization()[source]#

Fuses all the operations in the network.

In this function we only need to fuse layers that are not in the blocks. e.g. the reshaping layers added by the method.

Return type:

None

static add_specific_args(parent_parser)[source]#

This method is used to add the model specific arguments to the parent parser.

Return type:

ArgumentParser

training: bool#
class yamle.models.fc.ResidualFCModel(*args, **kwargs)[source]#

Bases: FCModel

This class is used to create a residual FC model.

Each hidden layer can be understood as a residual block. The input is added to the output of the hidden layer. All the hidden layers are followed by a ReLU activation and have the same dimension.

training: bool#