## 4 Proposed Method
### Modified Hourglass Network
#### 4.1.2 Spatial and Channel Attention Modules  
Spatial and channel attention modules are added at each hourglass stage to enhance the feature maps extracted from the network. Since our main focus is to obtain accurate output predictions for the text classes, we add the attention modules to the hourglass network so that they contribute to the best AP (average precision) for the text object classes. We found that the best position to place the attention modules is at the end of the encoder stage before the bottleneck layer for the channel attention, and at the end of the decoder stage at the final feature maps before the output prediction heads for the spatial attention. The intermediate feature map \(F\) of dimension \(C\times H\times W\) is passed through a 2D spatial attention weights \(M\)s and channel attention weights \(M\)c of dimension \(1\times H\times W\) and \(C\times 1\times 1\), respectively. Here, the attention maps/weights are element-wise multiplied with the original feature map \(F\) to obtain the refined feature map \(F^{\prime}\) and \(F^{\prime\prime}\) as shown in Equation (3). \[ \begin{split}\text{F}^{\prime}&=\text{M}_{\text{s}}( \text{F})\otimes\text{F}\\ \text{F}^{\prime\prime}&=\text{M}_{\text{c}}(\text{F })\otimes\text{F}\end{split}  \tag{3}\]  
The process of obtaining spatially refined features using the spatial attention module is illustrated above in Figure 12. \(\text{F}^{\text{s}}_{\text{avg}}\) and \(\text{F}^{\text{s}}_{\text{max}}\), the global average pooling and global max pooling operations across the channel axis, are used to reduce the feature dimensions from \(C\times H\times W\) to \(1\times H\times W\) for spatial attention. Avg-Pooling is a mechanism that optimizes a feature map's spatial size while also providing the network with translation invariance. However, in the attention modules, it is performed over the channel axis by selecting the average pixel value out of all the channels from the feature to reduce the dimension of the feature to a single dimension. Similarly, Max-Pooling is performed over the channel axis by selecting the maximum pixel value out of all the channels. Equation (4) illustrates how these 2D vectors are concatenated, sent to a (3 \(\times\) 3) convolution filter, and then used  
Figure 11: Depthwise separable convolution. in sigmoid activation to learn the inter-spatial relationship and create the spatial attention map \(M\)s of dimension, \(1\times H\times W\). \[ \begin{split}\text{M}_{\text{s}}(\text{F})&=\sigma \big{(}f^{3\times 3}([\text{AvgPool}(\text{F});\text{MaxPool}(\text{F})])\big{)}\\ &=\sigma\big{(}f^{3\times 3}\Big{(}[\text{F}_{\text{avg}}^{ \text{s}};\text{F}_{\text{max}}]\Big{)}\Big{)}\end{split}  \tag{4}\]  
where \(\sigma\) denotes the sigmoid function, \(f^{3\times 3}\) is the convolution filter size, \(\text{AvgPool}(\text{F})\) is the average pooling function, and \(\text{MaxPool}(\text{F})\) is the maximum pooling function. We use the number of filters as 16, 32, and 64 during convolution. Following sigmoid activation, these attention maps, which are effectively weighted spatial maps with values ranging from 0 to 1, are multiplied by the original feature map according to Equation (3) to produce the refined spatial attentive feature map. Figure 13 above shows how to use the channel attention module to obtain channel-wise refined features. Rather than using the traditional way to select the kernel for channel weight determination in the channel attention module, we employ the Efficient Channel Attention Network (ECANET) [47]. The authors claim that it is an enhancement over Squeeze-and-Excitation Attention (SENET) [54], where dimensionality reduction and dependent cross-channel interaction are resolved. The channel weights are learned by the SENET in relation to other channels, not in an independent manner. This is resolved by the ECANET by cross-channel interaction with regard to all other channels in this neighborhood and adaptive local neighborhood size 8.