A surface roughness detection method and system based on white light interferometric images
By building the FAMNet model, combining white light interference images and fusion attention mechanism, the problems of insufficient speed and accuracy in traditional detection methods are solved, and efficient and accurate surface roughness detection is achieved, which is suitable for industrial production.
Patent Information
- Application Number
- CN202411848841.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-16
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2044-12-16
AI Technical Summary
Existing surface roughness detection methods have problems such as slow detection speed, low accuracy, high cost and difficulty in deployment in complex environments. In particular, machine vision-based methods have difficulty achieving accurate detection under various processing methods.
A lightweight semantic segmentation model FAMNet with fusion attention mechanism is constructed. Through the feature extraction network and fusion attention module, channel and position attention mechanisms are combined to optimize surface roughness detection and use white light interferometry images for detection.
It improves the accuracy and speed of surface roughness detection, reduces computational complexity, is suitable for real-time monitoring in industrial production, simplifies the model structure, and facilitates deployment.
Smart Images

Figure CN119810039B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision, in particular to a surface roughness detection method and system based on white light interference images. BACKGROUND
[0002] With the continuous development of computer vision technology, it becomes more and more common to use deep learning models to detect the surface roughness of metal blocks to realize intelligent guidance of industrial production, and the industry is constantly realizing automatic and intelligent detection.
[0003] Surface roughness refers to the distance between the tiny peaks and valleys on the surface of a workpiece, which reflects the degree of microscopic unevenness on the surface of the workpiece. The smaller the surface roughness, the smoother the surface of the workpiece. The roughness of the surface of the workpiece will affect the wear resistance, fatigue resistance, vibration intensity, contact stiffness and noise of the workpiece. In manufacturing, the service life and reliability of the workpiece depend largely on the surface roughness. The larger the surface roughness, the smaller the effective area in contact with the workpiece surface, and the greater the pressure, resulting in greater frictional resistance and ultimately leading to wear of the work surface. Modern mechanical surface processing requires efficient and accurate evaluation of surface roughness.
[0004] With the rapid development of manufacturing industry, the traditional roughness detection method (stylus method) cannot meet the requirements of rapid and efficient full detection of roughness in mass production. The stylus method has the problems of slow detection speed, damage to the surface of the workpiece and low detection precision, and cannot realize high-speed surface roughness measurement. Although non-contact optical microscopes, interferometers and other non-contact, high-precision roughness measurement methods can be used, they are slow, expensive and difficult to deploy in complex environments, and are usually used for laboratory offline measurement. The roughness detection method based on machine vision has the characteristics of non-contact, fast detection speed, low price and easy installation, and has achieved certain research results. Different mechanical processing methods produce different texture information on the surface of the sample, making it difficult to detect roughness. It is important to provide a roughness detection method that is suitable for various roughness measurements, fast and efficient and real-time.
[0005] Current machine vision-based roughness online detection methods usually use a classification method, i.e. obtaining a roughness value from an input image. However, the surface roughness value contained in an image is not a uniform value, therefore, how to realize more accurate detection of surface roughness has become a technical problem that needs to be solved by those skilled in the art.
[0006] Therefore, the present application proposes a method that can detect different roughness values from an image online through semantic segmentation, making the detection results more accurate. SUMMARY
[0007] The application aims to provide a surface roughness detection method and system based on white light interference images, construct a lightweight semantic segmentation model FAMNet with a fusion attention mechanism, detect different roughness values for an image, improve the recognition ability of different surface roughness regions, make the detection results more accurate, and accurately, efficiently and quickly detect the roughness of a metal surface.
[0008] To achieve the above-mentioned purpose, the application provides the following solutions.
[0009] A surface roughness detection method based on white light interference images, comprising the following steps:
[0010] S1, obtaining a sample surface roughness dataset and pre-processing to obtain a training image set, wherein the training image set comprises multiple white light interference images of sample surface roughness;
[0011] S2, pre-training the FAMNet model based on the training image set, wherein the FAMNet model comprises a feature extraction network and a fusion attention module, the feature information of the white light interference image is extracted through the feature extraction network, and the feature information is enhanced and fused through the fusion attention module using the channel attention and position attention mechanism;
[0012] S3, after pre-training, further training the FAMNet model to optimize its detection ability for different surface roughness, and obtaining the trained FAMNet model as a surface roughness detection model;
[0013] S4, inputting a to-be-detected image into the trained FAMNet model to obtain a detection result.
[0014] Further, in S1, obtaining a sample surface roughness dataset and pre-processing to obtain a training image set, specifically comprising:
[0015] S101, using a white light interference device in cooperation with an image acquisition device to shoot a surface roughness image of a sample under a set illumination condition, to ensure that the image can accurately reflect the microstructure of the sample surface, wherein the surface roughness image is a white light interference image;
[0016] S102, determining the roughness value at the interference fringe of each surface roughness image according to the measurement data of the white light interference device, and taking the roughness value as the roughness label of each surface roughness image to guide the FAMNet model to learn the corresponding relationship between the surface roughness and the image features;
[0017] S103, pre-processing the collected surface roughness images;
[0018] S104, integrate the pre-processed surface roughness image and its corresponding roughness label to obtain a training image set.
[0019] Further, in S2, the FAMNet model is pre-trained based on the training image set, specifically including:
[0020] S201, the feature extraction network of the FAMNet model refines and extracts pre-fine-grained features through convolution modules and skip connections to obtain better local features, thereby obtaining feature information of the white light interference image.
[0021] S202, a fusion attention module is introduced into the FAMNet model to combine channel attention mechanism and position attention mechanism to enhance feature information from spatial and channel angles.
[0022] Further, in S201, the feature extraction network of the FAMNet model refines and extracts pre-fine-grained features through convolution modules and skip connections to obtain better local features, thereby obtaining feature information of the white light interference image, specifically including:
[0023] Feature X represents the roughness feature of the white light interference image, and the pre-fine-grained feature extraction obtains the feature X of each stage Stagei Each stage represents an extraction stage in the FAMNet model, and each stage contains a series of layers (such as convolution layers, pooling layers, activation layers, etc.), which together complete a certain specific processing or feature extraction on the input data; the calculation formula is shown in formulas (1)-(8):
[0024] X Stage0 =f(conv 7×7 (x)) (1)
[0025] f(X)=Relu(BN(X)) (2)
[0026] f1=f(conv 1×1 (X)) (3)
[0027] f2=f(conv 3×3 (f1)) (4)
[0028] F main =f(conv 1×1 (d2)) (5)
[0029] block1(X)=F main +f(conv 1×1 (X)) (6)
[0030] block2(X)=F main+Relu(X) (7)
[0031] X Stagei =f(block2(block1(X Stagei-1 )))(i=1,2,3,4) (8)
[0032] Among them, the original size of feature X is H×W×C, where H represents the original height of the feature map, W represents the original width of the feature map, and C represents the original number of channels of the feature map; the FAMNet model feature extraction has 0-5 extraction stages, X Stagei represents the output of the i-th extraction stage, X Stage0 represents the primary features obtained by the 7*7 convolution kernel, and Stagei (i=1,2,3,4) is the result obtained by passing the output of the previous stage Stagei-1 through two processing modules block1 and block2 in sequence, and then processing it through the function f(·); f(·) is the general paradigm of feature extraction; f(X) represents the new extracted features obtained by feature X after the BN layer and Relu activation function; conv k×k Indicates that a convolution kernel of size k*k is used; features f1 and f2 are extracted from the input feature X through continuous convolution operations, representing the features of the image at different levels respectively; in local feature extraction, f2 is first further processed through a 1×1 convolution layer to obtain the main feature F main , then F main The result of another 1×1 convolutional layer is added to the original input feature X to form the output block1(X) of the first layer block; then, block1(X) is added to the feature X processed by the ReLU activation function to obtain the output block2(X) of the second layer block; finally, the output block1(X) of the first layer block is processed by the second layer block. Stagei-1 ), and get the final output X Stagei .
[0033] Furthermore, in S202, a fusion attention module is introduced into the FAMNet model to combine the channel attention mechanism and the position attention mechanism to enhance feature information from the spatial and channel perspectives, specifically including:
[0034] The fusion attention module first extracts channel-dimensional features based on the channel attention mechanism for the input feature information to capture channel dependencies and enhance the connection between different channels, and then extracts spatial-dimensional features based on the position attention mechanism to capture position dependencies.
[0035] Further, in the S202, a fusion attention module is introduced in the FAMNet model, which combines the channel attention mechanism and the position attention mechanism to enhance the feature information from the spatial and channel angles. The specific calculation formula is as follows:
[0036] Q1,K1,V1=Conv(X input1 ) (9)
[0037] Q′1,K′1,V′1=Reshape(Q1,K1,V1) (10)
[0038]
[0039] X input2 =X output1 (13)
[0040] Q2,K2,V2=Conv(X input2 ) (14)
[0041] Q′2,K′2,V′2=Reshape(Linear(Q2,K2,V2)) (15)
[0042]
[0043] The FAM module performs channel dimension feature extraction on the input feature in the first stage to capture channel dependency and enhance the connection between different channels, and performs spatial dimension feature extraction in the second stage to capture position dependency and reduce the loss of position information.
[0044] In the first stage, as shown in formula (9), the input feature X generates query Q1, key K1 and value V1 vectors through convolution operation, with a size of CxHxW. Then, the query Q1, key K1 and value V1 vectors are reshaped into a shape Q'1, K'1, V'1 suitable for matrix multiplication, with a size of CxN, as shown in formula (10).
[0045] Then, the attention weight is obtained through the attention calculation formula, as shown in formula (11). This weight is then normalized by the Softmax function to obtain the normalized weight.
[0046] Next, the normalized weight is multiplied by the value vector to obtain the weighted value. This weighted value is added to the original input feature map X to obtain the output feature map X output1 , as shown in formula (12).
[0047] In the second stage, the output feature map X output1As a new input feature map, the second group of queries Q2, keys K2 and value V2 vectors are generated through formulas (13)-(14), and are adjusted through a linear layer Linear, as shown in formula (15), and the new attention weights are calculated again through matrix multiplication and a Softmax function, and are subjected to matrix multiplication with the weighted values, and finally are added with the input feature map to obtain the final output feature map X output2 As shown in formulas (16)-(17).
[0048] Further, in the S3, after pre-training, the FAMNet model is further trained, specifically including:
[0049] The FAMNet model is trained on two RTX 2080Ti graphic processors based on a deep learning framework PyTorch, with 20 iterations and a batch size of 64; an Adam optimizer is used to optimize the model parameters, with a weight decay of 0.0001, so as to improve the learning and generalization ability of the FAMNet model to the surface roughness features.
[0050] Further, the S3 further includes model performance evaluation:
[0051] The cross-entropy loss is selected as the loss function, and the accuracy, precision, recall and specificity are used as the evaluation indexes of the model, so as to evaluate and optimize the trained FAMNet model.
[0052] The application also provides a surface roughness detection system based on a white light interference image, which is used to execute the surface roughness detection method based on the white light interference image, and includes:
[0053] An image processing module is configured to acquire a sample surface roughness dataset and pre-process the sample surface roughness dataset to obtain a training image set, wherein the training image set includes multiple white light interference images of sample surface roughness.
[0054] A model construction and training module is configured to pre-train a FAMNet model based on the training image set, extract feature information of the white light interference image through a feature extraction network, and enhance and fuse the feature information through a fusion attention module by using a channel attention and a position attention mechanism, wherein the FAMNet model includes the feature extraction network and the fusion attention module.
[0055] The FAMNet model is further trained after pre-training, so as to optimize the detection ability of the FAMNet model to different surface roughness, and obtain a trained FAMNet model as a surface roughness detection model.
[0056] A detection module is configured to input a to-be-detected image into the trained FAMNet model to obtain a detection result.
[0057] Further, the application also provides a non-transitory computer-readable storage medium having stored thereon a computer program, wherein the computer program, when executed by a processor, implements the surface roughness detection method based on a white light interference image as described above.
[0058] According to the specific embodiments of the application, the surface roughness detection method and system based on a white light interference image provided by the application disclose the following technical effects:
[0059] (1) A semantic segmentation FAMNet model based on a fusion attention mechanism is constructed and trained, which optimizes the extraction and recognition ability of the surface roughness features in the white light interference image through the fusion attention mechanism, reduces the computational complexity of the model, and at the same time maintains the lightweight characteristics of the FAMNet model;
[0060] (2) The FAMNet model includes a feature extraction network and a fusion attention module, the fusion attention module combines a channel attention mechanism and a position attention mechanism, enhances feature information from the spatial and channel angles, and improves the learning ability of the model for different surface roughness features;
[0061] (3) In the pre-training stage, the FAMNet model learns the correlation of image features through a self-attention mechanism, effectively fuses the feature information of different regions, and improves the detection accuracy of the model for surface roughness;
[0062] (4) Cross-entropy loss is used as the loss function, and the model is optimized through accuracy, precision, recall rate, and specificity evaluation indexes, to ensure high prediction accuracy of the model;
[0063] (5) The white light interference image to be detected is input into the trained FAMNet model for surface roughness prediction, solving the problem of low efficiency of traditional metal surface roughness detection methods, and through the fusion attention mechanism, the performance of surface roughness prediction is improved, which is suitable for real-time monitoring of surface roughness in industrial production. BRIEF DESCRIPTION OF DRAWINGS
[0064] In order to more clearly illustrate the technical solutions of the embodiments of the application or the prior art, the drawings needed in the embodiments will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0065] Figure 1 The flowchart of the surface roughness detection method based on a white light interference image in the embodiments of the application;
[0066] Figure 2 A roughness detection network FAMNet model structure diagram based on a white light interference image is provided for an embodiment of the present application, wherein a is a flowchart of roughness detection of the FAMNet model, and b is a specific framework diagram of the FAMNet;
[0067] Figure 3 A network structure diagram of a core FAM module in the FAMNet is provided for an embodiment of the present application, wherein a represents a process of extracting features in a channel dimension, and b represents a process of extracting features in a spatial dimension;
[0068] Figure 4 An overall network structure diagram of the FAM module at different network stages is provided for an embodiment of the present application. DETAILED DESCRIPTION
[0069] The technical solutions in the embodiments of the present application will be described clearly and completely below with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of protection of the present application.
[0070] The purpose of the present application is to provide a surface roughness detection method and system based on a white light interference image, to construct and train a semantic segmentation FAMNet model based on a fusion attention mechanism, to input a to-be-detected image into the trained FAMNet model to obtain a detection result, and to solve the problem of low efficiency of existing metal surface roughness detection methods.
[0071] The FAMNet model effectively extracts and fuses the surface roughness features in the white light interference image through its fusion attention mechanism, not only reducing the size of the model, but also improving the detection speed and accuracy. The model can provide more accurate surface roughness prediction, thereby overcoming the defects of traditional detection methods in speed, deployment convenience, feature extraction capability, and detection accuracy.
[0072] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the present application will be further described in detail below with reference to the drawings and specific embodiments.
[0073] The embodiment of the present application provides a surface roughness detection method based on feature optimization, and a general roughness detection model suitable for various metal surfaces is constructed. In the embodiment, the model is applied to the roughness detection of various metal surfaces. By using an image acquisition device to capture the surface roughness image of the sample at the same position, and then using a white light interferometer to measure the roughness value corresponding to the sample image, the data set is divided into a training set, a validation set and a test set, wherein the training set and the validation set are used for model training, and the test set is used for evaluating the performance of the model. The construction and optimization process of the model is as follows: first, a FAMNet (Fusion Attention Mechanism Network) model is designed, then appropriate model parameters are selected, and then the prepared data set is used to train the model. After training, the performance of the model is evaluated through the validation set, and the model parameters are adjusted according to the evaluation results to further optimize the model. Finally, the model is evaluated using the test data set to ensure that the model performs as expected. Finally, the model is deployed in the actual surface roughness detection scene.
[0074] Specifically, as shown in Figure 1 The surface roughness detection method based on white light interference image provided by the embodiment of the present application comprises the following steps:
[0075] S1, obtaining a sample surface roughness data set and preprocessing to obtain a training image set, wherein the training image set comprises a plurality of white light interference images of sample surface roughness;
[0076] S2, pre-training the FAMNet model based on the training image set, extracting the feature information of the white light interference image through the feature extraction network, and enhancing and fusing the feature information through the fusion attention module using the channel attention and position attention mechanism, wherein the FAMNet model comprises a feature extraction network and a fusion attention module;
[0077] S3, after pre-training, the FAMNet model is further trained to optimize its detection ability for different surface roughness, and a trained FAMNet model is obtained as a surface roughness detection model;
[0078] Wherein, cross-entropy loss is selected as the loss function, accuracy, precision, recall and specificity are used as the evaluation indexes of the model, and the trained FAMNet model is evaluated and optimized;
[0079] S4, inputting the image to be detected into the trained FAMNet model to obtain a detection result.
[0080] The FAMNet model constructed and trained by the present application is as shown in Figure 2As shown, the image to be detected is input into the trained FAMNet model, and the prediction result is obtained through the softmax layer. The FAMNet model is composed of multiple stages, each stage containing multiple residual blocks that extract features through convolution operations and further optimize feature representations through fusion attention modules. The fusion attention module combines channel attention and position attention to improve the recognition accuracy of the model for different surface roughness features. In this way, the FAMNet model can effectively process white light interference images and accurately predict surface roughness, solving the limitations of traditional detection methods in speed, deployment convenience, feature extraction capability, and detection accuracy.
[0081] For example, in S1, a sample surface roughness dataset is obtained and preprocessed to obtain a training image set, specifically including:
[0082] S101, using a white light interference device in cooperation with an image acquisition device, a surface roughness image of the sample is photographed under a set illumination condition, to ensure that the image can accurately reflect the microstructure of the sample surface, and the surface roughness image is a white light interference image;
[0083] S102, according to the measurement data of the white light interference device, the roughness value at the interference fringe of each surface roughness image is determined, and the roughness value is used as the roughness label of each surface roughness image to guide the FAMNet model to learn the corresponding relationship between the surface roughness and the image features;
[0084] S103, the collected surface roughness images are preprocessed, including denoising, contrast enhancement, size standardization, etc., to improve the image quality and ensure the consistency and effectiveness of the model training;
[0085] S104, the preprocessed surface roughness images and their corresponding roughness labels are integrated to form the final training image set, providing a data basis for subsequent model training.
[0086] Specifically, in this embodiment, first, the surface roughness image of the sample at the same position is photographed using an image acquisition device. Then the roughness value corresponding to the sample image is obtained using a white light interferometer as a label value. Finally, the constructed surface roughness image dataset is divided into a training set, a validation set and a test set, wherein the training set and the validation set are used to train the model, and the test set is used to evaluate the performance of the model. The dataset contains a total of 6093 images. The training set, the validation set and the test set are divided according to the ratio of 7:2:1.
[0087] For example, in S2, the FAMNet model is pre-trained based on the training image set, specifically including:
[0088] S201, the feature extraction network of the FAMNet model refines the pre-fine-grained features step by step through convolution modules and skip connections to obtain better local features, and obtains the feature information of the white light interferogram image;
[0089] S202, a fusion attention module is introduced in the FAMNet model, which combines channel attention mechanism and position attention mechanism to enhance feature information from the spatial and channel angles;
[0090] The fusion attention module can improve the recognition and segmentation ability of the model for the surface roughness features in the white light interferogram image while maintaining the calculation efficiency.
[0091] The FAMNet model calculates the correlation of each channel in the white light interferogram image through the fusion attention mechanism, which is used as the information of the interaction between channels. The FAMNet model fuses the feature information of different channels to obtain mixed channel feature information, thereby integrating the features from the channel angle. This process involves inputting the feature information of different channels into two paths: one is the channel self-attention calculation path, which is used to evaluate the correlation between channels; the other is the feature fusion path, which is used to merge the feature information of different channels. In this way, the feature of each channel is fused and calculated with other channels to obtain enhanced channel features, thereby improving the recognition ability of the model for the surface roughness features.
[0092] Based on the images selected from the training image set, the feature extraction network is used for pre-training parameter learning in the pre-training stage, and the feature information of the image is interacted and fused through the convolution module and the fusion attention module.
[0093] In this embodiment, the FAMNet model directly receives the white light interferogram image as input and extracts and optimizes the surface roughness features through its internal fusion attention mechanism (FAM). The model effectively identifies and distinguishes different roughness levels in the image by combining channel attention and position attention. In the training stage, FAMNet enhances the representation ability of features through the fusion attention module and makes predictions through the softmax layer, thereby achieving accurate detection of surface roughness. After pre-training is completed, the FAMNet model can be used for online prediction, which simplifies the model structure, reduces the number of parameters, improves the detection speed, and is convenient for deployment in actual industrial environments. The lightweight design of the FAMNet model makes it easier to integrate into existing manufacturing processes while maintaining high detection accuracy.
[0094] Further, the S201, the feature extraction network of the FAMNet model refines the pre-fine-grained features step by step through convolution modules and skip connections to obtain better local features, and obtains the feature information of the white light interferogram image, specifically including:
[0095] In the present embodiment, the fusion attention module is used to extract feature information of the white light interferometric image and perform feature fusion; in order to improve the efficiency of feature extraction and capture finer local features, the FAMNet model uses a large convolution kernel to expand the receptive field, thereby capturing more extensive context information; in addition, by introducing skip connections and layer-wise refinement strategies, the model further enhances the expression ability of the features, ensuring that high-quality local features can be obtained at different scales; these enhanced features are then input into a multi-layer perceptron to further extract and fuse feature information, and finally obtain optimized features for surface roughness detection. This process improves the model's ability to recognize different roughness features in the white light interferometric image.
[0096] The network structure diagram of the FAMNet is shown in Figure 2 By extracting pre-fine-grained features to extract better local features, the accuracy and performance of the final recognition can be improved. The feature X represents the roughness features of the white light interferometric image, and the pre-fine-grained feature extraction obtains the features X Sagei of each extraction stage, where each stage represents an extraction stage in the FAMNet model, and each stage contains a series of layers (such as convolution layers, pooling layers, activation layers, etc.), which together complete a certain specific processing or feature extraction on the input data; the calculation formulas are shown in formulas (1)-(8):
[0097] X Stage0 = f(conv 7×7 (x)) (1)
[0098] f(X) = Relu(BN(X)) (2)
[0099] f1 = f(conv 1×1 (X)) (3)
[0100] f2 = f(conv 3×3 (f1)) (4)
[0101] F main = f(conv 1×1 (d2)) (5)
[0102] block1(X) = F main + f(conv 1×1 (X)) (6)
[0103] block2(X) = F main + Relu(X) (7)
[0104] X Stagei = f(block2(block1(X Stagei-1 )))(i = 1, 2, 3, 4) (8)
[0105] wherein the original size of the feature X is HxWxC, wherein H represents the original height of the feature map, W represents the original width of the feature map, and C represents the original channel number of the feature map; the FAMNet model feature extraction has 0-5 extraction stages, and X Stagei represents the output of the i-th extraction stage, X Stage0 represents the primary feature obtained by using a 7*7 convolution kernel, and Stagei (i = 1, 2, 3, 4) is the result obtained by sequentially passing the output of the previous stage Stagei-1 through two processing modules block1 and block2 and then processing through the function f(·); f(·) is a general norm of feature extraction; f(X) represents the new extracted feature of the feature X obtained through the BN layer and the Relu activation function; conv k×k represents that a k*k size convolution kernel is used; the features f1 and f2 are extracted from the input feature X through consecutive convolution operations, and respectively represent the features of the image at different levels; in local feature extraction, f2 first obtains the main feature F main through a 1x1 convolution layer for further processing, and then adds the result of F main and the original input feature X through another 1x1 convolution layer to form the output block1(X) of the first layer block; then, block1(X) is added to the feature X processed through the ReLU activation function to obtain the output block2(X) of the second layer block; finally, the output block1(X Stagei-1 of the first layer block is processed through the second layer block to obtain the final output X Stagei . This output will be used for subsequent surface roughness detection tasks. This process shows how the features are extracted step by step, providing detailed feature information for accurate detection of surface roughness.
[0106] Further, in the S202, a fusion attention module is introduced in the FAMNet model, which combines the channel attention mechanism and the position attention mechanism to enhance the feature information from the spatial and channel angles, specifically including:
[0107] The network structure diagram of the fusion attention module (FAM) is as shown in Figure 3 The fusion attention module first extracts the channel dimension features based on the channel attention mechanism to capture the channel dependency and enhance the connection between different channels, and then extracts the spatial dimension features based on the position attention mechanism to capture the position dependency and reduce the loss of position information.
[0108] In order to improve the efficiency of feature extraction, the fusion attention module adopts the combination of channel attention and position attention to generate attention weight mask to adjust the size of feature weight. This fusion attention mechanism provides effective feature fusion for the pre-training stage and enhances the model's ability to recognize different surface roughness features.
[0109] The fusion attention module enhances the network model's ability to perceive position information and learn local features, as shown in the specific calculation formulas (9)-(17):
[0110] Q1,K1,V1=Conv(X input1 ) (9)
[0111] Q′1,K′1,V′1=Reshape(Q1,K1,V1) (10)
[0112]
[0113] X input2 =X output1 (13)
[0114] Q2,K2,V2=Conv(X input2 ) (14)
[0115] Q′2,K′2,V′2=Reshape(Linear(Q2,K2,V2)) (15)
[0116]
[0117] The FAM module performs channel dimension feature extraction on the input features in the first stage to capture channel dependency and enhance the connection between different channels, and performs spatial dimension feature extraction in the second stage to capture position dependency and reduce the loss of position information.
[0118] In the first stage, as shown in formula (9), the input feature X generates query Q1, key K1 and value V1 vectors through convolution operation, with a size of C×H×W; then, the query Q1, key K1 and value V1 vectors are reshaped (Reshape) into a shape Q'1,K'1,V'1 suitable for matrix multiplication, with a size of C×N, as shown in formula (10);
[0119] Then, the attention weight is obtained through the attention calculation formula, as shown in formula (11), and this weight is then normalized through the Softmax function to obtain the normalized weight;
[0120] Next, the normalized weight and the value vector are matrix multiplied to obtain the weighted value, and the weighted value is added to the original input feature map X to obtain the output feature map X output1 As shown in formula (12);
[0121] In the second stage, the output feature map X output1 As a new input feature map, the second set of queries Q2, keys K2 and value V2 vectors are generated through formulas (13)-(14) and adjusted through a linear layer Linear, as shown in formula (15). The new attention weight is calculated again through matrix multiplication and the Softmax function, and matrix multiplied with the weighted value, and finally added to the input feature map to obtain the final output feature map X output2 As shown in formulas (16)-(17).
[0122] The design of the entire fusion attention module allows the model to weight and fuse features at different stages, thereby enhancing the model's ability to recognize surface roughness features. Figure 3 The detailed structure design of the fusion attention mechanism is shown, which includes feature transmission, reshaping and transposition operations, which together realize effective fusion and enhancement of features.
[0123] Further, in the S3, after pre-training, the FAMNet model is further trained, specifically including:
[0124] The FAMNet model is trained on two RTX 2080Ti graphics processing units based on the deep learning framework PyTorch, with 20 iterations and a batch size of 64; the Adam optimizer is used to optimize the model parameters, with a weight decay of 0.0001, to improve the learning and generalization ability of the FAMNet model for surface roughness features.
[0125] In addition, the FAMNet model trained in the embodiment of the present application is used to predict the roughness of the test set divided from the sample surface roughness data set in S1. The cross-entropy loss is selected as the loss function, and the mean intersection over union (MioU), pixel accuracy (PA) and average accuracy (MA) are used as the evaluation indicators of the model, specifically including:
[0126] In this embodiment, the loss function calculation formula is shown in formula (18), where N represents the total number of pictures in the data set, HxW represents the resolution size of the picture, Y ij is defined as the label of picture i class j, M ij is the probability output of class j obtained by inputting picture i into the model.
[0127]
[0128] MIoU is used as the main evaluation index. MIoU is an index widely used for semantic segmentation algorithm evaluation, which can comprehensively consider the prediction accuracy of each class and provide overall evaluation results. By calculating MIoU, the performance of different models or different parameter configurations on the semantic segmentation task can be compared, thereby verifying the effectiveness and accuracy of the FAMNet model. IoU (intersection-union ratio) measures the similarity between the prediction result and the true label by calculating the ratio of the overlapping area to its union. Specifically, for each class, the IoU of the class can be calculated and averaged to obtain the MIoU, as shown in formula (19).
[0129]
[0130]
[0131] where w represents the total number of classes. When calculating the final average, the default background class must also be included; p uv represents the number of times class u is incorrectly predicted as class v; p vu represents the number of results that are initially class u but are predicted as class v; p uu represents class u being correctly predicted as class u.
[0132] Finally, the trained FAMNet detection model is used for testing and analysis of the detection effect.
[0133] Table 1 prediction accuracy of different models
[0134]
[0135] In this embodiment, compared with existing models, the parameters and computational complexity of the FAMNet model are minimized. As shown in Table 1, in the machine vision semantic segmentation task, the segmentation and recognition accuracy MIoU of the FAMNet model reaches 86.3%, which is higher in performance than the currently best-performing model Mask2Former, and the computational performance is improved by about 77.66%, and the parameters are about 63.59% lower than Mask2Former. The FAMNet model is slightly better than the Mask2Former model. In terms of pixel accuracy, the FAMNet model is 3% higher than the UNet++. In terms of average accuracy, the FAMNet model is equivalent to the UNet++. The present application uses parameters and computational complexity as the main evaluation index. When the overall subdivision quality evaluation standard MIoU is comparable, overall, the FAMNet model achieves the best result at present.
[0136] In real-world detection scenarios, some samples predicted by the present invention were made of oxygen-free copper, with a predicted field of view of 1920 × 1200 pixels. The inference times of the FAMNet model and other algorithms in real-time detection scenarios are shown in Table 2. The FAMNet model constructed by the present invention achieved an inference speed of 30.3 frames per second, achieving the best performance compared to other algorithms. The inference latency was only 33 milliseconds, 69% faster than Mask2former and 18% faster than Unet++. This demonstrates that the present method effectively balances recognition accuracy and speed, ensuring stable and efficient operation in the high-precision machining industry, where real-time detection is crucial.
[0137] Table 2 Inference speed of different models
[0138]
[0139] To explore the performance effects of the network structure design, experiments were conducted using different backbones. Detailed results are shown in Table 3. ResNet50 and ResNet101 were used as backbones, achieving performance of 77.5% and 84.4%, respectively. In terms of segmentation and recognition accuracy, ResNet101, as the backbone, outperformed ResNet50 by approximately 9%, though requiring more parameter calculations.
[0140] Table 3 Performance comparison of different backbones
[0141]
[0142] In order to study the performance impact of putting the fusion attention mechanism designed by the present invention into the model architecture, the FAM module is placed Figure 4 The different positions shown. The present invention was experimentally tested after three extraction stages (Stage 2, Stage 3, Stage 4). The detailed results are shown in Table 4. It can be seen that when fused after Stage 2, MIoU only reached 78.5, and the effects of PixelAccuracy and MeanAccuracy were also very poor. After being put into Stage 4 for fusion, the performance improved by about 8%, and after being integrated into Stage 3, it reached 86.3, an increase of about 10%. As shown in Table 4, it can be clearly seen that adding the FAM module after the third extraction stage (Stage 4) can achieve the best roughness recognition accuracy, and the parameter performance and computational complexity are comparable.
[0143] Table 4 Performance comparison of fusion attention mechanism modules placed at different positions
[0144]
[0145] The application also provides a system for surface roughness detection based on a white light interference image, which is used to execute the method for surface roughness detection based on a white light interference image.
[0146] An image processing module is configured to acquire a sample surface roughness data set and pre-process the sample surface roughness data set to obtain a training image set, wherein the training image set comprises a plurality of white light interference images of sample surface roughness.
[0147] A model construction and training module is configured to pre-train a FAMNet model based on the training image set, extract feature information of the white light interference images through a feature extraction network, and enhance and fuse the feature information through a fusion attention module by using a channel attention and a position attention mechanism, wherein the FAMNet model comprises the feature extraction network and the fusion attention module.
[0148] The FAMNet model is further trained after pre-training to optimize the detection capability of the FAMNet model for different surface roughnesses, and a trained FAMNet model is obtained as a surface roughness detection model.
[0149] A detection module is configured to input a to-be-detected image into the trained FAMNet model to obtain a detection result.
[0150] In addition, the application further provides a non-transitory computer-readable storage medium, which stores a computer program, and the computer program is characterized in that the computer program is executed by a processor to implement the method for surface roughness detection based on a white light interference image.
[0151] Of course, those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by a computer program to instruct related hardware (such as a processor, a controller, etc.) to complete, and the program can be stored in a computer-readable storage medium, and the program can include the processes of the above-mentioned method embodiments when executed. The storage medium can be a memory, a disk, an optical disk, etc.
[0152] The above description of the disclosed embodiments enables a person skilled in the art to implement or use the application. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein can be implemented in other embodiments without departing from the spirit or scope of the application. Therefore, the application will not be limited to the embodiments shown herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A surface roughness detection method based on white light interference imaging, characterized in that: The following steps are involved: S1, obtaining a sample surface roughness dataset and preprocessing it to obtain a training image set, wherein the training image set includes a plurality of white light interference images of the sample surface roughness; S2, pre-training the FAMNet model based on the training image set, wherein the FAMNet model includes a feature extraction network and a fusion attention module, extracting feature information of the white light interferometer image through the feature extraction network, and enhancing and fusing the feature information through the fusion attention module using channel attention and position attention mechanisms; S3, after pre-training, further training the FAMNet model to optimize its detection ability for different surface roughnesses, and obtain the trained FAMNet model as the surface roughness detection model; S4, input the image to be detected into the trained FAMNet model to obtain the detection result; Wherein, in said S1, obtaining a sample surface roughness dataset and preprocessing it to obtain a training image set specifically includes: S101, using a white light interferometer device in conjunction with an image acquisition device to capture a surface roughness image of the sample under set lighting conditions, ensuring that the image can accurately reflect the microstructure of the sample surface, wherein the surface roughness image is a white light interferometer image; S102, determining the roughness value at the interference fringes of each surface roughness image based on the measurement data of the white light interferometer, and using the roughness value as the roughness label of each surface roughness image to guide the FAMNet model to learn the correspondence between surface roughness and image features; S103, preprocessing the collected surface roughness image; S104, integrating the pre-processed surface roughness images and their corresponding roughness labels to obtain a training image set; In S2, the FAMNet model is pre-trained based on the training image set, specifically including: S201, the feature extraction network of the FAMNet model uses convolution modules and skip connections to gradually refine and extract pre-fine-grained features to obtain better local features and obtain feature information of the white light interference image; S202: The FAMNet model introduces a fusion attention module that combines the channel attention mechanism and the position attention mechanism to enhance feature information from both spatial and channel perspectives. Specifically, it includes: The fusion attention module first extracts channel-dimensional features based on the channel attention mechanism for the input feature information to capture channel dependencies and enhance the connection between different channels. It then extracts spatial-dimensional features based on the position attention mechanism to capture position dependencies. The calculation formula is as follows: ; ; ; ; ; ; ; ; ; The fusion attention module performs channel-dimensional feature extraction on the input features in the first stage to capture channel dependencies and enhance the connection between different channels, and performs spatial-dimensional feature extraction in the second stage to capture position dependencies; In the first stage, as shown in formula (9), the input features X Generate queries through convolution operations ,key Sum vector, size C×H×W; then, query ,key Sum The vector is reshaped into a shape suitable for matrix multiplication , the size is C×N, as shown in formula (10); Then, the attention weight is obtained by the attention calculation formula, as shown in formula (11). This weight is then normalized by the Softmax function to obtain the normalized weight; Next, the normalized weights are matrix multiplied with the value vector to obtain the weighted value, which is added to the original input feature map X to obtain the output feature map , as shown in formula (12); In the second stage, the output feature map As a new input feature map, the second set of queries is generated through formulas (13)-(14) ,key Sum Vector, and adjusted by the linear layer Linear, as shown in formula (15), and again calculated by matrix multiplication and Softmax function to obtain the new attention weight, and matrix multiplication with the weighted value, and finally added to the input feature map to obtain the final output feature map , as shown in formulas (16)-(17).
2. The surface roughness detection method based on white light interference image according to claim 1, characterized in that: In step S201, the feature extraction network of the FAMNet model uses convolution modules and skip connections to gradually refine and extract pre-fine-grained features to obtain better local features and obtain feature information of the white light interference image, specifically including: feature X Represents the roughness feature of the white light interference image, and the features of each extraction stage are obtained through pre-fine-grained feature extraction , the calculation formula is shown in formula (1)-(8): ; ; ; ; ; ; ; ; Among them, the characteristics X The original size is H×W×C, where H represents the original height of the feature map, W represents the original width of the feature map, and C represents the original number of channels of the feature map. The FAMNet model feature extraction has 0-5 extraction stages. Indicates the i The output of the extraction stage, Represents the primary features obtained by the 7*7 convolution kernel; f (·) is the general paradigm of feature extraction; f ( X ) indicates characteristics X New extracted features obtained after BN layer and Relu activation function; Indicates the use of k * k Convolution kernel size; features and It is extracted from the input feature X through continuous convolution operations, representing the features of the image at different levels; in local feature extraction, First, the main features are further processed through a 1×1 convolution layer , then Added to the original input feature X through another 1×1 convolutional layer to form the output of the first layer block ; Then, Features processed by ReLU activation function X Add together to get the output of the second layer block ; Finally, the output of the first layer block is processed by the second layer block , and get the final output .
3. The surface roughness detection method based on white light interference image according to claim 1, characterized in that: In S3, after pre-training, the FAMNet model is further trained, specifically including: The FAMNet model was trained on two RTX 2080Ti graphics processors based on the deep learning framework PyTorch, with 20 iterations and a batch size of 64. The model parameters were optimized using the Adam optimizer with a weight decay of 0.0001 to improve the FAMNet model's ability to learn and generalize surface roughness features.
4. The surface roughness detection method based on white light interference image according to claim 1, characterized in that: The S3 also includes model performance evaluation: Cross entropy loss is selected as the loss function, and accuracy, precision, recall and specificity are used as evaluation indicators of the model to evaluate and optimize the trained FAMNet model.
5. A surface roughness detection system based on white light interference image, used to perform the surface roughness detection method based on white light interference image according to any one of claims 1 to 4, characterized in that: include: An image processing module is used to obtain a sample surface roughness data set and preprocess it to obtain a training image set, wherein the training image set includes a plurality of white light interference images of the sample surface roughness; A model building and training module is used to pre-train the FAMNet model based on the training image set, extract feature information of the white light interferometer image through the feature extraction network, and enhance and fuse the feature information using the channel attention and position attention mechanisms through the fusion attention module, wherein the FAMNet model includes the feature extraction network and the fusion attention module; It is also used to further train the FAMNet model after pre-training to optimize its detection ability for different surface roughnesses, and obtain the trained FAMNet model as a surface roughness detection model; The detection module is used to input the image to be detected into the trained FAMNet model to obtain the detection result.
6. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the surface roughness detection method based on white light interference image according to any one of claims 1 to 4 is implemented.
Citation Information
Patent Citations
Method and device for detecting mid-frequency errors of large-aperture optical elements
CN108050937A
Object number determination method and device, equipment, medium and program product
CN114612402A