(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)
| 162 | """ |
| 163 | |
| 164 | def __init__(self, dim, num_heads, window_size=7, shift_size=0, |
| 165 | mlp_ratio=4., qkv_bias=True, qk_scale=None, drop=0., attn_drop=0., drop_path=0., |
| 166 | act_layer=nn.GELU, norm_layer=nn.LayerNorm): |
| 167 | super().__init__() |
| 168 | self.dim = dim |
| 169 | self.num_heads = num_heads |
| 170 | self.window_size = window_size |
| 171 | self.shift_size = shift_size |
| 172 | self.mlp_ratio = mlp_ratio |
| 173 | assert 0 <= self.shift_size < self.window_size, "shift_size must in 0-window_size" |
| 174 | |
| 175 | self.norm1 = norm_layer(dim) |
| 176 | self.attn = WindowAttention( |
| 177 | dim, window_size=to_2tuple(self.window_size), num_heads=num_heads, |
| 178 | qkv_bias=qkv_bias, qk_scale=qk_scale, attn_drop=attn_drop, proj_drop=drop) |
| 179 | |
| 180 | self.drop_path = DropPath(drop_path) if drop_path > 0. else nn.Identity() |
| 181 | self.norm2 = norm_layer(dim) |
| 182 | mlp_hidden_dim = int(dim * mlp_ratio) |
| 183 | self.mlp = Mlp(in_features=dim, hidden_features=mlp_hidden_dim, act_layer=act_layer, drop=drop) |
| 184 | |
| 185 | self.H = None |
| 186 | self.W = None |
| 187 | |
| 188 | def forward(self, x, mask_matrix): |
| 189 | """ Forward function. |
nothing calls this directly
no test coverage detected