Unified callable function API of Inferers. Args: inputs: model input data for inference. network: target model to execute inference. supports callables such as ``lambda x: my_torch_model(x, additional_config)`` args: other optional args to
(self, inputs: torch.Tensor, network: nn.Module, *args: Any, **kwargs: Any)
| 720 | self.kwargs = kwargs |
| 721 | |
| 722 | def __call__(self, inputs: torch.Tensor, network: nn.Module, *args: Any, **kwargs: Any): # type: ignore |
| 723 | """Unified callable function API of Inferers. |
| 724 | |
| 725 | Args: |
| 726 | inputs: model input data for inference. |
| 727 | network: target model to execute inference. |
| 728 | supports callables such as ``lambda x: my_torch_model(x, additional_config)`` |
| 729 | args: other optional args to be passed to the `__call__` of cam. |
| 730 | kwargs: other optional keyword args to be passed to `__call__` of cam. |
| 731 | |
| 732 | """ |
| 733 | cam: CAM | GradCAM | GradCAMpp |
| 734 | if self.cam_name == "cam": |
| 735 | cam = CAM(network, self.target_layers, *self.args, **self.kwargs) |
| 736 | elif self.cam_name == "gradcam": |
| 737 | cam = GradCAM(network, self.target_layers, *self.args, **self.kwargs) |
| 738 | else: |
| 739 | cam = GradCAMpp(network, self.target_layers, *self.args, **self.kwargs) |
| 740 | |
| 741 | return cam(inputs, self.class_idx, *args, **kwargs) |
| 742 | |
| 743 | |
| 744 | class SliceInferer(SlidingWindowInferer): |