SHAP: Сессия Tensorflow 2 пуста
Я довольно новичок в питоне соотв. тензор поток 2.0 с керасом.
У меня есть обученная модель, и я хочу теперь интерпретировать ее с помощью SHAP. Но использование DeepExplainer не работает. Я получаю следующую ошибку
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-19-38e59444e33c> in <module>
2
3 data = x_train[:200]
----> 4 explainer = shap.DeepExplainer(model, data)
5
~/python/lib/python3.7/site-packages/shap/explainers/deep/__init__.py in __init__(self, model, data, session, learning_phase_flags)
78
79 if framework == 'tensorflow':
---> 80 self.explainer = TFDeepExplainer(model, data, session, learning_phase_flags)
81 elif framework == 'pytorch':
82 self.explainer = PyTorchDeepExplainer(model, data)
~/python/lib/python3.7/site-packages/shap/explainers/deep/deep_tf.py in __init__(self, model, data, session, learning_phase_flags)
139 if self.data[0].shape[0] > 5000:
140 warnings.warn("You have provided over 5k background samples! For better performance consider using smaller random sample.")
--> 141 self.expected_value = self.run(self.model_output, self.model_inputs, self.data).mean(0)
142
143 # find all the operations in the graph between our inputs and outputs
~/python/lib/python3.7/site-packages/shap/explainers/deep/deep_tf.py in run(self, out, model_inputs, X)
282 for t in self.learning_phase_flags:
283 feed_dict[t] = False
--> 284 return self.session.run(out, feed_dict)
285
286 def custom_grad(self, op, *grads):
~/python/lib/python3.7/site-packages/tensorflow/python/client/session.py in run(self, fetches, feed_dict, options, run_metadata)
948 try:
949 result = self._run(None, fetches, feed_dict, options_ptr,
--> 950 run_metadata_ptr)
951 if run_metadata:
952 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
~/python/lib/python3.7/site-packages/tensorflow/python/client/session.py in _run(self, handle, fetches, feed_dict, options, run_metadata)
1096 raise RuntimeError('Attempted to use a closed Session.')
1097 if self.graph.version == 0:
-> 1098 raise RuntimeError('The Session graph is empty. Add operations to the '
1099 'graph before calling run().')
1100
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().
Вот как выглядит моя модель:
model = keras.models.Sequential()
# Input size of VOCABULAR_SIZE with 50-neuron-layer
model.add(keras.layers.Dense(50, input_shape=(VOCABULAR_SIZE,), activation='relu'))
# Hidden layer
model.add(keras.layers.Dense(25, activation='relu'))
# Hidden layer in size of tags
# Sigmoid returns each output between 0 and 1
model.add(keras.layers.Dense(tags_count, activation='sigmoid'))
model.summary()
Я что-то пропустил? Не могли бы вы, ребята, помочь мне?