Encoders#
PyTorch Encoders#
AlexNet#
- class fusionlab.encoders.AlexNet(cin=3, spatial_dims=2)[source]#
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.- Return type:
Tensor
VGG#
- class fusionlab.encoders.VGG16(cin=3, spatial_dims=2)[source]#
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.
- class fusionlab.encoders.VGG19(cin=3, spatial_dims=2)[source]#
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.
InceptionNet#
- class fusionlab.encoders.InceptionNetV1(cin=3, spatial_dims=2)[source]#
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.
ResNet#
- class fusionlab.encoders.ResNet(block, layers, zero_init_residual=False, groups=1, width_per_group=64, replace_stride_with_dilation=None, norm_layer=None, cin=3, spatial_dims=2)[source]#
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.- Return type:
Tensor
EfficientNet#
- class fusionlab.encoders.EfficientNet(inverted_residual_setting, cin=3, stochastic_depth_prob=0.2, last_channel=None, norm_layer=None, spatial_dims=2)[source]#
- __init__(inverted_residual_setting, cin=3, stochastic_depth_prob=0.2, last_channel=None, norm_layer=None, spatial_dims=2)[source]#
EfficientNet V1 and V2 main class
- Parameters:
inverted_residual_setting (Sequence[Union[MBConvConfig, FusedMBConvConfig]]) – Network structure
dropout (float) – The droupout probability
stochastic_depth_prob (float) – The stochastic depth probability
num_classes (int) – Number of classes
norm_layer (Optional[Callable[..., nn.Module]]) – Module specifying the normalization layer to use
last_channel (int) – The number of channels on the penultimate layer
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.- Return type:
Tensor
ConvNeXt#
- class fusionlab.encoders.ConvNeXt(in_chans=3, depths=[3, 3, 9, 3], dims=[96, 192, 384, 768], drop_path_rate=0.0, layer_scale_init_value=1e-06, spatial_dims=2)[source]#
- A PyTorch impl ofA ConvNet for the 2020s -
- Parameters:
in_chans (int) – Number of input image channels. Default: 3
num_classes (int) – Number of classes for classification head. Default: 1000
depths (tuple(int)) – Number of blocks at each stage. Default: [3, 3, 9, 3]
dims (int) – Feature dimension at each stage. Default: [96, 192, 384, 768]
drop_path_rate (float) – Stochastic depth rate. Default: 0.
layer_scale_init_value (float) – Init value for Layer Scale. Default: 1e-6.
head_init_scale (float) – Init scaling value for classifier weights and biases. Default: 1.
- forward(x)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.
Vision Transformer#
- class fusionlab.encoders.ViT(in_channels, img_size, patch_size, hidden_size=768, mlp_dim=3072, num_layers=12, num_heads=12, pos_embed='conv', dropout_rate=0.0, spatial_dims=2, qkv_bias=False, save_attn=False)[source]#
Vision Transformer (ViT), based on: “Dosovitskiy et al., An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale <https://arxiv.org/abs/2010.11929>”
ViT supports Torchscript but only works for Pytorch after 1.8.
source code: Project-MONAI/MONAI
- __init__(in_channels, img_size, patch_size, hidden_size=768, mlp_dim=3072, num_layers=12, num_heads=12, pos_embed='conv', dropout_rate=0.0, spatial_dims=2, qkv_bias=False, save_attn=False)[source]#
- Parameters:
in_channels (int) – dimension of input channels.
img_size (Union[Sequence[int], int]) – dimension of input image.
patch_size (Union[Sequence[int], int]) – dimension of patch size.
hidden_size (int, optional) – dimension of hidden layer. Defaults to 768.
mlp_dim (int, optional) – dimension of feedforward layer. Defaults to 3072.
num_layers (int, optional) – number of transformer blocks. Defaults to 12.
num_heads (int, optional) – number of attention heads. Defaults to 12.
pos_embed (str, optional) – position embedding layer type. Defaults to “conv”.
num_classes (int, optional) – number of classes if classification is used. Defaults to 2.
dropout_rate (float, optional) – faction of the input units to drop. Defaults to 0.0.
spatial_dims (int, optional) – number of spatial dimensions. Defaults to 3.
qkv_bias (bool, optional) – apply bias to the qkv linear layer in self attention block. Defaults to False.
save_attn (bool, optional) – to make accessible the attention in self attention block. Defaults to False.
- forward(x, return_features=False)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.
Mix Transformer#
- class fusionlab.encoders.MiT(in_channels=3, embed_dims=[32, 64, 160, 256], depths=[2, 2, 2, 2])[source]#
Mix Transformer
source code: sithu31296/semantic-segmentation
- forward(x, return_features=False)[source]#
Defines the computation performed at every call.
Should be overridden by all subclasses.
Note
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.- Return type:
Tensor