Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using grad-cam in ONNX for deployment. #543

Open
GKG1312 opened this issue Nov 27, 2024 · 0 comments
Open

Using grad-cam in ONNX for deployment. #543

GKG1312 opened this issue Nov 27, 2024 · 0 comments

Comments

@GKG1312
Copy link

GKG1312 commented Nov 27, 2024

Hi @jacobgil ,
This can sound dumb, but I want grad-cam as a feature in my deployment service. All the model I am using there are in ONNX format. I tried direct conversion of gradcam to onnx, but failed as it uses back tracing of gradients. I wanted to ask if there is a way to use gradcam in onnx formatted model or if is there any way to use gradcam in deployment to edge devices?

Also if I am defining my model as given below:

class MultiTaskEfficientNet(nn.Module):
    def __init__(self, num_ftrs, model):
        super(MultiTaskEfficientNet, self).__init__()
        self.backbone = nn.Sequential(*list(model.children())[:-1])

        # Define a dropout layer with the specified dropout rate
        self.dropout = nn.Dropout(p=0.4)

        self.classifier_1 = nn.Linear(num_ftrs, 1)
        self.classifier_2 = nn.Linear(num_ftrs, 1)
        self.classifier_3 = nn.Linear(num_ftrs, 1)
        self.classifier_4 = nn.Linear(num_ftrs, 1)

    def forward(self, x):
        feature_map = self.backbone(x)
        x = torch.flatten(feature_map, 1)

        # Apply dropout after flattening the feature map
        x = self.dropout(x)

        class1 = torch.sigmoid(self.classifier_1(x))
        class2 = torch.sigmoid(self.classifier_2(x))
        class3 = torch.sigmoid(self.classifier_3(x))
        class4 = torch.sigmoid(self.classifier_4(x))
        return {
            'class1': class1,
            'class2': class2,
            'class3': class3,
            'class4': class4
        }

How can I generate GradCAM images for each class. I am trying the general method but encountering error while passing predicted output as target output in gradcam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant