I am using SHAP method to explain the classification results of VGG16 model for three classes. I am using GPU. My code is as follows
code for VGG16 model is:
class CNNModel(nn.Module):
def init(self):
super(CNNModel, self).init()
self.vgg16 = models.vgg16(pretrained=True)
in_feats = self.vgg16.classifier[6].in_features
self.vgg16.classifier[6] = nn.Linear(in_feats, 3)
def forward(self, x):
x = self.vgg16(x)
return x
code for SHAP method is:
batch = next(iter(test_loader))
images, _ = batch
background = images[:10].to(device)
test_images = images[1:6].to(device)
e = shap.DeepExplainer(model, background)
shap_values, indexes = e.shap_values(test_images, ranked_outputs=3)
I am getting following runtime error
RuntimeError: Output 0 of BackwardHookFunctionBackward is a view and is being modified inplace. This view was created inside a custom Function (or because an input was returned as-is) and the autograd logic to handle view+inplace would override the custom backward associated with the custom Function, leading to incorrect gradients. This behavior is forbidden. You can fix this by cloning the output of the custom Function.
Previously this code was working but now it does not work. Can anyone please help me to solve this error