Skip to main content
. 2023 Oct 10;13(20):3165. doi: 10.3390/diagnostics13203165
Algorithm 2: FeaturesEnhancement(FeatureMaps): Enhances the features of the given feature maps using a self-attention mechanism
Input FeatureMaps: The feature maps are extracted from an AlexNet CNN model.
Output: Enhance the features of the given feature maps using a self-attention mechanism.
Step 1 Extract feature maps using the CNN model: FeatureMaps = Extract-Maps().
Step 2 Compute spatial attention: ComputeSpatialAttention(FeatureMaps): begin.
Repeat for position in FeatureMaps:
 AttentionScores = SpatialAttentionScores(position)
 WeightedSumFeatures = WeightedSumFeatures(FeatureMaps, AttentionScores, position)
[End for Loop]
SpatialAttentionMaps SpatialAttention(FeatureMaps)
End function
Step 3 Compute channel attention: ChannelAttention(FeatureMaps): begin.
Repeat for channel in FeatureMaps:
 AttentionScores = ChannelAttentionScores(channel)
 WeightedChannelFeatures = WeightedChannelFeatures(FeatureMaps, AttentionScores, channel)
 ChannelAttentionFeatureMaps = ChannelAttention(FeatureMaps)
[End for loop]
[end function]
Step 4 CombineAttention(SpatialAttentionFeatureMaps, ChannelAttentionFeatureMaps)
Step 5 EnhancedFeatureMaps = ElementWiseMultiply(SpatialAttentionFeatureMap, ChannelAttentionFeatureMap)
Step 6 EnhancedFeatureMaps = Combine (SpatialAttentionFeatureMaps, ChannelAttentionFeatureMaps)
[End of Algorithm]