Skip to content

Lrp tutorial added #668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Conversation

JohannesK14
Copy link

Reference Issues

664

Changes

Addition of an LRP tutorial and a sample image. The tutorial replicates the results of the basic PyTorch LRP implementation provided by the LRP authors using the LRP class of captum.

@facebook-github-bot
Copy link
Contributor

Hi @JohannesK14!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link
Contributor

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@bilalsal bilalsal requested a review from NarineK May 13, 2021 01:11
@NarineK NarineK requested a review from vivekmig July 6, 2021 18:47
@NarineK
Copy link
Contributor

NarineK commented Jul 8, 2021

Thank you for the tutorial, @JohannesK14! We will provide review comments soon!

A quick question: Where is the castle.jpeg from ? We need to know the copyright permissions and the attribution required for that image.

Copy link
Contributor

@NarineK NarineK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you very much for working on this tutorial, @JohannesK14 ! Overall looks great to me.

One ask:
Since we are adding more tutorials to Captum I'm thinking that perhaps we can combine this with the resnet one and call it Resnet_VGG_TorchVision_Interpret.ipynb, if we want to showcase LRP example explicitly for VGG. The content of this tutorial can be added to the bottom of the Resnet_VGG_TorchVision_Interpret.ipynb file.
In the top of theResnet_VGG_TorchVision_Interpret file we can briefly describe that we are showcasing LRP for VGG as well.

Feel free to add an example of LRP for Resnet as well in that same notebook.
https://github.com/pytorch/captum/blob/master/tutorials/Resnet_VGG_TorchVision_Interpret.ipynb

If you combine those tutorials, I'd also suggest that you do minor adjustments for the website text as well:
https://github.com/pytorch/captum/blob/master/website/tutorials.json#L17
https://github.com/pytorch/captum/blob/master/website/pages/tutorials/index.js#L70

Couple more minor comments:
"As one see" -> "As one can see" ?
"Currently implemented in captum are " -> "Currently implemented rules in captum are " ? 
 Also, do you mind adding here a link to the documentation for the recommended rules ?

@JohannesK14
Copy link
Author

Thank you for the tutorial, @JohannesK14! We will provide review comments soon!

A quick question: Where is the castle.jpeg from ? We need to know the copyright permissions and the attribution required for that image.

Hello @NarineK ,

I took the image from here: https://git.tu-berlin.de/gmontavon/lrp-tutorial

I could ask the author for the copyright permission.

@JohannesK14
Copy link
Author

JohannesK14 commented Jul 9, 2021

Regarding your second comment:

Of course, I can add the tutorial to the Resnet_TorchVision_Interpret.ipynb. But then I would suggest omitting VGG and just use Resnet and also the swan picture. Otherwise, it will look a little bit thrown together, I think. And Resnet is also more interesting than VGG, because there you need the implementation with back hooks for the skip connections.

And you would not need copyright permission for the castle anymore.

I will have a look into that in the next few days.

@NarineK
Copy link
Contributor

NarineK commented Jul 9, 2021

Regarding your second comment:

Of course, I can add the tutorial to the Resnet_TorchVision_Interpret.ipynb. But then I would suggest omitting VGG and just use Resnet and also the swan picture. Otherwise, it will look a little bit thrown together, I think. And Resnet is also more interesting than VGG, because there you need the implementation with back hooks for the skip connections.

And you would not need copyright permission for the castle anymore.

I will have a look into that in the next few days.

Hi @JohannesK14, agree, let's use Resnet and the swan image instead.

@NarineK
Copy link
Contributor

NarineK commented Sep 21, 2021

@JohannesK14 would you have time to address the comments in this PR as discussed previously ?

@aobo-y aobo-y self-assigned this Mar 1, 2022
@HeinrichAD
Copy link

Unfortunately, the example notebook does not work anymore.

image

RuntimeError: Output 0 of BackwardHookFunctionBackward is a view and is being modified inplace. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function.


I like the example. Does anybody has an idea how to solve the issue?
I mean, since it's a pre-trained model, we can't just change the inline relu layer to a "normal" relu layer, for example.

@JohannesK14
Copy link
Author

@HeinrichAD I just set the inplace flag to false. Why do you see a problem there? To my knowledge, the inplace functionality could save some memory, but should deliver the same results in a VGG.

@NarineK Sorry for my long absence. I tried the switch to the ResNet architecture this morning. Unfortunately, the design of the composition of the rules for the ResNet18 architecture is more complicated than I thought it would be. I don't have the time to tinker with the rules to create a acceptable result for the visualization of the attributions, which I am very sorry for. Therefore, I switched to the picture of the swan, which also gives a pleasant result and avoids copyright issues.

Do you think I should still merge it with the ResNet tutorial as you suggested earlier?

@HeinrichAD
Copy link

@JohannesK14 I looked into the source code [1]. In this case it will be the same. So no problems here.

[1] https://pytorch.org/vision/main/_modules/torchvision/models/vgg.html#vgg16

facebook-github-bot pushed a commit that referenced this pull request Feb 1, 2023
Summary:
Building on top of this pull request: #668

Pull Request resolved: #1105

Reviewed By: aobo-y

Differential Revision: D42811693

Pulled By: skim9

fbshipit-source-id: 23b07caf6bc161fbac35f225070c4f74ba206743
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants