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

Method __init__

models/aios/backbones/swin_transformer.py:188–228  ·  view source on GitHub ↗
(self,
                 dim,
                 num_heads,
                 window_size=7,
                 shift_size=0,
                 mlp_ratio=4.,
                 qkv_bias=True,
                 qk_scale=None,
                 drop=0.,
                 attn_drop=0.,
                 drop_path=0.,
                 act_layer=nn.GELU,
                 norm_layer=nn.LayerNorm)

Source from the content-addressed store, hash-verified

186 norm_layer (nn.Module, optional): Normalization layer. Default: nn.LayerNorm
187 """
188 def __init__(self,
189 dim,
190 num_heads,
191 window_size=7,
192 shift_size=0,
193 mlp_ratio=4.,
194 qkv_bias=True,
195 qk_scale=None,
196 drop=0.,
197 attn_drop=0.,
198 drop_path=0.,
199 act_layer=nn.GELU,
200 norm_layer=nn.LayerNorm):
201 super().__init__()
202 self.dim = dim
203 self.num_heads = num_heads
204 self.window_size = window_size
205 self.shift_size = shift_size
206 self.mlp_ratio = mlp_ratio
207 assert 0 <= self.shift_size < self.window_size, 'shift_size must in 0-window_size'
208
209 self.norm1 = norm_layer(dim)
210 self.attn = WindowAttention(dim,
211 window_size=to_2tuple(self.window_size),
212 num_heads=num_heads,
213 qkv_bias=qkv_bias,
214 qk_scale=qk_scale,
215 attn_drop=attn_drop,
216 proj_drop=drop)
217
218 self.drop_path = DropPath(
219 drop_path) if drop_path > 0. else nn.Identity()
220 self.norm2 = norm_layer(dim)
221 mlp_hidden_dim = int(dim * mlp_ratio)
222 self.mlp = Mlp(in_features=dim,
223 hidden_features=mlp_hidden_dim,
224 act_layer=act_layer,
225 drop=drop)
226
227 self.H = None
228 self.W = None
229
230 def forward(self, x, mask_matrix):
231 """Forward function.

Callers

nothing calls this directly

Calls 3

WindowAttentionClass · 0.85
MlpClass · 0.85
__init__Method · 0.45

Tested by

no test coverage detected