marcoancona / DeepExplain

A unified framework of perturbation and gradient-based attribution methods for Deep Neural Networks interpretability. DeepExplain also includes support for Shapley Values sampling. (ICLR 2018)
https://arxiv.org/abs/1711.06104
MIT License
729 stars 133 forks source link

Error if dimensions other than first are None for the input vector #36

Closed linchundan88 closed 5 years ago

linchundan88 commented 5 years ago

if some dimensions of input are not specified, for example (None, None, None, 3)

Method elrp works fine, but deeplift raises an error. (Both traditional API and Explainer API.) TypeError: 'NoneType' object cannot be interpreted as an integer.

In v0.1, it seems to work OK.

linchundan88 commented 5 years ago
input_tensor = model.layers[0].input
fModel = Model(inputs=input_tensor, outputs=model.layers[-1].output)
target_tensor = fModel(input_tensor)

In this case, input_tensor will be none.

linchundan88 commented 5 years ago

Another problem, if I load a model from file, I must predict one time before generating saliency maps ,otherwise it will raise an exception: "tensorflow.python.framework.errors_impl.InternalError: Blas SGEMM launch failed : m=21609, n=128, k=64

But if I use this model to predict one time, after that DeepExplain run well.

marcoancona commented 5 years ago

About the first issue, do you know the shape of the input? In this case, you can define the input shape in the model. DeepLIFT needs to run the model on a baseline first, so the dimensions need to be known (or you can pass the baseline= parameter explicitly)

linchundan88 commented 5 years ago

I can change the input shape in the model, but I have a lot of models, it will take a long time. I want to know how to pass the baseline= parameter explicitly. Can you give me an example? I use Keras most of the time. Thanks in advance.

linchundan88 commented 5 years ago

baseline must be a numpy array with the size of the input. I found it.

such as : baseline1 = np.zeros((image_size, image_size, 3)) explainer = de.get_explainer('deeplift', target_tensor, input_tensor, baseline=baseline1)