(self, input_var)
| 519 | return x.permute(0, 2, 1).reshape(B, -1, Hp, Wp) |
| 520 | |
| 521 | def forward(self, input_var): |
| 522 | output = {} |
| 523 | x = input_var['image'] |
| 524 | |
| 525 | if isinstance(x, NestedTensor): |
| 526 | x, mask = x.decompose() |
| 527 | else: |
| 528 | mask = None |
| 529 | |
| 530 | # pre_input padding for test support |
| 531 | x = self._normalization(x) |
| 532 | |
| 533 | if self.round_padding: |
| 534 | # pre_input padding for non standard img size support, *** used when test image size varies and not divisible by 32 *** |
| 535 | stride = self.patch_embed.patch_size |
| 536 | assert stride[0] == stride[1] |
| 537 | stride = max(stride[0], self.round_padding) |
| 538 | output["prepad_input_size"] = [x.shape[-2], x.shape[-1]] # h, w for sem_seg_postprocess |
| 539 | target_size = (torch.tensor((x.shape[-1], x.shape[-2])) + (stride - 1)).div(stride, rounding_mode="floor") * stride # w, h |
| 540 | padding_size = [ # [l,r,t,b] |
| 541 | 0, |
| 542 | target_size[0] - x.shape[-1], |
| 543 | 0, |
| 544 | target_size[1] - x.shape[-2], |
| 545 | ] |
| 546 | x = F.pad(x, padding_size, value=0.).contiguous() |
| 547 | if mask is not None: |
| 548 | mask = F.pad(mask, padding_size, value=True).contiguous() # 0: content, 1: pad |
| 549 | # pre_input padding for test support >>> end |
| 550 | output["image"] = x |
| 551 | |
| 552 | if isinstance(input_var['image'], NestedTensor) and self.pad_attn_mask: |
| 553 | output['backbone_output'] = NestedTensor(self.forward_features(x), mask) |
| 554 | else: |
| 555 | output['backbone_output'] = self.forward_features(x) |
| 556 | input_var.update(output) |
| 557 | return input_var |
| 558 | |
| 559 | |
| 560 | def vit_base_patch16(pretrained=False, load_pos_embed=True, pretrain_path=None, pos_embed_interp=False, **kwargs): |
nothing calls this directly
no test coverage detected