CNN-Transformer core casting sheet intelligent classification method based on particle swarm optimization

By using a particle swarm optimization CNN-Transformer network, combining local feature extraction of CNN with global relation modeling of Transformer, the problem of limited accuracy in the classification of core casting thin sections was solved, and high-precision and automated intelligent classification of core casting thin sections was achieved.

CN121661393APending Publication Date: 2026-03-13XI'AN PETROLEUM UNIVERSITY
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-11-26
Publication Date
2026-03-13

AI Technical Summary

Technical Problem

Among existing methods for classifying thin sections of rock core castings, CNN models struggle to capture global information, Transformer models lack the ability to extract local features, and the network architecture relies on manual design, which limits classification accuracy.

Method used

A CNN-Transformer network based on particle swarm optimization is adopted. Local texture features are extracted by CNN and transformed by feature serialization module before being input into Transformer encoder for global relation modeling. Particle swarm optimization algorithm is used to automatically optimize key network architecture parameters.

Benefits of technology

It achieves high-precision intelligent classification of thin section images of rock core castings, improves classification accuracy and automation, reduces the blindness of manual parameter adjustment, and has more comprehensive feature extraction capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121661393A_ABST
    Figure CN121661393A_ABST
Patent Text Reader

Abstract

The invention provides a CNN-Transformer core casting sheet intelligent classification method based on particle swarm optimization, and the method is characterized in that the method comprises the following steps: 1), obtaining a core casting sheet image data set, carrying out the cleaning and preprocessing of the data, and converting the data set into a format suitable for model training; 2) optimizing network architecture parameters by using a particle swarm optimization algorithm, and constructing a six-dimensional particle swarm including CNN depth, CNN channel number, projection dimension, Transform depth, attention head number and Dropout rate; (3) constructing a CNN-Transform serial network according to the optimal parameters obtained in the step (2); 4) inputting the training set into a serial network for learning and training, and constructing a rock core casting body slice classification model; 5) calculating a classification loss function, and optimizing the model by adopting a cross entropy loss function to obtain an optimal parameter combination; and 6) according to the rock core casting body slice classification model obtained by training, using test set data to verify model performance, and performing classification prediction on the rock core casting body slices. The invention discusses the intelligent classification method of the core casting body slices based on CNN-Transformer of particle swarm optimization, and the method can obtain a better classification result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of oil and gas reservoir evaluation in petroleum geological exploration, specifically involving: an intelligent classification method for core casting thin sections based on particle swarm optimization and CNN-Transformer. Background Technology

[0002] In the field of oil and gas exploration and development, the pore structure of reservoir rocks is a key factor determining oil and gas storage capacity and seepage characteristics. Core casting thin section analysis is one of the most direct and effective methods for studying the microscopic pore structure of reservoirs. By accurately identifying and classifying the pore type, size, morphology, and distribution in thin section images, important geological evidence can be provided for reserve assessment, production prediction, and development planning.

[0003] Traditional classification of core casting thin sections relies primarily on visual observation and manual identification by geological experts. This method has several significant drawbacks: First, it is highly subjective, with differing identification standards and experiences among experts leading to inconsistent classification results. Second, it is inefficient, as frame-by-frame observation and manual annotation consume considerable time and manpower, making it difficult to meet the demands of rapid processing of massive amounts of exploration data. Third, for pore types with complex structures and blurred boundaries, human visual identification is prone to errors.

[0004] To overcome the shortcomings of manual identification, researchers began exploring automated image analysis techniques. Early methods were mainly based on traditional digital image processing algorithms, such as thresholding, edge detection, and morphological analysis. These methods are sensitive to image quality, and their feature extractors have weak generalization ability. When faced with core thin sections with diverse pore morphologies, complex mineral compositions, and varying imaging conditions, the classification accuracy is often unsatisfactory.

[0005] With the development of artificial intelligence technology, deep learning methods, represented by Convolutional Neural Networks (CNNs), have achieved great success in image classification tasks. Through their hierarchical convolution and pooling operations, CNNs can effectively extract hierarchical features such as local texture, edges, and shapes from images, improving the automation and accuracy of pore classification to a certain extent. However, standard CNNs have a limited receptive field, and their feature extraction is essentially local, making it difficult to effectively capture global structural information and long-range dependencies across large spaces in an image, such as identifying the overall outline of large dissolution pores or the extension trend of microcracks.

[0006] In recent years, Transformer models, originating from the field of natural language processing, have been successfully applied to computer vision tasks. The Vision Transformer (ViT), through its self-attention mechanism, can model the relationships between image patches from a global perspective, effectively capturing long-distance dependencies and compensating for the shortcomings of CNNs in global feature extraction. However, standard ViT treats all image patches equally when processing images, lacking the inductive biases inherent in CNNs (such as locality and translation invariance). This results in a weaker ability to extract fine local details and typically requires pre-training on larger datasets to achieve ideal results.

[0007] Therefore, how to effectively integrate the powerful local feature extraction capability of CNN and the excellent global relationship modeling capability of Transformer, and automatically optimize the network architecture to achieve the best classification performance based on the unique properties of core casting thin section images, is a technical problem that urgently needs to be solved in the field of intelligent classification of core casting thin sections. Summary of the Invention

[0008] To address the shortcomings of existing core casting thin section classification methods, such as the difficulty of CNN models in capturing global information, the insufficient local feature extraction capability of Transformer models, and the limitation of classification accuracy due to reliance on manual network architecture design, this invention provides an intelligent classification method for core casting thin sections based on CNN-Transformer with particle swarm optimization. This method constructs a serial CNN-Transformer network, uses CNN to extract local texture features from the core image, transforms these features through a feature serialization module, and inputs them into a Transformer encoder for global relational modeling. Furthermore, a particle swarm optimization (PSO) algorithm is introduced to automatically optimize key network architecture parameters, thereby achieving high-precision intelligent classification of pore types. The method includes the following steps:

[0009] To achieve the above objectives, the technical solution adopted by the present invention is as follows:

[0010] 1) Obtain the image dataset of the core casting thin section, divide the dataset into training set, test set and validation set according to the proportion, and perform size standardization and data augmentation on the images to convert them into a format suitable for model training, validation and prediction (224×224×3);

[0011] 2) Optimize the network architecture parameters using the dataset from step 1) using PSO: Initialize a particle swarm containing 6 dimensions including CNN depth, number of CNN channels, projection dimension, Transformer depth, number of attention heads, and Dropout rate. Decode the position parameters of each particle to obtain the specific network architecture parameters. Build a CNN-Transformer model based on the parameters and quickly train it on the validation set to evaluate its fitness. Iterate and update the particle velocity and position until convergence, and retain the globally optimal architecture parameters.

[0012] 3) Based on the globally optimal parameters obtained in step 2), construct a sequential network (SN): Based on the optimized parameters, build a CNN feature extraction module containing variable depth convolutional layers (CL) and pooling layers (PL) to extract local features (LF); flatten, linearly project, and encode the position through the feature sequencer module (FSM); input a Transformer encoder containing a variable number of layers multi-head self-attention mechanism (MHSA) and a feed-forward network (FFN) to achieve global relation modeling (GRM) and obtain the complete CNN-Transformer sequential network structure;

[0013] 4) Input the training set obtained in step 1) into the CNN-Transformer model for learning and training, optimize the network parameters through the backpropagation algorithm (BA), and construct the Core Pore Classification Model (CPCM).

[0014] 5) Calculate the classification loss function (CLF) to determine the optimal combination of model parameters;

[0015] 6) Based on the trained core casting thin section classification model, use the test set data from step 1) to verify the model performance, calculate the classification accuracy (CA), precision (P), recall (R), and other indicators, and predict the core casting thin section images to be classified, outputting the classification results for five pore types: medium pore throat, small pore throat, microcrack, dissolution enlarged pore, and feldspar dissolution pore.

[0016] Furthermore, in step 1), the entire dataset is first randomly divided into a training set, a validation set, and a test set in a ratio of 8:1:1. The training set is used to learn the model weight parameters; the validation set is used to evaluate the performance of different network architectures during PSO optimization and to perform early stopping judgment and hyperparameter adjustment during model training; the test set does not participate in the training process at all and is only used to evaluate the generalization ability of the model. The data is then cleaned, and damaged or abnormally formatted images are checked and removed; then all images are preprocessed. First, the image size is uniformly adjusted to 224×224 pixels, and then the pixel value range is linearly scaled from [0, 255] to the range of [0, 1] to eliminate the influence of different image sizes and lighting conditions on classification accuracy; the normalization formula is shown in equation (1):

[0017]

[0018] In the above formula, X norm The normalized pixel value is X, while the original pixel value is X. min and X max These represent the minimum and maximum pixel values ​​in the data. Furthermore, the data augmentation strategies employed include: random 90-degree rotation, horizontal and vertical flipping, small-range translation and scaling, adding slight Gaussian noise and Gaussian blur, and adjusting image brightness and contrast. During geometric transformations, reflection fill is used to fill the boundaries, avoiding black border artifacts and ensuring the realism of the enhanced image.

[0019] Furthermore, in step 2), when optimizing the network architecture using the PSO algorithm, each candidate network architecture is encoded as a particle, the position of which is determined by a 6-dimensional real vector p. i =(p i1 p i2 p i3 p i4 p i5 p i6 This is represented by ) . The decoding rule for this vector is as follows: the first dimension p i1 After linear transformation and rounding, it is mapped to the depth of the CNN feature extraction module, ranging from [4, 6] layers; the second dimension p i2The mapping is to the maximum number of channels in the CNN, ranging from [384, 640]; the third dimension p i3 The mapping is the projection dimension of the feature serialization module, ranging from [512, 1024]; the fourth dimension p i4 Mapped to the depth of the Transformer encoder, ranging from [8, 12] layers; the fifth dimension p i5 Used to select a suitable number of attention heads from a preset set {6, 8, 12, 16} to ensure that it is divisible by the projection dimension; the sixth dimension p i6 This is mapped to the Dropout rate in the network, ranging from [0.1, 0.2]. The fitness evaluation process is as follows: a PSO-CNN-Transformer model is constructed based on the decoded architecture parameters. The training set is used for rapid training for 5 epochs, with 10 batches trained in each epoch. The cross-entropy loss and classification accuracy are calculated on the validation set for 5 batches. The sum of the validation set loss and the accuracy penalty term is used as the fitness function. The smaller the fitness value, the better the architecture performance. During the iteration process, the velocity and position of each particle are updated according to its current position, the individual's historical best position, and the population's global historical best position. The update formulas are shown in equations (2) and (3):

[0020] v i (t+1)=w·v i (f)+c1·r1·(pbest i (t)-x i (i))+c2·r2·(gbest(t)-x i (t)) (2)

[0021] x i (t+1)=x i (t)+v i (t+1)(3)

[0022] In the above formula, w is the inertia weight, c1 and c2 are learning factors, r1 and r2 are random numbers between [0, 1], and pbest i is the best historical position of an individual particle, and gbest is the best historical position of the entire population.

[0023] Furthermore, the specific process in step 3) is as follows:

[0024] 3.1) Input an image with dimensions of 224×224×3, and optimize the D based on PSO. cnn and C cnn The parameters dynamically construct a convolutional network containing convolutional and pooling layers of variable depth. The network is composed of D... cnnThe system consists of stacked convolutional blocks, each containing a 3×3 convolutional layer, a batch normalization layer, a ReLU activation function, a max pooling layer, and a dropout layer. The number of channels increases layer by layer until it reaches C. cnn Finally, an adaptive average pooling layer is used to unify the feature map size to 7×7, extract local features, and output the CNN feature map.

[0025] 3.2) For the CNN feature map F cnn Perform flattening, linear projection, and positional encoding operations. First, flatten the feature map into a sequence. Where 49 represents the number of spatial locations; then, the features of each spatial location are transformed from C through a linear projection layer. cnn Dimensional mapping to D proj Dimension, obtained Finally, learnable positional encoding is added. The serialized features are obtained. The projection and encoding process is shown in equation (4):

[0026] F proj =Linear(Flatten(F cnn )+E pos (4)

[0027] 3.3) Add a learnable classification token (CLS Token) to the front end of the serialization feature. form F input Input to D trans Global relation modeling is achieved in a Transformer encoder composed of stacked encoder layers. Each encoder layer contains a multi-head self-attention mechanism and a feedforward network with a variable number of layers. The number of heads in the MHSA is N. heads The decision is made. The formula for calculating multi-head self-attention is shown in equation (5):

[0028]

[0029] In the above formula, d k This is the dimension of the key vector. (Transformer encoder output) Extract the feature vector corresponding to the CLS token. As a global feature representation, the complete CNN-Transformer serial network structure is obtained.

[0030] Furthermore, the specific process in step 4) is as follows: the CLS token feature vector output by the Transformer encoder obtained in step 3) is... The input is fed into a classification head, which consists of two fully connected layers. The first layer inputs the features from D... projThe first layer maps to 384 dimensions, and after passing through the GELU activation function and Dropout, the second layer maps to a 5-dimensional output. The final layer uses the Softmax activation function to output a 5-dimensional probability distribution vector, corresponding to the predicted probabilities of five categories: medium-sized pores with throats, small pores with throats, microcracks, dissolution-enlarged pores, and feldspar dissolution pores.

[0031] Furthermore, in step 4), the model training uses the Cross-Entropy Loss Function (CELF) as the objective function, and optimizes the network weight parameters through the Backpropagation Algorithm (BA). The Cross-Entropy Loss Function is suitable for multi-class classification tasks and can effectively measure the difference between the model's predicted probability distribution and the true label distribution. Its calculation formula is shown in equation (6):

[0032]

[0033] In the above formula, C represents the total number of categories (5 in this invention), and y i p represents the true label (1 if the sample belongs to class i, 0 otherwise). i The model predicts the probability that a sample belongs to class i. Model training uses the AdamW optimizer, which adds weight decay decoupling to the Adam optimizer, better preventing overfitting. During training, the loss is monitored using the validation set; if the validation set loss does not decrease for several consecutive epochs, overfitting is prevented.

[0034] Furthermore, in step 6), classification accuracy, precision, recall, and F1 score are used to comprehensively evaluate the model performance. The F1 score is the harmonic mean of precision and recall. The specific calculation formulas are as follows:

[0035]

[0036] In the above formula, TP represents true positives, TN represents true negatives, FP represents false positives, and FN represents false negatives. Furthermore, a confusion matrix is ​​generated to visually demonstrate the model's classification performance across various categories.

[0037] The beneficial effects of this invention are:

[0038] 1. This invention presents an intelligent classification method for thin sections of rock core castings based on particle swarm optimization and CNN-Transformer. The method trains the model using core images and evaluates the classification results. This invention is simple to implement, highly automated, and significantly improves classification accuracy compared to traditional methods.

[0039] 2. In this invention, preprocessing and enhancing the thin section image data of the core casting is to ensure the quality and diversity of the input data. The PSO algorithm is used for automatic network architecture search to efficiently find the optimal model configuration, avoiding the blindness of manual parameter tuning and ensuring the accuracy of subsequent classification.

[0040] 3. In this invention, by employing a CNN-Transformer serial network architecture, this model possesses more comprehensive feature extraction capabilities. The CNN feature extraction module can deeply capture the local texture features of pores, while the Transformer encoder can mine global structural information and long-range dependencies. By serially connecting the two, it is possible to more accurately identify complex cast sheet types. Attached Figure Description

[0041] Figure 1 This is a flowchart of the PSO-optimized CNN-Transformer intelligent classification method for core casting thin sections in this invention.

[0042] Figure 2 This is a diagram of the CNN-Transformer model optimized based on PSO in this invention.

[0043] Figure 3 This is a diagram of the CNN model network structure in this invention.

[0044] Figure 4 This is a diagram of the network structure of the Transformer model in this invention.

[0045] Figure 5 The following is an example diagram illustrating five categories of core casting thin sheets in a specific embodiment.

[0046] Figure 6 This is a schematic diagram illustrating how the data augmentation strategy enhances an image in a specific embodiment.

[0047] Figure 7 This is a confusion matrix diagram in a specific embodiment.

[0048] Figure 8 The training and validation loss and accuracy curves are shown in a specific embodiment. Detailed Implementation

[0050] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the specific implementation methods and structural features of the present invention will be described in detail below with reference to the accompanying drawings and embodiments. The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. Example

[0051] See Figure 1 The PSO-optimized CNN-Transformer intelligent classification method for core casting thin sections provided in this embodiment includes the following steps:

[0052] 1) Obtain the image dataset of thin sections of rock core castings. The converted images are shown in the figure. Divide the dataset into training set, test set and validation set in a ratio of 8:1:1. Perform size standardization and data augmentation on the images and convert them into a format suitable for model training, validation and prediction.

[0053] 2) See Figure 2 Based on the dataset in step 1), the PSO optimization algorithm is used to optimize the network architecture parameters: a 6-dimensional PSO is initialized, which includes CNN depth, number of CNN channels, projection dimension, Transformer depth, number of attention heads and Dropout rate. The specific network architecture configuration is obtained by decoding the position parameters of each particle. A fusion model is built accordingly and fast training and fitness evaluation are completed on the validation set. The particle velocity and position are iteratively updated until the algorithm converges, and the globally optimal architecture parameters are retained.

[0054] 3) Based on the globally optimal parameters obtained in step 2), construct a CNN feature extraction module containing variable depth convolutional layers and pooling layers to achieve local feature extraction (see...). Figure 3 The feature sequencer module performs feature flattening, linear projection, and positional encoding; the input is a Transformer encoder with a variable-layer multi-head self-attention mechanism and a feedforward network (see...). Figure 4 This completes the global relationship modeling, forming a complete CNN-Transformer serial network structure;

[0055] 4) Input the training set from step 1) into the above serial network and predict the output by calculating the forward propagation model.

[0056] 5) Calculate the prediction error using the loss function and update the training parameters using the backpropagation algorithm. Train for 10 epochs to obtain the trained core casting thin section classification model;

[0057] 6) Use the test set from step 1) to verify the performance of the trained model and calculate core evaluation metrics such as classification accuracy, precision, and recall. Based on the model, predict the thin section images of the core casting to be classified and output the classification results of five pore types: medium pore throat, small pore throat, microcrack, dissolution enlargement pore, and feldspar dissolution pore.

[0058] The experimental data in this embodiment comes from the Z fault block in the southern oilfield of China and the S oilfield in the northern part of Shaanxi Province, such as Figure 5 As shown, the blue areas represent microporous structures filled with liquid colloid, the black areas represent crude oil or sludge, and the other gray or white areas represent rock debris and cement. Based on porosity development characteristics, the core images are divided into five categories: small-pore, fine-throat and medium-pore, medium-throat cores in the Z-block. Figure 5 (a) Figure 5 (b)), and microfractures, dissolution enlargement pores, and feldspar dissolution pores in the S oilfield ( Figure 5 (c) Figure 5 (d) Figure 5 (e)).

[0059] In this embodiment, in step 1), the core casting thin section image dataset is divided into a training set, a test set, and a validation set in an 8:1:1 ratio. Data augmentation is then performed on each set, and the specific augmentation results are shown in Table 1. Examples of augmentation are provided below. Figure 6 As shown.

[0060] Table 1. Data Augmentation Results

[0061]

[0062] In this embodiment, the specific process in step 2) is as follows:

[0063] 2.1) Initialize a 6-dimensional particle swarm optimization that includes CNN depth, number of CNN channels, projection dimension, Transformer depth, number of attention heads, and Dropout rate.

[0064] 2.2) Decode the position parameters of each particle to obtain the specific network architecture configuration, including CNN depth, number of CNN channels, projection dimension, Transformer depth, number of attention heads and Dropout rate.

[0065] 2.3) Build the model and perform rapid training and fitness evaluation on the validation set.

[0066] 2.4) Iteratively update particle velocity and position until the algorithm converges, at which point the globally optimal architecture parameters are retained.

[0067] In implementation, the PSO algorithm and the optimized parameters are shown in Table 2.

[0068] Table 2 PSO Optimization Parameters

[0069]

[0070] In this embodiment, the specific process in step 3) is as follows:

[0071] 3.1) Input an image with dimensions of 224×224×3. Dynamically construct a convolutional network containing variable-depth convolutional layers and pooling layers based on the CNN depth and CNN channel number parameters obtained through PSO optimization. The network consists of multiple stacked convolutional blocks, each block containing a 3×3 convolutional layer, a batch normalization layer, a ReLU activation function, a max pooling layer, and a Dropout layer. The number of channels is increased layer by layer until the maximum number of channels determined by PSO optimization is reached. Finally, an adaptive average pooling layer is used to unify the feature map size to 7×7, extract local features, and output the CNN feature map.

[0072] 3.2) Flattening, linear projection, and positional encoding operations on CNN feature maps: First, the feature maps are flattened into a sequence form, where 49 represents the number of spatial locations; then, a linear projection layer maps the features of each spatial location from the CNN channel number dimension to the projection dimension determined by PSO optimization; finally, learnable positional encoding is added to obtain serialized features;

[0073] 3.3) Add a learnable classification token to the front end of the serialization features to form a complete input sequence; input it into a Transformer encoder consisting of stacked encoder layers whose number of layers is determined by PSO optimization to achieve global relation modeling; each encoder layer contains a multi-head self-attention mechanism and a feedforward network, and the number of heads for multi-head self-attention is determined by PSO optimization; after the Transformer encoder outputs, extract the feature vector corresponding to the CLS token as the global feature representation.

[0074] 3.4) The CLS token feature vector is input into the classification head, which consists of two fully connected layers. The first layer maps the features from the projection dimension determined by PSO optimization to 384 dimensions. After passing through the GELU activation function and Dropout, the second layer maps to a 5-dimensional output. The last layer uses the Softmax activation function to output a 5-dimensional probability distribution vector, which corresponds to the predicted probability of five categories: medium pore throat, small pore throat, microcrack, dissolution enlargement pore, and feldspar dissolution pore.

[0075] In this embodiment, in step 4), after inputting the training set from step 1) into the serial network constructed in step 3), the output is predicted by calculating the forward propagation model.

[0076] In this embodiment, in step 5), the prediction error is calculated using the cross-entropy loss function, and the AdamW optimizer is used to update all trainable parameters of the CNN and Transformer through the backpropagation algorithm. The model is trained for 10 epochs to obtain the trained core casting thin section classification model.

[0077] In this embodiment, the specific process in step 6) is as follows:

[0078] Based on this model, the thin section images of the core casting to be classified are predicted, and the classification results of five pore types are output: medium pore with throat, small pore with throat, microcrack, dissolution enlarged pore, and feldspar dissolution pore. Figure 7 The image shows the confusion matrix of the model on the test set. The diagonal elements represent the number of correctly classified samples. It can be seen that all five pore types achieved high recognition accuracy. Figure 8 The training process curves of the model are shown. Both the training loss and the validation loss show a decreasing trend and gradually converge, with no overfitting phenomenon. The training accuracy and validation accuracy steadily improve, indicating that the model has good generalization ability.

[0079] Furthermore, the model performance was validated using a test set. The validation results are shown in Table 3, which compares the accuracy of different models on the core casting thin section classification task. The proposed PSO-CNN-Transformer model achieves an overall accuracy of 93.1%, which is 16.2%–20.0%, 13.1%, and 7.5% higher than traditional CNN models (ResNet-50, VGG-16, EfficientNet-B0), standard Transformer models, and CNN-Transformer models without PSO optimization, respectively.

[0080] Table 3. Comparison of accuracy of different models on the core casting thin section classification task.

[0081]

[0082] Further analysis of model performance is presented in Table 4, comparing the performance of different models on the core casting thin section classification task. The PSO-CNN-Transformer model has 82.0M parameters, a 14.4% reduction compared to the unoptimized CNN-Transformer model. Simultaneously, the training time per round decreased from 1285 seconds to 1075 seconds, improving training efficiency by 16.3%. In terms of classification performance, the model achieved precision, recall, and F1 score of 93.7%, 93.1%, and 93.0%, respectively, representing improvements of 7.8%, 7.5%, and 7.3% compared to the CNN-Transformer model. This demonstrates that PSO optimization not only improved model accuracy but also significantly enhanced generalization ability and computational efficiency, fully validating the effectiveness of the sequential fusion of the PSO optimization algorithm and CNN-Transformer in the core casting thin section classification task. After training, the resulting classification model can automatically classify and identify new core images.

[0083] Table 4 Performance comparison of different models on the core casting thin section classification task

[0084]

[0085] In summary, the intelligent classification method for core casting thin sections based on particle swarm optimization and CNN-Transformer can be applied to the intelligent classification task of pores. This method can achieve good prediction results and performs well in handling complex pore structure features.

[0086] The above description, in conjunction with specific embodiments, provides a further detailed explanation of the present invention. It should not be construed that the specific implementation of the present invention is limited to these descriptions. For those skilled in the art, various simple deductions or substitutions can be made without departing from the concept of the present invention, and all such modifications and substitutions should be considered within the scope of protection of the present invention.

Claims

1. A method for intelligent classification of thin sections of core castings based on particle swarm optimization and CNN-Transformer, characterized in that: Includes the following steps: 1) Obtain the image dataset of the core casting thin section, divide the dataset into training set, test set and validation set according to the proportion, and perform size standardization and data augmentation on the images to convert them into a format suitable for model training, validation and prediction (224×224×3); 2) Optimize the network architecture parameters of the dataset from step 1) using the Particle Swarm Optimization (PSO) algorithm: Initialize a particle swarm containing 6 dimensions including CNN depth, number of CNN channels, projection dimension, Transformer depth, number of attention heads, and Dropout rate. Decode the position parameters of each particle to obtain the specific network architecture parameters. Build a CNN-Transformer model based on the parameters and quickly train it on the validation set to evaluate its fitness. Iterate and update the particle velocity and position until convergence, and retain the globally optimal architecture parameters. 3) Based on the globally optimal parameters obtained in step 2), construct a Sequential Network (SN): Based on the optimized parameters, build a CNN feature extraction module containing variable depth convolutional layers (CL) and pooling layers (PL) to extract local features (LF); flatten, linearly project, and positionally encode through the Feature Sequentialization Module (FSM). Input a Transformer encoder containing a variable-layer multi-head self-attention mechanism (MHSA) and a feed-forward network (FFN) to achieve global relation modeling (GRM) and obtain the complete CNN-Transformer serial network structure. 4) Input the training set obtained in step 1) into the CNN-Transformer model for learning and training, optimize the network parameters through the backpropagation algorithm (BA), and construct the Core Pore Classification Model (CPCM). 5) Calculate the classification loss function (CLF) to determine the optimal combination of model parameters; 6) Based on the trained core casting thin section classification model, use the test set data from step 1) to verify the model performance, calculate the classification accuracy (CA), precision (P), recall (R), and other indicators, and predict the core casting thin section images to be classified, outputting the classification results for five pore types: medium pore throat, small pore throat, microcrack, dissolution enlarged pore, and feldspar dissolution pore.

2. The intelligent classification method for thin sections of core castings based on particle swarm optimization and CNN-Transformer as described in claim 1, characterized in that, In step 1), the entire dataset is first randomly divided into a training set, a validation set, and a test set in a ratio of 8:1:

1. The data is then cleaned, and damaged or formatted images are removed. Subsequently, all images are preprocessed: first, the image size is uniformly adjusted to 224×224 pixels, and then the pixel value range is linearly scaled from [0, 255] to the [0, 1] interval to eliminate the influence of different image sizes and lighting conditions on classification accuracy. The data augmentation strategies employed include: random 90-degree rotation, horizontal and vertical flipping, small-range translation and scaling, adding slight Gaussian noise and Gaussian blur, and adjusting image brightness and contrast. When performing geometric transformations, a reflection fill method is used to fill the boundaries to avoid black edge artifacts and ensure the realism of the enhanced image.

3. The intelligent classification method for thin sections of core castings based on particle swarm optimization and CNN-Transformer as described in claim 2, characterized in that, In step 2), when optimizing the network architecture using the PSO optimization algorithm, each candidate network architecture is encoded as a particle, whose position is represented by a 6-dimensional real vector. The decoding rules for this vector are as follows: the first dimension, after linear transformation and rounding, is mapped to the depth of the CNN feature extraction module, ranging from [4, 6] layers; the second dimension is mapped to the maximum number of channels in the CNN, ranging from [384, 640]; the third dimension is mapped to the projection dimension of the feature sequencer module, ranging from [512, 1024]; the fourth dimension is mapped to the depth of the Transformer encoder, ranging from [8, 12] layers; and the fifth dimension is used to select a suitable attention head from the preset set {6, 8, 12, 16}. The sixth dimension is mapped to the Dropout rate in the network, ranging from [0.1, 0.2]. The fitness evaluation process is as follows: a PSO-CNN-Transformer model is constructed based on the decoded architecture parameters. The model is trained quickly for 5 epochs using the training set, with 10 batches trained in each epoch. The cross-entropy loss and classification accuracy are calculated on the validation set for the 5 batches. The sum of the validation set loss and the accuracy penalty term is used as the fitness function. The smaller the fitness value, the better the architecture performance. During the iteration process, the velocity and position of each particle are updated based on its current position, the individual's historical best position, and the global historical best position of the population.

4. The intelligent classification method for thin sections of core castings based on particle swarm optimization and CNN-Transformer as described in claim 3, characterized in that, The specific process in step 3) is as follows: 3.1) Input an image with dimensions of 224×224×3. Dynamically construct a convolutional network containing variable-depth convolutional layers and pooling layers based on the CNN depth and CNN channel number parameters obtained through PSO optimization. The network consists of multiple stacked convolutional blocks, each block containing a 3×3 convolutional layer, a batch normalization layer, a ReLU activation function, a max pooling layer, and a Dropout layer. The number of channels is increased layer by layer until the maximum number of channels determined by PSO optimization is reached. Finally, an adaptive average pooling layer is used to unify the feature map size to 7×7, extract local features, and output the CNN feature map. 3.2) Flattening, linear projection, and positional encoding operations on CNN feature maps: First, the feature maps are flattened into a sequence form, where 49 represents the number of spatial locations; then, a linear projection layer maps the features of each spatial location from the CNN channel number dimension to the projection dimension determined by PSO optimization; finally, learnable positional encoding is added to obtain serialized features; 3.3) Add a learnable classification token to the front end of the serialization features to form a complete input sequence; input it into a Transformer encoder consisting of stacked encoder layers whose number of layers is determined by PSO optimization to achieve global relation modeling; each encoder layer contains a multi-head self-attention mechanism and a feedforward network, and the number of heads for multi-head self-attention is determined by PSO optimization; after the Transformer encoder outputs, extract the feature vector corresponding to the CLS token as the global feature representation. 3.4) The CLS token feature vector is input into the classification head, which consists of two fully connected network layers. The first layer maps the features from the projection dimension determined by PSO optimization to 384 dimensions. After passing through the GELU activation function and Dropout, the second layer maps to a 5-dimensional output. The last layer uses the Softmax activation function to output a 5-dimensional probability distribution vector, which corresponds to the predicted probabilities of five categories: medium pore throat, small pore throat, microcrack, dissolution enlargement pore, and feldspar dissolution pore, respectively, thus obtaining the complete CNN-Transformer serial network structure.

5. The intelligent classification method for thin sections of core castings based on particle swarm optimization and CNN-Transformer as described in claim 4, characterized in that, The specific process in step 4) is as follows: after inputting the training set from step 1) into the serial network constructed in step 3), the output is predicted by calculating the model through forward propagation.

6. The intelligent classification method for thin sections of core castings based on particle swarm optimization and CNN-Transformer as described in claim 5, characterized in that, In step 5), the cross-entropy loss function is used as the objective function for model training, and the network weight parameters are optimized through the backpropagation algorithm. The AdamW optimizer is used for model training. This optimizer adds weight decay decoupling on the basis of Adam, which can better prevent model overfitting. During the training process, the loss change is monitored through the validation set. When the validation set loss does not decrease for several consecutive epochs, early stopping is triggered to prevent overfitting.

7. The intelligent classification method for thin sections of core castings based on particle swarm optimization and CNN-Transformer as described in claim 6, characterized in that, In step 6), classification accuracy, precision, recall, and F1 score are used to comprehensively evaluate the model performance; the F1 score is the harmonic mean of precision and recall; at the same time, a confusion matrix is ​​generated to visually demonstrate the model's classification performance in each category.