# A Multi-Scale Rebar Detection Network with an Embedded Attention Mechanism
## 3 Methods
### Add CA Attention Module  
The small and dense rebar targets make it difficult for the network to extract the feature information of the rebar cross-section. Meanwhile, the background in the image produces extensive redundancy when the network performs convolution, and the iterative accumulation swamps part of the target information, which leads to the low accuracy of model detection. To address the above problems, we add a coordinate attention (CA) mechanism that embeds location information into the backbone's channel [28]. CA can capture not only cross-channel information but also direction-aware and location-aware information, combining channel attention and spatial attention to make the model locate and identify targets more accurately. In addition, adding CA has almost no computational overhead to the network, and the model weights hardly increase. CA consists of two steps: the coordination of information embedding and attention generation. Figure 6 shows the structure of CA. Coordinate information embedding: The channel relations and long-term dependencies are encoded by precise location information, and the channel attention is decomposed into two one-dimensional feature-encoding processes that aggregate features along two spatial directions. After decomposition, the channel can capture long-range dependencies along one spatial direction, while location information can be retained along the other spatial direction. The specific steps are to input a feature map \(X\) of dimension \(C\times H\times W\) and encode the channel along the horizontal and vertical directions with two pooling kernels of dimensions (\(H\), \(1\)) and (\(1\), \(W\)), respectively. The \(c\)th channel outputs feature maps of \(\mathrm{z}_{c}^{h}(h)\) and \(\mathrm{z}_{c}^{w}(w)\), respectively, as shown in Equations (4) and (5). \[\mathrm{z}_{c}^{h}(h)=\frac{1}{W}\sum\limits_{0\leq i<W}\mathrm{x}_{c}(h,i) \tag{4}\]  
\[\mathrm{z}_{c}^{w}(w)=\frac{1}{H}\sum\limits_{0\leq j<H}\mathrm{x}_{c}(j,w) \tag{5}\] \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Feature Map** & \(\mathbf{20\times 20}\) & \(\mathbf{40\times 40}\) & \(\mathbf{80\times 80}\) & \(\mathbf{160\times 160}\) \\ \hline
**Receptive Field** & **Larger** & **Large** & **Middle** & **Small** \\ \hline \multirow{4}{*}{**Anchor boxes**} & (\(36\), \(32\)) & (\(23\), \(21\)) & (\(15\), \(14\)) & (\(7\), \(7\)) \\  & (\(39\), \(39\)) & (\(26\), \(27\)) & (\(15\), \(16\)) & (\(9\), \(8\)) \\ \cline{1-1}  & (\(45\), \(45\)) & (\(31\), \(28\)) & (\(18\), \(17\)) & (\(8\), \(10\)) \\ \cline{1-1}  & (\(56\), \(54\)) & (\(31\), \(33\)) & (\(19\), \(20\)) & (\(11\), \(11\)) \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Anchor box assignment table. Attention generation: The spatial information in the vertical and horizontal directions is encoded using batch normalization and nonlinear operations, and then the encoded information is segmented using convolution, while the channels of the attention map are adjusted to the number of channels of the input feature map. This is performed by cascading the feature maps \(z^{h}\) and \(z^{w}\) generated by the coordinate-information-embedding process and performing an \(F_{1}\)-transform using the shared \(1\times 1\) convolution operation, as shown in Equation (6). \[f=\delta(F_{1}([z^{h},z^{w}])) \tag{6}\]  
where \(f\in R^{C/r\times(H+W)}\) is an intermediate feature map encoding spatial information in the horizontal and vertical directions, \(r\) denotes the compression ratio, \(f\) is divided into separate tensors \(f^{h}\in R^{C/r\times H}\) and \(f^{w}\in R^{C/r\times W}\), and then two \(1\times 1\) convolutions \(F_{h}\) and \(F_{w}\) convert \(f^{h}\) and \(f^{w}\) to the same number of channels as the feature map \(X\). The weights \(g^{h}\) (Equation (7)) and \(g^{w}\) (Equation (8)) are obtained by normalization and weighted fusion using the Sigmoid function.