# An Oracle Bone Inscriptions Detection Algorithm Based on Improved YOLOv8
## 2 Materials and Methods
### The Proposed Method
#### 2.4.3 Adding CBAM Attention Module  
The complex background of OBI rubbing images and the small image area occupied by some of the detection targets lead to the presence of a significant proportion of extraneous features in the image iteration. To selectively enhance the feature channels that contain the most target information while also minimizing the disruption caused by invalid targets, enhancing the detection effect of the targets of interest, and thus enhancing the model's overall detection precision, this study embeds CBAM into the OBI detection algorithm. In recent years, attention modules have emerged rapidly, and common attention mechanisms include SE [24], GAM [25], EMA [26], and CBAM.  
CBAM innovatively incorporates a spatial attention mechanism based on retaining the original channel attention mechanism, thereby comprehensively optimizing the network in terms of both channel and spatial dimensions. This measure enables an optimized network to more accurately capture key features encompassing both channel-wise and spatial aspects, significantly improving the model's efficiency in extracting features from both the channel and spatial dimensions. Figure 5 illustrates the structure of the CBAM.  
The CBAM processes the input feature map, \(F\), by first obtaining its channel attention feature, \(M_{c}(F)\). Multiplying the features element-wise with \(F\) yields the channel-refined feature \(F^{\prime}\). It then computes the spatial attention feature \(M_{\text{s}}(F^{\prime})\) of \(F^{\prime}\), multiplies it with \(F^{\prime}\) element-wise, and obtains the final refined feature. This enhanced refined feature is used as the input for subsequent network layers, effectively preserving key information while suppressing noise and irrelevant information. Formulas (11) and (12) outline the entire attention procedure.  
\[F^{\prime}=M_{c}(F)\otimes F \tag{11}\]  
\[F^{\prime\prime}=M_{\text{s}}\big{(}F^{\prime}\big{)}\otimes F^{\prime} \tag{12}\]  
The input feature map undergoes max-pooling and average-pooling operations and feeds the resulting feature map into a shared multi-layer perceptron. Then, the feature maps generated by the shared MLP are combined, and the outcome is scaled by using the sigmoid function to derive the channel attention, \(M_{c}\). Multiplying \(M_{c}\) with the feature map element-wise yields the channel-refined feature. The channel attention module's architecture is schematically represented in Figure 6.  
The channel attention module successively applies max-pooling and average-pooling to the refined channel features, stacks the results along the same dimension, adjusts the channel numbers using a convolutional layer, and utilizes the sigmoid function to derive spatial attention, \(M_{\text{s}}\). Eventually, the channel-refined feature is element-wise multiplied with \(M_{\text{s}}\) to obtain the final refined feature. Figure 7 illustrates the spatial attention module's structure.  
Figure 5: CBAM structure.  
Figure 6: Channel attention module.  
CBAMs can be easily integrated into most mainstream networks, thus effectively improving the ability of network models to extract features without significantly increasing the computational complexity and number of parameters. Therefore, in this paper, the CBAM is embedded before the SPPF in the YOLOv8_n model.