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

Method __init__

semantic_sam/backbone/swin.py:197–239  ·  view source on GitHub ↗
(
        self,
        dim,
        num_heads,
        window_size=7,
        shift_size=0,
        mlp_ratio=4.0,
        qkv_bias=True,
        qk_scale=None,
        drop=0.0,
        attn_drop=0.0,
        drop_path=0.0,
        act_layer=nn.GELU,
        norm_layer=nn.LayerNorm,
    )

Source from the content-addressed store, hash-verified

195 """
196
197 def __init__(
198 self,
199 dim,
200 num_heads,
201 window_size=7,
202 shift_size=0,
203 mlp_ratio=4.0,
204 qkv_bias=True,
205 qk_scale=None,
206 drop=0.0,
207 attn_drop=0.0,
208 drop_path=0.0,
209 act_layer=nn.GELU,
210 norm_layer=nn.LayerNorm,
211 ):
212 super().__init__()
213 self.dim = dim
214 self.num_heads = num_heads
215 self.window_size = window_size
216 self.shift_size = shift_size
217 self.mlp_ratio = mlp_ratio
218 assert 0 <= self.shift_size < self.window_size, "shift_size must in 0-window_size"
219
220 self.norm1 = norm_layer(dim)
221 self.attn = WindowAttention(
222 dim,
223 window_size=to_2tuple(self.window_size),
224 num_heads=num_heads,
225 qkv_bias=qkv_bias,
226 qk_scale=qk_scale,
227 attn_drop=attn_drop,
228 proj_drop=drop,
229 )
230
231 self.drop_path = DropPath(drop_path) if drop_path > 0.0 else nn.Identity()
232 self.norm2 = norm_layer(dim)
233 mlp_hidden_dim = int(dim * mlp_ratio)
234 self.mlp = Mlp(
235 in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop
236 )
237
238 self.H = None
239 self.W = None
240
241 def forward(self, x, mask_matrix):
242 """Forward function.

Callers

nothing calls this directly

Calls 3

WindowAttentionClass · 0.70
MlpClass · 0.70
__init__Method · 0.45

Tested by

no test coverage detected