utils

class mfai.pytorch.models.utils.AbsolutePosEmdebding(input_shape, num_features, feature_last=False)[source]

Bases: Module

Absolute pos embedding. Learns a position dependent bias for each pixel/node of each feature map.

Parameters:
forward(x)[source]

Define the computation performed at every call.

Should be overridden by all subclasses. :rtype: Tensor

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.

Parameters:

x (Tensor)

Return type:

Tensor

mfai.pytorch.models.utils.expand_to_batch(x, batch_size)[source]

Expand tensor with initial batch dimension.

Return type:

Tensor

Parameters:
mfai.pytorch.models.utils.features_last_to_second(x)[source]

Moves features from the last dimension to the second dimension.

Return type:

Tensor

Parameters:

x (Tensor)

mfai.pytorch.models.utils.features_second_to_last(y)[source]

Moves features from the second dimension to the last dimension.

Return type:

Tensor

Parameters:

y (Tensor)

mfai.pytorch.models.utils.init_(tensor, dim_idx=-1)[source]
Return type:

Tensor

Parameters:
mfai.pytorch.models.utils.patch_first_conv(model, new_in_channels, default_in_channels=3, pretrained=True)[source]
Return type:

None

Parameters:
  • model (Module)

  • new_in_channels (int)

  • default_in_channels (int)

  • pretrained (bool)

Change first convolution layer input channels. In case:

in_channels == 1 or in_channels == 2 -> reuse original weights. in_channels > 3 -> make random kaiming normal initialization.

mfai.pytorch.models.utils.replace_strides_with_dilation(module, dilation)[source]

Patch Conv2d modules replacing strides with dilation.

Return type:

None

Parameters: