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

关于注意力热力图可视化 #19

Open
yjdzyr opened this issue Jun 25, 2024 · 6 comments
Open

关于注意力热力图可视化 #19

yjdzyr opened this issue Jun 25, 2024 · 6 comments
Labels
question Further information is requested

Comments

@yjdzyr
Copy link

yjdzyr commented Jun 25, 2024

Bug

非常感谢作者提供这个优秀的项目,我想问一下代码应该如何可视化注意力的热力图,能否提供一个例子,以便了解图片中各个区域对模型作出预测的影响有多大。期待作者的回复!

Uploading 35bfb787d0c252b0831a92517d85091.png…

环境信息

No response

补充信息

No response

@yjdzyr yjdzyr added the bug Something isn't working label Jun 25, 2024
@xiuqhou
Copy link
Owner

xiuqhou commented Jun 25, 2024

原始的DETR论文《End-to-End Object Detection with Transformers》中Fig. 3给出了注意力图的可视化,其中每个query都会和特征图计算SelfAttention,得到一幅和特征图尺寸相同的attention map,因此可以给定query绘制attention map

但现在大部分DETR方法在编码器部分都采用的MultiScaleDeformableAttention,每个query只会和16个点计算注意力,所以不能产生完整的attention map

如果想了解图片每个区域对预测的贡献,可以尝试GradCAM等方法( https://github.com/jacobgil/pytorch-grad-cam?tab=readme-ov-file

@xiuqhou xiuqhou added question Further information is requested and removed bug Something isn't working labels Jun 27, 2024
@yjdzyr
Copy link
Author

yjdzyr commented Jun 27, 2024

非常感谢作者的回答,我查看了GradCAM方法,但在提供的例子里没有发现DETR相关的例子,寻找了相关教程但是还是难于复现backbone和encoder的可视化,恳请作者大大提供一些帮助,非常感谢

1 similar comment
@yjdzyr
Copy link
Author

yjdzyr commented Jun 27, 2024

非常感谢作者的回答,我查看了GradCAM方法,但在提供的例子里没有发现DETR相关的例子,寻找了相关教程但是还是难于复现backbone和encoder的可视化,恳请作者大大提供一些帮助,非常感谢

@xiuqhou
Copy link
Owner

xiuqhou commented Jun 28, 2024

好的,后续我会考虑尝试把GradCAM相关的可视化集成进来,不过最近比较忙,要等一段时间。

如果你有自己实现的想法或比较着急要用,可以参考下面别的项目是如何将GradCAM集成到他们的项目中的。
基本上流程是首先从各个框架中得到模型和test_pipeline,然后调用grad_cam提供的方法进行可视化,有一定挑战但应该不难。

xiuqhou added a commit that referenced this issue Jul 3, 2024
@xiuqhou
Copy link
Owner

xiuqhou commented Jul 3, 2024

我在代码中增加了关于GradCAM的实例代码(grad_cam/grad_cam.ipynb)和(#12)提到的可视化特征图的实例代码(grad_cam/feat_show.ipynb)。

这两个可视化只是基础的实例,您可以参考这两个实现进行更进一步的修改。

@yjdzyr
Copy link
Author

yjdzyr commented Jul 3, 2024

非常感谢作者提供的代码!这将对我提供非常大的帮助!期待作者后续更优秀的项目!

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

No branches or pull requests

2 participants