Segmentation Model#
UNet#
ResUNet#
UNet++#
TransUNet#
- class fusionlab.segmentation.TransUNet(in_channels=3, img_size=224, num_classes=2, zero_head=False, decoder_channels=[256, 128, 64, 16], hidden_size=768, n_skip=3, skip_channels=[512, 256, 64, 16], patch_size=(16, 16))[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.
UNETR#
- class fusionlab.segmentation.UNETR(in_channels, out_channels, img_size, feature_size=16, hidden_size=768, mlp_dim=3072, num_heads=12, pos_embed='fc', dropout_rate=0.0, spatial_dims=2)[source]#
UNETR based on: “Hatamizadeh et al., UNETR: Transformers for 3D Medical Image Segmentation <https://arxiv.org/abs/2103.10504>”
source code: Project-MONAI/MONAI
- __init__(in_channels, out_channels, img_size, feature_size=16, hidden_size=768, mlp_dim=3072, num_heads=12, pos_embed='fc', dropout_rate=0.0, spatial_dims=2)[source]#
- Parameters:
in_channels (
int) – dimension of input channels.out_channels (
int) – dimension of output channels.img_size (
int) – dimension of input image.feature_size (
int) – dimension of network feature size.hidden_size (
int) – dimension of hidden layer.mlp_dim (
int) – dimension of feedforward layer.num_heads (
int) – number of attention heads.pos_embed (
str) – position embedding layer type.norm_name – feature normalization type and arguments.
conv_block – bool argument to determine if convolutional block is used.
res_block – bool argument to determine if residual block is used.
dropout_rate (
float) – faction of the input units to drop in ViT.spatial_dims (
int) – number of spatial dimensions.
- forward(x_in)[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.
SegFormer#
- class fusionlab.segmentation.SegFormer(num_classes=6, mit_encoder_type='B0')[source]#
SegFormer: Simple and Efficient Design for Semantic Segmentation with Transformers<https://arxiv.org/abs/2105.15203>
source code: sithu31296/semantic-segmentation
- Parameters:
num_classes (int) – number of classes to segment
mit_encoder_type (str) – type of MiT encoder, one of [‘B0’, ‘B1’, ‘B2’, ‘B3’, ‘B4’, ‘B5’]
- forward(inputs)[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
HuggingFace Segmentation Model#
- class fusionlab.segmentation.HFSegmentationModel(model, num_cls=None, loss_fct=CrossEntropyLoss())[source]#
Base Hugginface-pytoch model wrapper class of the segmentation model
- forward(x, labels=None)[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.