MCPcopy Create free account
hub / github.com/alinlab/SelfPatch / SwinTransformer

Class SwinTransformer

segmentation/backbones/swin.py:463–754  ·  view source on GitHub ↗

Swin Transformer backbone. This backbone is the implementation of `Swin Transformer: Hierarchical Vision Transformer using Shifted Windows `_. Inspiration from https://github.com/microsoft/Swin-Transformer. Args: pretrain_img_size (int

Source from the content-addressed store, hash-verified

461
462@BACKBONES.register_module()
463class SwinTransformer(BaseModule):
464 """Swin Transformer backbone.
465
466 This backbone is the implementation of `Swin Transformer:
467 Hierarchical Vision Transformer using Shifted
468 Windows <https://arxiv.org/abs/2103.14030>`_.
469 Inspiration from https://github.com/microsoft/Swin-Transformer.
470
471 Args:
472 pretrain_img_size (int | tuple[int]): The size of input image when
473 pretrain. Defaults: 224.
474 in_channels (int): The num of input channels.
475 Defaults: 3.
476 embed_dims (int): The feature dimension. Default: 96.
477 patch_size (int | tuple[int]): Patch size. Default: 4.
478 window_size (int): Window size. Default: 7.
479 mlp_ratio (int): Ratio of mlp hidden dim to embedding dim.
480 Default: 4.
481 depths (tuple[int]): Depths of each Swin Transformer stage.
482 Default: (2, 2, 6, 2).
483 num_heads (tuple[int]): Parallel attention heads of each Swin
484 Transformer stage. Default: (3, 6, 12, 24).
485 strides (tuple[int]): The patch merging or patch embedding stride of
486 each Swin Transformer stage. (In swin, we set kernel size equal to
487 stride.) Default: (4, 2, 2, 2).
488 out_indices (tuple[int]): Output from which stages.
489 Default: (0, 1, 2, 3).
490 qkv_bias (bool, optional): If True, add a learnable bias to query, key,
491 value. Default: True
492 qk_scale (float | None, optional): Override default qk scale of
493 head_dim ** -0.5 if set. Default: None.
494 patch_norm (bool): If add a norm layer for patch embed and patch
495 merging. Default: True.
496 drop_rate (float): Dropout rate. Defaults: 0.
497 attn_drop_rate (float): Attention dropout rate. Default: 0.
498 drop_path_rate (float): Stochastic depth rate. Defaults: 0.1.
499 use_abs_pos_embed (bool): If True, add absolute position embedding to
500 the patch embedding. Defaults: False.
501 act_cfg (dict): Config dict for activation layer.
502 Default: dict(type='LN').
503 norm_cfg (dict): Config dict for normalization layer at
504 output of backone. Defaults: dict(type='LN').
505 with_cp (bool, optional): Use checkpoint or not. Using checkpoint
506 will save some memory while slowing down the training speed.
507 Default: False.
508 pretrained (str, optional): model pretrained path. Default: None.
509 frozen_stages (int): Stages to be frozen (stop grad and set eval mode).
510 -1 means not freezing any parameters.
511 init_cfg (dict, optional): The Config for initialization.
512 Defaults to None.
513 """
514
515 def __init__(self,
516 pretrain_img_size=224,
517 in_channels=3,
518 embed_dims=96,
519 patch_size=4,
520 window_size=7,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected