Forward function.
(self, x)
| 564 | |
| 565 | |
| 566 | def forward(self, x): |
| 567 | """Forward function.""" |
| 568 | tic = time.time() |
| 569 | x = self.patch_embed(x) |
| 570 | Wh, Ww = x.size(2), x.size(3) |
| 571 | |
| 572 | x = x.flatten(2).transpose(1, 2) |
| 573 | x = self.pos_drop(x) |
| 574 | |
| 575 | outs = {} |
| 576 | for i in range(self.num_layers): |
| 577 | layer = self.layers[i] |
| 578 | x_out, H, W, x, Wh, Ww = layer(x, Wh, Ww) |
| 579 | if i in self.out_indices: |
| 580 | norm_layer = getattr(self, f'norm{i}') |
| 581 | x_out = norm_layer(x_out) |
| 582 | |
| 583 | out = x_out.view(-1, H, W, self.num_features[i]).permute(0, 3, 1, 2).contiguous() |
| 584 | outs["res{}".format(i + 2)] = out |
| 585 | |
| 586 | if len(self.out_indices) == 0: |
| 587 | outs["res5"] = x_out.view(-1, H, W, self.num_features[i]).permute(0, 3, 1, 2).contiguous() |
| 588 | |
| 589 | toc = time.time() |
| 590 | return outs |
| 591 | |
| 592 | def train(self, mode=True): |
| 593 | """Convert the model into training mode while keep layers freezed.""" |
nothing calls this directly
no outgoing calls
no test coverage detected