albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.25k stars 234 forks source link

`is_layer_at_idx` not implemented #264

Closed adrhill closed 1 year ago

adrhill commented 3 years ago

The function is_layer_at_idx currently doesn't return anything when it should be returning a boolean value after checking the layer:

https://github.com/albermax/innvestigate/blob/c6ce89323d686a52d793177efd8d1dda3bd9526a/src/innvestigate/utils/keras/checks.py#L446-L448

This is used in all analyzers that inherit from LRP and use the kwargs until_layer_rule and until_layer_idx:

https://github.com/albermax/innvestigate/blob/c3295be173b99e9fb587bec7bee4cacafeae8a2f/src/innvestigate/analyzer/relevance_based/relevance_analyzer.py#L399-L410

As Python evaluates bool(None) as False instead of throwing an error, the until_layer_rule never gets applied.

Currently only LRPSequentialPresetBFlatUntilIdx and user-defined composite LRP methods are affected, so this bug should be fixed before merging #261. Until then PR #263 adds a NotImplementedError.

HugoTex98 commented 3 years ago

Hi @adrhill !

Given the example in https://github.com/adrhill/innvestigate/blob/adrhill/custom-composite/examples/notebooks/imagenet_composite_lrp.ipynb, without the application of until_layer_rule , the only rule being applied to the model is the one specified in rule?

adrhill commented 3 years ago

Hi HugoTex98,

that notebook is work in progress from PR #261 , which hasn't been merged yet due to this issue.

That being said, you can still use LRP without the until_layer_rule:

analyzer = LRP(
    model_wo_softmax, 
    rule="Z",
    input_layer_rule="Bounded",
    bn_layer_rule="Z"
)
HugoTex98 commented 3 years ago

Thanks @adrhill!

Btw, do you have any idea of a possible release date for this LRP with the until_layer_rule?

adrhill commented 3 years ago

It's high up on my to-do list, but it will have to wait until the TF2 release, which should be ready soon.