Industrial finished product microdefect detection method based on generative adversarial network
By constructing a generative adversarial network that includes a geometric structure transformation module and a topological structure analysis module, the problems of insufficient generation capability and explicit expression of topological structure in existing technologies for micro-defect detection are solved, high-precision micro-defect detection and classification are achieved, and the recognition capability and stability of the detection system are improved.
Patent Information
- Application Number
- CN202510924991.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-04
- Publication Date
- 2025-10-10
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing methods for detecting micro-defects in industrial finished products have deficiencies in terms of controllability of generation capabilities, geometric modeling resolution, explicit expression of topological structures, and coordination with training objectives, making it difficult to achieve high-precision and explainable micro-defect detection and classification.
A generator network consisting of a geometric structure transformation module and a discriminator network consisting of a topological structure analysis module are constructed. Through adversarial structure training, defect image modeling, regional connectivity structure extraction and type label prediction are achieved. Combining image acquisition, network training, inference output and classification judgment, a complete detection process is formed.
It improves the ability to accurately model the spatial position, structural morphology and type labels of micro-defect areas, enhances the recognition ability and classification accuracy of the detection system in complex backgrounds, and realizes a closed-loop detection solution from data acquisition to structured reasoning.
Smart Images

Figure CN120766029A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of image intelligent processing and industrial quality control, and particularly relates to an industrial finished product micro-defect detection method based on a generative adversarial network. BACKGROUND
[0002] With the development of intelligent manufacturing and machine vision, the industrial product quality detection link is gradually evolving from traditional manual visual inspection to image recognition and automatic detection system driven by deep learning. Image processing technology can quickly complete defect detection, marking and classification tasks without contacting the workpiece by extracting features, pattern matching and classification judgment from the surface image of the industrial finished product, significantly improving the detection efficiency and consistency. Currently, deep learning has become the mainstream technology path in this field, among which convolutional neural networks, semantic segmentation networks and target detection models are widely used in surface defect detection, position positioning and defect attribute recognition tasks, forming a relatively mature technical system.
[0003] However, for industrial finished products with inconspicuous surface microstructure features, strong texture interference or variable defect morphology, the existing detection methods based on discriminative models still have certain limitations. First, traditional convolutional structures are prone to feature expression ambiguity when facing non-rigid deformation, complex lighting and occluded background, resulting in insufficient sensitivity to small cracks, depressions, spots and other fine-grained defects. Second, most existing methods rely on a large amount of data with accurate pixel-level annotations for training, which has high annotation cost, weak generalization ability, and unstable performance when there is shape diversity in the defect area. In addition, the fixed structure of convolutional neural networks makes it difficult to adapt to the significant differences in spatial distribution and topological structure of different types of defects, and the model often lacks explicit modeling capability for high-order graph topological elements such as "structural connectivity", "boundary morphology" and "hollow area".
[0004] In recent years, generative adversarial networks (GAN) as a deep learning structure with image synthesis and distribution alignment capabilities have been introduced into image enhancement, anomaly detection and unsupervised representation learning in multiple scenarios. GAN builds an adversarial relationship between the generator and the discriminator, so that the generator learns a high-dimensional mapping consistent with the distribution of real images under the feedback of the discriminator, thereby showing high fidelity and diversity in defect image synthesis and simulation. In the task of industrial surface defect detection, some studies have attempted to use GAN to generate defect versions of normal images and compare them with real defect images to find abnormal areas, and some methods also combine semantic segmentation structures for defect area positioning. However, most of these methods still remain at the level of overall image modeling and do not deeply depict the joint relationship between the geometric deformation, spatial topological structure and type attributes of the defect area, resulting in insufficient detection granularity, inconsistent classification results with actual defect patterns, and serious impact on model explainability and engineering deployment feasibility.
[0005] In this context, there is still a lack of a complete detection framework that integrates geometric algebraic modeling capabilities, topological structure analysis capabilities, and controllable generation mechanisms to achieve accurate synthesis, structural deconstruction, and type classification of micro-defect regions with limited input images. In particular, existing GAN structures mostly use standard convolutional decoding paths, lacking support for spatial position encoding in generated images, defect control vector guidance, and dynamic modeling of affine transformations. Discriminator structures generally rely on global image discrimination or patch-based sub-region discrimination, without introducing explicit topological analysis modules to extract pixel-level connectivity features and quantitative indicators of void structures, making it difficult to support regional saliency modeling at the micro-defect level. At the same time, current mainstream training methods still use a single image-level adversarial loss function, without considering the joint optimization mechanism between defect intensity, structural connectivity, and classification labels, resulting in difficult convergence of model training or poor robustness.
[0006] In summary, existing methods for detecting surface defects in finished industrial products still have significant deficiencies in terms of controllability of generation capabilities, geometric modeling resolution, explicit expression of topological structures, and coordination of training objectives. These deficiencies are unable to meet the requirements for high-precision, interpretable micro-defect detection and classification tasks. Therefore, it is urgent to propose a generative adversarial network architecture with a geometric structure transformation mechanism, topological feature perception capabilities, and a multi-output joint optimization strategy. This architecture can accurately model and identify tiny defect areas in terms of spatial location, structural morphology, and type labels, and support a complete closed-loop processing flow during the training and inference stages, thereby improving the detection capabilities and model stability of industrial vision systems in practical applications.
[0007] Therefore, how to provide a method for detecting micro-defects in industrial finished products based on generative adversarial networks is an urgent problem that those skilled in the art need to solve. Summary of the Invention
[0008] One purpose of the present invention is to propose a method for detecting micro-defects in industrial finished products based on a generative adversarial network. The present invention constructs a generator network including a geometric structure transformation module and a discriminator network including a topological structure analysis module, and jointly realizes the modeling of defect images, regional connectivity structure extraction and type label prediction. It describes in detail the complete process from image acquisition, network training, inference output to mask generation and classification judgment, and has the advantages of strong structural modeling ability, high fine-grained recognition ability and strong interpretability of detection results.
[0009] According to an embodiment of the present invention, a method for detecting micro-defects in industrial finished products based on a generative adversarial network includes the following steps:
[0010] S1. Collect high-resolution images of the surface of industrial finished products and construct a dataset containing normal images and defect images;
[0011] S2. Encode the training image, extract the image feature vector, and concatenate it with the defect type vector as input to the generator network containing the geometric structure transformation module. The generator network outputs the defect candidate image;
[0012] S3. Input the defect candidate image into the discriminator network including the topological structure analysis module. The discriminator network outputs the authenticity judgment result, structural connectivity feature index and defect type prediction label;
[0013] S4, an adversarial structure based on the generator network and the discriminator network, using image datasets for joint training, and updating the generator network parameters and the discriminator network parameters through backpropagation;
[0014] S5. Input the image to be detected into the trained generator network and discriminator network to generate the corresponding defect candidate image, structural connectivity feature index and defect type prediction label;
[0015] S6. Generate a defect probability map based on the defect candidate image and the structural connectivity feature index, further generate a defect saliency map and a binary defect mask, and locate the spatial position of the defect area in the original image;
[0016] S7. Combine the defect type prediction label, defect saliency map and binary defect mask to output the micro-defect detection results and classification results.
[0017] Optionally, the geometric structure transformation module includes an image encoding unit, a geometric algebra processing unit, and an image decoding unit:
[0018] The input of the image encoding unit is the training image, and the output is the image feature vector;
[0019] The input of the geometric algebra processing unit is the image feature vector and the defect type vector, and it performs a combination of rotation transformation, scaling transformation and affine transformation to output an intermediate feature map;
[0020] The input of the image decoding unit is the intermediate feature map, and the output is the defect candidate image.
[0021] Optionally, the topology structure analysis module includes a topology feature extraction unit and a topology index calculation unit:
[0022] The input of the topological feature extraction unit is the defect candidate image, and the output is the structural connectivity feature;
[0023] The input of the topological index calculation unit is the structural connectivity feature, and the output is the structural connectivity feature index and the defect type prediction label.
[0024] Optionally, the S1 specifically includes:
[0025] S11. Deploy image acquisition devices on industrial production lines to capture high-resolution images of the surfaces of industrial finished products;
[0026] S12, performing deduplication and brightness normalization processing on the collected image to unify the lighting conditions and background texture of the image;
[0027] S13, labeling the image, and dividing the image into a normal image and a defective image according to whether the image contains a defective area;
[0028] S14, constructing a corresponding defect mask for each defect image to indicate the spatial position of the defect area;
[0029] S15. The normal images, defect images and corresponding defect masks are uniformly organized into an image dataset as training inputs for the generator network and the discriminator network.
[0030] Optionally, the S2 specifically includes:
[0031] S21. Each training image in the image dataset is input into the image encoding unit to extract the image feature vector. The image encoding unit is composed of a multi-layer convolutional neural network and outputs an image feature tensor f with a dimension of C×H×W. x , where C represents the number of channels, H and W represent the height and width of the feature map respectively;
[0032] S22. Construct a defect type vector, which is denoted as v d =[d1,d2,,d n ], where d i represents the control factor of the i-th defect, and n represents the total number of defect categories;
[0033] S23, image feature tensor f x Flatten and map to a one-dimensional image feature vector f x ', and with the defect type vector v d Spliced into a combined vector z = [f x ',v d ];
[0034] S24. Construct a geometric transformation activation function based on GELU:
[0035]
[0036] Where x is the input real number, and tanh represents the hyperbolic tangent function;
[0037] S25, input the combined vector z into the geometric structure transformation module in the generator network, and the geometric structure transformation module transforms the two-dimensional space position vector p = [x1, x2] T Perform a combined transformation:
[0038]
[0039] wherein, T(p) represents a transformed position vector, p is a two-dimensional coordinate sub-vector in the input vector, W1, W2 are learnable transformation matrices, b1, b2 are learnable bias vectors, is a geometric transformation activation function, and σ represents an output control function;
[0040] S26, input the transformed intermediate feature map to an image decoding unit, and the image decoding unit generates a defect candidate image by using a deconvolution structure, wherein the defect candidate image has the same size as the input image.
[0041] Optionally, the S3 specifically includes:
[0042] S31, input the defect candidate image to a discriminator network comprising a topological structure analysis module, and the topological structure analysis module comprises a topological feature extraction unit and a topological index calculation unit;
[0043] S32, the topological feature extraction unit performs structural analysis on the defect candidate image to extract a topological feature vector v t =[c, h, e], wherein c represents the number of connected regions identified based on the eight-neighborhood rule, h represents the number of hollow regions surrounded by high-intensity pixels, and e represents the number of closed contours extracted by an edge detection algorithm;
[0044] S33, the topological index calculation unit calculates a structural connectivity feature index s
[0045] s t =α1c+α2h+α3e;
[0046] wherein, s t is the structural connectivity feature index, and α1, α2, α3 are preset weight coefficients;
[0047] S34, the topological index calculation unit inputs the topological feature vector to a defect type prediction branch, and outputs a defect type prediction label y d through a classification network;
[0048] S35, the discriminator network outputs a authenticity discrimination result y r , the structural connectivity feature index s t , and the defect type prediction label y d , wherein y r represents whether the defect candidate image is derived from a real defect image in the image data set.
[0049] Optionally, the S4 specifically includes:
[0050] S41, select normal images and defect image samples from the image data set, input them into the generator network and the discriminator network respectively, generate defect candidate images, and output authenticity discrimination results, structure connectivity feature indicators and defect type prediction labels by the discriminator network;
[0051] S42, construct the total loss function of the discriminator network:
[0052]
[0053] Wherein, L D is the total loss function of the discriminator network, x represents a real image sample, represents a defect candidate image output by the generator network, D(x) and are the discrimination probabilities of the discriminator network for real images and defect candidate images respectively, s t represents the structure connectivity feature indicator of the real image, represents the structure connectivity prediction value of the discriminator network for the defect candidate image, y k represents the kth element of the defect type label, represents the corresponding prediction probability, n is the total number of defect types, λ1, λ2 and λ3 are the weighting coefficients of the three loss terms;
[0054] S43, update the learnable parameters of the generator network and the discriminator network using the back propagation algorithm, and the generator network aims to minimize the generation loss, and the discriminator network aims to minimize the loss function L D ;
[0055] S44, set a maximum training round threshold and a loss convergence threshold, and terminate the training process when any condition is met;
[0056] S45, save the model parameters of the generator network and the discriminator network when the training is completed.
[0057] Optionally, the S5 specifically comprises:
[0058] S51, input the image to be detected into an image encoding unit to extract an image feature vector;
[0059] S52, splice the image feature vector and a preset defect type vector to form an input vector of the generator network;
[0060] S53, input the input vector of the generator network into the trained generator network to generate a defect candidate image;
[0061] S54, input the defect candidate image into the trained discriminator network to output authenticity discrimination results, structure connectivity feature indicators and defect type prediction labels;
[0062] S55. The defect candidate image, structural connectivity feature index and defect type prediction label are used as the output results of the reasoning stage.
[0063] Optionally, the S6 specifically includes:
[0064] S61, inputting the defect candidate image and the structural connectivity feature index into the defect map generation module, where the defect candidate image comes from the generator network and the structural connectivity feature index is calculated by the discriminator network;
[0065] S62. Adjust the pixel intensity in the defect candidate image based on the structural connectivity feature index to generate a defect probability map. The defect probability map is a single-channel grayscale image containing pixel-level defect probability values of the same size as the original image.
[0066] S63, applying image filtering and enhancement operations to the defect probability map to generate a defect saliency map, wherein the image filtering method is high-pass filtering, and the enhancement operations include local contrast enhancement and edge enhancement;
[0067] S64, performing a fixed threshold segmentation operation on the defect saliency map to generate a binary defect mask, wherein a pixel value of 1 in the binary defect mask represents a pixel in a defective area, and a pixel value of 0 represents a pixel in a non-defective area;
[0068] S65 , reading the coordinates of all pixels with a value of 1 in the binary defect mask, establishing a set of defective pixels at corresponding positions in the original input image, and outputting a coordinate set and bounding box parameters of the defective area to form a spatial positioning result of the defective area.
[0069] Optionally, the S7 specifically includes:
[0070] S71. Receive defect type prediction labels, defect saliency maps, and binary defect masks, which come from the discriminator network, image enhancement module, and image segmentation module, respectively.
[0071] S72, marking connected domains for all pixels with a value of 1 in the binary defect mask to construct a set of micro-defect regions, each of which corresponds to a set of image space coordinates;
[0072] S73, calculating the average response value of the corresponding position in the saliency map in each micro-defect area, and extracting the category index corresponding to the maximum value of the corresponding defect type prediction label probability;
[0073] S74, combining each micro-defect region with the corresponding significance intensity and category index to generate a micro-defect detection result entry, the entry including the position coordinates, intensity value and category number;
[0074] S75. Group all micro-defect detection result entries into a result set, where each entry in the result set corresponds to the final detection output and classification number of a spatial defect area.
[0075] The beneficial effects of the present invention are:
[0076] This paper designs a method for detecting micro-defects in industrial finished products based on a generative adversarial network. By introducing an image encoding unit, a geometric algebra processing unit, and an image decoding unit into the generator structure, the method can perform spatial transformation processing on the feature representation of the input image, thereby constructing an intermediate feature image with structural deformation capabilities. The geometric algebra processing unit completes the explicit modeling of microscale defect morphology by combining affine mapping, nonlinear activation functions, and control vector inputs. Compared with traditional convolutional neural networks, this structure has more flexible spatial adaptability and can more effectively simulate the deformation characteristics of defects, thereby improving the structural separation and distinguishability of defect areas in the generated image.
[0077] The discriminator architecture comprises a topological structure analysis module, comprised of a topological feature extraction unit and a topological index calculation unit. This module not only verifies the authenticity of the input image but also quantitatively extracts high-level topological information, such as the number of connected regions, void structure, and edge contours. It then outputs structural connectivity feature indices and a defect type prediction label. This module enables the discriminator to not only focus on image texture distribution but also capture the diversity of structural relationships within the image. This makes it particularly well-suited for processing micro-defect regions characterized by spatial structural perturbations, blurred boundaries, or overlapping morphologies. Combining topological indices with category labels enables accurate assessment of potential defect areas in the generator's output image.
[0078] During model training, a joint adversarial training framework was constructed, incorporating image authenticity discrimination loss, structural connectivity regression loss, and defect classification loss. The generator and discriminator were collaboratively optimized under a unified objective, making the model training process stable and the defect modeling process controllable. During the inference phase, image feature encoding, defect candidate image generation, discriminant output structural indicators and labels, and fusion generation of defect saliency maps and mask maps ultimately achieved spatial localization and type labeling of micro-defect areas. The overall process forms a closed-loop detection solution from data acquisition, model construction, joint training, to structured reasoning, improving the detection system's ability to identify and classify micro-defects in complex backgrounds. BRIEF DESCRIPTION OF THE DRAWINGS
[0079] The accompanying drawings are used to provide a further understanding of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings:
[0080] Fig. 1 This is a flow chart of a method for detecting micro-defects in industrial finished products based on a generative adversarial network proposed by the present invention;
[0081] Fig. 2 This is a schematic diagram of the generator network structure of an industrial finished product micro-defect detection method based on a generative adversarial network proposed in the present invention;
[0082] Fig. 3 This is a flowchart of defect mask generation and detection result output for an industrial finished product micro-defect detection method based on a generative adversarial network proposed by the present invention. DETAILED DESCRIPTION
[0083] The present invention will now be described in further detail with reference to the accompanying drawings, which are simplified schematic diagrams that illustrate the basic structure of the present invention in a schematic manner.
[0084] refer to Figs. 1-3 A method for detecting micro-defects in industrial finished products based on a generative adversarial network comprises the following steps:
[0085] S1. Collect high-resolution images of the surface of industrial finished products and construct a dataset containing normal images and defect images;
[0086] S2. Encode the training image, extract the image feature vector, and concatenate it with the defect type vector as input to the generator network containing the geometric structure transformation module. The generator network outputs the defect candidate image;
[0087] S3. Input the defect candidate image into the discriminator network including the topological structure analysis module. The discriminator network outputs the authenticity judgment result, structural connectivity feature index and defect type prediction label;
[0088] S4, an adversarial structure based on the generator network and the discriminator network, using image datasets for joint training, and updating the generator network parameters and the discriminator network parameters through backpropagation;
[0089] S5. Input the image to be detected into the trained generator network and discriminator network to generate the corresponding defect candidate image, structural connectivity feature index and defect type prediction label;
[0090] S6. Generate a defect probability map based on the defect candidate image and the structural connectivity feature index, further generate a defect saliency map and a binary defect mask, and locate the spatial position of the defect area in the original image;
[0091] S7. Combine the defect type prediction label, defect saliency map and binary defect mask to output the micro-defect detection results and classification results.
[0092] The present invention constructs a complete defect detection process, integrating image acquisition, generator image synthesis, discriminator topology analysis, joint training and multiple outputs, effectively supporting the full-process modeling requirements from original images to micro-defect identification and classification, and adapting to the multi-scale feature expression of microstructural defects in complex industrial scenarios.
[0093] In this embodiment, the geometric structure transformation module includes an image encoding unit, a geometric algebra processing unit and an image decoding unit:
[0094] The input of the image encoding unit is the training image, and the output is the image feature vector;
[0095] The input of the geometric algebra processing unit is the image feature vector and the defect type vector, and it performs a combination of rotation transformation, scaling transformation and affine transformation to output an intermediate feature map;
[0096] The input of the image decoding unit is the intermediate feature map, and the output is the defect candidate image.
[0097] The present invention introduces an image encoding unit, a geometric algebra processing unit and an image decoding unit into the generator network, establishes a geometric transformation path based on a control vector, and enables the generator to have the ability to finely control spatial characteristics such as defect position, direction, and scale.
[0098] In this embodiment, the topology structure analysis module includes a topology feature extraction unit and a topology index calculation unit:
[0099] The input of the topological feature extraction unit is the defect candidate image, and the output is the structural connectivity feature;
[0100] The input of the topological index calculation unit is the structural connectivity feature, and the output is the structural connectivity feature index and the defect type prediction label.
[0101] The present invention establishes a discriminator's quantitative expression of the structural connectivity and local topological features of the defect image by constructing a topological feature extraction unit and a topological index calculation unit, providing a measurable structural basis for subsequent classification decisions and abnormality judgment.
[0102] In this embodiment, the S1 specifically includes:
[0103] S11. Deploy image acquisition devices on industrial production lines to capture high-resolution images of the surfaces of industrial finished products;
[0104] S12, performing deduplication and brightness normalization processing on the collected image to unify the lighting conditions and background texture of the image;
[0105] S13, labeling the image, and dividing the image into a normal image and a defective image according to whether the image contains a defective area;
[0106] S14, constructing a corresponding defect mask for each defect image to indicate the spatial position of the defect area;
[0107] S15. The normal images, defect images and corresponding defect masks are uniformly organized into an image dataset as training inputs for the generator network and the discriminator network.
[0108] The present invention establishes a complete data organization process through image acquisition, deduplication normalization, precise labeling and mask construction, which not only ensures the diversity and accuracy of training samples, but also provides basic support for pixel-level supervision of defect areas.
[0109] In this embodiment, S2 specifically includes:
[0110] S21. Each training image in the image dataset is input into the image encoding unit to extract the image feature vector. The image encoding unit is composed of a multi-layer convolutional neural network and outputs an image feature tensor f with a dimension of C×H×W. x , where C represents the number of channels, H and W represent the height and width of the feature map respectively;
[0111] S22. Construct a defect type vector, which is denoted as v d =[d1,d2,,d n ], where d i represents the control factor of the i-th type of defect, and n represents the total number of defect categories;
[0112] S23, image feature tensor f x Flatten and map to a one-dimensional image feature vector f x ', and with the defect type vector v d Spliced into a combined vector z = [f x ',v d ];
[0113] S24. Construct a geometric transformation activation function based on GELU:
[0114]
[0115] Where x is the input real number, and tanh represents the hyperbolic tangent function;
[0116] S25, input the combined vector z into the geometric structure transformation module in the generator network, and the geometric structure transformation module transforms the two-dimensional space position vector p = [x1, x2] T Perform a combined transformation:
[0117]
[0118] Where T(p) represents the transformed position vector, p is the two-dimensional coordinate subvector in the input vector, W1 and W2 are learnable transformation matrices, b1 and b2 are learnable bias vectors, is the geometric transformation activation function, σ represents the output control function;
[0119] S26. Input the transformed intermediate feature map into the image decoding unit. The image decoding unit uses a deconvolution structure to generate a defect candidate image. The size of the defect candidate image is consistent with the input image.
[0120] The present invention realizes the combined expression and control drive of input defect features in the generator network through steps such as image encoding, vector splicing, activation function construction and spatial transformation modeling, thereby enhancing the simulation capability of complex spatial structure deformation.
[0121] In this embodiment, S3 specifically includes:
[0122] S31, inputting the defect candidate image into a discriminator network including a topological structure analysis module, wherein the topological structure analysis module includes a topological feature extraction unit and a topological index calculation unit;
[0123] S32, the topological feature extraction unit performs structural analysis on the defect candidate image and extracts the topological feature vector v t =[c,h,e], where c represents the number of connected regions identified based on the eight-neighborhood rule, h represents the number of holes surrounded by high-intensity pixels, and e represents the number of closed contours extracted by the edge detection algorithm;
[0124] S33. The topology index calculation unit calculates the structural connectivity characteristic index according to the topology characteristic vector:
[0125] s t =α1c+α2h+α3e;
[0126] Among them, s t is the structural connectivity characteristic index, α1, α2, and α3 are preset weight coefficients;
[0127] S34, the topology index calculation unit inputs the topology feature vector into the defect type prediction branch, and outputs the defect type prediction label y through the classification network d ;
[0128] S35, the discriminator network outputs the authenticity judgment result y r , structural connectivity characteristic index s t and defect type prediction label y d , where y r Indicates whether the defect candidate image comes from a real defect image in the image dataset.
[0129] The present invention constructs topological feature vectors and defines structural connectivity index formulas, enabling the discriminator to accurately respond to topological structure changes in micro-defect images, and can output multiple structural indicators and defect labels to support multi-branch task collaborative training.
[0130] In this embodiment, the S4 specifically includes:
[0131] S41. Select normal image and defect image samples from the image dataset and input them into the generator network and the discriminator network respectively to generate defect candidate images. The discriminator network then outputs the authenticity judgment result, structural connectivity feature index and defect type prediction label.
[0132] S42. Construct the total loss function of the discriminator network:
[0133]
[0134] Among them, L D is the total loss function of the discriminator network, x represents the real image sample, Denotes the defect candidate image output by the generator network, D(x) and are the discrimination probabilities of the discriminator network for real images and defect candidate images, s t Represents the structural connectivity feature index of the real image, represents the structural connectivity prediction value of the discriminator network for the defect candidate image, y k represents the kth element of the defect type label, represents the corresponding predicted probability, n is the total number of defect types, λ1, λ2, and λ3 are the weighting coefficients of the three losses;
[0135] S43, use the back propagation algorithm to update the learnable parameters of the generator network and the discriminator network. The generator network aims to minimize the generation loss, and the discriminator network aims to minimize the loss function L D for the goal;
[0136] S44, setting a maximum training round number threshold and a loss convergence threshold, and terminating the training process when either condition is met;
[0137] S45. Save the model parameters of the generator network and the discriminator network when training is completed.
[0138] This paper proposes a joint loss function construction method in the adversarial training process, integrating three types of objectives: authenticity, structural connectivity and defect classification into a unified optimization framework, effectively improving the stability and convergence effect of the model training process.
[0139] In this embodiment, the S5 specifically includes:
[0140] S51, inputting the image to be detected into the image encoding unit to extract the image feature vector;
[0141] S52, concatenating the image feature vector with a preset defect type vector to form an input vector of the generator network;
[0142] S53, inputting the generator network input vector into the trained generator network to generate defect candidate images;
[0143] S54, inputting the defect candidate image into the trained discriminator network, and outputting the authenticity discrimination result, structural connectivity feature index and defect type prediction label;
[0144] S55. The defect candidate image, structural connectivity feature index and defect type prediction label are used as the output results of the reasoning stage.
[0145] The present invention maintains a structure consistent with the training process in the inference stage, supports the input of the image to be tested, and completes feature extraction, candidate image generation, structural indicators and label output in sequence, ensuring the end-to-end consistency of the model in inference deployment.
[0146] In this embodiment, S6 specifically includes:
[0147] S61, inputting the defect candidate image and the structural connectivity feature index into the defect map generation module, where the defect candidate image comes from the generator network and the structural connectivity feature index is calculated by the discriminator network;
[0148] S62. Adjust the pixel intensity in the defect candidate image based on the structural connectivity feature index to generate a defect probability map. The defect probability map is a single-channel grayscale image containing pixel-level defect probability values of the same size as the original image.
[0149] S63, applying image filtering and enhancement operations to the defect probability map to generate a defect saliency map, wherein the image filtering method is high-pass filtering, and the enhancement operations include local contrast enhancement and edge enhancement;
[0150] S64, performing a fixed threshold segmentation operation on the defect saliency map to generate a binary defect mask, where a pixel value of 1 in the binary defect mask represents a pixel in a defective area, and a pixel value of 0 represents a pixel in a non-defective area;
[0151] S65 , reading the coordinates of all pixels with a value of 1 in the binary defect mask, establishing a set of defective pixels at corresponding positions in the original input image, and outputting a coordinate set and bounding box parameters of the defect area to form a spatial positioning result of the defect area.
[0152] The application proposes a construction process of a defect probability map, a saliency map and a binary mask, guides an image enhancement and segmentation process through structural connectivity, and makes the defect area have clear boundaries and continuity in the spatial dimension, which is beneficial to subsequent positioning analysis.
[0153] In the embodiment, the S7 specifically includes:
[0154] S71, receiving a defect type prediction label, a defect saliency map and a binary defect mask, the three data are respectively from a discriminator network, an image enhancement module and an image segmentation module;
[0155] S72, performing connected domain labeling on all pixel points with a value of 1 in the binary defect mask, and constructing a micro defect region set, each micro defect region corresponding to a group of image spatial coordinates;
[0156] S73, calculating the average response value of the corresponding position in the saliency map in each micro defect region, and extracting the class index corresponding to the maximum value of the probability of the corresponding defect type prediction label;
[0157] S74, combining each micro defect region with the corresponding saliency intensity and class index to generate a micro defect detection result entry, the entry including position coordinates, intensity value and class number;
[0158] S75, combining all micro defect detection result entries to form a result set, each entry in the result set corresponding to the final detection output and classification number of a spatial defect region.
[0159] The application realizes the fusion output of the micro defect detection result in the three-dimensional information of spatial position, response intensity and defect category through connected domain extraction, saliency fusion and defect type matching, and supports the classification record and accurate tracking of defect events by the industrial system.
[0160] Embodiment 1:
[0161] In order to verify the feasibility of the application in implementation, the application is applied to the surface quality detection link of a mobile phone metal frame of an electronic manufacturing enterprise. The production line is located in Suzhou Industrial Park, Jiangsu, and is an automatic processing enterprise with a monthly output of 450,000 middle frames. Since the surface quality requirement of such products is extremely high, common micro defects include fine cracks, small area paint falling, wear scratches, metal indentation and slight peeling, which not only challenge the traditional visual system, but also increase the cost of artificial recheck and customer complaints. The existing detection algorithm based on template matching and static rules is prone to false detection and missed detection under different batches of raw materials and complex background interference, and the detection accuracy is less than 90%, especially in the edge chamfer area or high reflection material.
[0162] The proposed method for detecting micro-defects in industrial finished products based on a generative adversarial network (GAN) is deployed as an integrated defect detection system on this production line. The system primarily consists of an image acquisition unit, a trained generator network, and a discriminator network, supporting inference and structured output of real-time image acquisition. Image acquisition utilizes dual-side lighting and a dual-view industrial camera. Two 8192×5460 resolution images are captured for each product, covering the front and curved edges to ensure comprehensive coverage. After brightness normalization, noise suppression, and mask initialization preprocessing, the captured images enter the model input stage.
[0163] During model operation, the system first encodes the image features and concatenates the image feature vector with a preset defect type control vector as a combined input, which is then fed into the generator network. The generator's internal geometric structure transformation module performs an affine transformation with control weights and nonlinearly transforms the image using the GELU activation function. This outputs an intermediate feature map, which is then used by the decoder module to generate defect candidate images. The candidate images are then fed into the discriminator network. The topological feature extraction module automatically calculates the structural connectivity features present in the image, such as the number of connected regions, the number of voids, and the number of edge-enclosed contours. The topological index calculation unit then synthesizes the structural connectivity index and outputs a plausibility score and defect type prediction.
[0164] To verify the performance of the present invention, 600 randomly sampled products were tested in mid-March 2025, including 65 manually confirmed defective samples. During the detection process, the system outputs a defect probability map based on the candidate image and structural connectivity, generates a saliency map after filtering and enhancement, and generates a binary defect mask through threshold segmentation, and outputs the spatial position of the defect area. The system takes no more than 2 seconds per piece in the entire reasoning phase, and the final detection accuracy reaches 97.5%, of which the defect missed detection rate is reduced to 2 cases, and the false detection rate does not exceed 0.5%. This performance is significantly better than the original template algorithm system (accuracy of 88%, missed detection rate of over 5%), reflecting the technical advantages of the present invention in identifying fine, complex, and irregular micro-defects.
[0165] Ten sets of sample data extracted from the complete inspection batch, covering common defect types, system output significance scores, structural connectivity indicators, predicted labels and detection error rates, are shown in Table 1:
[0166] Table 1. Sample results of industrial finished product micro-defect detection
[0167]
[0168] As can be seen from Table 1, the saliency scores output by the generator network are generally above 0.7, indicating that the model has strong response capability to defect areas; the structural connectivity index remains consistent with the complexity of the defect contour, and the index value of structural defects such as cracks and faults is close to 0.9, having obvious discrimination; the error rate is kept below 3%, and the error of DEF-006 is as low as 0.8%, verifying the consistency of the model prediction and the actual label. All defect types can be accurately classified by the system, and there is no serious misclassification phenomenon.
[0169] This embodiment shows that the present application can complete accurate positioning and automatic classification of multi-class micro-defects under high-resolution acquisition scenarios, has high adaptability and stability, and is particularly suitable for industrial fields such as intelligent manufacturing assembly lines, electronic device detection, automobile part detection and the like which have high requirements for fine-grained defect identification.
[0170] The above describes only the preferred specific embodiments of the present application, but the protection scope of the present application is not limited thereto, and any person skilled in the art can make equivalent replacements or changes to the technical solutions and inventive concepts of the present application within the technical range disclosed by the present application, which should be covered within the protection scope of the present application.
Claims
1. A method for detecting micro-defects in industrial finished products based on generative adversarial networks, characterized in that: The steps include: S1. Collect high-resolution images of the surface of industrial finished products and construct a dataset containing normal images and defect images; S2. Encode the training image, extract the image feature vector, and concatenate it with the defect type vector as input to the generator network containing the geometric structure transformation module. The generator network outputs the defect candidate image; S3. Input the defect candidate image into the discriminator network including the topological structure analysis module. The discriminator network outputs the authenticity judgment result, structural connectivity feature index and defect type prediction label; S4, an adversarial structure based on the generator network and the discriminator network, using image datasets for joint training, and updating the generator network parameters and the discriminator network parameters through backpropagation; S5. Input the image to be detected into the trained generator network and discriminator network to generate the corresponding defect candidate image, structural connectivity feature index and defect type prediction label; S6. Generate a defect probability map based on the defect candidate image and the structural connectivity feature index, further generate a defect saliency map and a binary defect mask, and locate the spatial position of the defect area in the original image; S7. Combine the defect type prediction label, defect saliency map and binary defect mask to output the micro-defect detection results and classification results.
2. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The geometric structure transformation module includes an image encoding unit, a geometric algebra processing unit and an image decoding unit: The input of the image encoding unit is the training image, and the output is the image feature vector; The input of the geometric algebra processing unit is the image feature vector and the defect type vector, and it performs a combination of rotation transformation, scaling transformation and affine transformation to output an intermediate feature map; The input of the image decoding unit is the intermediate feature map, and the output is the defect candidate image.
3. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The topology structure analysis module includes a topology feature extraction unit and a topology index calculation unit: The input of the topological feature extraction unit is the defect candidate image, and the output is the structural connectivity feature; The input of the topological index calculation unit is the structural connectivity feature, and the output is the structural connectivity feature index and the defect type prediction label.
4. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: Said S1 specifically includes: S11. Deploy image acquisition devices on industrial production lines to capture high-resolution images of the surfaces of industrial finished products; S12, performing deduplication and brightness normalization processing on the collected image to unify the lighting conditions and background texture of the image; S13, labeling the image, and dividing the image into a normal image and a defective image according to whether the image contains a defective area; S14, constructing a corresponding defect mask for each defect image to indicate the spatial position of the defect area; S15. The normal images, defect images and corresponding defect masks are uniformly organized into an image dataset as training inputs for the generator network and the discriminator network.
5. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The S2 specifically includes: S21. Each training image in the image dataset is input into the image encoding unit to extract the image feature vector. The image encoding unit is composed of a multi-layer convolutional neural network and outputs an image feature tensor f with a dimension of C×H×W. x , where C represents the number of channels, H and W represent the height and width of the feature map respectively; S22. Construct a defect type vector, which is denoted as v d =[d1,d2,,d n ], where d i represents the control factor of the i-th defect, and n represents the total number of defect categories; S23, image feature tensor f x Flatten and map to a one-dimensional image feature vector f x ', and with the defect type vector v d Spliced into a combined vector z = [f x ',v d ]; S24. Construct a geometric transformation activation function based on GELU: Where x is the input real number, and tanh represents the hyperbolic tangent function; S25, input the combined vector z into the geometric structure transformation module in the generator network, and the geometric structure transformation module transforms the two-dimensional space position vector p = [x1, x2] T Perform a combined transformation: Where T(p) represents the transformed position vector, p is the two-dimensional coordinate subvector in the input vector, W1 and W2 are learnable transformation matrices, b1 and b2 are learnable bias vectors, is the geometric transformation activation function, σ represents the output control function; S26. Input the transformed intermediate feature map into the image decoding unit. The image decoding unit uses a deconvolution structure to generate a defect candidate image. The size of the defect candidate image is consistent with the input image.
6. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The S3 specifically includes: S31, inputting the defect candidate image into a discriminator network including a topological structure analysis module, wherein the topological structure analysis module includes a topological feature extraction unit and a topological index calculation unit; S32, the topological feature extraction unit performs structural analysis on the defect candidate image and extracts the topological feature vector v t =[c,h,e], where c represents the number of connected regions identified based on the eight-neighborhood rule, h represents the number of holes surrounded by high-intensity pixels, and e represents the number of closed contours extracted by the edge detection algorithm; S33. The topology index calculation unit calculates the structural connectivity characteristic index according to the topology characteristic vector: s t =α1c+α2h+α3e; Among them, s t is the structural connectivity characteristic index, α1, α2, and α3 are preset weight coefficients; S34, the topology index calculation unit inputs the topology feature vector into the defect type prediction branch, and outputs the defect type prediction label y through the classification network d ; S35, the discriminator network outputs the authenticity judgment result y r , structural connectivity characteristic index s t and defect type prediction label y d , where y r Indicates whether the defect candidate image comes from a real defect image in the image dataset.
7. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The S4 specifically includes: S41. Select normal image and defect image samples from the image dataset and input them into the generator network and the discriminator network respectively to generate defect candidate images. The discriminator network then outputs the authenticity judgment result, structural connectivity feature index and defect type prediction label. S42. Construct the total loss function of the discriminator network: Among them, L D is the total loss function of the discriminator network, x represents the real image sample, Denotes the defect candidate image output by the generator network, D(x) and are the discrimination probabilities of the discriminator network for real images and defect candidate images, s t Represents the structural connectivity feature index of the real image, represents the structural connectivity prediction value of the discriminator network for the defect candidate image, y k represents the kth element of the defect type label, represents the corresponding predicted probability, n is the total number of defect types, λ1, λ2, and λ3 are the weighting coefficients of the three losses; S43, use the back propagation algorithm to update the learnable parameters of the generator network and the discriminator network. The generator network aims to minimize the generation loss, and the discriminator network aims to minimize the loss function L D for the goal; S44, setting a maximum training round number threshold and a loss convergence threshold, and terminating the training process when either condition is met; S45. Save the model parameters of the generator network and the discriminator network when training is completed.
8. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The S5 specifically includes: S51, inputting the image to be detected into the image encoding unit to extract the image feature vector; S52, concatenating the image feature vector with a preset defect type vector to form an input vector of the generator network; S53, inputting the generator network input vector into the trained generator network to generate defect candidate images; S54, inputting the defect candidate image into the trained discriminator network, and outputting the authenticity discrimination result, structural connectivity feature index and defect type prediction label; S55. The defect candidate image, structural connectivity feature index and defect type prediction label are used as the output results of the reasoning stage.
9. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The S6 specifically includes: S61, inputting the defect candidate image and the structural connectivity feature index into the defect map generation module, where the defect candidate image comes from the generator network and the structural connectivity feature index is calculated by the discriminator network; S62. Adjust the pixel intensity in the defect candidate image based on the structural connectivity feature index to generate a defect probability map. The defect probability map is a single-channel grayscale image containing pixel-level defect probability values of the same size as the original image. S63, applying image filtering and enhancement operations to the defect probability map to generate a defect saliency map, wherein the image filtering method is high-pass filtering, and the enhancement operations include local contrast enhancement and edge enhancement; S64, performing a fixed threshold segmentation operation on the defect saliency map to generate a binary defect mask, where a pixel value of 1 in the binary defect mask represents a pixel in a defective area, and a pixel value of 0 represents a pixel in a non-defective area; S65 , reading the coordinates of all pixels with a value of 1 in the binary defect mask, establishing a set of defective pixels at corresponding positions in the original input image, and outputting a coordinate set and bounding box parameters of the defect area to form a spatial positioning result of the defect area.
10. The method for detecting micro-defects of industrial finished products based on a generative adversarial network according to claim 1, characterized in that: The S7 specifically includes: S71. Receive defect type prediction labels, defect saliency maps, and binary defect masks, which come from the discriminator network, image enhancement module, and image segmentation module, respectively. S72, marking connected domains for all pixels with a value of 1 in the binary defect mask to construct a set of micro-defect regions, each of which corresponds to a set of image space coordinates; S73, calculating the average response value of the corresponding position in the saliency map in each micro-defect area, and extracting the category index corresponding to the maximum value of the corresponding defect type prediction label probability; S74, combining each micro-defect region with the corresponding significance intensity and category index to generate a micro-defect detection result entry, the entry including the position coordinates, intensity value and category number; S75. Group all micro-defect detection result entries into a result set, where each entry in the result set corresponds to the final detection output and classification number of a spatial defect area.
Citation Information
Cited By
Defect image generation method and device, computer equipment and readable storage medium
CN121147200A