Forward function.
(self, x)
| 488 | self.norm = None |
| 489 | |
| 490 | def forward(self, x): |
| 491 | """Forward function.""" |
| 492 | # padding |
| 493 | _, _, H, W = x.size() |
| 494 | if W % self.patch_size[1] != 0: |
| 495 | x = F.pad(x, (0, self.patch_size[1] - W % self.patch_size[1])) |
| 496 | if H % self.patch_size[0] != 0: |
| 497 | x = F.pad(x, (0, 0, 0, self.patch_size[0] - H % self.patch_size[0])) |
| 498 | |
| 499 | x = self.proj(x) # B C Wh Ww |
| 500 | if self.norm is not None: |
| 501 | Wh, Ww = x.size(2), x.size(3) |
| 502 | x = x.flatten(2).transpose(1, 2) |
| 503 | x = self.norm(x) |
| 504 | x = x.transpose(1, 2).view(-1, self.embed_dim, Wh, Ww) |
| 505 | |
| 506 | return x |
| 507 | |
| 508 | |
| 509 | class SwinTransformer(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected