Feature map interpolation.
(self, x, scale_factor: float, size: Tuple[int, int])
| 272 | return self.interpolate(x, scale_factor=1.0/factor, size=size) |
| 273 | |
| 274 | def interpolate(self, x, scale_factor: float, size: Tuple[int, int]): |
| 275 | """ Feature map interpolation. """ |
| 276 | B, N, C = x.shape |
| 277 | H, W = size |
| 278 | assert N == 1 + H * W |
| 279 | |
| 280 | cls_token = x[:, :1, :] |
| 281 | img_tokens = x[:, 1:, :] |
| 282 | |
| 283 | img_tokens = img_tokens.transpose(1, 2).reshape(B, C, H, W) |
| 284 | img_tokens = F.interpolate( |
| 285 | img_tokens, scale_factor=scale_factor, recompute_scale_factor=False, mode='bilinear', align_corners=False) |
| 286 | img_tokens = img_tokens.reshape(B, C, -1).transpose(1, 2) |
| 287 | |
| 288 | out = torch.cat((cls_token, img_tokens), dim=1) |
| 289 | |
| 290 | return out |
| 291 | |
| 292 | def forward(self, x1, x2, x3, x4, sizes: List[Tuple[int, int]]): |
| 293 | _, S2, S3, S4 = sizes |
no outgoing calls
no test coverage detected