albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.24k stars 235 forks source link

[BUG] NotImplementedError raised every time layers are checked with _do_model_checks() for analyzers inheriting from AnalyzerBase #323

Open juliowissing-iis opened 8 months ago

juliowissing-iis commented 8 months ago

Describe the bug

When creating an analyzer that uses model checks (e.g., LRPSequentialPresetA), a NotImplementedError is raised for every check that should only be a warning. This originates from the snippet (lines 120-125 in analyzer/base.py):

if check_type == "exception":
    raise NotAnalyzeableModelException(tmp_message)
if check_type == "warning":
    # TODO(albermax) only the first warning will be shown
    warnings.warn(tmp_message)
raise NotImplementedError()

Steps to reproduce the bug

import tensorflow as tf
import innvestigate
tf.compat.v1.disable_eager_execution()

model = _   # create model with non-ReLU activation
analyzer = innvestigate.analyzer.LRPSequentialPresetA(model)

Expected behavior

As LRPSequentialPresetA only has a check with check_type "warning" no exception should be raised, just a warning. To fix this I changed the abovementioned snippet to:

if check_type == "exception":
    raise NotAnalyzeableModelException(tmp_message)
elif check_type == "warning":
    # TODO(albermax) only the first warning will be shown
    warnings.warn(tmp_message)
else: 
    raise NotImplementedError("Check type {} unkown".format(check_type))

Platform information