I've been trying to replicate this code and I have been stuck on this particular issue. When I try to run shap.GradientExplainer() for the 7th layer, I keep getting the same error:
1 def map2layer(x, layer):
----> 2 feed_dict = dict(zip([model.layers[7].input], [preprocess_input(x.copy())]))
3 print(feed_dict.keys().type)
4 return K.get_session().run(model.layers[layer].input, feed_dict)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/keras_tensor.py in __hash__(self)
259 def __hash__(self):
260 raise TypeError('Tensors are unhashable. (%s)'
--> 261 'Instead, use tensor.ref() as the key.' % self)
262
263 # Note: This enables the KerasTensor's overloaded "right" binary
TypeError: Tensors are unhashable. (KerasTensor(type_spec=TensorSpec(shape=(None, 56, 56, 128), dtype=tf.float32, name=None), name='block2_pool/MaxPool:0', description="created by layer 'block2_pool'"))Instead, use tensor.ref() as the key.
I have tried downgrading my tensorflow version to below 2.0 but it still hasn't worked. Would love to hear a fix for this.