Complex workpiece surface defect generation method and system

Through the improved FastGAN model, dynamic fusion mechanism and multi-head dynamic attention mechanism, the target defect image is generated, and the problems of low efficiency and insufficient accuracy of surface defect detection of CRRC locks in the prior art are solved, achieving more efficient and accurate detection effects.

CN119624952AInactive Publication Date: 2025-03-14LASER RES INST OF SHANDONG ACAD OF SCI
View PDF 11 Cites 0 Cited by

Patent Information

Application Number
CN202510151714.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-12
Publication Date
2025-03-14
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

When detecting surface defects of vehicle locks with complex structures, the prior art has problems such as low detection efficiency, susceptible to subjective factors, and inability to meet high-precision requirements.

Method used

The improved FastGAN model is adopted, combining dynamic fusion mechanisms and multi-head dynamic attention mechanisms to generate target defect images, thereby improving the accuracy of surface defect detection.

Benefits of technology

The speed of target defect image generation is improved, the authenticity of target defect samples and the diversity of defect types are increased, and the accuracy and efficiency of detection are improved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119624952A_ABST
    Figure CN119624952A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of defect generation, in particular to a complex workpiece surface defect generation method and system. The complex workpiece surface defect generation method comprises the following steps: acquiring a defect image of a workpiece; defects exist on the surface of the workpiece, and the defect image comprises the defects; generating a target defect image based on the defect image and an improved FastGAN model; the improved FastGAN model comprises a dynamic fusion mechanism and a multi-head dynamic attention mechanism; pasting the target defect image to a basic image of the basic workpiece, and determining a target workpiece image; and the basic workpiece has no defect. Various target defect images are generated based on the defect images of the workpieces, so that defect samples of various workpieces, namely target workpieces, can be obtained by combining the target defect images. The target defect image generation speed is improved, and the authenticity of the target defect sample and the diversity of defect types are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of defect generation, and in particular to a method and system for generating surface defects of complex workpieces. Background Art

[0002] In recent years, with the rapid development of my country's automobile industry, the production and ownership of automobiles have increased significantly, and the quality requirements for automobile parts have also increased accordingly. As an important part of automobile door locks, the quality of car locks is directly related to the safety performance and user experience of the car. The surface defects of car locks have become a key factor affecting their quality, and the solution to this problem needs to be guaranteed by efficient and accurate detection technology. Therefore, car lock surface defect detection has gradually become an important research direction in the field of industrial automation detection.

[0003] In the related technologies, the detection of surface defects of car lock buckles mainly relies on manual visual inspection or single focal plane detection methods based on traditional visual technology. These technologies meet the basic requirements of car lock buckle production quality to a certain extent. For example, manual visual inspection can find obvious defects through the operator's experience, while single focal plane visual inspection uses image processing technology to capture local defects. However, with the increase in the complexity of car lock buckle structures and the continuous improvement of industrial production efficiency, the limitations of traditional methods have gradually become apparent.

[0004] Although relevant technologies have been widely used, they have many shortcomings. Manual visual inspection relies heavily on the operator's experience and attention, has low detection efficiency and is easily affected by subjective factors, making it difficult to ensure consistency in large-scale production. On the other hand, although single-focal plane visual inspection has achieved a certain degree of automation, it often misses or misdetects due to viewing angle limitations when dealing with the complex topography of car locks. In addition, these methods are usually unable to adapt to complex inspection scenarios with high-precision requirements, and thus cannot meet the stringent requirements of the modern automotive industry for high-quality parts. Summary of the invention

[0005] To solve the above problems, the embodiments of the present application provide a method and system for generating surface defects of complex workpieces to solve the problem of insufficient sample defects. By acquiring images of the surface of the vehicle lock buckle and using improved defect generation technology, the surface defects of the vehicle lock buckle can be accurately restored to improve the accuracy of surface defect detection.

[0006] In some embodiments, a method for generating surface defects of a complex workpiece is provided, including: acquiring a defect image of the workpiece; there are defects on the surface of the workpiece, and the defect image includes defects; based on the defect image and an improved FastGAN model, a target defect image is generated; the improved FastGAN model includes a dynamic fusion mechanism and a multi-head dynamic attention mechanism; the target defect image is pasted to a base image of a base workpiece to determine the target workpiece image; there are no defects in the base workpiece.

[0007] By using the complex workpiece surface defect generation method provided in the embodiment of the present application, a variety of target defect images are generated based on the defect image of the workpiece, so that defect samples of various workpieces, i.e., target workpieces, can be obtained by combining the target defect images. The speed of generating target defect images is improved, and the authenticity of target defect samples and the diversity of defect types are increased.

[0008] Optionally, acquiring a defect image of a workpiece includes: acquiring a first image and a second image; the first image includes a background; the second image includes the workpiece and the background; and determining the defect image based on the first image and the second image.

[0009] Optionally, based on the first image and the second image, determining the defect image includes: based on the first image, cropping the second image to determine the complete image of the workpiece; marking the defect area in the complete image; cropping the defect area to determine the image of the defect area; combining the image of the defect area with a preset background to determine the defect image.

[0010] Optionally, based on the defect image and the improved FastGAN model, a target defect image is generated, including: based on the defect image, using the improved FastGAN model to generate high-resolution features and low-resolution features; based on the high-resolution features and the low-resolution features, using the improved FastGAN model to generate the target defect image.

[0011] Optionally, before generating a target defect image based on the defect image and the improved FastGAN model, the method further includes: improving the initial FastGAN model based on a dynamic fusion mechanism and a multi-head dynamic attention mechanism to determine a primary FastGAN model; acquiring training data; training the primary FastGAN model based on the training data to determine an improved FastGAN model.

[0012] Optionally, the initial FastGAN model includes a skip layer excitation mechanism; the initial FastGAN model is improved based on a dynamic fusion mechanism and a multi-head dynamic attention mechanism, and a primary FastGAN model is determined, including: introducing a dynamic fusion mechanism to improve the skip layer excitation mechanism; introducing a multi-head dynamic attention mechanism to construct a dependency relationship between high-resolution features and low-resolution features.

[0013] Optionally, a dynamic fusion mechanism is introduced to improve the jump layer incentive mechanism, including: Introducing learnable weight parameters in the skip layer incentive mechanism ; Among them, after introducing the learnable weight parameters, the feature fusion function of the skip layer excitation mechanism is: ; in, It is a low-resolution feature; It is the feature transformation process of SLE, including adaptive average pooling, convolution layer and Sigmoid activation function; is a high-resolution feature, is the output feature after fusion; And / or, the transfer function of the multi-head dynamic attention mechanism is: ; in, and are the learnable weights of the multi-head dynamic attention mechanism, represents the Sigmoid activation function, Represents the activation function applied to the pooled features to introduce nonlinearity and remove negative values; Represents low-resolution features Perform an average pooling operation; It is a weighted high-resolution feature to combine the global information of low-resolution features.

[0014] Optionally, the training data includes real defect images, and the primary FastGAN model includes a generator and a discriminator; the primary FastGAN model is trained based on the training data to determine an improved FastGAN model, including: S01, generating a defect image based on the real defect image based on the generator output; S02, inputting the image to be discriminated into the discriminator to determine the type of the image to be discriminated; the image to be discriminated includes a real defect image or a generated defect image; S03, when the type of the image to be discriminated is different from the real type of the image to be discriminated, improving the generator and executing step S01 again.

[0015] Optionally, the target defect image is pasted onto the base image of the base workpiece to determine the target workpiece image, including: pasting the center point of the target defect image onto the target pasting point on the base image; adjusting the transparency parameter of the target defect image to merge the target defect image with the base image; and based on an image smoothing algorithm, adjusting the edge between the target defect image and the base image to determine the target workpiece image to improve the degree of fusion between the target defect and the base image.

[0016] In some embodiments, a complex workpiece surface defect generation system is provided, including: an image acquisition module, configured to acquire images of the workpiece and the background; a defect generation module, communicatively connected to the image acquisition module; the defect generation module is configured to obtain a defect image of the workpiece; there are defects on the surface of the workpiece, and the defect image includes defects; based on the defect image and an improved FastGAN model, a target defect image is generated; the improved FastGAN model includes a dynamic fusion mechanism and a multi-head dynamic attention mechanism; the target defect image is pasted to the workpiece, and the target workpiece is determined, and the target workpiece includes a target defect.

[0017] It can be understood that the beneficial effects that can be achieved by the technical solution provided by the complex workpiece surface defect generation system provided above can refer to the beneficial effects in the complex workpiece surface defect generation method and any of its optional implementations, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0018] In order to more clearly illustrate the technical solution of the present application, the drawings required for use in the embodiments are briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0019] Figure 1 A structural block diagram of a complex workpiece surface defect generation system provided in an embodiment of the present application; Figure 2 A schematic diagram of an image acquisition module provided in an embodiment of the present application acquiring an image of a workpiece; Figure 3 A flow chart of a method for generating surface defects of a complex workpiece provided in an embodiment of the present application; Figure 4 A schematic diagram of an improved FastGAN model provided in an embodiment of the present application; Figure 5 The target workpiece images provided in the embodiment of the present application; wherein (a) is a first target workpiece image, (b) is a second target workpiece image, and (c) is a third target workpiece image; Figure 6 A schematic diagram of defect location distribution provided in an embodiment of the present application.

[0020] Reference numerals: 1. Image acquisition module; 11. Industrial camera; 2. Defect generation module; 21. Computer; 22. Mobile phone; 3. Workpiece; 41. Dynamic fusion mechanism; 42. Multi-head dynamic attention mechanism. DETAILED DESCRIPTION

[0021] The technical solutions in the embodiments of the present application will be described clearly below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, rather than all of the embodiments. Based on the embodiments of the present application, other embodiments obtained by ordinary technicians in this field without making creative work all belong to the protection scope of the present application.

[0022] In the following, the terms "first", "second", etc. are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first", "second", etc. may explicitly or implicitly include one or more of the features. In the description of this application, unless otherwise specified, "plurality" means two or more.

[0023] In addition, in the present application, directional terms such as "upper", "lower", "inner" and "outer" are defined relative to the orientation of the components schematically placed in the drawings. It should be understood that these directional terms are relative concepts. They are used for relative description and clarification, and they can change accordingly according to the changes in the orientation of the components placed in the drawings.

[0024] Figure 1 This is a structural block diagram of the complex workpiece surface defect generation system provided in an embodiment of the present application.

[0025] Figure 2 A schematic diagram of the image acquisition module provided in an embodiment of the present application acquiring an image of a workpiece.

[0026] Combination Figure 1 and Figure 2 As shown, an embodiment of the present application provides a complex workpiece surface defect generation system, including: an image acquisition module 1 and a defect generation module 2. The image acquisition module 1 is configured to acquire an image of a workpiece 3 and an image of a background, and the surface of the workpiece 3 has defects. The defect generation module 2 is communicatively connected to the image acquisition module 1. The defect generation module 2 is configured to receive an image of the workpiece 3 and an image of the background, and is also configured to generate a target defect image based on the image of the workpiece 3, the image of the background and the improved FastGAN model, and to generate a workpiece image having a target defect by combining the target defect image with the workpiece.

[0027] The complex workpiece surface defect generation system provided in the embodiment of the present application is adopted. Based on the defects on the surface of the workpiece 3, an improved FastGAN model is used to generate diversified target defect images, increase the types of generated defects, improve the speed of target defect image generation, increase the authenticity of target defect samples and the diversity of defect types.

[0028] Specifically, based on an image of a workpiece with defects, an image of the defects is extracted, and the image of the defects is input into the improved FastGAN model, and the output of the improved FastGAN model is the target defect image.

[0029] It is worth noting that the target defect provided in the embodiment of the present application is a collection of defect images, which may include one or more different defect images, and the defect types corresponding to the defect images are the same or different, which increases the authenticity of the generated defect samples and the diversity of defect types.

[0030] Figure 3 A flow chart of a method for generating surface defects of a complex workpiece provided in an embodiment of the present application.

[0031] Combination Figure 1 and Figure 2 The complex workpiece surface defect generation system shown in the embodiment of the present application also provides a complex workpiece surface defect generation method, such as Figure 3 As shown, the complex workpiece surface defect generation method includes steps S1 to S3, which are as follows: Step S1, obtaining a defect image of a workpiece; there are defects on the surface of the workpiece, and the defect image includes the defects.

[0032] In this step, the defect image is acquired so as to generate a target defect image based on the defect image.

[0033] Optionally, step S1 includes step S11 and step S12, which are specifically as follows: Step S11, acquiring a first image and a second image; the first image includes a background; the second image includes a workpiece and a background.

[0034] Step S12: determining a defect image based on the first image and the second image.

[0035] In this embodiment, the background image in the second image is removed by cropping the first image, thereby obtaining an image of the workpiece, and then obtaining an image of the surface defects of the workpiece, that is, a defect image. In this way, background interference can be effectively removed, thereby obtaining purer workpiece image sample data.

[0036] Specifically, the image acquisition module includes an industrial camera, which captures a background image and a workpiece image, namely a first image and a second image, respectively under the same environmental conditions, and then transmits the captured images to the defect generation module.

[0037] Optionally, step S12 includes steps S121 to S124, which are specifically as follows: Step S121 , based on the first image, the second image is cropped to determine a complete image of the workpiece.

[0038] Step S122, marking the defective area in the complete image.

[0039] In this step, the labelme marking tool is used to mark the defective area.

[0040] For example, different labels can be given to defects according to their types, including scratches, pits, and pores, etc., so as to facilitate the training of the FastGAN model.

[0041] Step S123, cropping the defective area to determine the image of the defective area.

[0042] Exemplarily, the size of the complete image is 4024×3096, and the size of the image of the defective area is 512×512.

[0043] Step S124, combining the image of the defect area with a preset background to determine a defect image.

[0044] In this step, the background is preset to be black, which makes it easier to distinguish the defect area from the background and facilitates the subsequent training of the FastGAN model. Specifically, the FastGAN model hardly needs to learn the features of the black background and only focuses on the defect area, which improves the training speed and training effect.

[0045] In this embodiment, a complete image of the workpiece is cropped out through a pixel-level difference operation, and then a defective area in the complete image is cropped, and the defective area is combined with a preset background to obtain a defective image.

[0046] Optionally, step S124 further includes step S125 and step S126, which are specifically as follows: Step S125, using the threshold segmentation technology to select a preset background area in the defect image.

[0047] Step S126, adding a transparent channel in the preset background area.

[0048] In this embodiment, a transparent channel is added to the preset background area to reduce the focus on the background during FastGAN model training, and only focus on the features of the defect area, thereby improving the training speed and training effect of the FastGAN model.

[0049] Step S2, generating a target defect image based on the defect image and the improved FastGAN model; the improved FastGAN model includes a dynamic fusion mechanism and a multi-head dynamic attention mechanism.

[0050] In this step, different defect types are generated using FastGAN that introduces dynamic fusion mechanism (Dynamic Fusion) and multi-head dynamic attention mechanism (Multi-Head Dynamic Attention, MHDA).

[0051] Figure 4 A schematic diagram of an improved FastGAN model provided in an embodiment of the present application.

[0052] Combination Figure 4 As shown, the improved FastGAN model includes a dynamic fusion mechanism 41 and a multi-head dynamic attention mechanism 42. Specifically, this is a model block diagram of the generator in the FastGAN model, where the generator uses multiple modules to generate images, including: ConvTranspose, SLE-DM, dynamic fusion mechanism 41 and multi-head dynamic attention mechanism 42. The detailed introduction of the improved FastGAN model is as follows: First, R 256×1×1 The noise vector is used as the input of the model, which represents standard random initialization, such as sampling from a normal distribution. ConvTranspose (4×4, s=1, p=0) means: amplify the noise input and generate the initial feature feat_4. Through BatchNorm and GLU activation functions, the stability and nonlinear expression ability of the feature distribution are improved. The generated feature feat_4 is the first step output of the deep learning model generator.

[0053] Secondly, the feature resolution of each layer is gradually increased by gradually enlarging the multi-level features (from feat_4 to feat_512) through transposed convolution, and the feature resolution of each layer becomes larger in turn, such as Figure 4 As shown in , the change steps of features feat_4 to feat_512 ​​are: feat_4, feat_8, feat_16, feat_32, feat_64, feat_128, feat_256, feat_512. In each upsampling stage, modular designs (such as SLE-DM and Skip-layer Excitation) are used to dynamically adjust the features and improve the expressiveness of the generator.

[0054] Specifically, SLE-DM (Skip-Layer Excitation with Diffusion Model) is a feature enhancement module that performs skip connections on cross-layer features and performs feature fusion through a diffusion mechanism. This preserves the information of low-level features while enhancing the expressiveness of high-level features. It is particularly suitable for detail enhancement of high-resolution features in image generation tasks. Figure 4 In the block diagram of , SLE-DM modules appear in multiple stages to connect the contextual information between feature maps.

[0055] Furthermore, the complementary information of multi-scale features (such as feat_64 and feat_128) is processed through a dynamic fusion mechanism 41 to generate high-quality features R 128×64×64 The generator’s attention to feature details is further strengthened through a multi-head dynamic attention mechanism42 to improve the quality of image details and enhance global consistency.

[0056] Finally, based on the feature feat_512, the final image is generated through the convolution layer of Conv (3×3, s=1, p=1). Activation function Tanh: Ensure that the pixel value range of the output image is , which facilitates standardized processing in image tasks.

[0057] Optionally, step S2 includes step S21 and step S22, which are specifically as follows: Step S21, based on the defect image, using the improved FastGAN model to generate high-resolution features and low-resolution features.

[0058] Step S22, based on the high-resolution features and the low-resolution features, the target defect image is generated using the improved FastGAN model.

[0059] In this embodiment, the defect image is output to the improved FastGAN model, and the output of the improved FastGAN model is the target defect image. Through the improved FastGAN model, diversified target defect images are generated, the types of generated defects are increased, the speed of generating target defect images is improved, and the authenticity of target defect samples and the diversity of defect types are increased.

[0060] Optionally, before step S2, steps S23 to S25 are also included, which are specifically as follows: Step S23, improving the initial FastGAN model based on the dynamic fusion mechanism and the multi-head dynamic attention mechanism, and determining the primary FastGAN model.

[0061] Specifically, in order to generate high-resolution target defect images, the generator of the FastGAN model requires a deeper network structure to adapt to the complex hierarchical features in the data. However, deeper networks introduce weak gradient flows, increase computational costs, and slow down training due to the increase in the number of parameters. Although traditional solutions such as residual blocks (ResBlock) and skip layer excitation mechanisms (Skip-Layer Excitation, SLE) have alleviated these problems to a certain extent, they are still limited in their design scope.

[0062] Specifically, FastGAN designs a skip layer excitation mechanism (SLE) and a self-supervised discriminator. SLE not only maintains gradient flow and feature recalibration through cross-resolution skip connections and channel-level multiplication operations, but also effectively avoids a significant increase in computational overhead. The original SLE mechanism is defined as: ; in, , and is the feature map of the input and output of the SLE module, It consists of a set of fully connected layers and non-linear activation functions to generate weighting coefficients for high-resolution feature maps. is the weight of the fully connected layer. Applied to high-resolution feature maps , element-wise multiplication Channel weighting is implemented.

[0063] In FastGAN, the discriminator acts as a feature encoder, responsible for extracting the intermediate feature map of the input image and training it through self-supervised learning to force it to extract more descriptive features. In addition, the discriminator is equipped with a small decoder for reconstructing the input image, thereby providing strong regularization for the discriminator. In form: ; in, yes The extracted intermediate feature map, function Contains Processing and decoder functions Represents the real image Sample This approach improves the feature extraction capability of the discriminator while enhancing the performance of the generator without significantly increasing the computational burden.

[0064] In order to improve the effect of skip connections and reduce the computational burden, the embodiment of the present application introduces a dynamic fusion mechanism and a multi-head dynamic attention mechanism in the generator. These dynamic fusion mechanisms and multi-head dynamic attention mechanisms work together to effectively fuse multi-resolution features and model long-range dependencies in a hierarchical structure. The specific improvement scheme is as follows.

[0065] Optionally, the initial FastGAN model includes a skip layer excitation mechanism; step S23 includes step S231 and step S232, which are specifically as follows: Step S231, introducing a dynamic fusion mechanism to improve the jump layer incentive mechanism.

[0066] In this step, a dynamic fusion mechanism is integrated into the jump layer excitation mechanism to further improve the ability to transfer cross-layer features. At the same time, the contribution of features in different layers is dynamically adjusted, so that the model can capture complex image features more flexibly.

[0067] The core of the skip layer excitation module is to directly pass the information of shallow features to the deep layer through the skip connection between shallow features and deep features to retain more spatial information. After integrating the dynamic fusion strategy, the fusion weights of shallow features and deep features can be dynamically adjusted according to the content of the current features, thereby avoiding over-reliance on a single layer of features.

[0068] Optionally, step S231 includes step S2311, which is specifically as follows: Step S2311, introducing learnable weight parameters into the jump layer incentive mechanism .

[0069] Among them, after introducing the learnable weight parameters, the feature fusion function of the skip layer excitation mechanism is: ; in, It is a low-resolution feature; It is the feature transformation process of SLE, including adaptive average pooling, convolution layer and Sigmoid activation function; is a high-resolution feature, is the output feature after fusion.

[0070] Step S232, introduce a multi-head dynamic attention mechanism to construct the dependency relationship between high-resolution features and low-resolution features.

[0071] SLE focuses on channel recalibration and fails to capture complex dependencies between dimensions and spatial hierarchies. To address this problem, we introduce a multi-head dynamic attention mechanism to model cross-dimensional dependencies. Each attention head focuses on a unique feature subspace, and the aggregated output can provide a richer representation of hierarchical relationships.

[0072] After introducing the multi-head dynamic attention mechanism, different feature subspaces are modeled through multiple attention heads, and each head focuses on the dependencies between different dimensions or spatial levels. The dynamics are introduced on the basis of multiple heads, so that the attention weights can be adaptively adjusted according to the input features. MHDA can better capture the global relationship of feature maps, not just limited to the calibration between local channels.

[0073] Optionally, step S232 includes step S2321, which is specifically as follows: Step S2321, the transfer function of the multi-head dynamic attention mechanism is: ; in, and are the learnable weights of the multi-head dynamic attention mechanism, represents the Sigmoid activation function, Represents the activation function applied to the pooled features to introduce nonlinearity and remove negative values; Represents low-resolution features Perform an average pooling operation; It is a weighted high-resolution feature to combine the global information of low-resolution features.

[0074] Step S25, obtaining training data.

[0075] Step S26: training the primary FastGAN model based on the training data to determine an improved FastGAN model.

[0076] In this step, obtaining training data can be understood as executing step S1 on a workpiece with defects on its surface, that is, obtaining preliminary training data. The purpose of using the training data to train the primary FastGAN model is to enable the primary FastGAN model to learn the relevant features of the defects, including shape and category, so that after inputting a defect image of a new workpiece, a more accurate target defect image can be generated more quickly.

[0077] In this embodiment, the primary FastGAN model is trained by using the training data so that the primary FastGAN model can learn the features of the defect image and then generate the target defect image.

[0078] Optionally, the training data includes real defect images, and the primary FastGAN model includes a generator and a discriminator; step S25 includes steps S01 to S03, which are specifically as follows: S01, generating a defect image based on the real defect image output by the generator.

[0079] S02, inputting the image to be judged into the discriminator to determine the type of the image to be judged; the image to be judged includes a real defect image or a generated defect image.

[0080] S03, when the type of the image to be judged is different from the real type of the image to be judged, improve the generator and execute step S01 again.

[0081] In this embodiment, by looping through the above steps S01 to S03, the primary FastGAN model is trained to obtain an improved FastGAN model, thereby improving the speed and accuracy of the improved FastGAN model in generating target defect images.

[0082] Step S3, pasting the target defect image to the base image of the base workpiece, determining the target workpiece image, and determining that the base workpiece has no defects.

[0083] Optionally, step S3 includes steps S31 to S33, which are specifically as follows: Step S31, pasting the center point of the target defect image to the target pasting point on the base image.

[0084] In this step, the target pasting point is any point in the randomly selected preset area, and the selection rule of the preset area is: when the center point of the target defect image is pasted to the target pasting point, the edge of the target defect image will not exceed the edge of the base image. Exemplarily, the minimum value of the distance from any point in the target area to the edge of the base image is L1, and the minimum value from the center point of the target defect image to the edge of the target defect image is L2, and L1>L2.

[0085] Step S32, adjusting the transparency parameter of the target defect image to merge the target defect image with the base image.

[0086] Step S33, based on the image smoothing algorithm, adjusting the edge between the target defect image and the base image, and determining the target workpiece image, so as to improve the fusion degree between the target defect and the base image.

[0087] In this embodiment, the target defect image is pasted and fused to the workpiece to generate defect samples, thereby improving the authenticity and quantity of the defect samples and facilitating subsequent defect identification on the workpiece surface.

[0088] By using the complex workpiece surface defect generation method provided in the embodiment of the present application, a variety of target defect images are generated based on the defect image of the workpiece, so that defect samples of various workpieces, i.e., target workpiece images, can be obtained by combining the target defect images. The speed of generating the target defect images is improved, and the authenticity of the target defect samples and the diversity of defect types are increased.

[0089] Figure 5 The target workpiece image provided in the embodiment of the present application. Figure 5 (a) is the first target workpiece image. Figure 5 (b) is the second target workpiece image. Figure 5 (c) is the third target workpiece image.

[0090] Figure 5Three types of generated target workpiece images are schematically shown, combined with Figure 5 As shown, the target workpiece image generated by the complex workpiece surface defect generation method provided in the embodiment of the present application has high definition and the distribution positions of the defects are diverse. Specifically, the first target workpiece image (such as Figure 5 (a)), the second target workpiece image (as shown in Figure 5 (b)) and the third target workpiece image (as shown in Figure 5 The defects in (c) are distributed differently and the images are relatively clear.

[0091] Figure 6 A schematic diagram of defect location distribution provided in an embodiment of the present application. Figure 6 (a) is a schematic diagram of defect location distribution generated by the initial FastGan model. Figure 6 (b) is a defect position distribution diagram generated by the improved FastGAN model provided in the embodiment of the present application. x and y represent the position of the defect relative to the workpiece, for example, if the size of the complete image of the workpiece is 10 cm × 10 cm, and the defect is located 2 cm from the upper edge and 2 cm from the right edge of the complete image of the workpiece, then the x-axis of the defect in the position distribution diagram is 0.8 and the y-axis is 0.8.

[0092] For example, in combination Figure 6 As shown in (a), the defects are mainly concentrated in three places of the workpiece and are unevenly distributed. Figure 6 As shown in (b), the defects are evenly distributed on the workpiece. It can be seen that the defect distribution positions generated by the method provided in the embodiment of the present application are more even.

[0093] Specifically, in terms of training speed, using a defective block of 512×512 size for sample training, using the initial FastGan model for training, the time is 3 days, and using the improved FastGAN model provided in the embodiment of the present application for training, the time is 6 hours. It can be seen that the training speed of the initial FastGan model is slow.

[0094] Tables 1 and 2 below show the improvement in the authenticity and diversity of defect generation of the improved FastGAN model provided by the embodiment of the present application compared to the initial FastGan model. Table 1 is a table showing the relationship between the FID parameter and the number of iterations of the initial FastGan model and the improved FastGAN model, and Table 2 is a table showing the relationship between the IS parameter and the number of iterations of the initial FastGan model and the improved FastGAN model.

[0095] Table 1 Relationship between FID parameters and iteration number of the initial FastGan model and the improved FastGAN model ; It can be seen from Table 1 above that, when the number of iterations is the same, the Frichetti inner distance of the improved FastGAN model provided in the embodiment of the present application is Compared with the initial FastGan model, the improved FastGAN model provided in the embodiment of the present application generates more realistic images. Among them, FID is used to quantify the difference between the distribution of generated images and real images. FID evaluates the quality and diversity of generated images by comparing the statistical distribution of generated images and real images in high-dimensional feature space.

[0096] Table 2 Relationship between IS parameters and iteration number of the initial FastGan model and the improved FastGAN model ; It can be seen from Table 2 above that, under the same number of iterations, the Inception score (IS) of the improved FastGAN model provided in the embodiment of the present application is higher than that of the initial FastGan model, that is, the image diversity generated by the improved FastGAN model provided in the embodiment of the present application is higher. Among them, IS is used to evaluate the quality and diversity of generated images. IS not only measures the clarity of a single generated image, but also focuses on whether the generated image has sufficient diversity as a whole.

[0097] Corresponding to the above-mentioned embodiment of the method for generating surface defects of complex workpieces, the present application also provides an embodiment of a system for generating surface defects of complex workpieces. The system for generating surface defects of complex workpieces includes: an image acquisition module and a defect generation module. The image acquisition module is configured to acquire an image of the workpiece and an image of the background. The defect generation module is communicatively connected to the image acquisition module. The defect generation module is configured to acquire a defect image of the workpiece; there are defects on the surface of the workpiece, and the defect image includes defects; based on the defect image and the improved FastGAN model, a target defect image is generated; the improved FastGAN model includes a dynamic fusion mechanism and a multi-head dynamic attention mechanism; the target defect image is pasted to the workpiece, and the target workpiece is determined, and the target workpiece includes a target defect.

[0098] By using the complex workpiece surface defect generation system provided in the embodiment of the present application, a variety of target defect images are generated based on the defect image of the workpiece, so that defect samples of various workpieces, i.e., target workpieces, can be obtained by combining the target defect images. The speed of generating target defect images is improved, and the authenticity of target defect samples and the diversity of defect types are increased.

[0099] It should be noted that those skilled in the art will easily think of other embodiments of the present application after considering the specification and practicing the application disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary technical means in the art that are not disclosed in the present application. The specification and examples are only regarded as exemplary, and the true scope of the present application is indicated by the claims.

[0100] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. A method for generating surface defects of a complex workpiece, characterized in that: include: Acquire defect images of workpieces; There is a defect on the surface of the workpiece, and the defect image includes the defect; Based on the defect image and the improved FastGAN model, a target defect image is generated; the improved FastGAN model includes a dynamic fusion mechanism and a multi-head dynamic attention mechanism; The target defect image is pasted onto a base image of a base workpiece to determine a target workpiece image; the base workpiece has no defects.

2. The method for generating surface defects of complex workpieces according to claim 1, characterized in that: The step of obtaining a defect image of a workpiece includes: Acquire a first image and a second image; the first image includes a background; the second image includes the workpiece and the background; The defect image is determined based on the first image and the second image.

3. The method for generating surface defects of complex workpieces according to claim 2, characterized in that: The step of determining the defect image based on the first image and the second image includes: Based on the first image, cropping the second image to determine a complete image of the workpiece; marking defective areas in the complete image; cropping the defective area to determine an image of the defective area; The image of the defect area is combined with a preset background to determine the defect image.

4. The method for generating surface defects of complex workpieces according to claim 1, characterized in that: The step of generating a target defect image based on the defect image and the improved FastGAN model includes: Based on the defect image, generating high-resolution features and low-resolution features using the improved FastGAN model; Based on the high-resolution features and the low-resolution features, a target defect image is generated using the improved FastGAN model.

5. The method for generating surface defects of complex workpieces according to claim 1, characterized in that: Before generating a target defect image based on the defect image and the improved FastGAN model, the method further includes: Improving the initial FastGAN model based on the dynamic fusion mechanism and the multi-head dynamic attention mechanism to determine the primary FastGAN model; Get training data; The primary FastGAN model is trained based on the training data to determine the improved FastGAN model.

6. The method for generating surface defects of complex workpieces according to claim 5, characterized in that: The initial FastGAN model includes a skip layer excitation mechanism; the initial FastGAN model is improved based on the dynamic fusion mechanism and the multi-head dynamic attention mechanism to determine the primary FastGAN model, including: Introducing the dynamic fusion mechanism to improve the jump layer incentive mechanism; The multi-head dynamic attention mechanism is introduced to construct the dependency relationship between high-resolution features and low-resolution features.

7. The method for generating surface defects of a complex workpiece according to claim 6, characterized in that: The introducing of the dynamic fusion mechanism to improve the jump layer incentive mechanism includes: Introducing learnable weight parameters into the skip layer incentive mechanism ; Among them, after introducing the learnable weight parameters, the feature fusion function of the jump layer excitation mechanism is: ; in, It is a low-resolution feature; It is the feature transformation process of SLE, including adaptive average pooling, convolution layer and Sigmoid activation function; is a high-resolution feature, is the output feature after fusion; And / or, the transfer function of the multi-head dynamic attention mechanism is: ; in, and are the learnable weights of the multi-head dynamic attention mechanism, represents the Sigmoid activation function, Represents the activation function applied to the pooled features to introduce nonlinearity and remove negative values; Represents low-resolution features Perform an average pooling operation; It is a weighted high-resolution feature to combine the global information of low-resolution features.

8. The method for generating surface defects of complex workpieces according to claim 5, characterized in that: The training data includes real defect images, and the primary FastGAN model includes a generator and a discriminator; and the step of training the primary FastGAN model based on the training data to determine the improved FastGAN model includes: S01, generating a defect image based on the real defect image output by the generator; S02, inputting the image to be judged into the discriminator to determine the type of the image to be judged; the image to be judged includes the real defect image or the generated defect image; S03, when the type of the image to be determined is different from the real type of the image to be determined, improving the generator and executing step S01 again.

9. The method for generating surface defects of complex workpieces according to claim 1, characterized in that: The step of pasting the target defect image to the base image of the base workpiece to determine the target workpiece image includes: Paste the center point of the target defect image to the target pasting point on the base image; Adjusting the transparency parameter of the target defect image so that the target defect image is merged with the base image; Based on an image smoothing algorithm, the edge between the target defect image and the base image is adjusted to determine the target workpiece image, so as to improve the fusion degree between the target defect and the base image.

10. A complex workpiece surface defect generation system, characterized in that: include: An image acquisition module is configured to acquire an image of the workpiece and an image of the background; A defect generation module, communicatively connected to the image acquisition module; The defect generation module is configured to obtain a defect image of a workpiece; there is a defect on the surface of the workpiece, and the defect image includes the defect; Based on the defect image and the improved FastGAN model, a target defect image is generated; the improved FastGAN model includes a dynamic fusion mechanism and a multi-head dynamic attention mechanism; the target defect image is pasted to the workpiece, and a target workpiece is determined, wherein the target workpiece includes a target defect.

Citation Information

Patent Citations

  • Aluminum plate eddy current detection image defect segmentation method based on improved generative adversarial network

    CN112215803A

  • Steel rail surface defect image expansion method based on attention mechanism and DCGAN

    CN114842284A

  • Defect image generation method based on generative adversarial network and image fusion facility

    CN115272808A

  • Method for generating surface defect image of electric power safety tool

    CN116071352A

  • Training method of defect data generation model

    CN116188516A