albermax / innvestigate

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

allow_lambda_layers parameter not working for SmoothGrad and IntegratedGradients #157

Open valentinodavide opened 5 years ago

valentinodavide commented 5 years ago

Hi, I believe there may be an issue with SmoothGrad and IntegratedGradients methods when there's need to set allow_lambda_layers=True during the creation of the analyzer.

In particular I think that "allow_lambda_layers" is missing in kwargs_keys defined in the __init__() method of both classes SmoothGrad and IntegratedGradient, so it cannot be passed to the inner Gradient constructor for both methods.

A snippet of the code I use is the following (but the same happens for method "integrated_gradients"):

analyzer = innvestigate.create_analyzer("smoothgrad", model, allow_lambda_layers=True)
analyzer.analyze(preprocessed_input)

while the stacktrace is:

Traceback (most recent call last):
  File "/home/davide/PycharmProjects/innvestigate-gui/innvestigate-gui/main.py", line 890, in visualize
    allow_lambda_layers=True)
  File "/usr/local/lib/python3.6/dist-packages/innvestigate/analyzer/__init__.py", line 140, in create_analyzer
    return analyzer_class(model, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/innvestigate/analyzer/gradient_based.py", line 310, in __init__
    **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/innvestigate/analyzer/wrapper.py", line 219, in __init__
    *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/innvestigate/analyzer/wrapper.py", line 97, in __init__
    *args, **kwargs)
  File "/usr/local/lib/python3.6/dist-packages/innvestigate/analyzer/wrapper.py", line 49, in __init__
    *args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'allow_lambda_layers'

Among these 2 methods, with all the others creating the analyzer with allow_lambda_layers=True works correctly.

If you need any extra information let me know. Thanks.