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

GradCAM for Dual Attention ViT #474

Open
tayyabapucit opened this issue Dec 26, 2023 · 1 comment
Open

GradCAM for Dual Attention ViT #474

tayyabapucit opened this issue Dec 26, 2023 · 1 comment

Comments

@tayyabapucit
Copy link

How can I use Grad CAM for Dual Attention ViT Transformer (davit_tiny.msft_in1k).
I tried to use reshape transform with height,width 7,7 and 14,14
I need to figure out which layer to use or how to reshape the output.

I've successfully used GradCAM, EigenCAM, and ScoreCAM with ResNet, DenseNets, VGG, ViT, and SwinVit. Results are amazing for all these models.

Any Help?

@tayyabapucit
Copy link
Author

Ok, I've figured it out.
It worked with
target_layers = [list(model.backbone.modules())[-13]]

and

def reshape_transform2(tensor, height=7, width=7):

result = tensor.reshape(tensor.size(0),
    height, width, tensor.size(2))

# ??Bring the channels to the first dimension,
# like in CNNs.
result = result.transpose(2, 3).transpose(1, 2)

return result

Am I doint it right.?

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