Git Product home page Git Product logo

Comments (4)

CloseChoice avatar CloseChoice commented on June 8, 2024 3

Puuhh, this seems pretty tough to fix. I tried to set every ReLU activation to inplace=False but that still fails at the line

out += identity

of the resnet module with the same error. Strangely this works if I replace it with

out = out + identity

but then the shapes mismatch.

from shap.

CloseChoice avatar CloseChoice commented on June 8, 2024

Thanks for the reproducible example. I can confirm this on master.

I will have a look at this in the upcoming weeks.

from shap.

samiraat avatar samiraat commented on June 8, 2024

I am attempting to apply DeepExplainer for resnet50 and densenet121 and I am getting BackwardHookFunctionBackward error msg. I tried to modify the ReLU activation to disable the inplace operation by setting it to False. I am using the following approach to update the inplace:

class ModifiedDenseNet121(nn.Module):
    def __init__(self, pretrained=True, input_channels=3, num_classes=1000):
        super(ModifiedDenseNet121, self).__init__()
        self.densenet = models.densenet121(weights=DenseNet121_Weights.DEFAULT if pretrained else None)
        if input_channels != 3:
            self.densenet.features[0] = nn.Conv2d(input_channels, 64, kernel_size=7, stride=2, padding=3, bias=False)
        self.densenet.classifier = nn.Linear(self.densenet.classifier.in_features, num_classes)
        # Fix the usage of ReLU activation with inplace=True
        for module in self.densenet.modules():
            if isinstance(module, nn.ReLU):
                module.inplace = False
    def forward(self, x):
        return self.densenet(x)

However, I'm still encountering a runtime error: RuntimeError: Output 0 of BackwardHookFunctionBackward is a view and is being modified inplace. Any guidance or updates on how to resolve this error would be greatly appreciated. Thank you!

from shap.

CloseChoice avatar CloseChoice commented on June 8, 2024

If you really need this maybe have a look at captum. Would be great if you could report back your findings, so that we can borrow a couple of ideas from them

from shap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.