Open cdeterman opened 2 years ago
Hey @cdeterman, Thanks for opening the issue. I think the above error relates to this.:
To summarize, eager mode needs to be disabled to run CF/CEM algorithms because we use TF1.x constructs in the code.
Although I think the above should be fixed by disabling eager execution as you do? Perhaps also try:
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
I've tried/guessed at recreating your error with the same lib versions:
from sklearn.model_selection import train_test_split
from sklearn import datasets
import xgboost as xgb
iris = datasets.load_iris()
X = iris.data
y = iris.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
dtrain = xgb.DMatrix(X_train, label=y_train)
dtest = xgb.DMatrix(X_test, label=y_test)
param = {'max_depth': 3, 'eta': 0.3, 'silent': 1, 'objective': 'multi:softprob', 'num_class': 3}
num_round = 20
bst = xgb.train(param, dtrain, num_round)
# import tensorflow as tf
# tf.compat.v1.disable_eager_execution()
from alibi.explainers import CounterfactualProto
def predict_fn(x):
return bst.inplace_predict(x)
shape = (1,) + X_train.shape[1:]
proto_explainer = CounterfactualProto(predict_fn, shape, use_kdtree=True, theta=10., feature_range=(-.5, .5))
The above reproduces the issue and uncommenting the disable_eager_execution
solves it for me:
import tensorflow as tf
tf.compat.v1.disable_eager_execution()
Can you give more information about your model and/or a minimal working example?
I have an xgboost model I am trying to run couterfactuals on using the CounterfactualProto explainer. Given the RuntimeError I see below, I tired to disable the eager execution using the method found here but the problem did not go away. Is this something that has been encountered before? Please let me know if more information is required?
Packages: alibi - 0.6.4 tensorflow - 2.7.1 xgboost - 1.2.1