(
self,
dim,
depth,
num_heads,
window_size=7,
mlp_ratio=4.0,
qkv_bias=True,
qk_scale=None,
drop=0.0,
attn_drop=0.0,
drop_path=0.0,
norm_layer=nn.LayerNorm,
downsample=None,
use_checkpoint=False,
)
| 367 | """ |
| 368 | |
| 369 | def __init__( |
| 370 | self, |
| 371 | dim, |
| 372 | depth, |
| 373 | num_heads, |
| 374 | window_size=7, |
| 375 | mlp_ratio=4.0, |
| 376 | qkv_bias=True, |
| 377 | qk_scale=None, |
| 378 | drop=0.0, |
| 379 | attn_drop=0.0, |
| 380 | drop_path=0.0, |
| 381 | norm_layer=nn.LayerNorm, |
| 382 | downsample=None, |
| 383 | use_checkpoint=False, |
| 384 | ): |
| 385 | super().__init__() |
| 386 | self.window_size = window_size |
| 387 | self.shift_size = window_size // 2 |
| 388 | self.depth = depth |
| 389 | self.use_checkpoint = use_checkpoint |
| 390 | |
| 391 | # build blocks |
| 392 | self.blocks = nn.ModuleList( |
| 393 | [ |
| 394 | SwinTransformerBlock( |
| 395 | dim=dim, |
| 396 | num_heads=num_heads, |
| 397 | window_size=window_size, |
| 398 | shift_size=0 if (i % 2 == 0) else window_size // 2, |
| 399 | mlp_ratio=mlp_ratio, |
| 400 | qkv_bias=qkv_bias, |
| 401 | qk_scale=qk_scale, |
| 402 | drop=drop, |
| 403 | attn_drop=attn_drop, |
| 404 | drop_path=drop_path[i] if isinstance(drop_path, list) else drop_path, |
| 405 | norm_layer=norm_layer, |
| 406 | ) |
| 407 | for i in range(depth) |
| 408 | ] |
| 409 | ) |
| 410 | |
| 411 | # patch merging layer |
| 412 | if downsample is not None: |
| 413 | self.downsample = downsample(dim=dim, norm_layer=norm_layer) |
| 414 | else: |
| 415 | self.downsample = None |
| 416 | |
| 417 | def forward(self, x, H, W): |
| 418 | """Forward function. |
nothing calls this directly
no test coverage detected