pytorch / captum

Model interpretability and understanding for PyTorch
https://captum.ai
BSD 3-Clause "New" or "Revised" License
4.96k stars 499 forks source link

AttributeError: 'NoneType' object has no attribute 'relevance_input' #1238

Open Pei4579 opened 10 months ago

Pei4579 commented 10 months ago

I'm using LRP for my resnet model by loading in .pth file. However, it raises "AttributeError: 'NoneType' object has no attribute 'relevance_input'" while I'm trying to apply the following code. lrp = LRP(down_model) attribution = lrp.attribute((use1, use2), target = np.argmax(dataset[a][-1])) I've checked the type of everything is the same as the tutorial you provided, the only difference is the model, but the model works well when I apply it to Saliency as the following code:

saliency = Saliency(down_model) attribution = saliency.attribute((use1, use2), target = np.argmax(dataset[a][-1]))

Thanks in advance!

YUN-MAN commented 10 months ago

I had same problem 😬😬

krebso commented 10 months ago

Hello there, do you set the rules beforhand? If you are using custom layers, this might be an issue. From docs - Custom rules for a given layer need to be defined as attribute module.rule and need to be of type PropagationRule.

Pei4579 commented 9 months ago

Thanks for the quick reply. Yes, I found that the rule is the key to solving. Should I write a new rule similar to the Propagation Rule for replacing it or do I need to modify the source code? Do you have any custom model rules samples or example experiments for reference? Thanks!

krebso commented 9 months ago

Hey, I used composite LRP from this paper for VGG-16. Both Gamma and Epsilon rule are part of captum and I did not bother with the input layer rule yet. I ended using AlphaBeta in the end, instead of the Gamma tho.