Skip to content
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

is_layer_at_idx not implemented #264

Closed
adrhill opened this issue Jul 6, 2021 · 4 comments · Fixed by #308
Closed

is_layer_at_idx not implemented #264

adrhill opened this issue Jul 6, 2021 · 4 comments · Fixed by #308
Labels

Comments

@adrhill
Copy link
Collaborator

adrhill commented Jul 6, 2021

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

def is_layer_at_idx(layer, index, ignore_reshape_layers=True):
"""Checks if layer is a layer at index index, by repeatedly applying is_input_layer()."""
kgraph = get_kgraph()

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

# apply rule to first self._until_layer_idx layers
if self._until_layer_rule is not None and self._until_layer_idx is not None:
for i in range(self._until_layer_idx + 1):
rules.insert(
0,
(
lambda layer, foo, bound_i=i: kchecks.is_layer_at_idx(
layer, bound_i
),
self._until_layer_rule,
),
)

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.

@adrhill adrhill added the bug label Jul 6, 2021
@HugoTex98
Copy link

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
Copy link
Collaborator Author

adrhill commented Jul 20, 2021

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
Copy link

Thanks @adrhill!

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

@adrhill
Copy link
Collaborator Author

adrhill commented Jul 20, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants