I used shap to interpret my cnn model like this:
explainer = shap.DeepExplainer(model=model, data = X_train[0:10])
shap_values = explainer.shap_values(X_test[0:10])
When shap tries to get the output shape in its internal function, you get this error
AttributeError
Traceback (most recent call last)
<ipython-input-9-5d9f53dcf3ce> in <cell line: 1>()
----> 1 explainer = shap.DeepExplainer(model=model, data = X_train[0:10])
2 shap_values = explainer.shap_values(X_test[0:10])
1 frames
/usr/local/lib/python3.10/dist-packages/shap/explainers/_deep/deep_tf.
py in __init__(self, model, data,
session, learning_phase_flags)
170 self.phi_symbolics = [None]
171 else:
--> 172 noutputs = self.model_output.shape.as_list()[1]
173 if noutputs is not None:
174 self.phi_symbolics = [None for i in range(noutputs)]
AttributeError: 'tuple' object has no attribute 'as_list'
I guess it’s because of the tensorflow version, how can I fix this error?
my package versions:
tensorflow==2.16.1
shap==0.45.1
I tried to load my trained model (model.keras) with tensorflow==2.15.0 version to solve this problem, but I got an error.
New contributor
Amirhossein is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.