fusionlab.layers.patch_embed.patch_embedding module#
- class fusionlab.layers.patch_embed.patch_embedding.PatchEmbedding(in_channels, img_size, patch_size, hidden_size, pos_embed_type='conv', dropout_rate=0.0, spatial_dims=2)[source]#
Bases:
ModuleA patch embedding block, based on: “Dosovitskiy et al., An Image is Worth 16x16 Words: Transformers for Image Recognition at Scale <https://arxiv.org/abs/2010.11929>”
- __init__(in_channels, img_size, patch_size, hidden_size, pos_embed_type='conv', dropout_rate=0.0, spatial_dims=2)[source]#
- Parameters:
in_channels (
int) – dimension of input channels.img_size (
Union[int,Sequence[int]]) – dimension of input image.patch_size (
Union[int,Sequence[int]]) – dimension of patch size.hidden_size (
int) – dimension of hidden layer.num_heads – number of attention heads.
pos_embed_type (
str) – position embedding layer type.dropout_rate (
float) – faction of the input units to drop.spatial_dims (
int) – number of spatial dimensions.
- 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.
- training: bool#