# Pavement Disease Visual Detection by Structure Perception and Feature Attention Network
## 3 Structure Perception and Feature Attention Network
### Feature Attention Network  
In order to improve the accuracy and robustness of pavement disease detection, this paper instantiates the feature attention module by CBAM [37], which can partly overcome the limitations of traditional CNN in dealing with objects with different scales, shapes, and orientations, and enable the model to focus on the crucial features of pavement diseases by simultaneously enhancing the channel and spatial attentions of the feature maps without significantly increasing the computational complexity, thus improving the overall performance of the model. As shown in Figure 5, CBAM consists of two key modules, namely, channel attention module and spatial attention module. The channel attention module aims to enhance the feature representation of each channel. It firstly aggregates the spatial information of input feature maps using both average-pooling and max-pooling operations and generates two different spatial context descriptors denoted as \(\mathbf{F}_{\text{Avg}}^{\text{c}}\) and \(\mathbf{F}_{\text{max}}^{\text{c}}\), respectively. These two descriptors are then fed into a shared network to produce the channel attention map \(\mathbf{M}_{\text{c}}(\mathbf{F})\), and the shared network is instantiated as a multi-layer perceptron (MLP) with one hidden layer. In order to reduce the number of parameters, the channel number of feature maps is firstly reduced by a factor of \(r\), and then expanded to the original number after activation to obtain two output feature  
Figure 4: Illustration of structure perception module. (**a**) illustration of DCNv2; (**b**) illustration of C2f_DCNv2. vectors, which are finally merged with element-wise summation to produce the channel attention map. Formally, it can be expressed as (1):  
\[ \begin{split}\mathbf{M}_{\text{c}}(\mathbf{F})&=\sigma \big{(}\text{MLP}(\text{AvgPool}(\mathbf{F}))+\text{MLP}(\text{MaxPool}( \mathbf{F}))\big{)}\\ &=\sigma\Big{(}\mathbf{W}_{1}\Big{(}\mathbf{W}_{0}\Big{(}\mathbf{ F}_{\text{Avg}}^{\text{c}})\Big{)}+\mathbf{W}_{1}(\mathbf{W}_{0}(\mathbf{F}_{\text{ max}}^{\text{c}}))\Big{)},\end{split}  \tag{1}\]  
where \(\sigma\) represents the Sigmoid activation function, \(\mathbf{M}_{\text{c}}\) is the channel attention feature map, \(\mathbf{W}_{0}\in R^{\text{C}/r\times\text{C}}\) and \(\mathbf{W}_{1}\in R^{\text{C}\times\text{C}/r}\), \(\mathbf{M}_{c}\in R^{\text{C}\times 1\times 1}\) denote the MLP weights. The spatial attention module intends to emphasize the importance of different locations in images. In order to obtain the spatial attention, the average-pooling and max-pooling operations along the channel axis are applied and the corresponding outputs are concatenated to generate an efficient feature descriptor, which are then convolved by a standard convolution layer to produce a spatial feature map, by which the important regions of an image can be highlighted and the influence of unimportant regions can be reduced. Formally, it can be computed by (2):  
\[ \begin{split}\mathbf{M}_{\text{s}}(\mathbf{F})&= \sigma\Big{(}f^{7\times 7}([\text{AvgPool}(\mathbf{F});\text{MaxPool}(\mathbf{F})]) \Big{)}\\ &=\sigma\Big{(}f^{7\times 7}\Big{(}\Big{[}\mathbf{F}_{\text{Avg}}^{ \text{s}}\,;\mathbf{F}_{\text{max}}^{\text{s}}\,\Big{]}\Big{)}\Big{)},\end{split}  \tag{2}\]  
where \(f^{7\times 7}\) represents the convolution operation with a filter size of \(7\times 7\), \(\mathbf{M}_{\text{s}}\) is the spatial attention feature map, \(\mathbf{F}_{\text{Avg}}^{\text{s}}\) and \(\mathbf{F}_{\text{max}}^{\text{s}}\) are the feature vectors generated by the max and average pooling operations. To instantiate the feature attention network, CBAM is inserted before the SPPF layer of the backbone network. Under the influence of attention mechanism, the feature maps received by the SPPF layer will be more focused on the disease area, helping the SPPF layer to better fuse the information from different scales and generate more accurate and rich feature representations.