(self, x)
| 588 | self.head = head |
| 589 | |
| 590 | def forward(self, x): |
| 591 | # convert to list |
| 592 | if not isinstance(x, list): |
| 593 | x = [x] |
| 594 | idx_crops = torch.cumsum(torch.unique_consecutive( |
| 595 | torch.tensor([inp.shape[-1] for inp in x]), |
| 596 | return_counts=True, |
| 597 | )[1], 0) |
| 598 | start_idx, output = 0, torch.empty(0).to(x[0].device) |
| 599 | for end_idx in idx_crops: |
| 600 | _out = self.backbone(torch.cat(x[start_idx: end_idx])) |
| 601 | # The output is a tuple with XCiT model. See: |
| 602 | # https://github.com/facebookresearch/xcit/blob/master/xcit.py#L404-L405 |
| 603 | if isinstance(_out, tuple): |
| 604 | _out = _out[0] |
| 605 | # accumulate outputs |
| 606 | output = torch.cat((output, _out)) |
| 607 | start_idx = end_idx |
| 608 | # Run the head forward on the concatenated features. |
| 609 | return self.head(output) |
| 610 | |
| 611 | |
| 612 | def get_params_groups(model): |
nothing calls this directly
no outgoing calls
no test coverage detected