fusilli.utils.check_model_validity

This module contains functions to check the validity of the model modifications, such as checking the data type of the modifications and checking the input image dimensions of the modifications.

Functions

check_dtype(attribute, correct_dtype, ...)

Check if the modification is of the correct data type.

check_fused_layers(fused_layers, fused_dim)

Check that the fused layers within the fusion model (meaning the layers that take place after the fusion) are of the correct data type (nn.Sequential) and that the first layer is a nn.Linear layer with the correct in_features.

check_img_dim(attribute, img_dim, attribute_name)

Check if the modification img layers are the correct dimension.

check_model_input(x[, tuple_flag, ...])

Check that the input to the model is of the correct length.

check_var_is_function(attribute, attribute_name)

Check if the modification is a function.

check_dtype(attribute, correct_dtype, attribute_name)[source]

Check if the modification is of the correct data type.

Parameters:
  • attribute (object) – Attribute to check.

  • correct_dtype (object) – Correct data type.

  • attribute_name (str) – Name of the attribute to check (for the error message)

Raises:

TypeError – If the modification is not of the correct data type.

check_fused_layers(fused_layers, fused_dim)[source]

Check that the fused layers within the fusion model (meaning the layers that take place after the fusion) are of the correct data type (nn.Sequential) and that the first layer is a nn.Linear layer with the correct in_features. Also returns the output dimension of the fused layers for the final prediction layers of the model.

Parameters:
  • fused_layers (nn.ModuleDict) – Fused layers of the model.

  • fused_dim (int) – Dimension of the fused layers.

Returns:

  • fused_layers (nn.ModuleDict) – Fused layers of the model. First layer is modified to have the correct in_features.

  • out_dim (int) – Output dimension of the fused layers.

check_img_dim(attribute, img_dim, attribute_name)[source]

Check if the modification img layers are the correct dimension.

Parameters:
  • attribute (object) – Attribute to check.

  • img_dim (object) – Correct img dimensions.

  • attribute_name (str) – Name of the attribute to check (for the error message)

Raises:

TypeError – If the modification is not of the correct data type.

check_model_input(x, tuple_flag=False, correct_length=2)[source]

Check that the input to the model is of the correct length.

Parameters:
  • x (tuple or torch.Tensor) – Input to the model’s forward function. Should either be a tuple of length 2 for multi-modal methods or a torch tensor for uni-modal methods.

  • tuple_flag (bool) – Flag to indicate whether the input is supposed to be a tuple (for graph based models mainly).

  • correct_length (int) – Correct length of the input to the model if it is multi-modal. Default is 2. Could be 3 for the graph methods.

check_var_is_function(attribute, attribute_name)[source]

Check if the modification is a function.

Parameters:
  • attribute (object) – Attribute to check.

  • attribute_name (str) – Name of the attribute to check (for the error message)

Raises:

TypeError – If the modification is not a function.