Forward function.
(self, x)
| 320 | self.norm = None |
| 321 | |
| 322 | def forward(self, x): |
| 323 | """Forward function.""" |
| 324 | _, _, H, W = x.size() |
| 325 | if W % self.patch_size[1] != 0: |
| 326 | x = F.pad(x, (0, self.patch_size[1] - W % self.patch_size[1])) |
| 327 | if H % self.patch_size[0] != 0: |
| 328 | x = F.pad(x, (0, 0, 0, self.patch_size[0] - H % self.patch_size[0])) |
| 329 | |
| 330 | x = self.proj(x) # B C Wh Ww |
| 331 | if self.norm is not None: |
| 332 | Wh, Ww = x.size(2), x.size(3) |
| 333 | x = x.flatten(2).transpose(1, 2) |
| 334 | x = self.norm(x) |
| 335 | x = x.transpose(1, 2).view(-1, self.embed_dim, Wh, Ww) |
| 336 | |
| 337 | return x |
| 338 | |
| 339 | |
| 340 | class FocalNet(nn.Module): |
nothing calls this directly
no outgoing calls
no test coverage detected