A sa-cnn measurement model construction and grinding screw curved surface roughness measurement method
By constructing an SA-CNN measurement model and combining image acquisition and data augmentation, the problems of large measurement errors and cumbersome operation of screw surface roughness in existing technologies have been solved, realizing fast and accurate measurement of screw curved surface roughness and improving the convenience and accuracy of measurement.
Patent Information
- Application Number
- CN202311109596.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Priority Date
- 2023-08-24
- Filing Date
- 2023-08-31
- Publication Date
- 2026-01-02
- Estimated Expiration
- 2043-08-31
AI Technical Summary
Existing roughness measurement methods suffer from large measurement errors, limited measurement objects, and restricted measurement environments, making it difficult to meet the numerical measurement needs of screw surface roughness. In particular, the measurement accuracy of the surface roughness of the curved screw surface after belt grinding is poor and the operation is cumbersome.
An SA-CNN measurement model is constructed. Through image acquisition and data augmentation, and by combining self-attention layers and dropout layers, the training of the convolutional neural network is improved, enabling fast and accurate measurement of the surface roughness of the screw. Self-attention layers are used to improve the model's generalization ability, dropout layers are used to prevent overfitting, and the GeLU activation function is used to enhance nonlinear modeling capabilities.
It enables rapid and accurate measurement of screw surface roughness, improving the convenience and accuracy of measurement. The prediction accuracy of the SA-CNN model is superior to that of the basic CNN and VGG-16.
Smart Images

Figure CN117151168B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of roughness measurement, in particular to a method for measuring the roughness of a screw surface by collecting images to make a SA-CNN measurement model. BACKGROUND
[0002] As an important transmission element, screw plays an important role in mechanical engineering and transportation. In recent years, the demand for screw in the oil drilling, military, equipment transportation and other industries is increasing. The surface roughness of screw directly affects the working performance and reliability of screw rotor, so the accuracy, efficiency and reliability of roughness measurement are very important. Therefore, a surface roughness measurement method is needed to quickly and accurately obtain the roughness value of the processed screw.
[0003] The existing roughness measurement methods mainly include contact profilometer and non-contact measurement method based on machine vision, which have the problems of large measurement error, single measurement object and limited measurement environment. At the same time, the existing roughness measurement method for grinding screw surface has poor measurement accuracy and complicated operation, which cannot meet the demand of screw surface roughness measurement. Therefore, a new grinding screw surface roughness measurement method based on SA-CNN model is proposed. SUMMARY
[0004] The present application provides a grinding screw surface roughness measurement method based on image collection, which can quickly obtain the roughness value of the screw workpiece surface image and improve the accuracy and convenience of surface roughness measurement.
[0005] To achieve the above purpose, the present application provides the following technical scheme: a SA-CNN measurement model construction method, characterized by comprising a SA-CNN measurement model and a data set making.
[0006] The steps of making the SA-CNN measurement model are as follows:
[0007] S1, determine the initial structure of the network, including convolution layer, pooling layer, full connection layer and activation layer, and preliminarily test the model effect;
[0008] S2, add corresponding self-attention layer and discard layer hierarchy to improve the training effect of the network model;
[0009] S3, according to the network structure determined in S2, train the picture sample, take the error function of the predicted value and the actual value as the model evaluation standard, adjust the network layer hyperparameters until the error function reaches the minimum error standard of the model measurement;
[0010] S4, output the trained model, input the surface image to be measured into the model to obtain the corresponding roughness value, and complete the measurement;
[0011] The data set is made as follows:
[0012] 1) image sample acquisition is performed;
[0013] 2) the obtained surface image is subjected to data enhancement;
[0014] 3) the obtained surface image is subjected to pretreatment;
[0015] 4) the data set is made and brought into the convolutional layer of the SA-CNN measurement model.
[0016] Compared with the prior art, the method has the beneficial effects that:
[0017] The method constructs a SA-CNN model, improves the phenomena of slow training speed, overfitting, large training result error and the like in the training of the convolutional neural network by adding network layers, and can quickly and accurately measure the surface roughness of a workpiece under the given measurement sample condition. A sand belt grinding screw surface roughness measurement method is made, and the measurement accuracy of the roughness is ensured.
[0018] The average error of the prediction data of the three groups of methods can be compared to obtain the accuracy of the prediction performance, and the prediction accuracy of the SA-CNN is higher than that of the basic CNN and VGG-16, and the accuracy is stronger. BRIEF DESCRIPTION OF DRAWINGS
[0019] Figure 1 It is a flowchart of the whole process of the measurement model.
[0020] Figure 2 It is an iteration loss comparison chart.
[0021] Figure 3 It is a prediction result comparison chart. DETAILED DESCRIPTION
[0022] 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.
[0023] The present application provides a technical solution: a SA-CNN measurement model construction method, comprising making a SA-CNN measurement model and a data set;
[0024] The steps of making the SA-CNN measurement model are as follows:
[0025] S1, determine the network initial structure, including convolution layer, pooling layer, full connection layer and activation layer, and preliminarily test the model effect;
[0026] S2, add corresponding self-attention layer and discard layer hierarchy, improve the network model training effect;
[0027] S3, according to the network structure determined in S2, train the picture sample, take the error function of the predicted value and the actual value as the model evaluation standard, adjust the network layer hyperparameters until the error function reaches the minimum error standard of the model measurement;
[0028] S4, output the trained model, input the surface image to be measured into the model, get the corresponding roughness value, and complete the measurement;
[0029] The data set is made as follows:
[0030] 1) image sample acquisition;
[0031] 2) data enhancement is performed on the obtained surface image;
[0032] 3) pre-process the obtained surface image;
[0033] 4) make a data set and bring it into the convolution layer of the SA-CNN measurement model.
[0034] The convolution layer collects information on the picture by rolling the batch filter on the picture, that is, the image and the convolution kernel are convolved, and the feature value can be obtained;
[0035] The convolution kernel in the neural network represents the corresponding weight, and the calculation formula is:
[0036] output = ∑ i w i x i +b
[0037] In the formula, b is the bias, output is the convolution layer output, and wi represents the weight related to the corresponding input element.
[0038] The pooling layer is used to reduce the size of the feature map, extract key features and reduce the amount of calculation, and the maximum pooling retains the maximum feature value of each region, and the output image size obtained is:
[0039] N = (W-F+2P) / S+1
[0040] In the formula, W is the width of the input image, F is the pooling window size, that is, FxF, P is the padding value, and S is the step; when the obtained N is not an integer, the down rounding (the maximum integer less than or equal to itself) is used.
[0041] The full connection layer connects each neuron with all neurons of its previous layer, integrating local information with class discriminability in the convolutional layer or the pooling layer.
[0042] The activation layer provides the network with nonlinear modeling capability by converting the input signal through a nonlinear activation function, so that the neural network can learn and represent more complex patterns and relationships; the nonlinear activation function is a GeLU activation function, which calculates the output value by bringing the input value into the defined function expression, and its calculation formula is:
[0043]
[0044] The batch normalization layer normalizes all data in this layer. For each input, the batch normalization layer will calculate the mean and variance, and normalize the input data; this will make the mean of the data close to 0 and the standard deviation close to 1, thereby speeding up the training process and improving the performance of the model, and the batch data is processed using the following formula:
[0045]
[0046] where x i+1 represents the data after batch normalization, μ B represents the mean of this batch of samples, σ B represents the sample variance; batch normalization stretches and shifts the data (i.e., parameters a and b).
[0047] The dropout layer prevents the neural network from over-relying on the relationship between specific neurons by randomly discarding the output of a portion of neurons during the training process, thereby improving the generalization ability of the model.
[0048] The self-attention layer calculates the similarity between each image feature vector in the input sequence and other feature vectors, and then assigns different weights to each element according to the similarity score; in this way, each element can be weighted and aggregated according to the importance of other elements to obtain a comprehensive representation, and the calculation process is as follows:
[0049] (1) The input sequence is transformed through three matrix transformations to obtain three feature matrices: query q, key k, and value v matrices;
[0050] (2) For each query vector q, calculate the similarity score with all key vectors k, and use the dot product attention method to calculate the score;
[0051] (3) Normalize the score to get the attention weight;
[0052] (4) using attention weights to weight sum the value vector v to obtain an aggregated representation; the calculation process formula is as follows:
[0053]
[0054] In the formula, dk represents the dimension of the vector; softmax is an operation for normalizing scores, and T represents matrix transposition.
[0055] The principle of the SA-CNN model for roughness measurement is as follows: first, input image data as the input of the network, each input image is represented by a three-dimensional array, including the width (256), height (256) and channel number (1, the camera output is a gray image) of the image; the convolution layer is the core layer in the SA-CNN, which is composed of multiple convolution kernels, each convolution kernel can be regarded as a local feature detector, which extracts features at different positions through a sliding window convolution operation, each convolution kernel will generate a feature map, and the parameters of the convolution kernel will automatically learn the image features through the training process; after the convolution operation, the activation layer will perform a nonlinear transformation on the output of the convolution layer to provide the network with nonlinear learning ability, so that the neural network can learn and represent more complex patterns and relationships, a GeLU activation function is used, the output value is calculated by bringing the input value into the defined function expression, which is a smooth activation function; the pooling layer is used to reduce the dimension of the feature map and retain important feature information, the maximum value in a given region is used as the output by using maximum pooling, which retains the prominent features of the image and reduces unimportant details; the dropout layer is a regularization technique used to prevent overfitting, a part of neurons are randomly set to 0 during the training process, which helps the model to better generalize new data and improve the robustness of the model; the self-attention layer calculates the relative importance between different elements and can establish long-distance dependencies in the feature matrix, and related information is concentrated in the required place, which has the characteristics of strong flexibility and parallel computing, can effectively capture semantic information and context relationships, and improve the performance of the model; the fully connected layer flattens the output of the previous layer and connects it with the weight, which converts the feature mapping of the previous layer into a higher level feature representation, converts and extracts the features, the fully connected layer usually contains multiple neurons, each neuron is connected with all the neurons of the previous layer; the output layer selects a leakyRelu function as the activation function to convert the converted feature mapping into the final prediction result; the trained model that meets the standard of the loss function is saved for subsequent measurement.
[0056] Referring to Figure 1 The application also provides a method for measuring the roughness of a ground screw curved surface, comprising an image sample acquisition and a SA-CNN measurement model construction method.
[0057] A method for measuring the surface roughness of a grinding screw is established using the acquired image samples and the SA-CNN measurement model construction method, and the roughness value is obtained.
[0058] Save the trained surface roughness measurement model of the grinding screw. Then, input the image of the surface to be measured into the model to obtain the corresponding roughness value, thus achieving the measurement objective. The specific method is as follows:
[0059] (1) Obtain the network input dataset: Roughness measurement was performed at the calibrated interval of 2 minutes of grinding. The TR200 profile measuring instrument was used, and the average value of 3 measurements was taken at each position. The CCD camera was used to take pictures of the corresponding positions of the screw roughness measurement to obtain the dataset of the grinding surface.
[0060] (2) Data augmentation is performed on the obtained surface images. To increase the generalization ability and robustness of the model, methods such as rotation, scaling, cropping, flipping, and interpolation are used to augment the sample images.
[0061] (3) The obtained surface image is preprocessed. First, contrast enhancement is performed using the Adaptive Histogram Equalization (AHE) algorithm, which provides good contrast enhancement while preserving image details and features. The calculation formula is as follows:
[0062] Calculate the cumulative histogram for each block:
[0063]
[0064] Calculate the histogram equalization transformation function:
[0065]
[0066] Applying the histogram equalization transformation function:
[0067] b eq (x,y)=T(f(x,y))
[0068] Where k represents the current gray level, h(i) represents the number of pixels at gray level i, L represents the number of gray levels, and M and N represent the width and height of the block, respectively. eq (x,y) represents the enhanced pixel value of pixel (x,y) in the block, and f(x,y) represents the original pixel value of pixel (x,y) in the block. Using the above calculation formula, histogram equalization is performed independently on each block, achieving local contrast enhancement of the image.
[0069] The image is enhanced in definition by unsharp masking, i.e. sharpening, by blurring the original image through Gaussian filtering to create a blurred image, enhancing the contrast of edges according to the difference between the blurred image and the original image, improving the definition of the image, and the calculation formula is as follows:
[0070] y(n,m) = x(n,m) + λz(n,m)
[0071] Where x(n,m) is the input image, y(n,m) is the output image, z(n,m) is the correction signal, and λ is a scaling factor that controls the enhancement effect.
[0072] Finally, the data image is normalized by using MinMax Scaling to preserve the information of the original image and only map the pixel value from the original range (0-255) to the new value range (0-1), and the calculation formula is as follows:
[0073]
[0074] Where X norm is the normalized data, X is the original data, X max is the maximum value in the original data, and X min is the minimum value in the original data.
[0075] Since the original image size is 1280x960, in order to reduce the computational complexity and improve the performance of the model, the input image needs to be reduced. The experimental results show that the size of 256x256 is most suitable for the constructed network, and the bicubic interpolation method is used for image reduction. The principle is based on bilinear interpolation on the nearest 16 grid points, and gradient information is used for more accurate estimation, and the calculation process is as follows:
[0076] In the nearest 16 grid points to the interpolation point (x,y), for each grid point (x ij ,y ij ), the interpolation weight w ij is calculated:
[0077] w ij = f(x ij ,y ij )·g(|x-x ij |)·g(|y-y ij |)
[0078] According to the interpolation weight w ij , the interpolation result f(x,y) is calculated:
[0079] f(x,y) = ∑w ij
[0080] (4) Construct the network infrastructure, define the hierarchy of the network, including convolutional layers, pooling layers, fully connected layers, activation function layers, preliminary test model effect, add corresponding self-attention layers, dropout layers and other hierarchical structures, and improve the network model training effect. First, the convolutional layer convolves the input image through the convolution kernel to obtain the feature map; a batch normalization layer is added after the convolutional layer to normalize each batch of input data, so that the data has a similar distribution in each feature dimension, accelerating the model training, improving stability and improving convergence; then use the activation function GeLU to perform nonlinear transformation on the feature map to enhance the model's expression ability; add a max pooling layer to retain the prominent features of the image while reducing the dimension of the feature map, reducing the number of parameters to avoid overfitting; a dropout layer is added after each convolutional layer to randomly set a portion of neurons to 0 during training, helping the model better generalize new data and improve the model's robustness; then add a self-attention mechanism layer to weight the information at each position in the input feature map to better capture the dependencies between different positions. It not only captures global dependencies, but also learns the importance weights of each position relative to other positions, better modeling long-range dependencies in the feature map, thereby improving model performance; the fully connected layer can learn the appropriate feature representation for the task by weighting and nonlinearly transforming the input data, and provide higher-level input for subsequent layers; finally, the output layer selects the leakyRelu function as the activation function to convert the transformed feature map into the final prediction result and calculate the loss evaluation indicator of the output prediction result.
[0081] (5) According to the network structure determined in step (4), the training effect is compared with the actual roughness value, and the value of the loss function is calculated. The mean square error (MSE), mean absolute error (MAE) and root mean square error (RMSE) are used as the loss function, and the network layer hyperparameters are adjusted until the error function reaches the minimum error standard of the model measurement.
[0082] (6) Save the trained network model, and in the future only need to input the image of the surface to be measured into the model to obtain the corresponding roughness value to achieve the measurement purpose.
[0083] Embodiment
[0084] According to the screw synchronous grinding device, the screw abrasive belt grinding surface test experiment task is implemented. The factors affecting the surface roughness of the screw include workpiece speed V g , abrasive belt speed V s , abrasive belt tension F s , grinding pressure F mThe roughness values were measured every 2 minutes and the screw surface images were taken at the corresponding positions by grinding for 20 minutes for each experimental group.
[0085] (1) The image samples and roughness values were obtained to prepare the network input data set. Some of the experimental data were arranged as shown in Table 1:
[0086] Table 1 Experimental data
[0087]
[0088] (2) The network structure and parameters were adjusted, and the network hierarchy was perfected, including convolutional layers, pooling layers, fully connected layers, and activation function layers. The hyperparameters were adjusted according to the training effect, the learning rate was set to 0.0001, the batch size was set to 32, the regularization parameter was set to 0.4, the number of heads of the self-attention mechanism layer was set to 4, and the number of iterations was set to 30000.
[0089] (3) According to the set parameters and experimental data, the SA-CNN was used for prediction, and the training results obtained were compared with the classic CNN model and VGG-16 model. Part of the roughness comparison results are shown in Figure 2 , the prediction model loss decline curve comparison is shown in Figure 3 , the SA-CNN model has faster convergence speed and smaller convergence value, indicating that it has good stability and generalization ability, and the specific prediction error values are shown in Table 2.
[0090] Table 2 Comparison of prediction error of three methods
[0091]
[0092] By comparing the average error of the training and prediction data of the three methods, it can be concluded that the accuracy of the prediction performance is high, and the average error of the SA-CNN is lower than that of the VGG-16 and the basic CNN, and the accuracy is stronger.
[0093] (4) The above model is saved for subsequent screw rotor surface roughness measurement.
[0094] In summary, the method can quickly measure the surface roughness of the screw workpiece by taking images, and has high accuracy.
Claims
1. A method for constructing a SA-CNN measurement model, characterized in that: It comprises making a SA-CNN measurement model and a data set; The steps of making the SA-CNN measurement model are as follows: S1, determining the initial structure of the network, including the convolution layer, the pooling layer, the full connection layer and the activation layer, and preliminarily testing the model effect; S2, adding the corresponding self-attention layer and the dropout layer hierarchy to improve the network model training effect; S3, training the picture sample according to the network structure determined in S2, taking the error function of the predicted value and the actual value as the model evaluation standard, and adjusting the network layer hyperparameters until the error function reaches the minimum error standard of the model measurement; S4, outputting the trained model, inputting the surface image to be measured into the model to obtain the corresponding roughness value, and completing the measurement; The steps of making the data set are as follows: 1) image sample acquisition; 2) data enhancement on the obtained surface image; 3) preprocessing of the obtained surface image; 4) making a data set and bringing it into the convolution layer of the SA-CNN measurement model; The activation layer converts the input signal through a nonlinear activation function to provide the network with nonlinear modeling capability, so that the neural network can learn and represent more complex patterns and relationships; the nonlinear activation function is a GeLU activation function, which calculates the output value by bringing the input value into the defined function expression, and the calculation formula is as follows: ; The batch normalization layer normalizes all data in the layer, and for each input, the batch normalization layer will calculate the mean and variance and normalize the input data; this will make the mean of the data close to 0 and the standard deviation close to 1, thereby speeding up the training process and improving the performance of the model, and the batch data is processed using the following formula: ; wherein denotes the data after batch normalization, denotes the mean of this batch sample, denotes the sample variance; batch normalization does a stretch and shift (i.e. parameters a and b) to the data; The dropout layer prevents the neural network from over-relying on the relationship between specific neurons by randomly discarding the output of a portion of neurons during the training process, thereby improving the generalization ability of the model; The self-attention layer calculates the similarity between each image feature vector in the input sequence and other feature vectors, and then assigns different weights to each element according to the similarity score; in this way, each element can be weighted and aggregated according to the importance of other elements to obtain a comprehensive representation, and the calculation process is as follows: (1) the input sequence is transformed by three matrixes to obtain three feature matrices: query q, key k and value v matrix; (2) for each query vector q, calculate the similarity score with all key vectors k, and use dot product attention to calculate the score; (3) normalize the score to obtain the attention weight; (4) use the attention weight to perform weighted summation on the value vector v to obtain the aggregated representation; The calculation process formula is as follows: ; where d k denotes the dimension of the vector; softmax is an operation that normalizes scores; and T denotes matrix transpose.
2. The SA-CNN measurement model construction method of claim 1, wherein: The convolution layer collects information on the picture through a batch filter rolling on the picture, that is, the image and the convolution kernel are convolved to obtain the feature value; The convolution kernel in the neural network represents the corresponding weight, and the calculation formula is as follows: ; In the formula, b is the bias, output is the convolution layer output, and wi represents the weight related to the corresponding input element.
3. The SA-CNN measurement model construction method of claim 1, wherein: The pooling layer adopts maximum pooling to reserve the maximum feature value of each region in order to reduce the size of the feature map, extract key features and reduce the amount of calculation, and the size of the output image obtained is: ; In the formula, W is the width of the input image, F is the size of the pooling window, that is, FxF, P is the padding value, and S is the step size; when the obtained N is not an integer, the down rounding (less than or equal to the maximum integer of itself) is used.
4. The SA-CNN measurement model construction method of claim 1, wherein: The full connection layer is fully connected with all neurons of the previous layer, and integrates the local information with class distinction in the convolution layer or the pooling layer.
5. A method of measuring surface roughness of a ground screw curve surface, characterized by: The method comprises image sample acquisition and the SA-CNN measurement model construction method according to any one of claims 1-4. A method for measuring the surface roughness of a ground screw curved surface is established by using the acquired image sample and the SA-CNN measurement model construction method, and the roughness value is obtained. The trained measurement model of the surface roughness of the ground screw curved surface is saved, and subsequently, the surface image to be measured is input into the model, so that the corresponding roughness value is obtained, and the measurement purpose is achieved.
Citation Information
Patent Citations
MOOCs science prediction model construction method based on attention mechanism
CN116028861A
Method, apparatus and system for managing machine learning model
WO2022095523A1