Saliency methods for TensorFlow
Project description
Saliency Methods
Introduction
This repository contains code for SmoothGrad, as well as implementations of several other saliency techniques. Each of these techniques can also be augmented with SmoothGrad. The techniques implemented in this library are:
- Vanilla Gradients (paper, paper)
- Guided Backpropogation (paper)
- Integrated Gradients (paper)
- Occlusion
- Grad-CAM (paper)
This list is by no means comprehensive. We are accepting pull requests to add new methods!
Download
git clone https://github.com/pair-code/saliency
cd saliency
Usage
Each saliency mask class extends from the SaliencyMask base class. This class
contains the following methods:
__init__(graph, session, y, x): Constructor of the SaliencyMask. This can modify the graph, or sometimes create a new graph. Often this will add nodes to the graph, so this shouldn't be called continuously.yis the output tensor to compute saliency masks with respect to,xis the input tensor with the outer most dimension being batch size.GetMask(x_value, feed_dict): Returns a mask of the shape of non-batchedx_valuegiven by the saliency technique.GetSmoothedMask(x_value, feed_dict): Returns a mask smoothed of the shape of non-batchedx_valuewith the SmoothGrad technique.
The visualization module contains two visualization methods:
VisualizeImageGrayscale(image_3d, percentile): Marginalizes across the absolute value of each channel to create a 2D single channel image, and clips the image at the given percentile of the distribution. This method returns a 2D tensor normalized between 0 to 1.VisualizeImageDiverging(image_3d, percentile): Marginalizes across the value of each channel to create a 2D single channel image, and clips the image at the given percentile of the distribution. This method returns a 2D tensor normalized between -1 to 1 where zero remains unchanged.
If the sign of the value given by the saliency mask is not important, then use
VisualizeImageGrayscale, otherwise use VisualizeImageDiverging. See
the SmoothGrad paper for more details on which visualization method to use.
Examples
This example iPython notebook shows these techniques is a good starting place.
Another example of using GuidedBackprop with SmoothGrad from TensorFlow:
from guided_backprop import GuidedBackprop
import visualization
...
# Tensorflow graph construction here.
y = logits[5]
x = tf.placeholder(...)
...
# Compute guided backprop.
# NOTE: This creates another graph that gets cached, try to avoid creating many
# of these.
guided_backprop_saliency = GuidedBackprop(graph, session, y, x)
...
# Load data.
image = GetImagePNG(...)
...
smoothgrad_guided_backprop =
guided_backprop_saliency.GetMask(image, feed_dict={...})
# Compute a 2D tensor for visualization.
grayscale_visualization = visualization.VisualizeImageGrayscale(
smoothgrad_guided_backprop)
This is not an official Google product.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file saliency-0.0.3.tar.gz.
File metadata
- Download URL: saliency-0.0.3.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
333dd7d24a527798449d7c2d128143229cdc74bca170eef19afc945d60e3b6c1
|
|
| MD5 |
7748fc9a1862c750c3d6339ed599823f
|
|
| BLAKE2b-256 |
84f3a5443d5d684a85d1942e4af008b9e0d4b3538d339576c355ef1987ff7ba7
|
File details
Details for the file saliency-0.0.3-py2.py3-none-any.whl.
File metadata
- Download URL: saliency-0.0.3-py2.py3-none-any.whl
- Upload date:
- Size: 17.6 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8a4ee2c3184c7b7782cf9a1d2e62179c564b09980561d932ab8aa6ed79f6367
|
|
| MD5 |
727207d194498db25142c03d198cce02
|
|
| BLAKE2b-256 |
34e670868723ef1bd75de2dcee9c6774f53ef0f3a1635125211d4674d4d9c4f3
|