Forward function.
(self, x)
| 477 | self.norm = None |
| 478 | |
| 479 | def forward(self, x): |
| 480 | """Forward function.""" |
| 481 | # padding |
| 482 | _, _, H, W = x.size() |
| 483 | if W % self.patch_size[1] != 0: |
| 484 | x = F.pad(x, (0, self.patch_size[1] - W % self.patch_size[1])) |
| 485 | if H % self.patch_size[0] != 0: |
| 486 | x = F.pad(x, (0, 0, 0, self.patch_size[0] - H % self.patch_size[0])) |
| 487 | |
| 488 | x = self.proj(x) # B C Wh Ww |
| 489 | if self.norm is not None: |
| 490 | Wh, Ww = x.size(2), x.size(3) |
| 491 | x = x.flatten(2).transpose(1, 2) |
| 492 | x = self.norm(x) |
| 493 | x = x.transpose(1, 2).view(-1, self.embed_dim, Wh, Ww) |
| 494 | |
| 495 | return x |
| 496 | |
| 497 | |
| 498 | class SwinTransformer(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected