| 580 | _load_pretrained_encoder(self, weights) |
| 581 | |
| 582 | def forward(self, x: torch.Tensor) -> dict[str, torch.Tensor]: |
| 583 | if self.mode == HoVerNetMode.ORIGINAL.value: |
| 584 | if x.shape[-1] != 270 or x.shape[-2] != 270: |
| 585 | raise ValueError("Input size should be 270 x 270 when using HoVerNetMode.ORIGINAL") |
| 586 | else: |
| 587 | if x.shape[-1] != 256 or x.shape[-2] != 256: |
| 588 | raise ValueError("Input size should be 256 x 256 when using HoVerNetMode.FAST") |
| 589 | |
| 590 | x = self.conv0(x) |
| 591 | short_cuts = [] |
| 592 | |
| 593 | for i, block in enumerate(self.res_blocks): |
| 594 | x = block.forward(x) |
| 595 | |
| 596 | if i <= 2: |
| 597 | short_cuts.append(x) |
| 598 | |
| 599 | x = self.bottleneck(x) |
| 600 | x = self.upsample(x) |
| 601 | |
| 602 | output = { |
| 603 | HoVerNetBranch.NP.value: self.nucleus_prediction(x, short_cuts), |
| 604 | HoVerNetBranch.HV.value: self.horizontal_vertical(x, short_cuts), |
| 605 | } |
| 606 | if self.type_prediction is not None: |
| 607 | output[HoVerNetBranch.NC.value] = self.type_prediction(x, short_cuts) |
| 608 | |
| 609 | return output |
| 610 | |
| 611 | |
| 612 | def _load_pretrained_encoder(model: nn.Module, state_dict: OrderedDict | dict): |