# High-Frequency Workpiece Image Recognition Model Based on Hybrid Attention Mechanism
## 2 Approach
### Lightweight Re-Evaluation Attention Module (LRAM)  
The spatial information of different feature maps has visual and semantic differences, which is crucial for extracting effective channel features. However, due to the high spatial information dimension and large data volume of the feature map, the computational cost of processing spatial information is high, making it difficult to train the neural network and limiting the network's application value. To solve this problem, this paper proposes a lightweight re-evaluation attention module (LRAM), which captures the global range dependence between spatial positions and aims to enhance the network's representation ability by combining channel attention with feature map spatial information. Its structure is shown in Figure 8.  
As can be seen from Figure 8, the LRAM can be divided into two steps: spatial information compression and channel feature extraction. In order to obtain channel attention, the feature maps of different channels need to be re-estimated. However, due to the large spatial dimension of the front layer of the convolutional neural network, the complex feature information, and the high computational cost, it is difficult to perform the re-estimation operation directly. Therefore, average pooling is used to compress the spatial size of the feature map while retaining sufficient spatial information and providing a lighter input for subsequent channel feature extraction. Assume that the input feature map is \(\mathbf{X}_{1}\in\mathbb{R}^{C\times H\times W}\) and that \(C\), \(H\), and \(W\) represent the number of feature channels, height, and width, respectively. The input feature map \(\mathbf{X}_{1}\) is average-pooled along each feature map to obtain the intermediate layer feature map \(\mathbf{R}\):  
\[\mathbf{R}=[r_{1},r_{2},\dots,r_{c}]=F_{pool}(X_{1}), \tag{8}\]  
where the height and width of \(r_{n}\) and \(n\in\{1,2,\dots,C\}\) are \(H^{\prime}\) and \(W^{\prime}\), respectively, and \(H^{\prime}<H,W^{\prime}<W\), and \(F_{pool}(\cdot)\) represent average pooling. After obtaining the intermediate feature map \(\mathbf{R}\), the importance of each feature map channel \(r_{n}\) is modeled through the global depth convolution kernel \(l_{n}\), whose structure is shown in Figure 9. Global convolution in global depth convolution can directly extract important channel features from all the spatial information of the feature map. At the same time, the amount of calculation is significantly reduced through depth convolution and the important information corresponding to different channels is independently captured. Therefore, the use of global deep convolution can enable the network to iteratively learn the optimal convolution-kernel parameters, perceive and make full use of the wider spatial information in the feature map, and at the same time reduce the computational cost as much as possible so that the network can perform feature processing in a more efficient manner extract. Figure 8: IRAM structure diagram. Assume that S is the attention weight of \(R\), and obtain \(R\in\mathbb{R}^{C\times H^{\prime}\times W^{\prime}}\) by global depth convolution of the intermediate feature map \(S\in\mathbb{R}^{C\times 1\times 1}\):  
\[S=[S_{1},S_{1},\dots,S_{C}]=F_{gdc}(R), \tag{9}\]  
where \(F_{gdc}(\cdot)\) represents the global depthwise convolution. Since \(r_{n}\) and \(l_{n}\) have the same size, the result of the depthwise convolution operation is a scalar, which is then used through the activation function to obtain the attention weight \(s_{n}\) of \(r_{n}\):  
\[S_{n}=\sigma(r_{n}\odot\ l_{n}), \tag{10}\]  
where \(\sigma(\cdot)\) represents the sigmoid function. The feature maps of different channels are generated by different convolution kernels, which can capture different types of features and have different effects on network performance.