Forward function.
(self, x, l, l_mask)
| 462 | raise TypeError('pretrained must be a str or None') |
| 463 | |
| 464 | def forward(self, x, l, l_mask): |
| 465 | """Forward function.""" |
| 466 | x = self.patch_embed(x) |
| 467 | |
| 468 | Wh, Ww = x.size(2), x.size(3) |
| 469 | if self.ape: |
| 470 | # interpolate the position embedding to the corresponding size |
| 471 | absolute_pos_embed = F.interpolate(self.absolute_pos_embed, size=(Wh, Ww), mode='bicubic') |
| 472 | x = (x + absolute_pos_embed).flatten(2).transpose(1, 2) # B Wh*Ww C |
| 473 | else: |
| 474 | x = x.flatten(2).transpose(1, 2) |
| 475 | x = self.pos_drop(x) |
| 476 | |
| 477 | outs = [] |
| 478 | for i in range(self.num_layers): |
| 479 | layer = self.layers[i] |
| 480 | x_out, H, W, x, Wh, Ww = layer(x, Wh, Ww, l, l_mask) |
| 481 | |
| 482 | if i in self.out_indices: |
| 483 | norm_layer = getattr(self, f'norm{i}') |
| 484 | x_out = norm_layer(x_out) # output of a Block has shape (B, H*W, dim) |
| 485 | |
| 486 | out = x_out.view(-1, H, W, self.num_features[i]).permute(0, 3, 1, 2).contiguous() |
| 487 | outs.append(out) |
| 488 | |
| 489 | return tuple(outs) |
| 490 | |
| 491 | def train(self, mode=True): |
| 492 | """Convert the model into training mode while keep layers freezed.""" |
nothing calls this directly
no outgoing calls
no test coverage detected