我的博客

attention 可视化

目录

matplotlib 图像叠加显示热力图

https://blog.csdn.net/nkhgl/article/details/103183978

1
2
plt.imshow(np.hstack(img[i].cpu().numpy().reshape(3,224*224, 1)).reshape(224,224,3))
plt.imshow(rescale(xx), alpha=0.4, cmap=plt.cm.hot, vmin=0, vmax=1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
i = 1
xx = []
for l in attentions[i][-49:].reshape(7,7):
x = []
for v in l:
x += [v] * 32
xx += [x] * 32
cimg = np.hstack(img[i].cpu().numpy().reshape(3,224*224, 1)).reshape(224,224,3)
plt.imshow(cimg)
heatmap = np.array(rescale(attentions[i][-49:].reshape(7,7)))
# heatmap = np.array(attentions[i][-49:].reshape(7,7))
heatmap = cv2.resize(100-heatmap, (224, 224))
# heatmap = np.uint8(255 * heatmap) # 将热力图转换为RGB格式
# heatmap = cv2.applyColorMap(heatmap, cv2.COLORMAP_JET) # 将热力图应用于原始图像
# plt.imshow(heatmap, alpha=0.4, vmin=0, vmax=1)
# plt.imshow(heatmap, alpha=0.4, cmap=plt.cm.hot, vmin=0, vmax=1)
# plt.imshow(heatmap, alpha=0.4, cmap='rainbow', vmin=0, vmax=1)
plt.imshow(heatmap, alpha=0.4, cmap=plt.cm.RdBu, vmin=0, vmax=100)

cnn 热力图

https://zhuanlan.zhihu.com/p/53683453

https://blog.csdn.net/Einstellung/article/details/82858974

https://www.jianshu.com/p/0431d6d89d8e

https://www.cnblogs.com/taotingz/p/11309333.html

评论无需登录,可以匿名,欢迎评论!