A basic Swin Transformer layer for one stage. Args: dim (int): Number of input channels. depth (int): Number of blocks. drop (float, optional): Dropout rate. Default: 0.0 attn_drop (float, optional): Attention dropout rate. Default: 0.0 drop_path (float |
| 611 | |
| 612 | |
| 613 | class VSSLayer(nn.Module): |
| 614 | """ A basic Swin Transformer layer for one stage. |
| 615 | Args: |
| 616 | dim (int): Number of input channels. |
| 617 | depth (int): Number of blocks. |
| 618 | drop (float, optional): Dropout rate. Default: 0.0 |
| 619 | attn_drop (float, optional): Attention dropout rate. Default: 0.0 |
| 620 | drop_path (float | tuple[float], optional): Stochastic depth rate. Default: 0.0 |
| 621 | norm_layer (nn.Module, optional): Normalization layer. Default: nn.LayerNorm |
| 622 | downsample (nn.Module | None, optional): Downsample layer at the end of the layer. Default: None |
| 623 | use_checkpoint (bool): Whether to use checkpointing to save memory. Default: False. |
| 624 | """ |
| 625 | |
| 626 | def __init__( |
| 627 | self, |
| 628 | dim, |
| 629 | depth, |
| 630 | attn_drop=0., |
| 631 | drop_path=0., |
| 632 | norm_layer=nn.LayerNorm, |
| 633 | downsample=None, |
| 634 | use_checkpoint=False, |
| 635 | d_state=16, |
| 636 | spatial_aug_flag=1, |
| 637 | START_flag=1, |
| 638 | START_p=1.0, |
| 639 | START_token_prob=0.75, |
| 640 | START_batch_prob=0.5, |
| 641 | START_attention_mode=0, |
| 642 | **kwargs, |
| 643 | ): |
| 644 | super().__init__() |
| 645 | self.dim = dim |
| 646 | self.use_checkpoint = use_checkpoint |
| 647 | |
| 648 | self.blocks = nn.ModuleList([ |
| 649 | VSSBlock( |
| 650 | hidden_dim=dim, |
| 651 | drop_path=drop_path[i] if isinstance(drop_path, list) else drop_path, |
| 652 | norm_layer=norm_layer, |
| 653 | attn_drop_rate=attn_drop, |
| 654 | d_state=d_state, |
| 655 | spatial_aug_flag=spatial_aug_flag, |
| 656 | START_flag=START_flag, |
| 657 | START_p=START_p, |
| 658 | START_token_prob=START_token_prob, |
| 659 | START_batch_prob=START_batch_prob, |
| 660 | START_attention_mode=START_attention_mode, |
| 661 | ) |
| 662 | for i in range(depth)]) |
| 663 | |
| 664 | if True: # is this really applied? Yes, but been overriden later in VSSM! |
| 665 | def _init_weights(module: nn.Module): |
| 666 | for name, p in module.named_parameters(): |
| 667 | if name in ["out_proj.weight"]: |
| 668 | p = p.clone().detach_() # fake init, just to keep the seed .... |
| 669 | nn.init.kaiming_uniform_(p, a=math.sqrt(5)) |
| 670 |
no outgoing calls
no test coverage detected
searching dependent graphs…