shap / shap

A game theoretic approach to explain the output of any machine learning model.
https://shap.readthedocs.io
MIT License
22.85k stars 3.29k forks source link

SHAP AttributeError: 'Tensor' object has no attribute 'copy' #2057

Open souzaoen opened 3 years ago

souzaoen commented 3 years ago

Good evening from Brazil.

My name is Raphael, I´m undergraduate student from PUC-Rio and I´m trying to use SHAPLEY on a academic work but I´m having a problem when i try to load a dataset from google drive (I am using google colab).

I am getting the following message:

shap.image_plot for an XAI problem but i´m getting the following problem: /usr/local/lib/python3.7/dist-packages/shap/maskers/_image.py in inpaint(self, x, mask, method) 100 reshaped_mask = mask.reshape(self.input_shape).astype(np.uint8).max(2) 101 if reshaped_mask.sum() == np.prod(self.input_shape[:-1]): --> 102 out = x.reshape(self.input_shape).copy() 103 out[:] = out.mean((0, 1)) 104 return out.flatten() AttributeError: 'Tensor' object has no attribute 'copy'

SHAP issue.txt

the problem is on a line close to the end of the code: shap_values = explainer(test_images[1:3], max_evals=500, batch_size=50, outputs=shap.Explanation.argsort.flip[:1] )

defoishugo commented 3 years ago

Hi,

Could you please share with us the dataset so we can reproduce the reported issue?

Regards,

Hugo

souzaoen commented 3 years ago

Sorry for the late answer!

The folder containing google drive files is the following.

https://drive.google.com/drive/folders/16mo7Tqnkb9RbBF8_XWJFlMWyeMWHPsRp?usp=sharing

Best regards!

Enviado do Email para Windows 10

De: Hugo DEFOIS Enviado:segunda-feira, 28 de junho de 2021 06:24 Para: slundberg/shap Cc:Raphael de Souza e Almeida; Author Assunto: Re: [slundberg/shap] SHAP AttributeError: 'Tensor' object has no attribute 'copy' (#2057)

Hi, Could you please share with us the dataset so we can reproduce the reported bug? Regards, Hugo — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.

defoishugo commented 3 years ago

The new information still cannot help to reproduce the reported bug, since we don't have the imports you did, or the Dataset class definition.

souzaoen commented 3 years ago

Sorry for the low data, I will send the link for the complete work.There you will find:

Link: https://drive.google.com/drive/folders/1vvoSQyIEgH84PYanvwy3dfmrZvvF9Qgu?usp=sharing

Folders: • Colab Notebooks: there is a file, “Trabalho INF2420.ipynb”, that is the colab that i was findin the error, but i made some changes and I think i might solve the issue, but i needed to change some code to do that. As I pretend to use SHAP on my Thesis (diferent work, but still using computer vision) could you please confirm that what I made was correct? • Data: holds the dataset used. The folder “Explainable” I used on SHAP, the folders “COVID” and “non-COVID” I used to train the Neural Network.

Once again thank you for your help! It is really important to me as I’m new on this area.

Best regards!

Raphael

Enviado do Email para Windows 10

De: Hugo DEFOIS Enviado:quinta-feira, 1 de julho de 2021 06:46 Para: slundberg/shap Cc:Raphael de Souza e Almeida; Author Assunto: Re: [slundberg/shap] SHAP AttributeError: 'Tensor' object has no attribute 'copy' (#2057)

The new information still cannot help to reproduce the reported bug, since we don't have the imports you did, or the Dataset class definition. — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or unsubscribe.