MCPcopy Create free account
hub / github.com/UX-Decoder/Semantic-SAM / __init__

Method __init__

semantic_sam/backbone/swin.py:537–627  ·  view source on GitHub ↗
(
        self,
        pretrain_img_size=224,
        patch_size=4,
        in_chans=3,
        embed_dim=96,
        depths=[2, 2, 6, 2],
        num_heads=[3, 6, 12, 24],
        window_size=7,
        mlp_ratio=4.0,
        qkv_bias=True,
        qk_scale=None,
        drop_rate=0.0,
        attn_drop_rate=0.0,
        drop_path_rate=0.2,
        norm_layer=nn.LayerNorm,
        ape=False,
        patch_norm=True,
        out_indices=(0, 1, 2, 3),
        frozen_stages=-1,
        use_checkpoint=False,
    )

Source from the content-addressed store, hash-verified

535 """
536
537 def __init__(
538 self,
539 pretrain_img_size=224,
540 patch_size=4,
541 in_chans=3,
542 embed_dim=96,
543 depths=[2, 2, 6, 2],
544 num_heads=[3, 6, 12, 24],
545 window_size=7,
546 mlp_ratio=4.0,
547 qkv_bias=True,
548 qk_scale=None,
549 drop_rate=0.0,
550 attn_drop_rate=0.0,
551 drop_path_rate=0.2,
552 norm_layer=nn.LayerNorm,
553 ape=False,
554 patch_norm=True,
555 out_indices=(0, 1, 2, 3),
556 frozen_stages=-1,
557 use_checkpoint=False,
558 ):
559 super().__init__()
560
561 self.pretrain_img_size = pretrain_img_size
562 self.num_layers = len(depths)
563 self.embed_dim = embed_dim
564 self.ape = ape
565 self.patch_norm = patch_norm
566 self.out_indices = out_indices
567 self.frozen_stages = frozen_stages
568
569 # split image into non-overlapping patches
570 self.patch_embed = PatchEmbed(
571 patch_size=patch_size,
572 in_chans=in_chans,
573 embed_dim=embed_dim,
574 norm_layer=norm_layer if self.patch_norm else None,
575 )
576
577 # absolute position embedding
578 if self.ape:
579 pretrain_img_size = to_2tuple(pretrain_img_size)
580 patch_size = to_2tuple(patch_size)
581 patches_resolution = [
582 pretrain_img_size[0] // patch_size[0],
583 pretrain_img_size[1] // patch_size[1],
584 ]
585
586 self.absolute_pos_embed = nn.Parameter(
587 torch.zeros(1, embed_dim, patches_resolution[0], patches_resolution[1])
588 )
589 trunc_normal_(self.absolute_pos_embed, std=0.02)
590
591 self.pos_drop = nn.Dropout(p=drop_rate)
592
593 # stochastic depth
594 dpr = [

Callers

nothing calls this directly

Calls 4

_freeze_stagesMethod · 0.95
PatchEmbedClass · 0.70
BasicLayerClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected