trw.train.grad_cam
¶
Module Contents¶
Classes¶
Gradient-weighted Class Activation Mapping |
Attributes¶
- trw.train.grad_cam.logger¶
- class trw.train.grad_cam.GradCam(model: torch.nn.Module, find_convolution: Callable[[torch.nn.Module, Union[trw.basic_typing.Batch, torch.Tensor]], Optional[Mapping]] = graph_reflection.find_last_forward_convolution, post_process_output: Callable[[Any], torch.Tensor] = guided_back_propagation.post_process_output_id)¶
Gradient-weighted Class Activation Mapping
This is based on the paper “Grad-CAM: Visual Explanations from Deep Networks via Gradient-based Localization”, Ramprasaath R et al.
- __call__(self, inputs: Union[trw.basic_typing.Batch, torch.Tensor], target_class_name: str = None, target_class: int = None) Optional[Tuple[str, Mapping]] ¶
- Parameters
inputs – the inputs to be fed to the model
target_class_name –
the output node to be used. If None: * if model output is a single tensor then use this as target output
else it will use the first OutputClassification output
target_class – the index of the class to explain the decision. If None, the class output will be used
- Returns
a tuple (output name, a dictionary (input_name, GradCAMs))