Coder Social home page Coder Social logo

fullgrad-saliency's Introduction

Full-Gradient Saliency Maps

This is the reference implementation of the FullGrad saliency method described in our NeurIPS 2019 publication "Full-Gradient Representation for Neural Network Visualization".

This repository implements three methods:

  1. The reference FullGrad saliency method, which aggregates layerwise gradient maps multipled with the bias terms
  2. Simple FullGrad, which omits computation of bias parameters and simply aggregates layerwise gradient maps
  3. Smooth FullGrad, which aggregates noise averaged layerwise gradient maps with the bias terms

The related full-gradient decomposition is implemented within FullGrad. Note that while full-gradient decomposition applies to any ReLU neural network, FullGrad saliency is specific to CNNs.

In addition, the following methods from literature are also implemented:

  1. Input-gradient (paper)
  2. Grad-CAM (paper)
  3. SmoothGrad (paper)

Examples

FullGrad SimpleFullGrad SmoothFullGrad
FullGrad Simple FullGrad Smooth FullGrad
GradCAM Input-Gradient SmoothGrad
Grad-CAM Input-Gradients SmoothGrad

Usage

Simply run python dump_images.py, the saliency maps should be saved consequently in a results folder.

Interfaces

The FullGrad class has the following methods implemented.

from saliency.fullGrad import FullGrad

# Initialize FullGrad object
fullgrad = FullGrad(model)

# Check completeness property
# done automatically while initializing object
fullgrad.checkCompleteness()

# Obtain fullgradient decomposition
input_gradient, bias_gradients = 
fullgrad.fullGradientDecompose(input_image, target_class)

# Obtain saliency maps
saliency_map = fullgrad.saliency(input_image, target_class)

We also introduce variants called SimpleFullGrad and SmoothFullGrad which have no completeness property or decomposition.

from saliency.simple_fullgrad import SimpleFullGrad
from saliency.smooth_fullgrad import SmoothFullGrad

# Initialize Simple / Smooth FullGrad objects
simple_fullgrad = SimpleFullGrad(model)
smooth_fullgrad = SmoothFullGrad(model)

# Obtain saliency maps
saliency_map_simple = simple_fullgrad.saliency(input_image, target_class)
saliency_map_smooth = smooth_fullgrad.saliency(input_image, target_class)

This basic interface is retained for input-gradient, gradcam and smoothgrad methods as well.

Dependencies

torch torchvision cv2 numpy 

Research

If you found our work helpful for your research, please do consider citing us.

@inproceedings{srinivas2019fullgrad,
    title={Full-Gradient Representation for Neural Network Visualization},
    author={Srinivas, Suraj and Fleuret, François},
    booktitle={Advances in Neural Information Processing Systems (NeurIPS)},
    year={2019}
}

fullgrad-saliency's People

Contributors

rdjdejong avatar suraj-srinivas avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.