Code Monkey home page Code Monkey logo

nn_interpretability's Introduction

Interpretability of Neural Networks

Project overview

Pytorch implementation of various neural network interpretability methods and how they can interpret uncertainty awareness models.

The main implementation can be found in the nn_interpretability package. We also provide every method an accompanied Jupyter Notebook to demonstrate how we can use the nn_interpretability package in practice. Some of the methods are showcased together in one notebook for better comparison. Next to the interpretability functionality, we have defined a repository for models we trained and additional functionality for loading and visualizing data and the results from the interpretability methods. Furthermore, we have implemented uncertainty techniques to observe the behavior of interpretability methods under stochastical settings.

Activation Maximization AM in codespace (GAN) AM in codespace (DCGAN) DeConvNet
Vallina Backpropagation Guided Backpropagation Integrated Gradients SmoothGrad
Simple Taylor Decomposition Deep Taylor Decomposition LRP-0 LRP-ε
DeepLIFT Rescale DeepLIFT RevealCancel CAM Grad-CAM

DeepDream

Original Image VGG19 Layer:25 VGG19 Layer:25 Filter: 150

Setup

The main deliverable of this repository is the package nn_interpretability, which entails every implementation of a NN interpretability method that we have done as part of the course. It can be installed and used as a library in any project. In order to install it one should clone this repository and execute the following command:

pip install -e .

After that, the package can be used anywhere by importing it:

import nn_interpretability as nni

An example usage of a particular interpretability method can be found in the corresponding Jupyter Notebook as outlined below. We also prepared a general demonstration of the developed package in this Jupyter Notebook.

Image classified as tandem bicycle by pretrained VGG16
LRP Composite
Guided Backpropagation
DeepLIFT RevealCancel

Note: The package assume that layers of the model are constructed inside containers(e.g. features and classifier). This setting is due to the structure of the pretrained models from the model zoo. You could use torch.nn.Sequential or torch.nn.ModuleList to achieve this on your own model.

Interpretability methods

1. Model-based approaches

2. Decision-based approaches

3. Uncertainty

References

[1] Montavon, Grégoire and Samek, Wojciech and Müller, Klaus-Robert. Methods for interpreting and understanding deep neural networks. Digital Signal Processing, 73:1–15, Feb 2018. | Paper

[2] Chris Olah, Alexander Mordvintsev, and Ludwig Schubert. Feature visualization.Distill, 2017. | Paper

[3] Chris Olah et al. The Building Blocks of Interpretability.Distill, 2017. | Paper

[4] Karen Simonyan, Andrea Vedaldi, and Andrew Zisserman. Deep inside convolutional networks:Visualising image classification models and saliency maps, 2013. | Paper

[5] Matthew D Zeiler and Rob Fergus. Visualizing and understanding convolutional networks, 2013. | Paper

[6] Jost Springenberg, Alexey Dosovitskiy, Thomas Brox, and Martin Riedmiller. Striving for sim-plicity: The all convolutional net. 12 2014. | Paper

[7] Mukund Sundararajan, Ankur Taly, and Qiqi Yan. Axiomatic attribution for deep networks.CoRR, abs/1703.01365, 2017. | Paper

[8] Grégoire Montavon, Alexander Binder, Sebastian Lapuschkin, Wojciech Samek, and Klaus-Robert Müller.Layer-Wise Relevance Propagation: An Overview, pages 193–209. 09 2019. | Paper

[9] Daniel Smilkov, Nikhil Thorat, Been Kim, Fernanda B. Viégas, and Martin Wattenberg. Smooth-grad: removing noise by adding noise.CoRR, abs/1706.03825, 2017 | Paper

[10] B. Zhou, A. Khosla, Lapedriza. A., A. Oliva, and A. Torralba. Learning Deep Features forDiscriminative Localization.CVPR, 2016. | Paper

[11] Ramprasaath R. Selvaraju, Abhishek Das, Ramakrishna Vedantam, Michael Cogswell, DeviParikh, and Dhruv Batra. Grad-cam: Why did you say that? visual explanations from deepnetworks via gradient-based localization.CoRR, abs/1610.02391, 2016. | Paper

[12] Avanti Shrikumar, Peyton Greenside, and Anshul Kundaje. Learning important features throughpropagating activation differences, 2017. | Paper

[13] Alexander Mordvintsev, Christopher Olah, and Mike Tyka. Inceptionism: Going deeper intoneural networks, 2015. | Paper

[14] Yarin Gal and Zoubin Ghahramani. Dropout as a bayesian approximation: Representing modeluncertainty in deep learning, 2015. | Paper

[15] Murat Sensoy, Lance Kaplan, and Melih Kandemir. Evidential deep learning to quantify classifi-cation uncertainty, 2018. | Paper

[16] Chuan Guo, Geoff Pleiss, Yu Sun, and Kilian Q. Weinberger. On calibration of modern neuralnetworks, 2017. | Paper

nn_interpretability's People

Contributors

hans66hsu avatar miquelmn avatar pourmand1376 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nn_interpretability's Issues

DeepLIFT with rules

Hi,

I would like to use DeepLIFT for my finetuned models (Resnet, Densenet etc.), however it was only working with DeepLIFTRules.NoRule.
My dataset consist of RGB images (254, 254, 3). In example provided everything was working smoothly, but for my model, when I try using any Rules it give me errors.

For my densenet201 model with 37 classes:

interpreter = DeepLIFT(model, [str(i) for i in range(37)], None, DeepLIFTRules.RevealCancel)
for data in dataloaders['test']:
            image, label = data
            out = interpreter.interpret(image)

I got error:

  File "...\nn_interpretability_main\nn_interpretability\interpretation\deeplift\deeplift.py", line 252, in forward_hook
    self.inputs.append(input[0].data.clone().to(device))

AttributeError: 'list' object has no attribute 'data'

It is possible that the problem is with my models? Can I even run DeepLIFT with them for RGB images?

LRP for semantic segmentation

Nice work! I want to apply LRP to unet model for explaining semantic segmentation tasks. I looked up most implementations of the Pytorch version of LRP and almost none of them support semantic segmentation tasks. Does the LRP in this resource support the interpretation of semantic segmentation tasks? Thanks a lot!

LRP for time series forecasting

Hi,
Thanks for the well explained implementations. I want to apply LRP to LSTM for a multivariate time series forecasting task (to predict future values for multiple consecutive days). Will this LRP implementation support the forecasting tasks when the data is tabular?

LRP converting FC to CONV

Thanks for the excellent work!

I have a question, is it necessary to convert fully-connected strata to convolutional layers?

My model was not build in pytorch sequence, so I removed the outer traversal of the model but then traversing the model causes problem:

newlayer.weight = nn.Parameter(module.weight.reshape(n, channel_out, h_w[0], h_w[1]))

RuntimeError: shape '[128, 64, 24, 24]' is invalid for input of size 1179648

seems like the target number of parameters are multiple times larger than it should be..

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.