albermax / innvestigate

A toolbox to iNNvestigate neural networks' predictions!
Other
1.24k stars 235 forks source link

When create_analyzer_model() get You must feed a value for placeholder tensor 'xxx' with dtype float and shape [?,1] #294

Closed hwjworld closed 1 year ago

hwjworld commented 1 year ago

Hi, I'm trying to use innvestigate deep_taylor method to explain an model which trained on tabular data, that the tabular data has 41 feature columns and 1 binary class column. but keeps getting error below.

Traceback (most recent call last): File "/var/tmp/code/innvestigate_tabular_test/tt3.py", line 227, in <module> print(analyzer.analyze(e[0])) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/innvestigate/analyzer/network_base.py", line 250, in analyze self.create_analyzer_model() File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/innvestigate/analyzer/network_base.py", line 158, in create_analyzer_model model, analysis_inputs, stop_analysis_at_tensors = self._prepare_model( File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/innvestigate/analyzer/deeptaylor.py", line 148, in _prepare_model model_with_positive_output = kmodels.Model( File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/tensorflow/python/trackable/base.py", line 205, in _method_wrapper result = method(self, *args, **kwargs) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/keras/engine/functional.py", line 165, in __init__ self._init_graph_network(inputs, outputs) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/tensorflow/python/trackable/base.py", line 205, in _method_wrapper result = method(self, *args, **kwargs) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/keras/engine/functional.py", line 205, in _init_graph_network base_layer_utils.create_keras_history(self._nested_outputs) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/keras/engine/base_layer_utils.py", line 207, in create_keras_history _, created_layers = _create_keras_history_helper(tensors, set(), []) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/keras/engine/base_layer_utils.py", line 291, in _create_keras_history_helper constants[i] = backend.function([], op_input)([]) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/keras/backend.py", line 4577, in __call__ fetched = self._callable_fn(*array_vals, run_metadata=self.run_metadata) File "/var/tmp/code/innvestigate/venv/lib/python3.9/site-packages/tensorflow/python/client/session.py", line 1481, in __call__ ret = tf_session.TF_SessionRunCallable(self._session._session, tensorflow.python.framework.errors_impl.InvalidArgumentError: You must feed a value for placeholder tensor 'c11' with dtype float and shape [?,1] [[{{node c11}}]]

tensor 'c11' is vary, sometime 'c0', 'c6' etc...any column possible here.

The model: ` model = tf.keras.Sequential([ feature_layer, Dense(41, activation='relu'), Dense(41, activation='relu'), Dropout(.1), Dense(1) ]) model.compile(optimizer='adam', loss=tf.keras.losses.BinaryCrossentropy(from_logits=True), metrics=['accuracy'])

model.fit(train_ds, validation_data=val_ds, epochs=10) `

Then analyze it: tf.compat.v1.disable_eager_execution() analyzer = innvestigate.create_analyzer("deep_taylor", model) analyzer.analyze(single_e)

The model inputs:

Pasted Graphic 12

The single_e feed to analyzer.analyze():

(Dimensk

The error stack is in analyzer.analyze(instance_to_test) -> self.create_analyzer_model() ->self._prepare_model( self._model )

Environment: Python: 3.9 Tensorflow: 2.10.0 Keras: 2.10.0

Many thanks for reading question and help!

hwjworld commented 1 year ago

shape adjusted..