Forward function.
(self, x)
| 668 | # raise TypeError('pretrained must be a str or None') |
| 669 | |
| 670 | def forward_raw(self, x): |
| 671 | """Forward function.""" |
| 672 | x = self.patch_embed(x) |
| 673 | |
| 674 | Wh, Ww = x.size(2), x.size(3) |
| 675 | if self.ape: |
| 676 | # interpolate the position embedding to the corresponding size |
| 677 | absolute_pos_embed = F.interpolate(self.absolute_pos_embed, |
| 678 | size=(Wh, Ww), |
| 679 | mode='bicubic') |
| 680 | x = (x + absolute_pos_embed).flatten(2).transpose(1, |
| 681 | 2) # B Wh*Ww C |
| 682 | else: |
| 683 | x = x.flatten(2).transpose(1, 2) |
| 684 | x = self.pos_drop(x) |
| 685 | |
| 686 | outs = [] |
| 687 | for i in range(self.num_layers): |
| 688 | layer = self.layers[i] |
| 689 | x_out, H, W, x, Wh, Ww = layer(x, Wh, Ww) |
| 690 | # import pdb; pdb.set_trace() |
| 691 | |
| 692 | if i in self.out_indices: |
| 693 | norm_layer = getattr(self, f'norm{i}') |
| 694 | x_out = norm_layer(x_out) |
| 695 | |
| 696 | out = x_out.view(-1, H, W, |
| 697 | self.num_features[i]).permute(0, 3, 1, |
| 698 | 2).contiguous() |
| 699 | outs.append(out) |
| 700 | # in: |
| 701 | # torch.Size([2, 3, 1024, 1024]) |
| 702 | # outs: |
| 703 | # [torch.Size([2, 192, 256, 256]), torch.Size([2, 384, 128, 128]), \ |
| 704 | # torch.Size([2, 768, 64, 64]), torch.Size([2, 1536, 32, 32])] |
| 705 | return tuple(outs) |
| 706 | |
| 707 | def forward(self, tensor_list: NestedTensor): |
| 708 | x = tensor_list.tensors |