Shap DeepPlainer错误:' tuple'对象没有属性'设备'

发布于 2025-02-08 18:17:53 字数 1436 浏览 2 评论 0原文

我正在尝试为我的多元时间序列模型(pytorch)构建一个解释器,如下所示:

e = shap.DeepExplainer(
        model.to('cuda:1'), 
        torch.tensor(X_test_matrix,dtype=torch.float).to('cuda:1'))

x_test_matrix是3D矩阵,因为它是时间序列数据。 但是,我收到这样的错误:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-43-6aa8f8197e30> in <module>
      1 e = shap.DeepExplainer(
      2         model.to('cuda:1'),
----> 3         torch.tensor(X_test_matrix,dtype=torch.float).to('cuda:1'))

~/env/lib64/python3.6/site-packages/shap/explainers/_deep/__init__.py in __init__(self, model, data, session, learning_phase_flags)
     84             self.explainer = TFDeep(model, data, session, learning_phase_flags)
     85         elif framework == 'pytorch':
---> 86             self.explainer = PyTorchDeep(model, data)
     87 
     88         self.expected_value = self.explainer.expected_value

~/env/lib64/python3.6/site-packages/shap/explainers/_deep/deep_pytorch.py in __init__(self, model, data)
     55 
     56             # also get the device everything is running on
---> 57             self.device = outputs.device
     58             if outputs.shape[1] > 1:
     59                 self.multi_output = True

AttributeError: 'tuple' object has no attribute 'device'

如何解决此问题?

I am trying to to build an explainer for my multivariate time-series model (PyTorch) with SHAP as the following:

e = shap.DeepExplainer(
        model.to('cuda:1'), 
        torch.tensor(X_test_matrix,dtype=torch.float).to('cuda:1'))

Where X_test_matrix is a 3D matrix, since it is time-series data.
However, I receive an error like this:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-43-6aa8f8197e30> in <module>
      1 e = shap.DeepExplainer(
      2         model.to('cuda:1'),
----> 3         torch.tensor(X_test_matrix,dtype=torch.float).to('cuda:1'))

~/env/lib64/python3.6/site-packages/shap/explainers/_deep/__init__.py in __init__(self, model, data, session, learning_phase_flags)
     84             self.explainer = TFDeep(model, data, session, learning_phase_flags)
     85         elif framework == 'pytorch':
---> 86             self.explainer = PyTorchDeep(model, data)
     87 
     88         self.expected_value = self.explainer.expected_value

~/env/lib64/python3.6/site-packages/shap/explainers/_deep/deep_pytorch.py in __init__(self, model, data)
     55 
     56             # also get the device everything is running on
---> 57             self.device = outputs.device
     58             if outputs.shape[1] > 1:
     59                 self.multi_output = True

AttributeError: 'tuple' object has no attribute 'device'

How can I fix this issue?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

望笑 2025-02-15 18:17:54

我相信问题是由于CUDA指数。

这是否为您修复?

e = shap.DeepExplainer(
        model.to(torch.device('cuda')), torch.tensor(X_test_matrix, dtype=torch.float, device=torch.device('cuda'))

I believe the issue is due to the CUDA index.

Does this fix it for you?

e = shap.DeepExplainer(
        model.to(torch.device('cuda')), torch.tensor(X_test_matrix, dtype=torch.float, device=torch.device('cuda'))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文