utils¶
- class mfai.pytorch.models.utils.AbsolutePosEmdebding(input_shape, num_features, feature_last=False)[source]¶
Bases:
ModuleAbsolute pos embedding. Learns a position dependent bias for each pixel/node of each feature map.
- forward(x)[source]¶
Define the computation performed at every call.
Should be overridden by all subclasses. :rtype:
TensorNote
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- mfai.pytorch.models.utils.expand_to_batch(x, batch_size)[source]¶
Expand tensor with initial batch dimension.
- mfai.pytorch.models.utils.features_last_to_second(x)[source]¶
Moves features from the last dimension to the second dimension.
- mfai.pytorch.models.utils.features_second_to_last(y)[source]¶
Moves features from the second dimension to the last dimension.
- mfai.pytorch.models.utils.patch_first_conv(model, new_in_channels, default_in_channels=3, pretrained=True)[source]¶
- Return type:
- Parameters:
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.