A metal product surface defect detection method and system based on image generation

By using image generation technology to process surface defects of metal products, standardized images are generated and multi-scale feature analysis is performed. This solves the problem of difficulty in distinguishing between minute textures and subtle defects in existing technologies, and achieves high-precision detection and segmentation of surface defects of metal products.

CN122289140APending Publication Date: 2026-06-26西航思创(陕西)自动化科技有限公司
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
西航思创(陕西)自动化科技有限公司
Filing Date
2026-03-11
Publication Date
2026-06-26

AI Technical Summary

Technical Problem

Existing technologies for detecting surface defects in metal products are prone to confusing minute textures with minor defects, leading to false positives or false negatives. It is difficult to accurately segment defect areas that conform to actual deformation, especially in areas with complex geometries.

Method used

A method for detecting surface defects in metal products based on image generation is adopted. Standardized images are generated through image preprocessing, defect style vector processing and texture comparison screening are performed to generate a diverse set of defect images, and enhanced multi-scale feature maps are generated using convolutional attention weights. Candidate region analysis and region masking are performed, and the final defect detection result is generated by combining context fusion.

Benefits of technology

It improves the training efficiency and generalization ability of the model, significantly enhances the localization accuracy of slender defects and the ability to characterize irregularly shaped defects, ensures effective response to defects of different sizes, and enhances the spatial accuracy of the segmentation mask and the refinement of defect segmentation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122289140A_ABST
    Figure CN122289140A_ABST
Patent Text Reader

Abstract

This invention relates to the field of image generation technology, and solves the technical problems in the prior art where minute textures and subtle defects are easily confused, leading to false detections or missed detections, loss of local detail information, and difficulty in accurately segmenting defect areas that conform to actual deformation. In particular, it relates to a method and system for detecting surface defects of metal products based on image generation. The method comprises the following steps: acquiring the original image of the metal product; obtaining a standardized image of the metal product through image preprocessing based on the original image; using regional feature analysis for feature extraction to improve the spatial accuracy of the segmentation mask; and using a transposed convolutional upsampling ensemble graph convolutional network for context modeling to effectively enhance the continuity of defect edges and the integrity of internal regions, significantly improving the fineness of defect segmentation, especially for defects with irregular shapes and blurred edges.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image generation technology, and in particular to a method and system for detecting surface defects in metal products based on image generation. Background Technology

[0002] Image generation is a computer technology that creates visual content through algorithms. The method for detecting surface defects of metal products based on image generation generally involves acquiring a small number of real defect images and preprocessing them. Then, data augmentation techniques such as rotation, flipping, scaling, cropping, and adding noise are used to amplify the original defect samples. The amplified images are then input into a deep learning detection model for classification and recognition, and finally, the detection results are obtained.

[0003] Existing technologies are prone to confusing minute textures with subtle defects, leading to false positives or false negatives. This can easily result in the loss of local detail information. For example, when there are highly directional long strip-shaped scratches on the surface of a metal product, and the direction of the scratches is close to the direction of the workpiece texture, it is difficult to effectively distinguish between defects and textures. This leads to frequent false alarms in the detection model in this specific scenario. Or, when there are welded tee areas with complex geometric shapes on the surface of a metal product, defects are often distributed along irregular curved surfaces, making it difficult to accurately segment the defect areas that conform to the actual deformation. Summary of the Invention

[0004] To address the shortcomings of existing technologies, this invention provides a method for detecting surface defects in metal products based on image generation. This method solves the technical problems of existing technologies, which easily confuse minute textures with subtle defects, leading to false or missed detections, loss of local detail information, and difficulty in accurately segmenting defect areas that conform to actual deformation.

[0005] To solve the above-mentioned technical problems, the present invention provides the following technical solution: a method for detecting surface defects of metal products based on image generation, the method comprising the following steps: acquiring an original image of the metal product, and obtaining a standardized image of the metal product by image preprocessing based on the original image of the metal product; Defect style vectors are processed based on standardized metal product images to generate metal surface style vectors. Texture comparison and screening are performed on the metal surface style vectors to generate a diverse set of defect images. Convolutional attention weights are generated from a diverse set of defective images to obtain a coordinate attention weight map. Based on the coordinate attention weight map, feature fusion and dimensionality reduction are performed to generate an enhanced multi-scale feature map. Candidate region analysis is performed based on the enhanced multi-scale feature map to generate a set of regions of interest. Region masking is performed based on the region of interest set and enhanced multi-scale feature map to obtain the initial segmentation mask. Context fusion processing is then performed on the initial segmentation mask to obtain the final defect detection result.

[0006] Preferably, image preprocessing based on the original image of the metal product includes: obtaining a grayscale image of the metal product by image digitization processing based on the original image of the metal product; Image region extraction is performed on grayscale metal product images to generate metal product ROI images; The size of the ROI image of the metal product is normalized to obtain a standardized image of the metal product.

[0007] Preferably, defect style vector processing based on standardized metal product images includes: performing defect masking processing on standardized metal product images to obtain potential defect distribution parameters; Defect masks are generated based on the potential distribution parameters of defects to obtain the defect mask; Extract good sample images from standardized metal product images, perform texture style vector processing on the good sample images, and generate metal surface style vectors.

[0008] Preferably, the metal surface style vector is subjected to texture comparison screening, including: obtaining a preliminary synthesized defect image by performing defect texture synthesis processing based on the metal surface style vector and defect mask; Illumination consistency fusion is performed based on the preliminary synthesized defect image, good sample image and defect mask to generate an illumination defect image; Images of lighting defects are compared and screened to generate a diverse set of defect images.

[0009] Preferably, the generation of convolutional attention weights for a diverse set of defective images includes: extracting basic feature maps from the diverse set of defective images through convolutional features; Multi-scale extraction is performed on the basic feature map to generate a multi-scale feature map; Attention weights are generated based on multi-scale feature maps to obtain coordinate attention weight maps.

[0010] Preferably, the dimension reduction process based on the coordinate attention weight map through feature fusion includes: performing weighted feature fusion based on the coordinate attention weight map and the multi-scale feature map to obtain the attention-enhanced feature map; Pyramid pooling is performed on the attention-enhanced feature map to obtain a multi-receptive-field feature map. Feature dimensionality reduction is performed on the multi-receptive field feature map to generate an enhanced multi-scale feature map.

[0011] Preferably, candidate region analysis is performed based on the enhanced multi-scale feature map, including: obtaining the anchor point feature map by anchor point feature processing based on the enhanced multi-scale feature map; Foreground classification and boundary regression are performed based on anchor point feature maps to generate candidate region scores and candidate region coordinate offset values. Candidate regions are selected based on candidate region scores and candidate region coordinate offset values ​​to generate a set of regions of interest.

[0012] Preferably, region masking processing based on the region of interest set and the enhanced multi-scale feature map includes: generating a region feature map by region feature analysis based on the region of interest set and the enhanced multi-scale feature map; Region classification and refinement are performed based on region feature maps to obtain classification probabilities and regression biases. The initial segmentation mask is obtained by performing initial masking on the region feature map.

[0013] Preferably, the initial segmentation mask is subjected to context fusion processing, including: performing context association processing based on the initial segmentation mask and the region feature map to generate context-enhanced features; A fine-grained segmentation mask is obtained by performing fine-grained masking based on context-enhanced features; The classification probability, regression offset, and fine segmentation mask are fused to obtain the final defect detection result.

[0014] This technical solution also provides an image-based metal product surface defect detection system, which includes: The preprocessing module is used to acquire original images of metal products and obtain standardized images of metal products through image preprocessing based on the original images. The diversification module is used to process defect style vectors based on standardized metal product images, generate metal surface style vectors, perform texture comparison screening on the metal surface style vectors, and generate a diversified defect image set. The multi-scale module is used to generate convolutional attention weights on a diverse set of defect images to obtain a coordinate attention weight map. Based on the coordinate attention weight map, an enhanced multi-scale feature map is generated through feature fusion and dimensionality reduction. The region module is used to perform candidate region analysis based on the enhanced multi-scale feature map and generate a set of regions of interest. The detection result module is used to perform region masking based on the set of regions of interest and the enhanced multi-scale feature map to obtain the initial segmentation mask. The initial segmentation mask is then subjected to context fusion processing to obtain the final defect detection result.

[0015] By employing the above technical solution, the present invention provides a method and system for detecting surface defects in metal products based on image generation, which has at least the following beneficial effects: 1. This invention achieves standardized conversion of digital images through industrial imaging, avoiding random errors caused by traditional sampling. It uses adaptive threshold segmentation to extract regions of interest, accurately stripping away complex backgrounds. Compared with the fixed threshold method, it has stronger robustness. By scaling all images to a uniform size through bicubic interpolation normalization, it effectively improves the training efficiency and generalization ability of the model.

[0016] 2. This invention utilizes a style generative adversarial network and adaptive instance normalization to inject style into regions guided by defect masks. This allows the generated defect images to retain the unique light reflection characteristics of metallic materials while exhibiting rich diversity in defect morphology, effectively solving the problem of simultaneously ensuring texture realism and morphological diversity. Through illumination consistency fusion, it avoids harsh splicing traces. Quality screening is performed using the initial Fraser distance score, significantly improving the overall quality of the sample set and providing high-quality data support for the training of subsequent defect detection models.

[0017] 3. This invention enables the network to simultaneously capture the detailed texture of tiny scratches and the overall structure of large rust spots by grouping feature maps along the channel dimension and performing hierarchical convolutional fusion, thereby improving the feature representation capability of small workpieces. Combined with multidimensional attention weights, the model can accurately locate the spatial position of defects and suppress interference from complex backgrounds, significantly improving the localization accuracy of slender defects. By fusing global contextual information through the hollow spatial pyramid pooling module and parallel convolutional branches, the receptive field is expanded without loss of resolution, ensuring that the model can effectively respond to defects of different sizes.

[0018] 4. This invention employs regional feature analysis for feature extraction, which improves the spatial accuracy of the segmentation mask. After generating the initial segmentation mask through transposed convolution upsampling, a graph convolutional network is introduced for context modeling, which effectively enhances the continuity of defect edges and the integrity of internal regions. By mapping the context enhancement features to a fine segmentation mask through pointwise convolution, and by integrating classification, regression, and mask information, the precision of defect segmentation is significantly improved, especially for defects with irregular shapes and blurred edges. Attached Figure Description

[0019] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings: Figure 1 This is a flowchart of a method for detecting surface defects in metal products based on image generation according to the present invention; Figure 2 This is a structural block diagram of an image-based metal product surface defect detection system according to the present invention. Detailed Implementation

[0020] To make the above-mentioned objects, features, and advantages of the present invention more apparent and understandable, the present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. This will allow for a full understanding of how the present application uses technical means to solve technical problems and achieve technical effects, and to facilitate its implementation.

[0021] Example 1: Existing technologies are prone to confusing minute textures with subtle defects, leading to false positives or false negatives and easily causing the loss of local detail information. When there are welded tee areas with complex geometric shapes on the surface of metal products, defects are often distributed along irregular curved surfaces, making it difficult to accurately segment the defect areas that conform to the actual deformation. Please refer to [reference needed]. Figure 1 This embodiment provides a method for detecting surface defects in metal products based on image generation. It significantly improves the positioning accuracy of slender defects, ensures the model can effectively respond to defects of varying sizes, and has a stronger ability to characterize irregularly shaped defects with blurred edges. The method includes the following steps: S1. Acquire the original image of the metal product. Based on the original image of the metal product, obtain a standardized image of the metal product through image preprocessing. Existing technologies often use fixed threshold segmentation to extract the target area. When dealing with metal products with diverse shapes and strong surface reflections, such as hexagonal head screws, rivets, and flat washers, the segmentation effect is unstable. It is easy to misjudge background noise or reflective bright spots as the target area, which will interfere with subsequent feature extraction. Simple linear interpolation normalization methods are prone to losing feature information of subtle defects such as scratches and rust spots, which directly affects the accuracy and recall of defect detection. To solve the above problems, the specific implementation steps are as follows: S11. Based on the original image of the metal product, a grayscale image of the metal product is obtained through image digitization. In this step, the light intensity signal received at each pixel position in the original image is first converted into a continuously changing voltage signal by a photoelectric converter. The voltage value is proportional to the light intensity. Specifically, the relationship can be described as the voltage signal equals the light intensity multiplied by the photoelectric conversion coefficient. Then, the analog voltage signal is sent to the analog-to-digital converter, and the continuous voltage value is mapped to discrete gray levels through quantization. The quantization process can be described as: the gray value of each pixel is equal to its voltage signal divided by the quantization step size and then rounded down. At the same time, system noise is inevitably superimposed. In a mathematical formalization, this process can be expressed as the gray value equals the light intensity multiplied by the photoelectric conversion coefficient, then divided by the quantization step size, then the noise term is added, and finally the integer gray value is obtained through rounding. In actual industrial imaging systems, gain adjustment and offset correction are usually introduced, that is, the gray value equals the light intensity multiplied by the gain coefficient, plus the offset, and then the quantization is completed by analog-to-digital conversion.

[0022] S12. Based on the grayscale metal product image, extract the image region to generate the metal product ROI image. In this step, firstly, traverse all possible grayscale levels and use each grayscale level as a candidate threshold to divide the image pixels into two categories: foreground (metal product) and background. For each candidate threshold, calculate the proportion of foreground pixels to the total number of pixels in the image, the proportion of background pixels, the average grayscale value of the foreground, and the average grayscale value of the background. Then, calculate the inter-class variance under the threshold. The mathematical relationship can be described as: the inter-class variance is equal to the proportion of foreground pixels multiplied by the proportion of background pixels, and then multiplied by the square of the difference between the average grayscale value of the foreground and the average grayscale value of the background. Iterate through all gray levels and find the gray level that maximizes the inter-class variance. This gray level is the optimal binarization threshold. After obtaining the optimal threshold, compare the gray value of each pixel in the original grayscale image with this threshold: if the pixel gray value is greater than or equal to the threshold, mark the pixel as foreground; otherwise, mark it as background. This generates a binary image. Next, scan all foreground pixels in the binary image and record their row and column coordinates. By comparing, obtain the minimum and maximum values ​​of the row coordinates and column coordinates. These four coordinate values ​​determine the minimum bounding rectangle of the metal product region. Finally, use these four coordinates to crop the original grayscale image and extract the pixels within the rectangular area to obtain the ROI image of the metal product.

[0023] S13. Normalize the size of the ROI image of the metal product to obtain a standardized metal product image. In this step, for each target pixel position in the output image, it is first back-mapped to the corresponding floating-point coordinate in the input image according to the scaling ratio. There are sixteen original pixels with integer coordinates in the neighborhood of the floating-point coordinate. The gray value of the target pixel is equal to the weighted sum of the gray values ​​of these sixteen original pixels. The weight of each original pixel is determined by its distance from the floating-point coordinate in the horizontal and vertical directions. The weight value is calculated by a specific polynomial basis function, which can be expressed as a cubic function of distance. Specifically, the horizontal weight and the vertical weight are calculated according to the distance in the respective directions. The product of the two directional weights is the comprehensive contribution weight of the original pixel. The gray values ​​of all sixteen pixels are multiplied by their corresponding comprehensive weights and then summed to obtain the gray value of the target pixel. This process traverses all pixel coordinates of the output image and finally generates a standardized image with a completely uniform size.

[0024] This invention achieves standardized conversion of digital images through industrial imaging, avoiding random errors caused by traditional sampling. It uses adaptive threshold segmentation to extract regions of interest, accurately stripping away complex backgrounds. Compared with the fixed threshold method, it has stronger robustness. By scaling all images to a uniform size through bicubic interpolation normalization, it effectively improves the training efficiency and generalization ability of the model.

[0025] S2. Based on standardized metal product images, defect style vectors are processed to generate metal surface style vectors. Texture comparison is performed on the metal surface style vectors to generate a diverse defect image set. Existing data augmentation methods, such as random cropping, rotation, and noise addition, tend to result in limited diversity of the augmented dataset, model overfitting, and difficulty in accurately controlling the location and category of defects. Furthermore, when processing reflective metal surfaces, the generated defects often exhibit inconsistent lighting and blurred textures. When the metal product to be inspected has a curved structure, such as the arc surface of a cylindrical head screw, the defect in the image will be deformed and have different brightness due to surface reflection. Existing technologies usually cannot accurately simulate this optical distortion, resulting in deviations between the generated defect samples and the actual distribution of defects on curved surfaces, which in turn affects the generalization ability of the detection model on actual curved workpieces. To solve the above problems, the specific implementation steps are as follows: S21. Perform defect masking processing on standardized metal product images to obtain potential defect distribution parameters. The standardized metal product images include good sample images and defect images. The defect images are used as a reference, and category classification labels are set. In this step, the defect images first undergo multiple convolution operations. Each convolutional layer multiplies the input feature map with multiple learnable convolutional kernels element-wise and sums them, then adds them to the bias term. Subsequently, a nonlinear transformation is introduced through a nonlinear activation function, and the spatial dimension of the feature map is reduced through a pooling layer. High-level semantic features are gradually extracted. After multiple convolutions and pooling, the high-dimensional feature map is flattened into a one-dimensional feature vector. The feature vector is then fed into two parallel fully connected layers: one fully connected layer outputs a mean vector, which is calculated by multiplying the input feature vector with the weight matrix of the layer, and then adding the product to the bias vector; the other fully connected layer outputs a log-variance vector or a variance vector, but with different weights and biases. In addition, the defect category label is encoded in one-hot form as conditional information, which is usually combined with intermediate features through embedding or concatenation, so that the encoding process can learn different latent distributions for different defect types. Finally, the encoder outputs two sets of parameters: the mean vector and the log-variance vector, which fully describe the probability distribution characteristics of the defect image in the low-dimensional latent space, providing a key distribution basis for the subsequent generation of defect masks through reparameterized sampling.

[0026] S22. Defect mask generation is performed based on the latent distribution parameters of the defects to obtain the defect mask. In this step, a reparameterization sampling operation is first performed to extract specific latent variables from the latent distribution. Specifically, a noisy data is randomly generated from the standard normal distribution. The noisy data is multiplied by the variance to obtain a scaled random component. Then, this random component is added to the mean. The sum of the two is the latent variable obtained by sampling. This process ensures that the gradient can be backpropagated through the random sampling nodes, so that the entire model can be trained end-to-end. After obtaining the latent variables, they are input together with the defect category label into the decoder network of the conditional variational autoencoder. The decoder consists of multiple transposed convolutional layers and upsampling layers. Its calculation process is the reverse of that of the encoder: first, the latent variables and category labels are concatenated or embedded and fused to obtain a joint feature vector. Then, the feature vectors are mapped to an initial feature map through a fully connected layer. Next, multiple transposed convolution operations are performed. Each transposed convolutional layer takes the input feature map, multiplies it element-wise with a learnable convolutional kernel, and accumulates the results to gradually restore the spatial resolution. At the same time, a non-linear activation function is introduced to enhance the expressive power. Finally, a convolutional layer and a sigmoid activation function are used to compress the output values ​​to between 0 and 1, generating a two-dimensional probability map with the same size as the original image. The value of each pixel in this probability map represents the probability that the location belongs to a defect region. By setting a threshold, such as 0.5, it is binarized to finally obtain the defect mask, where the area with a pixel value of 1 represents the defect and the area with a pixel value of 0 represents the background.

[0027] S23. Extract good sample images from standardized metal product images, process the good sample images for texture style vectors, and generate metal surface style vectors. In this step, the good sample images first pass through a pre-trained convolutional feature extractor to convert the two-dimensional image data into a one-dimensional feature vector. The convolutional feature extractor automatically learns and extracts the one-dimensional feature vector from the input image by stacking multiple convolutional layers and pooling layers, or directly expands the image pixels as input. Then, the feature vector passes through multiple fully connected layers in sequence. The computation of each fully connected layer is as follows: the input feature vector is multiplied by the weight matrix of the layer, the result is added to the bias vector, and then a non-linear activation function, such as the ReLU function, is applied for non-linear transformation. This process is repeated many times, for example, 80 times. Each time, the feature vector output from the previous layer is used as input, gradually mapping the original image features to the style space. Mathematically, the operation of a fully connected layer can be described as follows: the output data is equal to the product of the input data and the weight matrix, plus the bias value. Then, an activation function is applied to each element in the result. After multiple layers of such linear transformations and non-linear activation combinations, a fixed-dimensional output vector, namely the metal surface style vector, is finally obtained, which is usually 512-dimensional.

[0028] S24. Based on the metal surface style vector and defect mask, a preliminary synthesized defect image is obtained through defect texture synthesis. In this step, the style vector is first converted into scaling and translation coefficients for each convolutional layer through a fully connected layer. At the same time, the defect mask is used as a spatial guide map and combined with the randomly initialized feature map to determine the location of the region where the texture needs to be synthesized. After each convolutional layer of the generator, the feature map is first normalized by instance, that is, the mean and variance of each channel of each sample are calculated independently. Then, the mean of the feature map is subtracted and then divided by the standard deviation to obtain the normalized feature. Next, an adaptive instance normalization operation is performed, which multiplies the scaling coefficient provided by the style vector with the normalized feature element by element and adds the translation coefficient provided by the style vector to achieve precise control of the statistical characteristics of the feature map. This process can be described as the output feature being equal to the normalized feature multiplied by the style scaling factor plus the style translation factor. Through multiple layers of such feature transformations, the generator gradually decodes the style information into a defect region image with a realistic metallic surface texture, outputting a preliminary synthesized defect image. The discriminator receives the synthesized image output by the generator and the real defect image as input, extracts features through multiple layers of convolutional networks, and finally outputs a realism score, representing the probability that the input image is a real sample rather than a synthesized sample. The discriminator's goal is to judge the real defect image as real and the image synthesized by the generator as fake, while the generator's goal is to make the synthesized image able to deceive the discriminator and make it judge it as real. The two compete against each other and evolve together in alternating training. The generator continuously optimizes its parameters to produce more realistic defect textures, while the discriminator continuously improves its ability to distinguish between real and fake images. Ultimately, the generator can synthesize images that are difficult to distinguish from real defects. The discriminator's judgment is quantified by calculating a loss function. The judgment logic is based on the cross-entropy loss calculation formula. The cross-entropy loss is used to quantify the accuracy of the judgment: for real images, the closer the discriminator's output value is to 1, the higher the probability of it being judged as real, and the smaller the corresponding negative log loss, indicating a correct judgment. For generated images, the closer the discriminator's output value is to 0, the higher the probability of it being judged as fake, and the smaller the corresponding negative log loss, indicating a correct judgment. The overall loss value reflects the discriminator's ability to distinguish between real and fake images; the smaller the loss, the more accurate the judgment.

[0029] S25. Based on the preliminary synthesized defect image, the good sample image, and the defect mask, perform illumination consistency fusion to generate an illumination defect image. In this step, the good image and the preliminary synthesized image are first divided into regions according to the defect mask. For non-defect regions, i.e., the positions where the mask value is zero, the original pixel values ​​of the good image are directly retained. For defect regions, i.e., the positions where the mask value is one, the pixel values ​​of the corresponding positions in the preliminary synthesized defect image are used, but they need to be multiplied by an illumination enhancement factor. The illumination enhancement factor is calculated based on the reflection characteristics of the metal curved surface and is obtained by performing gradient operation on the good image. Specifically, the grayscale gradient magnitude of each pixel in the good product image is first calculated. This magnitude reflects the degree of brightness change of the metal surface at that point and is related to the angle between the surface normal and the light source direction. Then, the gradient magnitude is multiplied by a preset adjustment coefficient, and the product is added to the numerical value to obtain the final illumination enhancement factor. The adjustment coefficient is between 0.2 and 0.5. This factor has a larger value in areas with large gradient changes, such as the edge of the surface or areas with rich texture, so that the synthesized defects obtain higher brightness enhancement in these areas. Finally, the synthesized pixel value of the defect area is multiplied pixel by pixel with the illumination enhancement factor at its corresponding position to achieve illumination correction.

[0030] S26. Compare and filter the images of lighting defects to generate a diverse set of defect images. In this step: First, the images of lighting defects and real defect images are input into a classification network pre-trained on a large image dataset. This network usually contains multiple convolutional layers and pooling layers. For each input image, the network outputs a high-dimensional feature vector at a specific layer, usually the last pooling layer. Then, the mean and covariance matrix of the feature vector of the generated image set and the mean and covariance matrix of the feature vector of the real defect image set are calculated respectively, and the distance score is obtained by summing them. The score is divided into two parts. The first part is the squared Euclidean distance between the feature mean of the generated image set and the feature mean of the real image set, which is the sum of the squares after subtracting the two mean vectors element by element. The second part is the difference measure between their covariance matrices, which is the sum of the traces of the two covariance matrices and the trace of the square root of the product of twice the covariance matrices. The lower the distance score, the closer the feature distribution of the generated image is to the feature distribution of the real image, and the higher the generation quality. By comparing the score of each generated image with a preset threshold, only samples with scores below the threshold are retained, and finally a diverse defect image set is obtained.

[0031] This invention utilizes a style generative adversarial network (GAN) and a mapping network to extract metal surface texture style vectors from good product images. Adaptive instance normalization is then used to inject the style into regions guided by defect masks, enabling the generated defect images to retain both the unique light reflection characteristics of the metal material and rich diversity in defect morphology. This effectively solves the problem of simultaneously ensuring texture realism and morphological diversity. Illumination consistency fusion avoids harsh stitching marks, and quality screening using the Fraser initial distance score significantly improves the overall quality of the sample set, providing high-quality data support for the training of subsequent defect detection models.

[0032] S3. Convolutional attention weights are generated for diverse defect image sets to obtain coordinate attention weight maps. Based on the coordinate attention weight maps, feature fusion and dimensionality reduction are performed to generate enhanced multi-scale feature maps. Existing technologies based on convolutional neural networks with fixed receptive fields are difficult to adapt to defects with significant size differences at the same time. They are prone to confusion between small textures and subtle defects, leading to false detections or false negatives. Stacking single dilated convolutions often results in the loss of local detail information, which is not conducive to fine edge segmentation. When there are highly directional long strip scratches on the surface of metal products, and the scratch direction is close to the workpiece texture direction, traditional attention mechanisms only focus on the importance of channels and ignore precise location information, making it difficult to effectively distinguish between defects and textures. This leads to frequent false alarms in the detection model in this specific scenario. To solve the above problems, the specific steps are as follows: S31. Based on the diverse defect image set, a basic feature map is obtained by extracting features through convolution. In this step, a large-size convolution kernel with 7 rows and 7 columns is constructed. The convolution kernel performs operations on the input image position by position in a sliding window manner. At each window position, all weight coefficients in the convolution kernel are multiplied element by element with the pixel values ​​of the image covered by the window. All product results are summed and added to a learnable bias term to obtain the output value at that position. This process traverses the entire image to generate an initial feature response map. The feature response map is then input into the batch normalization module. Batch normalization first calculates the mean and variance of all pixel values ​​in each feature channel within a small batch of data. Then, it subtracts the mean of the corresponding channel from each feature value and divides it by the sum of the square root of the standard deviation of that channel and a very small constant to obtain the normalized feature. Next, learnable scaling and translation parameters are introduced. The normalized feature is multiplied element-wise by the scaling parameters and then added element-wise by the translation parameters to complete the linear transformation of the feature distribution. Finally, the normalized feature map is non-linearly activated by a linear rectifier unit. This unit sets all negative values ​​to zero and keeps positive values ​​unchanged. That is, the output value is equal to the larger of the input value and zero, so that the original defect image is converted into a basic feature map with a fixed number of channels.

[0033] S32. Perform multi-scale extraction on the basic feature map to generate a multi-scale feature map. In this step, the basic feature map is first evenly divided into four subsets along the channel dimension. Each subset contains the same number of feature channels. For the first set of features, a 3x3 convolution kernel is directly applied to perform convolution operation. That is, the weights of the convolution kernel are multiplied element-wise with the feature values ​​at the corresponding positions and then summed to obtain the first set of output features. For the second set of features, its original features are added element-wise with the output features of the first set. That is, the values ​​at the corresponding positions are added, and then the result of the addition is input into another 3x3 convolution kernel to obtain the second set of output features. The processing method for the third set of features is similar to that of the second set. The original features are added element-wise to the output features of the second set, and then a 3x3 convolution is performed to obtain the third set of outputs. The fourth set of features is obtained by adding the original features to the output features of the third set, and then performing a 3x3 convolution. This hierarchical connection method allows the convolutional operations of subsequent sets to integrate the feature information processed by the preceding sets, thereby gradually expanding the receptive field without significantly increasing the number of parameters. This enables the network to capture small-scale details, such as fine scratches, and large-scale structures, such as large areas of rust spots, at the same time. Finally, the four sets of output features after convolution are spliced ​​along the channel dimension, that is, combined into a whole feature map according to the channel order. This feature map is the final output multi-scale feature map.

[0034] S33. Attention weights are generated based on multi-scale feature maps to obtain coordinate attention weight maps. In this step, global average pooling is first performed on all pixel values ​​of each row in the multi-scale feature map along the height direction of the image. That is, the feature values ​​of all column positions in each row are summed and then divided by the number of columns to obtain a horizontal feature vector. This vector encodes the global response of each row. At the same time, global average pooling is performed on all pixel values ​​of each column along the width direction of the image. That is, the feature values ​​of all row positions in each column are summed and then divided by the number of rows to obtain a vertical feature vector. This vector encodes the global response of each column. Next, the feature vectors in these two directions are input into a 1x1 convolutional layer for transformation. This convolution operation multiplies the feature value at each position with the learnable convolutional kernel weights and sums the results to obtain a new feature representation. Then, the Sigmoid activation function is applied to the convolution output, which maps each output value to between 0 and 1, forming two attention weight maps in two directions, representing the importance of each row and each column in the image, respectively. Finally, the horizontal attention weight map and the vertical attention weight map are multiplied position by position, that is, the values ​​at corresponding positions in the two maps are multiplied to obtain a two-dimensional coordinate attention weight map.

[0035] S34. Perform feature weighted fusion based on the coordinate attention weight map and the multi-scale feature map to obtain the attention-enhanced feature map. In this step, the weight value at each position in the coordinate attention weight map is multiplied by the feature values ​​of all channels at the corresponding spatial position in the multi-scale feature map. This process can be described as follows: For each pixel position in the feature map, its value in each channel is multiplied by the weight value at the same position in the attention weight map. Through this position-by-position multiplication, the feature values ​​of the regions with higher attention weights, i.e., the key positions that the model judges to have potential defects, can be retained and relatively amplified, while the feature values ​​of the regions with lower attention weights, i.e., the background or irrelevant texture regions, are suppressed. The entire operation does not change the size and number of channels of the feature map, but only recalibrates the feature intensity at each spatial position.

[0036] S35. Based on the attention-enhanced feature map, pyramid pooling is performed to obtain a multi-receptive field feature map. In this step, four parallel convolution branches are first set up. The first branch uses a 1-row, 1-column ordinary convolution, i.e., a dilation rate of 1, to perform convolution operations on the input feature map. The weights of the convolution kernel are multiplied element-wise with the feature values ​​at the corresponding positions and then summed to retain fine local features. The second branch uses a 3-row, 3-column convolution kernel, but the dilation rate is set to 6, which means that each weight of the convolution kernel is sampled at a interval of 6 pixels on the feature map, thereby expanding the receptive field without increasing the number of parameters. Its calculation method is still to multiply the weights with the feature values ​​of the sampled points and then sum them. The third branch also uses a 3x3 convolution kernel with a dilation rate increased to 12, further expanding the sampling interval to capture a wider range of context. The fourth branch uses a 3x3 convolution kernel with a dilation rate of 18 to obtain a global receptive field. Meanwhile, the fifth branch performs global average pooling on the input feature map, which involves summing the feature values ​​at all locations in the entire feature map and dividing by the total number of pixels to obtain a feature vector containing global statistical information. Subsequently, it is restored to the same spatial size as the input feature map through convolution and upsampling operations, allowing global information to be fused with local information. Finally, the output feature maps of these five branches are concatenated along the channel dimension, that is, combined into a whole feature map according to the channel order. This feature map is the final output multi-receptive field feature map.

[0037] S36. Perform feature dimensionality reduction on the multi-receptive field feature map to generate an enhanced multi-scale feature map. In this step, the multi-receptive field feature map is input into a set of learnable row-and-column convolutional kernels. The size of each convolutional kernel is the same as the number of channels in the input feature map. For each spatial location in the output feature map, the calculation method is to multiply the values ​​of all channels in the input feature map at that location element-wise with the weight coefficients of the corresponding channels in the current convolutional kernel, then sum all the product results, and add them to a learnable bias term to obtain an output channel at that location. The process of calculating the number of output channels is repeated, and the number of output channels is determined by the number of convolutional kernels. Each convolutional kernel independently generates one output channel. Through this linear combination method of position-wise weighted summation, the number of channels in the input feature map is compressed to a preset low dimension, such as 256 dimensions. The entire operation does not change the height and width of the feature map, but only performs information fusion and dimensionality reduction in the channel dimension, removing redundant information and making the feature representation more compact and efficient. The final output enhanced multi-scale feature map retains the contextual information of multiple receptive fields while reducing the computational complexity of subsequent operations.

[0038] This invention achieves this by grouping feature maps along the channel dimension and fusing them through hierarchical convolution, enabling the network to simultaneously capture the detailed texture of tiny scratches and the overall structure of large-area rust spots. This effectively solves the problem of insufficient feature representation capability of traditional single-scale convolution for small workpieces such as spring washers. By combining global average pooling along the horizontal and vertical directions with multidimensional attention weights, the model can accurately locate the spatial position of defects and suppress interference from complex backgrounds, significantly improving the localization accuracy of slender defects. By fusing global contextual information through a hollow spatial pyramid pooling module and parallel convolution branches, the receptive field is expanded without loss of resolution, ensuring that the model can effectively respond to defects of different sizes.

[0039] S4. Analyze candidate regions based on the enhanced multi-scale feature map to generate a set of regions of interest. Existing technologies rely on low-level image features, which are slow to compute and have unstable recall rates. Although the anchor point mechanism based on sliding windows is fast, the size and proportion of the preset anchor point box are fixed and have poor adaptability to defects with varying shapes, which can easily generate invalid candidate boxes. To solve the above problems, the specific steps are as follows: S41. Based on the enhanced multi-scale feature map, anchor point feature map is obtained through anchor point feature processing. In this step, a set of learnable 3x3 convolutional kernels are slid across the enhanced multi-scale feature map position by position. For each local region covered by the sliding window, each weight coefficient in the convolutional kernel is multiplied element-wise with the feature value at the corresponding position in the feature map. That is, the feature value at all positions within the window is multiplied by the weight at the corresponding position of the convolutional kernel. Then, all the product results are summed and added to a learnable bias term to obtain an output value corresponding to the center position of the window. This process is executed in parallel by multiple convolutional kernels. Each convolutional kernel independently performs the above multiplication and addition operations to generate an independent output channel. The convolutional kernel traverses all spatial positions on the feature map according to the set stride. The multiplication and addition operation is repeated once every time it moves to a new position. Since the size of the convolutional kernel is 3x3 and the boundary information is usually maintained by padding operation, the height and width of the output feature map are consistent with the input feature map. Finally, the operation results of multiple convolutional kernels are combined along the channel dimension to form the anchor point feature map.

[0040] S42. Based on the anchor point feature map, perform foreground classification and boundary regression processing to generate candidate region scores and candidate region coordinate offset values. In this step, each convolutional layer contains a set of learnable 1-row, 1-column convolutional kernels. The number of convolutional kernels determines the number of output channels. At each spatial location of the anchor point feature map, the feature vector at that location is operated on with the weight matrices of the two convolutional layers respectively. Taking the foreground classification convolutional layer as an example, it contains two convolutional kernels. Each convolutional kernel is multiplied element-wise with the feature vector, that is, each component of the feature vector is multiplied with the weight at the corresponding position in the convolutional kernel. Then, all products are summed and added to the bias term corresponding to the convolutional kernel to obtain an output value at that position. Two convolutional kernels operate independently, generating two output values, representing the scores of whether the preset anchor point belongs to the background or the foreground, respectively. Similarly, the bounding box regression convolutional layer contains four convolutional kernels, each performing the same multiply-accumulate operation to generate four output values, representing the offsets of the predicted bounding box relative to the preset anchor point box in terms of the horizontal coordinate of the center point, the vertical coordinate of the center point, the width offset, and the height offset, respectively. These two convolutional layers synchronously slide and compute at all spatial locations of the anchor point feature map, finally outputting two feature maps with the same spatial size as the input feature map. One is the candidate region score, containing two scores at each spatial location, and the other is the candidate region coordinate offset value, containing four offsets at each spatial location.

[0041] S43. Select candidate regions based on candidate region scores and candidate region coordinate offset values ​​to generate a set of regions of interest. In this step, for each anchor point position on the feature map, multiple anchor boxes of different sizes and proportions are predefined. Each anchor box is determined by its center coordinates, width, and height. During the decoding process, the predicted four coordinate offset values ​​are applied to the corresponding anchor boxes. The new center point x-coordinate is equal to the x-coordinate component in the offset multiplied by the anchor box width, and the product is added to the anchor box center x-coordinate. The new center point y-coordinate is equal to the y-coordinate component in the offset multiplied by the anchor box height, and the product is added to the anchor box center y-coordinate. The new width is equal to the anchor box width multiplied by the exponent of the width component in the offset. The new height is equal to the anchor box height multiplied by the exponent of the height component in the offset. The relative offsets are converted into absolute coordinates to generate a large number of preliminary candidate boxes. Then, all candidate boxes are sorted according to the foreground score of each box in the candidate region score map. The highest-scoring candidate boxes are selected. Next, the non-maximum suppression algorithm is applied to traverse the sorted candidate boxes in turn. For the currently selected box, the intersection-union ratio (IUR) with all other candidate boxes with lower scores is calculated, which is the area of ​​the intersection region of the two boxes divided by the area of ​​the union region. If the IUR value exceeds a preset threshold, it is judged as overlapping and redundant and is removed. After the traversal is completed, the remaining candidate boxes are the final set of regions of interest.

[0042] This invention extracts anchor point features and combines them with classification and analysis using convolutional kernels of different sizes to ensure that each location can encode local contextual information while sharing underlying features. This results in high computational efficiency. When converting the predicted offset to absolute coordinates, the width and height of the anchor point box are introduced as scaling factors, enabling the offset to adapt to targets of different sizes and improving positioning accuracy. While maintaining recall, this invention significantly improves the quality of the analysis region, providing accurate input for fine segmentation and classification of defects.

[0043] S5. Based on the region of interest set and enhanced multi-scale feature map, region masking is performed to obtain the initial segmentation mask. The initial segmentation mask is then subjected to context fusion processing to obtain the final defect detection result. Existing technologies only predict based on local features and lack explicit modeling of the relationship between pixels within the region. This leads to jagged or discontinuous segmentation results at the defect edges. For small defects or defects with low contrast to the background, it is easy to miss detection or incomplete segmentation. In practical applications, when there is a welded tee area with complex geometry on the surface of metal products, the defect is often distributed along the weld or irregular curved surface. Due to the inability to effectively model the long-range dependency relationship between pixels within the region, it is difficult to accurately segment the defect area that conforms to the actual deformation. To solve the above problems, the specific implementation steps are as follows: S51. Based on the set of regions of interest and the enhanced multi-scale feature map, generate a region feature map through region feature analysis. In this step, firstly, the bounding box coordinates of each region of interest on the original image are mapped to the corresponding scale of the enhanced multi-scale feature map to obtain region coordinates in floating-point form. Then, each mapped region is divided into a preset number of grids, such as 7 rows and 7 columns, for a total of 49 grid units. For each grid unit, four sampling points are evenly set inside it. The position of each sampling point is determined by the boundary of the grid. Then, for each sampling point, based on its floating-point coordinates on the feature map, find the four neighboring integer coordinate pixels. The feature value of each neighboring pixel is multiplied by a weight coefficient. The weight coefficient is calculated using bilinear interpolation formulas based on the horizontal and vertical distances from the sampling point to the pixel. The weight equals the product of the horizontal and vertical weights, where the horizontal weight is 1 minus the difference between the horizontal coordinate of the sampling point and the horizontal coordinate of the pixel to its left. The vertical weight is similar. The weighted feature values ​​of four neighboring pixels are summed to obtain the feature value of the sampling point. Then, the feature values ​​of the four sampling points within a grid are averaged (summed and divided by four) to obtain the final feature value of that grid cell. This process iterates through all grid cells, ultimately generating a 7x7 feature map with the same number of channels as the input feature map. The above operation is repeated for each region of interest in the input set to obtain a set of fixed-size region feature maps.

[0044] S52. Based on the regional feature map, perform regional classification and refinement to obtain the classification probability and regression offset. In this step, for the input feature map, the pixel values ​​of all its channels are arranged in ascending order to form a long vector. This vector is then input into the classification fully connected layer, which contains multiple neurons. Each neuron corresponds to a defect category, including specific defect categories such as scratches, dents, and rust spots, as well as a background category, which includes the A-type nut. Each neuron performs a fully connected operation with the input vector, that is, each component of the input vector is multiplied by the corresponding weight coefficient and then summed. The bias term of the neuron is then added to obtain a raw score for the category. The raw scores for all categories are normalized using the Softmax function. This involves calculating the index value of each category's score and then dividing it by the sum of all category index values ​​to obtain the probability value for each category. The sum of all probabilities is 1. Simultaneously, the flattened feature vector is input into a fully connected regression layer containing four neurons, each corresponding to a fine-tuning offset of the bounding box: the horizontal offset of the center point, the vertical offset of the center point, the width offset, and the height offset. The calculation method for each neuron is the same: multiplying each component of the input vector by its corresponding weight, summing the results, and then adding the bias to obtain four offset values. Through the above calculations, for each candidate region, a probability vector is finally output, indicating the likelihood that the region belongs to any type of defect, along with a set of four offset values. These are used to fine-tune the position and size of the initial candidate box, thereby obtaining more accurate defect localization.

[0045] S53. Perform initial masking on the region feature map to obtain the initial segmentation mask. In this step, the region feature map is first input into one or more ordinary convolutional layers for feature transformation. Each ordinary convolutional layer extracts deeper features by multiplying the kernel weights with the local region feature values ​​element by element and summing the results. Then, the transformed feature map is input into the transposed convolutional layer. The transposed convolution operation can be understood as the inverse process of ordinary convolution: for each pixel value in the input feature map, it is multiplied with the weights of the transposed convolution kernel, and the product result is distributed to the corresponding region of the output feature map according to the stride. When the contributions of multiple input pixels overlap in the output region, these contribution values ​​are accumulated and summed to obtain the output feature map. By stacking multiple transposed convolutional layers, the spatial size of the feature map is gradually expanded, for example, from 7 rows and 7 columns upsampling to 14 rows and 14 columns, and then to 28 rows and 28 columns, finally reaching the preset mask output size, such as 896 rows and 896 columns. After each transposed convolutional layer, batch normalization and non-linear activation functions are usually followed to enhance expressive power. Finally, a 1 row and 1 column convolutional layer is used to compress the number of feature channels to 1, and a sigmoid activation function is applied to each pixel position, that is, the ratio of the exponential function of the feature value at that position to 1 is calculated, mapping the output value to between 0 and 1. This value represents the confidence probability that the pixel belongs to the defect region. The probability values ​​of all pixels are combined to form the initial segmentation mask, which has a size of 28 rows and 28 columns, with each element in the range of 0 to 1, providing a basic pixel-level segmentation basis for subsequent graph convolutional context modeling and fine mask prediction.

[0046] S54. Perform contextual association processing based on the initial segmentation mask and the region feature map to generate context-enhanced features. In this step, the initial segmentation mask and the region feature map are first concatenated along the channel dimension to form a new joint feature representation, where each pixel position contains both the original feature information and the initial segmentation probability. Then, the Euclidean distance between each pair of pixels is calculated based on the two-dimensional coordinates of all pixels in the region. For each pixel node, only the nearest neighbor nodes are retained to construct an adjacency matrix. The adjacency matrix is ​​then symmetrically normalized, that is, each element is divided by the product of the square roots of the corresponding node degree to obtain the normalized adjacency matrix. The normalized adjacency matrix and the joint feature matrix are multiplied. At this point, the feature of each node is replaced by a weighted sum of its own features and the features of all its neighboring nodes. The weights are determined by the coefficients in the normalized adjacency matrix. Then, the aggregated feature matrix is ​​multiplied by the learnable weight matrix, that is, the feature vector of each node is multiplied by the weight matrix to obtain the new features after linear transformation. Finally, a linear rectified activation function is applied to the transformation result, setting all negative values ​​to zero and keeping positive values ​​unchanged, introducing a nonlinear transformation. Through the above matrix multiplication and nonlinear activation, the features of each node are integrated with the contextual information in its local neighborhood, making the originally isolated pixel-level features spatially consistent. The final output context-enhanced feature map is consistent with the input region feature map in terms of spatial size, but the feature vector at each position encodes richer neighborhood relationships.

[0047] S55. Perform fine-grained masking based on context-enhanced features to obtain a fine-grained segmentation mask. In this step, for each spatial location in the context-enhanced feature map, which contains feature values ​​of multiple channels, a set of learnable 1-row, 1-column convolutional kernels are applied to each location. The number of channels in each convolutional kernel is the same as the number of channels in the input feature map. At the current location, each component of the feature vector is multiplied element-wise with the weight coefficient of the corresponding convolutional kernel. Then, all the product results are summed and added to a learnable bias term to obtain a scalar output value at that location. Since a single-channel fine-grained mask needs to be output, only one such convolutional kernel is needed. The convolution operation traverses all spatial locations of the feature map, generating a two-dimensional response map with the same spatial size as the input feature map. Each pixel value in the map represents the original response of that location belonging to the defect region. Then, the Sigmoid activation function is applied to each pixel in the response map, which calculates the exponent of the pixel value with the natural constant as the base, and divides it by the sum of the exponent and the number of pixels, mapping the response value to the interval between zero and one. This normalized value is the confidence probability that the pixel belongs to the defect region. The probability values ​​of all pixels are combined to form the final fine segmentation mask.

[0048] S56. The classification probability, regression offset, and fine segmentation mask are fused to obtain the final defect detection result. In this step, the classification probability vector is first compared with the probability values ​​of each category, such as scratches, dents, rust spots, and background. The category corresponding to the maximum probability is selected as the final category of the defect. This process is essentially comparing each component in the probability vector and finding the index corresponding to the maximum value. Then, the position coordinates of the initial candidate region are added to the predicted regression offset to obtain the refined bounding box: the new center point x-coordinate is equal to the initial center x-coordinate plus the x-coordinate offset, the new center point y-coordinate is equal to the initial center y-coordinate plus the y-coordinate offset, the new width is equal to the initial width multiplied by the exponent of the width offset, and the new height is equal to the initial height multiplied by the exponent of the height offset. The offset is applied to the initial bounding box through these multiplication and addition operations to obtain a more accurate location. Finally, the fine segmentation mask is directly used as the final pixel-level mask of the defect, where the value of each pixel represents the probability of belonging to the defect. The above operation is repeated for all candidate regions that pass the screening, and finally a set of detection results containing multiple defect instances is output. Each instance consists of a category label, a fine bounding box and a segmentation mask.

[0049] This invention employs regional feature analysis for feature extraction, improving the spatial accuracy of the segmentation mask. After generating an initial segmentation mask through transposed convolution upsampling, a graph convolutional network is introduced for contextual modeling, effectively enhancing the continuity of defect edges and the integrity of internal regions. By mapping the contextual enhancement features to a fine segmentation mask through pointwise convolution, and by integrating classification, regression, and mask information, the precision of defect segmentation is significantly improved, especially for defects with irregular shapes and blurred edges.

[0050] Example 2: Existing technologies are prone to confusing minute textures with subtle defects, leading to false positives or false negatives and easily causing the loss of local detail information. When there are welded tee areas with complex geometries on the surface of metal products, defects are often distributed along irregular curved surfaces, making it difficult to accurately segment the defect areas that conform to the actual deformation. Please refer to [link / reference needed]. Figure 2 The diagram shown is a structural block diagram of a metal product surface defect detection method based on image generation provided in this embodiment. The system includes a preprocessing module, a diversification module, a multi-scale module, a region module, and a detection result module. The preprocessing module is used to acquire original images of metal products and obtain standardized images of metal products through image preprocessing based on the original images. The diversification module is used to process defect style vectors based on standardized metal product images, generate metal surface style vectors, perform texture comparison screening on the metal surface style vectors, and generate a diversified defect image set. The multi-scale module is used to generate convolutional attention weights on a diverse set of defect images to obtain a coordinate attention weight map. Based on the coordinate attention weight map, an enhanced multi-scale feature map is generated through feature fusion and dimensionality reduction. The region module is used to perform candidate region analysis based on the enhanced multi-scale feature map and generate a set of regions of interest. The detection result module is used to perform region masking based on the set of regions of interest and the enhanced multi-scale feature map to obtain the initial segmentation mask. The initial segmentation mask is then subjected to context fusion processing to obtain the final defect detection result.

[0051] Those skilled in the art will understand that all or part of the steps in the methods of the above embodiments can be implemented by a program instructing related hardware. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Moreover, this application can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code, including but not limited to disk storage, CD-ROM, optical storage, etc.

[0052] The above embodiments provide a detailed description of the present invention. Specific examples have been used to illustrate the principles and implementation methods of the present invention. The descriptions of the above embodiments are only for the purpose of helping to understand the method and core ideas of the present invention. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of the present invention. Therefore, the content of this specification should not be construed as a limitation of the present invention.

Claims

1. A method for detecting surface defects in metal products based on image generation, characterized in that, The steps of this method are as follows: acquire the original image of the metal product, and obtain a standardized image of the metal product through image preprocessing based on the original image; Defect style vectors are processed based on standardized metal product images to generate metal surface style vectors. Texture comparison and screening are performed on the metal surface style vectors to generate a diverse set of defect images. Convolutional attention weights are generated from a diverse set of defective images to obtain a coordinate attention weight map. Based on the coordinate attention weight map, feature fusion and dimensionality reduction are performed to generate an enhanced multi-scale feature map. Candidate region analysis is performed based on the enhanced multi-scale feature map to generate a set of regions of interest. Region masking is performed based on the region of interest set and enhanced multi-scale feature map to obtain the initial segmentation mask. Context fusion processing is then performed on the initial segmentation mask to obtain the final defect detection result.

2. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, Based on the original image of the metal product, image preprocessing is performed, including: obtaining a grayscale image of the metal product from the original image of the metal product through image digitization; Image region extraction is performed on grayscale metal product images to generate metal product ROI images; The size of the ROI image of the metal product is normalized to obtain a standardized image of the metal product.

3. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, Defect style vector processing based on standardized metal product images includes: performing defect masking processing on standardized metal product images to obtain potential defect distribution parameters; Defect masks are generated based on the potential distribution parameters of defects to obtain the defect mask; Extract good sample images from standardized metal product images, perform texture style vector processing on the good sample images, and generate metal surface style vectors.

4. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, Texture comparison screening of metal surface style vectors includes: obtaining a preliminary synthesized defect image by performing defect texture synthesis processing based on the metal surface style vector and defect mask; Illumination consistency fusion is performed based on the preliminary synthesized defect image, good sample image and defect mask to generate an illumination defect image; Images of lighting defects are compared and screened to generate a diverse set of defect images.

5. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, Convolutional attention weight generation for diverse defect image sets includes: extracting basic feature maps from diverse defect image sets through convolutional feature extraction; Multi-scale extraction is performed on the basic feature map to generate a multi-scale feature map; Attention weights are generated based on multi-scale feature maps to obtain coordinate attention weight maps.

6. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, The dimensionality reduction process based on the coordinate attention weight map includes: performing weighted fusion of features based on the coordinate attention weight map and the multi-scale feature map to obtain the attention-enhanced feature map; Pyramid pooling is performed on the attention-enhanced feature map to obtain a multi-receptive-field feature map. Feature dimensionality reduction is performed on the multi-receptive field feature map to generate an enhanced multi-scale feature map.

7. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, Candidate region analysis is performed based on the enhanced multi-scale feature map, including: obtaining the anchor point feature map by processing the enhanced multi-scale feature map through anchor point features; Foreground classification and boundary regression are performed based on anchor point feature maps to generate candidate region scores and candidate region coordinate offset values. Candidate regions are selected based on candidate region scores and candidate region coordinate offset values ​​to generate a set of regions of interest.

8. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, Region masking based on region of interest set and enhanced multi-scale feature map includes: generating region feature map by region feature analysis based on region of interest set and enhanced multi-scale feature map; Region classification and refinement are performed based on region feature maps to obtain classification probabilities and regression biases. The initial segmentation mask is obtained by performing initial masking on the region feature map.

9. The method for detecting surface defects in metal products based on image generation according to claim 1, characterized in that, The initial segmentation mask is subjected to context fusion processing, including: performing context association processing based on the initial segmentation mask and the region feature map to generate context-enhanced features; A fine-grained segmentation mask is obtained by performing fine-grained masking based on context-enhanced features; The classification probability, regression offset, and fine segmentation mask are fused to obtain the final defect detection result.

10. A system for detecting surface defects in metal products based on image generation, as described in any one of claims 1-9, characterized in that, The system includes: The preprocessing module is used to acquire original images of metal products and obtain standardized images of metal products through image preprocessing based on the original images. The diversification module is used to process defect style vectors based on standardized metal product images, generate metal surface style vectors, perform texture comparison screening on the metal surface style vectors, and generate a diversified defect image set. The multi-scale module is used to generate convolutional attention weights on a diverse set of defect images to obtain a coordinate attention weight map. Based on the coordinate attention weight map, an enhanced multi-scale feature map is generated through feature fusion and dimensionality reduction. The region module is used to perform candidate region analysis based on the enhanced multi-scale feature map and generate a set of regions of interest. The detection result module is used to perform region masking based on the set of regions of interest and the enhanced multi-scale feature map to obtain the initial segmentation mask. The initial segmentation mask is then subjected to context fusion processing to obtain the final defect detection result.