# Research on Lightweight Lithology Intelligent Recognition System Incorporating Attention Mechanism
## 3 Model Introduction and Construction
### Improvement of MobileNetV2 Rockiness Recognition Model Incorporating Attention Mechanism  
It is crucial for the network to extract numerous shallow and deep aspects of the rocks when utilizing deep learning for lithology recognition. Although it can use a previously trained model to learn the deep and shallow features of the lithology classification task, which makes the amount of training data required for migration learning order of magnitude smaller, some researchers have primarily used the migration learning method when using deep learning for lithology recognition. This method does not require training a new model. However, take into account the subsequent issues: one must learn deeper and more abstract rock features, such as contour features, texture features, and tectonic features of rocks because some rocks' features and morphology are not regular, for example, similar rocks from different regions and periods may have some differences in external features; two) if a single MobileNetV2 lightweight CNN, although the model's recognition speed can be greatly improved, but compared with Resnet and InceptionV3 and other models. Therefore, in some situations, such as practical engineering and field exploration tasks where speed and lithology recognition accuracy may not be compatible at the same time, traditional convolutional neural networks or migration learning for fine-tuning training are not suitable for lithology recognition tasks.  
Therefore, the MobileNetV2 network has been enhanced to ensure compatibility of real-time detection and accuracy of rock recognition tasks at the same time, expand the network's universality for rock identification, and realize the real-time deployment of rock recognition system: (1) The channel attention module and spatial attention module in CBAM are integrated with the MobileNetV2 model in a serial connection after the second PW convolution. While the spatial attention module can reduce the interference of some difficult backgrounds and therefore impede the extraction of non-essential information, the channel attention module may promote the extraction of abstract characteristics such as texture features and rock construction features. (2) After the average pooling, a dropout layer is added, and the dropout rate is set to 0.5. This prevents the network from overfitting. The study output dimension (21 classes in this paper) is then switched to the output dimension of the fully linked layer, and each class of rocks is labeled and categorized accordingly.  
Figure 5 shows the original mobilenetV2 model, and the improved MobileNetV2 rock recognition model is depicted schematically in Figure 6. The network is primarily composed of two blocks: feature extraction and classification. The feature extraction part consists primarily of two ordinary convolutions, seven depth-separable convolutions with an inverted residual structure of fused attention mechanism, and one pooling. The classification part adopts a fully connected layer + Softmax structure, which is used to classify the network. According to Formula (10), the rocks are categorized, and the category with the highest level of confidence is chosen as the output category for the rocks. The cross-entropy function is then utilized as the loss function, as shown in Formula (11). The particular expression is as follows: to improve the classification results, the less the cross entropy, the closer the network output is to the real value corresponding to the labeling results.  
\[S(z)_{j}=\mathrm{e}^{z_{j}}/\sum_{k=1}^{N}\mathrm{e}^{z_{k}} \tag{10}\]\[L=-\sum_{i=1}^{M}\sum_{j=1}^{N}m_{ij}\ln n_{ij} \tag{11}\]  
where \(S(z)_{j}\) is the output confidence level corresponding to the \(j\)th class of rocks; \(N\) is the output image dimension, which is 21 classes in this paper; \(M\) is the total number of samples; \(N\) is the number of categories; \(m_{ij}\) is the predicted probability of category \(j\) at the \(i\)th sample; \(n_{ij}\) is the output probability of sample \(i\) at the \(j\)th category.