Shap: Gradient Explainer; LookupError: gradient registry has no entry for: shap_StridedSlice

Created on 3 Sep 2020  路  5Comments  路  Source: slundberg/shap

I am running the following code:

import shap 

explainer = shap.GradientExplainer(model, x_train)
shap_values = explainer.shap_values(x_test[:10])

I run into the following error:

LookupError: gradient registry has no entry for: shap_StridedSlice

Here is a summary of my model:

Model: "sequential_6"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
simple_rnn_6 (SimpleRNN)     (None, 10, 1)             12        
_________________________________________________________________
dense_6 (Dense)              (None, 10, 1)             2         
_________________________________________________________________
flatten (Flatten)            (None, 10)                0         
=================================================================
Total params: 14
Trainable params: 14
Non-trainable params: 0
_________________________________________________________________

My SHAP and TensorFlow versions are

  • shap: 0.35.0
  • tensorflow: 2.3.0

Error log

bug

Most helpful comment

@slundberg After changing my model structure a bit, I don't get that error anymore. Here is my new model summary:

Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
simple_rnn_4 (SimpleRNN)     (None, 607, 1)            12        
_________________________________________________________________
flatten_4 (Flatten)          (None, 607)               0         
_________________________________________________________________
dense_4 (Dense)              (None, 607)               369056    
=================================================================
Total params: 369,068
Trainable params: 369,068
Non-trainable params: 0
_________________________________________________________________

Note that the flatten layer was moved to before the dense layer.

@patricksferraz I don't think DeepExplainer is supported in TF2

All 5 comments

I wonder if this is new with TF 2.3, could you try on 2.2 or 2.1 and see if the same issue happens?

Similar error here with __DeepExplainer__:

import shap

background = x_train[np.random.choice(x_train.shape[0], 100, replace=False)]
e = shap.DeepExplainer(model, background )
shap_values = e.shap_values(x_test[:10])

Error:

LookupError: gradient registry has no entry for: shap_Softsign

Summary:

Model: "mlp"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
dense (Dense)                (None, 51)                969       
_________________________________________________________________
dense_1 (Dense)              (None, 88)                4576      
_________________________________________________________________
dense_2 (Dense)              (None, 76)                6764      
_________________________________________________________________
dense_3 (Dense)              (None, 51)                3927      
_________________________________________________________________
dense_4 (Dense)              (None, 2)                 104       
=================================================================
Total params: 16,340
Trainable params: 16,340
Non-trainable params: 0
_________________________________________________________________

__shap__: 0.35.0
__tensorflow__: 2.2.0

@slundberg After changing my model structure a bit, I don't get that error anymore. Here is my new model summary:

Model: "sequential_4"
_________________________________________________________________
Layer (type)                 Output Shape              Param #   
=================================================================
simple_rnn_4 (SimpleRNN)     (None, 607, 1)            12        
_________________________________________________________________
flatten_4 (Flatten)          (None, 607)               0         
_________________________________________________________________
dense_4 (Dense)              (None, 607)               369056    
=================================================================
Total params: 369,068
Trainable params: 369,068
Non-trainable params: 0
_________________________________________________________________

Note that the flatten layer was moved to before the dense layer.

@patricksferraz I don't think DeepExplainer is supported in TF2

Same issue :/

Same issue, using shap 0.37 (installed with pip) and Tensorflow 2.1.0. I think this worked correctly when using shap 0.36 (installed with conda).

Confirmed, it works in 0.36.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nickkimer picture nickkimer  路  4Comments

franciscorodriguez92 picture franciscorodriguez92  路  4Comments

resdntalien picture resdntalien  路  3Comments

yolle103 picture yolle103  路  3Comments

artemmavrin picture artemmavrin  路  4Comments