Visualizing explanations for image data

AI Explanations provides built-in visualization capabilities for your image data. When you request an explanation on an image classification model with a visualization configured, you'll get the predicted class along with an image overlay showing which pixels or regions contributed to the prediction.

The images below show visualizations on a husky image. The left visualization uses the integrated gradients method and highlights areas of positive attribution. The right visualization uses an XRAI method with a color gradient indicating areas of lesser (blue) and greater (yellow) influence in making a positive prediction.

A feature attribution visualization of a husky using integrated
       gradients
A feature attribution visualization of a husky using XRAI

The type of data you're working with can influence whether you use an integrated gradients or XRAI approach to visualizing your explanations.

  • XRAI tends to be better with natural images and provides a better high-level summary of insights, like showing that positive attribution is related to the shape of a dog's face.
  • Integrated gradients (IG) tends to provide details at the pixel level and is useful for uncovering more granular attributions.

Learn more about the attribution methods in the AI Explanations Overview page.

Getting started

Visualizations are configured per model as part of the explanation metadata file.

To add a new visualization for your model, include a visualization object within the inputs object you want to visualize. In the visualization object you can include options such as the type of overlay used, which attributions are highlighted, color, and more. All settings are optional.

To create another visualization with the same model, update the settings in the explanation_metadata.json file and redeploy the model.

Visualization options

The default and recommended settings depend on the attribution method (integrated gradients or XRAI). Below are a list of configuration options and how you might use them. For a full list of options values, see the API reference.

  • type: The type of visualization used. For integrated gradients, Outlines is set by default and shows regions of attribution, while Pixels shows per-pixel attribution. For XRAI, Pixels is the default setting and shows areas of attribution. Outlines is not recommended for XRAI.
  • polarity: The directionality of the highlighted attributions. positive is set by default, which highlights areas with the highest positive attributions. This means highlighting pixels that were most influential to the model's positive prediction. Setting polarity to negative highlights areas that lead the model to not predicting the positive class. Using a negative polarity can be useful for debugging your model by identifying false negative regions. You can also set polarity to both which shows positive and negative attributions.
  • clip_above_percentile: Excludes attributions above the specified percentile from the highlighted areas. Using the clip parameters together can be useful for filtering out noise and making it easier to see areas of strong attribution.
  • clip_below_percentile: Excludes attributions below the specified percentile. from the highlighted areas.
  • color_map: The color scheme used for the highlighted areas. Default is pink_green for integrated gradients, which shows positive attributions in green and negative in pink. For XRAI visualizations, the color map is a gradient. The XRAI default is viridis which highlights the most influential regions in yellow and the least influential in blue.
  • overlay_type: How the original image is displayed in the visualization. Adjusting the overlay can help increase visual clarity if the original image makes it difficult to view the visualization.

Example configurations

To get started, below are sample visualization objects that you can use as a starting point and images that show a range of settings applied.

Integrated gradients

For integrated gradients, you may need to adjust the clip values if the attribution areas are too noisy.

visualization: {
"type": "Outlines", # Can also use "Pixels"
"polarity": "positive",
"clip_below_percentile": 70,
"clip_above_percentile": 99.9,
"color_map": "pink_green",
"overlay_type": "grayscale"
}

Below are two visualizations using both the Outlines and Pixels types. The columns labeled "Highly predictive only," "Moderately predictive," and "Almost all" are examples of clipping at different levels that can help focus your visualization.

A feature attribution viz with outlines for IG attribution

A feature attribution viz with pixels for IG attribution

XRAI

For XRAI visualizations, we recommend starting with no clip values for XRAI because the overlay uses a gradient to show areas of high and low attribution.

visualization: {
"type": "Pixels", # Only valid option for XRAI
"polarity": "positive",
"clip_below_percentile": 0,
"clip_above_percentile": 100,
"color_map": "viridis",
"overlay_type": "grayscale"
}

The image below is an XRAI visualization using the default viridis color map and a range of overlay types. The areas in yellow indicate the most influential regions that contributed positively to the prediction.

A feature attribution vizualization for XRAI attribution

What's next

You can also use the What-If Tool to visualize your explanations. Refer to the example notebooks to learn more.