OcclusionSaliency
Perturbation-based saliency maps for image classifiers.
Slides a gray patch over the image and records how much the predicted class probability drops at each position. Regions whose occlusion causes a large drop are the ones the model relied on. Unlike Grad-CAM, this method needs no gradients or convolutional layers, so it works with every DashAI image classifier including the MLP; the trade-off is one model evaluation per patch position.
References
- [1] Zeiler, M.D. & Fergus, R. (2014). "Visualizing and Understanding Convolutional Networks." ECCV 2014. https://arxiv.org/abs/1311.2901
Parameters
- patch_size : integer, default=
16 - Side (in pixels) of the square patch that is occluded at each position. Smaller patches give finer maps but require more model evaluations.
- stride : integer, default=
8 - Step (in pixels) between consecutive patch positions. Smaller strides give smoother maps but require more model evaluations.
Methods
explain_instance(self, instances)
OcclusionSaliencyCompute an occlusion saliency map for each image.
Parameters
- instances : DashAIDataset
- Images to be explained; the first column must contain images.
Returns
- dict
- Dictionary with, for each image, the resized image, the saliency map and the model prediction.
fit(self, background_dataset, **kwargs)
OcclusionSaliencyStore class names in the model's class-index order.
Parameters
- background_dataset : Tuple[DatasetDict, DatasetDict]
- Tuple
(x, y)with the dataset splits. - **kwargs : Any
- Ignored; present for interface compatibility.
Returns
- OcclusionSaliency
- The fitted explainer instance (
self).
plot(self, explanation: dict) -> List[DashAI.back.core.artifacts.GroupedArtifacts]
OcclusionSaliencyRender each image as a saliency overlay plus a text summary.
Parameters
- explanation : dict
- Dictionary with the explanation generated by the explainer.
Returns
- List[GroupedArtifacts]
- A single grouped artifact with one group per explained image, each holding that image's saliency overlay and text summary.
get_schema(cls) -> dict
ConfigObjectGenerates the component related Json Schema.
Returns
- dict
- Dictionary representing the Json Schema of the component.
validate_and_transform(self, raw_data: dict) -> dict
ConfigObjectIt takes the data given by the user to initialize the model and returns it with all the objects that the model needs to work.
Parameters
- raw_data : dict
- A dictionary with the data provided by the user to initialize the model.
Returns
- dict
- A validated dictionary with the necessary objects.