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

Method __init__

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

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