Shap DeepPlainer错误:' tuple'对象没有属性'设备'
我正在尝试为我的多元时间序列模型(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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信问题是由于CUDA指数。
这是否为您修复?
I believe the issue is due to the CUDA index.
Does this fix it for you?