-
Notifications
You must be signed in to change notification settings - Fork 252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RuntimeError: The Session graph is empty. Add operations to the graph before calling run() #959
Comments
Hi @fraseralex96, Try to add the following lines as in the example from here: import tensorflow as tf
tf.get_logger().setLevel(40) # suppress deprecation messages
tf.compat.v1.disable_v2_behavior() # disable TF2 behaviour as alibi code still relies on TF1 constructs |
Hi Robert, Thank you for your response. Unfortunately I now receive the following error message when I build my NN model because of the above code:
|
Try to use tensorflow v2.10: pip install --upgrade tensorflow==2.10 |
Hi Robert, I get the following error message now when I try to run CEM (and also when I individually run the model I am trying to explain): `2023-08-03 11:04:01.763603: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:354] MLIR V1 optimization pass is not enabledValueError Traceback (most recent call last) File ~/.local/lib/python3.9/site-packages/alibi/explainers/cem.py:235, in CEM.init(self, predict, mode, shape, kappa, beta, feature_range, gamma, ae_model, learning_rate_init, max_iterations, c_init, c_steps, eps, clip, update_num_grad, no_info_val, write_dir, sess) File ~/.local/lib/python3.9/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs) File ~/.local/lib/python3.9/site-packages/keras/engine/input_spec.py:250, in assert_input_compatibility(input_spec, inputs, layer_name) ValueError: Input 0 of layer "conv1d_18" is incompatible with the layer: expected min_ndim=3, found ndim=2. Full shape received: (Dimension(10427), Dimension(1378))` I tested it and it is directly because of this code:
Do you have any suggestion? Thanks! |
My guess is that you input shape to the x_input = layers.Input(shape=(X_train.shape[1],1)) I think the correct initialisation is: x_input = layers.Input(shape=X_train.shape[1:]) You should be able to test if everything is ok by performing a forward pass through your model: model(X_train[:1]) See the documentation here. Also, since you are using conv1d, your training data must have the following shape (B, L, D), where B is the batch size, L is the sequence length, and D is the channels size. |
Hi Team,
I get the following error when trying to initialise the CEM explainer:
`---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
Input In [52], in <cell line: 4>()
2 shape = (1,) + X_train.shape[1:]
3 mode = 'PN'
----> 4 cem = CEM(model, mode, shape, kappa=0., beta=.1,
5 feature_range=(X_train.min(), X_train.max()),
6 gamma=100, max_iterations=1000,
7 c_init=1., c_steps=10, learning_rate_init=1e-2,
8 clip=(-1000.,1000.), no_info_val=-1.)
File ~/.local/lib/python3.9/site-packages/alibi/explainers/cem.py:107, in CEM.init(self, predict, mode, shape, kappa, beta, feature_range, gamma, ae_model, learning_rate_init, max_iterations, c_init, c_steps, eps, clip, update_num_grad, no_info_val, write_dir, sess)
105 if is_model: # Keras or TF model
106 self.model = True
--> 107 classes = self.sess.run(self.predict(tf.convert_to_tensor(np.zeros(shape), dtype=tf.float32))).shape[1]
108 else:
109 self.model = False
File ~/.local/lib/python3.9/site-packages/tensorflow/python/client/session.py:969, in BaseSession.run(self, fetches, feed_dict, options, run_metadata)
966 run_metadata_ptr = tf_session.TF_NewBuffer() if run_metadata else None
968 try:
--> 969 result = self._run(None, fetches, feed_dict, options_ptr,
970 run_metadata_ptr)
971 if run_metadata:
972 proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)
File ~/.local/lib/python3.9/site-packages/tensorflow/python/client/session.py:1119, in BaseSession._run(self, handle, fetches, feed_dict, options, run_metadata)
1117 raise RuntimeError('Attempted to use a closed Session.')
1118 if self.graph.version == 0:
-> 1119 raise RuntimeError('The Session graph is empty. Add operations to the '
1120 'graph before calling run().')
1122 # Create request.
1123 feed_dict_tensor = {}
RuntimeError: The Session graph is empty. Add operations to the graph before calling run().`
My model architecture is as follow:
`## CNN using functional API
def DeepIC50_tester(X_train, learning_rate, momentum, seed):
I run this code when initialising:
`# initialize CEM explainer
shape = (1,) + X_train.shape[1:]
mode = 'PN'
cem = CEM(model, mode, shape, kappa=0., beta=.1,
feature_range=(X_train.min(), X_train.max()),
gamma=100, max_iterations=1000,
c_init=1., c_steps=10, learning_rate_init=1e-2,
clip=(-1000.,1000.), no_info_val=-1.)`
Please assist! It would be much appreciated!
Alex
The text was updated successfully, but these errors were encountered: