# Surface Defect Detection of Rolled Steel Based on Lightweight Model
## 3 Methods and Principles
### The Improved Network
#### 3.2.2 Coordinate Attention Mechanism  
The channel attention mechanism assigns different weights to each feature channel according to its importance, allowing the neural network to focus on specific feature channels. The channel attention mechanism can improve the model's performance to a certain extent, but it often ignores the location information that is very important for generating spatially selective attention maps. The authors of the CA (Coordinate Attention) mechanism [36] added location information to the channel attention, which can help the model identify and locate objects more accurately. Its network structure is shown in Figure 4. Coordinate Attention decomposes channel attention into two one-dimensional feature encoding processes, capturing long-range dependencies along one spatial direction and retaining precise location information along the other. The generated feature maps are then separately encoded to form a pair of orientation-aware and position-sensitive feature maps, which can be complementarily applied to the input feature maps to enhance the representation of objects of interest.  
Coordinate Attention encodes channel relationships and long-term dependencies through precise location information. The specific operations are divided into two steps: coordinate information embedding and Coordinate Attention generation. In the process of coordinate information embedding, the global pooling is first decomposed into one-to-one one-dimensional feature encoding according to Equation (3):  
\[z_{c}=\frac{1}{H\times W}\sum_{i=1}^{H}\sum_{j=1}^{W}x_{c}(i,j) \tag{3}\]  
For input \(X\), using pooling kernels of size \((H,1)\) and \((1,W)\) to encode each channel along the horizontal and vertical coordinates, respectively, the output of the channel \(c\) of height \(h\) is as shown in Equation (4):  
\[z_{c}^{h}(h)=\frac{1}{W}\sum_{0<i<W}x_{c}(h,i), \tag{4}\]  
Figure 4: Coordinate Attention.  
the output of the channel \(c\) of width \(w\) is as shown in Equation (5):  
\[z_{c}^{w}(w)=\frac{1}{H}\sum_{0\leq j<H}x_{c}(j,w), \tag{5}\]  
the above two transformations aggregate features along two spatial directions to obtain a pair of direction-aware feature maps.  
To make use of the above information, in Coordinate Attention generation, the above transformation is firstly subjected to the concat operation. Then the convolution transformation function \(F_{1}\) is used to transform it, as shown in Equation (6):  
\[f=\delta(F_{1}([z^{h},z^{w}])), \tag{6}\]  
where \(\delta\) is the nonlinear activation function, and \(f\) is the intermediate feature map that encodes spatial information in horizontal and vertical directions.  
Then decompose \(f\) into tensors \(f^{h}\) and \(f^{w}\) along the spatial dimension, and use two \(1*1\) convolutional transforms \(F_{h}\) and \(F_{w}\) to transform \(f^{h}\) and \(f^{w}\) into tensors with the same number of channels, respectively, as shown in Equations (7) and (8):  
\[g^{h}=\sigma(F_{h}(f^{h})), \tag{7}\]  
\[g^{w}=\sigma(F_{w}(f^{w})), \tag{8}\]  
then the outputs \(g^{h}\) and \(g^{w}\) are extended as attention weights, respectively. The final output Y is as shown in Equation (9):  
\[y_{c}(i,j)=x_{c}(i,j)\times g_{c}^{h}(i)\times g_{c}^{w}(j) \tag{9}\]