MCPcopy Create free account
hub / github.com/MotrixLab/AiOS / __init__

Method __init__

models/aios/backbones/swin_transformer.py:526–626  ·  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.,
                 qkv_bias=True,
                 qk_scale=None,
                 drop_rate=0.,
                 attn_drop_rate=0.,
                 drop_path_rate=0.2,
                 norm_layer=nn.LayerNorm,
                 ape=False,
                 patch_norm=True,
                 out_indices=(0, 1, 2, 3),
                 frozen_stages=-1,
                 dilation=False,
                 use_checkpoint=False)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 5

_freeze_stagesMethod · 0.95
PatchEmbedClass · 0.85
BasicLayerClass · 0.85
printFunction · 0.50
__init__Method · 0.45

Tested by

no test coverage detected