chr5tphr / zennit

Zennit is a high-level framework in Python using PyTorch for explaining/exploring neural networks using attribution methods like LRP.
Other
200 stars 32 forks source link

New version of zennit produces wrong LRP heatmaps #44

Closed rachtibat closed 3 years ago

rachtibat commented 3 years ago

Hi,

it is a long time ago, I pulled all the new zennit updates. So I missed a lot of comments and I can not exactly point out where the LRP pipeline seems to have broken down the first time. For test purposes, I always use the same LeNet model pretrained on FashionMNIST. When I generate a heatmap with "epsilon_plus", I get with the old version of zennit the same heatmap as in Innvestigate. But the new version suddenly produces completely different heatmaps.

You can try it out with my code example on https://github.com/rachtibat/mnist_zennit I uploaded for you. Just change the import "zennit_old" to "zennit_new" and you see the difference. I changed the name of zennit.torchvision to zennit.torchvision_2 making it work fast and dirty (; (see https://github.com/chr5tphr/zennit/pull/6)

Do you think, I made a mistake or is zennit somehow computing the heatmaps differently?

Best

P.s. if this is really a bug, it might solve the other issues

rachtibat commented 3 years ago

Using "jet" cmap Old zennit: old old 1

New Zennit: new new 1

chr5tphr commented 3 years ago

Thanks, I'll have a look. Two things first:

chr5tphr commented 3 years ago

Found the problem, the gradient check in c984127 was only checking for .grad_fn. In the first layer, there may not be a .grad_fn yet, thus it should rather check for .requires_grad. I will prepare a MR.

rachtibat commented 3 years ago

Hi, Thanks for your suggestions. I tested your fix and it's working great!

Best