(self,
dim,
depth,
num_heads,
window_size=7,
mlp_ratio=4.,
qkv_bias=True,
qk_scale=None,
drop=0.,
attn_drop=0.,
drop_path=0.,
norm_layer=nn.LayerNorm,
downsample=None,
use_checkpoint=False)
| 357 | use_checkpoint (bool): Whether to use checkpointing to save memory. Default: False. |
| 358 | """ |
| 359 | def __init__(self, |
| 360 | dim, |
| 361 | depth, |
| 362 | num_heads, |
| 363 | window_size=7, |
| 364 | mlp_ratio=4., |
| 365 | qkv_bias=True, |
| 366 | qk_scale=None, |
| 367 | drop=0., |
| 368 | attn_drop=0., |
| 369 | drop_path=0., |
| 370 | norm_layer=nn.LayerNorm, |
| 371 | downsample=None, |
| 372 | use_checkpoint=False): |
| 373 | super().__init__() |
| 374 | self.window_size = window_size |
| 375 | self.shift_size = window_size // 2 |
| 376 | self.depth = depth |
| 377 | self.use_checkpoint = use_checkpoint |
| 378 | |
| 379 | # build blocks |
| 380 | self.blocks = nn.ModuleList([ |
| 381 | SwinTransformerBlock(dim=dim, |
| 382 | num_heads=num_heads, |
| 383 | window_size=window_size, |
| 384 | shift_size=0 if |
| 385 | (i % 2 == 0) else window_size // 2, |
| 386 | mlp_ratio=mlp_ratio, |
| 387 | qkv_bias=qkv_bias, |
| 388 | qk_scale=qk_scale, |
| 389 | drop=drop, |
| 390 | attn_drop=attn_drop, |
| 391 | drop_path=drop_path[i] if isinstance( |
| 392 | drop_path, list) else drop_path, |
| 393 | norm_layer=norm_layer) for i in range(depth) |
| 394 | ]) |
| 395 | |
| 396 | # patch merging layer |
| 397 | if downsample is not None: |
| 398 | self.downsample = downsample(dim=dim, norm_layer=norm_layer) |
| 399 | else: |
| 400 | self.downsample = None |
| 401 | |
| 402 | def forward(self, x, H, W): |
| 403 | """Forward function. |
nothing calls this directly
no test coverage detected