我正在使用 Swin Transformer 解决多类多标签分类的分层问题。我想在我的输入图像上可视化自我注意图,试图从模型中提取它们,不幸的是我没有成功完成这项任务。你能给我一个提示吗?我与您分享我尝试执行此任务的代码部分。
attention_maps = []
for module in model.modules():
#print(module)
if hasattr(module,'attention_patches'): #controlla se la variabile ha l' attributo
print(module.attention_patches.shape)
if module.attention_patches.numel() == 224*224:
attention_maps.append(module.attention_patches)
for attention_map in attention_maps:
attention_map = attention_map.reshape(224, 224, 1)
plt.imshow(sample['image'].permute(1, 2, 0), interpolation='nearest')
plt.imshow(attention_map, alpha=0.7, cmap=plt.cm.Greys)
plt.show()
``
In addition if you know about some explainability techniques, like Grad-CAM, which could be used with a hierarchical Swin Transformer, feel free to attach a link, it would be very helpful for me.