Skip to content
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

Input with unknown shape in Multiple-inputs models #45

Open
ghost opened this issue Aug 22, 2019 · 3 comments
Open

Input with unknown shape in Multiple-inputs models #45

ghost opened this issue Aug 22, 2019 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 22, 2019

Hi,
I was trying to use DeepExplain on a tensorflow model which has two inputs:

  • One is the input to the network with shape (?, 5000)
  • The other is the batch_size with an unknown shape

So when I am trying to use explain method:

from deepexplain.tensorflow import DeepExplain

sess = Model.sess

X = Model.x

B = Model.batch_size

T = Model.z

index = 0

with DeepExplain(session = sess) as de:

    attributions = []

    output_size = T.shape[-1]

    mask = np.zeros((1, output_size))

    mask[0][index] = 1

    att = de.explain("deeplift", T * mask, [X, B], [data, 256])

I get the following error:

c:\users\matin\src\deepexplain\deepexplain\tensorflow\methods.py in _set_check_baseline(self)
178 if self.baseline is None:
179 if self.has_multiple_inputs:
--> 180 self.baseline = [np.zeros([1,] + xi.get_shape().as_list()[1:]) for xi in self.X]
181 else:
182 self.baseline = np.zeros([1,] + self.X.get_shape().as_list()[1:])

"as_list() is not defined on an unknown TensorShape."

Is there a way to get around it?

@marcoancona
Copy link
Owner

The assumption is that all inputs have batch_size as the first dimension of the input tensor. This is what Keras does. As you have a pure TF model, it might be possible to fix DeepExplain to handle this case but it might be easier to define the size of your second input (which is always [1] as far as I understood)

@marcoancona
Copy link
Owner

Looking closer, the current DeepExplain requires each input to be at least two-dimensional. A workaround could be to define your second input as having shape [[1]]

@mbuet2ner
Copy link

On a similar note, I would like to use the occlusion techniques on a network where
model.input shape is (?, 3, 224, 224),
model.output shape is (?, 1000).

This of course works without any problems for the non-occlusion methods.

  • For both I tried to reshape the tensor via tf.reshape() to (1, 3, 224, 224) and (1, 1000) respectively. However, this deletes the metadata of the keras model 👎 .
  • Just copying the name to the new one was also successful unfortunately. I got the following error:
    ValueError: 'model_1/output_0/BiasAdd:0' is not a valid scope name.

Since I can not add a keras reshape layer once the model is trained, I am not really sure how to proceed. Maybe there is an easy fix for that?

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants