1
$\begingroup$

I read some attention mechanism papers, but I could not understand how it can be applied to an image (classification, detection, etc) using a CNN model. How does it affect the alignment scores and the weights? I would like to understand the application of that mechanism on images.

$\endgroup$

2 Answers 2

1
$\begingroup$

I would suggest you refer to the paper by Hu et al, Show, Attend and Tell: Neural Image Caption Generation with Visual Attention.

enter image description here The brief idea is that the network learns the 'areas' to focus on that are on the feature maps (the last layer of the feature detectors) which can be in return mapped back to a certain location on the image.

It is not a complex topic but requires some knowledge in RNNs and LSTMs as well that help with sequential data. Best of luck.

$\endgroup$
4
  • $\begingroup$ From the feature map, how the attention decide which points/feature to take into account? $\endgroup$
    – nour
    Commented Feb 7, 2021 at 21:35
  • $\begingroup$ How the attention decide which feature is relevant or no? $\endgroup$
    – nour
    Commented Feb 9, 2021 at 15:19
  • $\begingroup$ It mainly focus on higher weighed region. And it term of higher means higher probability. I refer you to watch this (youtube.com/watch?v=Tm5B3jdJO5Q) . $\endgroup$
    – AIFahim
    Commented Feb 16, 2021 at 5:36
  • $\begingroup$ This seems like a precursor to ViTs. You could replace step 3 with a Transformer as well. $\endgroup$ Commented Nov 5, 2021 at 17:15
1
$\begingroup$

Attention mechanisms in the context of image processing using Convolutional Neural Networks (CNNs) are used to allow the model to focus on specific parts of the image that are more relevant for the task at hand. This is like how we humans pay attention to certain parts of an image or scene while ignoring others.

In a typical CNN, all parts of the image contribute equally to the final decision. However, with an attention mechanism, the model learns to assign different weights to different parts of the image. These weights can be thought of as the importance of that part of the image for the final decision.

The attention mechanism works by computing a score (alignment score) for each part of the image. These scores are then normalized using a softmax function to produce the attention weights. The final output of the model is then a weighted sum of the feature maps, where the weights are the attention weights.

You can use the attention mechanism in different ways. For example, in image classification, the attention mechanism can be used to focus on the parts of the image that contain the object of interest. In object detection, the attention mechanism can be used to focus on the parts of the image where the objects are located.

The attention mechanism can improve the performance of the model by allowing it to focus on the most relevant parts of the image. It can also provide insights into what parts of the image the model is focusing on, which can be useful for understanding and interpreting the model's decisions.

If you would like to go in detail, then you can go through this article: https://www.analyticsvidhya.com/blog/2019/11/comprehensive-guide-attention-mechanism-deep-learning/

This article can also educate you with the transformers model and how the transformers model used attention mechanism in textual data.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.