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

Method __init__

semantic_sam/backbone/swin_new.py:526–616  ·  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

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