Steel surface defect image generation algorithm based on multi-granularity feature guidance
Through the algorithm guided by multi-granularity features, combined with the StyleGAN2-ADA network and the intra-class hybrid module, high-quality and diverse steel surface defect images are generated, which solves the problem of insufficient image generation quality and diversity in the existing technology, and significantly improves the data The feature space richness of the set and the performance of the detection model.
Patent Information
- Application Number
- CN202410751849.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-12
- Publication Date
- 2024-10-08
AI Technical Summary
Existing image generation methods based on generative adversarial networks are difficult to generate high-quality and diverse images when expanding the steel surface defect data set. As a result, the generated images are too different from the original data set and cannot effectively improve the feature space richness of the data set. , and the problem that the small sample data set is too small.
A steel surface defect image generation algorithm based on multi-granularity feature guidance is adopted. By constructing a multi-granularity feature extraction module and StyleGAN2-ADA network, combined with the feature fusion strategy and intra-class hybrid module, the application probability of the data enhancement module is dynamically adjusted to generate high-quality and Diverse images of steel surface defects.
It achieves the generation of high-quality and diverse steel surface defect images, effectively expands the data set, improves the performance and generalization ability of the detection model, and alleviates the problem of too small data set size.
Smart Images

Figure CN118747779A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of steel surface defect image data set expansion, and in particular relates to a steel surface defect image generation algorithm based on multi-granularity feature guidance. Background Art
[0002] In the research of surface defect detection based on deep learning, the dataset is required to be large enough to ensure the effectiveness of model training. However, in actual engineering operations with complex environments, obtaining a large number of defect samples often faces many difficulties such as more interference, poor quality, high cost and long time consumption, resulting in most industrial defect datasets being small sample datasets, which brings great challenges to defect detection tasks. Therefore, surface defect image expansion technology for small sample data scenarios has gradually attracted attention and development. Among them, the traditional data enhancement methods such as single image and multi-image enhancement, which are widely used at present, are often limited to simple transformation of original data, and it is difficult to effectively improve the richness of datasets in feature space. In contrast, generative adversarial networks have significant advantages in the field of dataset expansion, such as diversity, balance and efficiency. In the past few years, they have shown great research potential and application prospects with their excellent image generation capabilities. However, the existing image generation methods based on generative adversarial networks usually directly generate a whole new image, which requires a high feature learning ability of the network; at the same time, the existing number of datasets is difficult to drive the deep learning generation model with large parameters, so that the generated images usually lack sufficient structural information and have low image quality, which leads to the generated images being too different from the original dataset and cannot be used. Therefore, the present invention draws on the idea of conditional generative adversarial networks to propose a steel surface defect image generation algorithm based on multi-granularity feature guidance. The method proposed in the present invention can utilize the excellent image generation ability of the generative adversarial network, combined with a sophisticated feature control mechanism, to generate highly realistic and diverse steel surface defect images, thereby effectively expanding the existing steel surface defect image dataset and alleviating the problem of the current small scale of the steel surface defect dataset. Summary of the invention
[0003] The purpose of the present invention is to provide a steel surface defect image generation algorithm based on multi-granularity feature guidance, which can generate high-quality and diversified steel surface defect images in a targeted manner based on the idea of feature guidance, thereby effectively expanding the existing steel surface defect data set.
[0004] The object of the present invention is achieved through the following technical solution: a steel surface defect image generation algorithm based on multi-granularity feature guidance, comprising the following steps:
[0005] S1, obtaining a data set and performing preprocessing operations on the image data in the data set;
[0006] S2, based on the data set preprocessed in step S1, create a training data set;
[0007] S3, construct a multi-granularity feature extraction module to obtain vectors of three different granularity features from coarse to fine of the steel surface defect image;
[0008] S4. Build a steel surface defect image generation module based on StyleGAN2-ADA network;
[0009] S5. Construct a loss function based on the feature vector obtained in step S3;
[0010] S6, combining the multi-granularity feature extraction module of step S3, the steel surface defect image generation module of S4, and the loss function of S5; constructing a steel surface defect image generation model, and conducting experiments and evaluation on the generation model;
[0011] The multi-granularity feature extraction module in step S3 is specifically:
[0012] The multi-granularity feature extraction module consists of four main components: basic feature extraction layer, multi-granularity feature extraction branch, self-attention module and feature conversion module. Among them, the basic feature extraction layer adopts the pre-trained ResNet50 network, and the first residual block conv2_x is output. The multi-granularity feature extraction branch is designed after the basic feature extraction layer. It is three parallel feature extraction branches. These branches extract features of different granularities by adjusting the size of the convolution kernel and the convolution step. The self-attention module is introduced after the multi-granularity feature extraction branch. Based on the classic single-head attention mechanism, it highlights important features and suppresses irrelevant information, making the model more focused and effective when processing complex defect features. The feature conversion module uses a 1×1 convolution layer to process the output feature map of each branch, and uniformly reduces its channel number to 512, thereby achieving dimensional matching. Subsequently, through the global average pooling operation, the feature map is further compressed into a 1×1×512-dimensional feature vector, and the key feature information of the steel surface defect image at three different granularity levels of coarse, medium and fine is output.
[0013] The steel surface defect image generation module in step S4 is specifically:
[0014] The steel surface defect image generation module introduces a feature fusion strategy and an intra-class mixing module based on StyleGAN2-ADA: the feature fusion strategy weightedly fuses the three feature vectors of different granularities obtained in step S3 with the random initial latent vectors of the StyleGAN2-ADA generation model, generates new latent vectors, and sends them to different convolutional layers of the synthetic network; the intra-class mixing module draws on the idea of Mixup, limits the mixing to images in the same category, and integrates with the data enhancement module in StyleGAN2-ADA, sharing the ADA adaptive adjustment mechanism, and dynamically adjusts the application probability of the data enhancement module and the IM module according to the feedback system of ADA to optimize the training effect.
[0015] In step S5, a loss function is constructed, specifically:
[0016] The loss function consists of two parts: adversarial loss and feature matching loss. The adversarial loss can clearly guide the training process of the generator and discriminator in the defect image generation module, so that the generator can produce high-quality defect images, while ensuring that the entire network can effectively learn and optimize in the end-to-end training process. The content matching loss not only focuses on the similarity at the pixel level, but also emphasizes the consistency of features at a more abstract level, so it can effectively prevent the generator from overfitting to the specific pixel values of the training data. The final loss function is obtained by weighted summing the adversarial loss and the feature matching loss.
[0017] Furthermore, the step S1 includes the following sub-steps:
[0018] S11, performing a Gaussian filtering image denoising operation on the image data in the public dataset of steel surface defects;
[0019] S12. Perform an image enhancement operation of adaptive grayscale equalization on the image data in the public dataset of steel surface defects.
[0020] Furthermore, the step S2 includes the following sub-steps:
[0021] S21, obtaining the data set preprocessed in step S1, and adjusting the image resolution to 256×256;
[0022] S22. Part of the data set after the resolution adjustment is used as a training set, and the other part is used as a verification set; then the steel surface defect image generation model guided by multi-granularity features is trained and verified.
[0023] Furthermore, the step S3 includes the following sub-steps:
[0024] S31, using the ResNet50 network as the basic feature extraction layer, and taking the output of the first residual block conv2_x in the pre-trained ResNet50 network as the basis for feature extraction;
[0025] S32. Three parallel multi-granularity feature extraction branches are designed after the basic feature extraction layer. The size of the convolution kernel and the convolution step size are adjusted to achieve the extraction of features of different granularities. Coarse-grained branch: 5×5 convolution kernel and a larger step size of 2 are used for convolution to extract the rough features of the image, such as the overall shape and contour information; Medium-grained branch: medium-sized 3×3 convolution kernel and medium step size of 2 are used for convolution to extract medium-grained features of the image, such as local shape and texture information; Fine-grained branch: smaller 3×3 convolution kernel and smaller step size of 1 are used for convolution to capture subtle features in the image, such as fine changes in edges, tiny texture details, etc. In each branch, the number of channels of the two-layer convolution increases gradually to expand the expressive power of the features and provide richer and more detailed information for each feature level; in addition, batch normalization and ReLU activation function are introduced after each convolution operation to stabilize the training process while introducing nonlinearity to enhance the ability to capture complex features.
[0026] S33. The self-attention module is introduced after the multi-granularity feature extraction branch. The self-attention module first maps the input feature map to the query, key, and value spaces through three different 1×1 convolutional layers to obtain three new feature maps. Then, the query and key feature maps are matrix multiplied to obtain the attention score matrix, which represents the attention score of each position in the feature map to all other positions. Then, each row is normalized through the softmax function to obtain the attention weight matrix. Then, the attention weight matrix is matrix multiplied with the value feature map to obtain the weighted feature map. Finally, the weighted feature map is mapped back to the original number of channels through a 1×1 convolutional layer, and residually connected with the input feature map to obtain the final output feature map. The self-attention module effectively captures the relationship between each position and other positions in the feature map through the classic single-head attention mechanism, thereby highlighting important features and suppressing irrelevant information, making the model more focused and effective when processing complex defect features.
[0027] S34. After the self-attention module, a 1×1 convolutional layer is used to process the output feature map of each branch, reducing its number of channels to 512 to achieve dimensional matching. Subsequently, the feature map is further compressed through a global average pooling operation to obtain three 1×1×512-dimensional feature vectors v c 、v m 、v f , output the key feature information of steel surface defect images at three different granularity levels: coarse, medium and fine.
[0028] Furthermore, the step S4 includes the following sub-steps:
[0029] S41. The feature vectors of three different granularities obtained in step S3 are weightedly fused with the random initial latent vector of the StyleGAN2-ADA generation model to generate a new latent vector. The specific formulas are shown in formula (1) to formula (3):
[0030]
[0031]
[0032] Among them, v c 、v m 、v f They represent the coarse-grained, medium-grained, and fine-grained feature vectors output from the multi-granularity feature extraction module respectively; z is the random initial latent vector of the StyleGAN2-ADA model.
[0033] S42, the new potential vector z obtained after fusion c 、z m 、z f After being decoupled into three intermediate latent vectors w c 、w m 、w f , which is then converted into a style vector by affine transformation and input into different layers of the StyleGAN2-ADA synthesis network to control the feature expression of the generated image at different resolution layers. Specifically, the new latent vector w c The affine transformation is input to the 1st to 4th layers of the synthesis network to adjust the overall style and contour information of the image; the new latent vector w of the medium granularity is controlled m Input to the 5th to 8th layers of the synthesis network to adjust the texture and local morphology of the image; control the fine-grained new latent vector w f Input to the 9th to 14th layers of the synthesis network to refine the details and edge features of the image. The specific operation is as shown in formulas (4)-(6):
[0034]
[0035]
[0036]
[0037] Among them, w i is the style vector of the i-th layer; f style represents the affine transformation operation; w c 、w m 、w fis the new latent vector obtained after fusion.
[0038] Step S43: Add the designed intra-class mixing module (IM module) to the StyleGAN2-ADA network structure. The key features of the IM module are as follows:
[0039] (1) Pixel-level mixing of intra-class images: The IM module randomly selects pairs of images of the same class in the training batch for pixel-level mixing, with a fixed mixing coefficient of 0.5, to ensure that each image contributes equally during the mixing process, thereby enhancing the diversity of the generation process.
[0040] (2) Integrated adaptive enhancement: The IM module is integrated with the data enhancement module in StyleGAN2-ADA, sharing the ADA adaptive adjustment mechanism. The application probability of the data enhancement module and the IM module is dynamically adjusted according to the ADA feedback system to optimize the training effect.
[0041] During the training process, the application intensity of the IM module is controlled by the ADA mechanism, and shares an adjustment probability p∈[0,1] with the image enhancement process. This probability is dynamically adjusted according to the overfitting degree of the discriminator to maintain the generalization ability of the model and prevent overfitting. Specifically, the average positive and negative value E(sign(D(x)) of the discriminator output value of 4 consecutive batches of images is used as the feedback signal for adjustment. The calculation formula of D(x) is shown in formula (7):
[0042]
[0043] Where D is the output of the discriminator; x∈real means x is a real image; x∈fake means x is a generated image. When the E value is lower than the empirically set threshold (such as 0.6), it indicates that the discriminator is underfitting and does not need enhancement processing; when the E value exceeds the threshold, the enhancement probability p is activated and gradually increases, and two modules are applied to quickly adjust the model back to the ideal training state.
[0044] Furthermore, the step S5 includes the following sub-steps:
[0045] S51. Calculate the adversarial loss. The adversarial loss calculation formula is shown in formulas (8)-(10):
[0046] L adv =L G +L D (8)
[0047]
[0048]
[0049] Among them, x is the real image; z is the random initial latent vector; v c,v m ,v f are the feature vectors of three different granularities extracted by the feature module; h is the fusion function.
[0050] S52. Calculate feature matching loss. The calculation formula of feature matching loss is shown in formula (11):
[0051] L FM =||v c -v c || 2 +||v m -v m || 2 +||v f -v f || 2 (11)
[0052] Among them, v c 、v m 、v f are the coarse, medium and fine granularity feature vectors extracted by the feature extraction module from the real image x; v c 、v m 、v f is the corresponding feature vector extracted from the generated image by the feature extraction module.
[0053] S53. Calculate the final loss function, as shown in formula (11):
[0054] L=λ adv L adv +λ FM L FM (11)
[0055] Among them, L adv Indicates resistance loss; L FM represents feature matching loss; λ adv With λ FM They respectively represent the weight ratios of the two losses, which are used to balance the contributions of the two losses.
[0056] Furthermore, the step S6 includes the following sub-steps:
[0057] S61, integrating the modules constructed in steps S3 to S5 with the loss function into a steel surface defect image generation model guided by multi-granularity features, and conducting experiments to verify the feasibility and reliability of the model;
[0058] S62, performing experiments on the data set obtained in step S2 to obtain a generated steel surface defect image;
[0059] S63, performing subjective qualitative evaluation on the generated steel surface defect image;
[0060] S64, use the FID value index to objectively evaluate the quality of the generated steel surface defect image and the model convergence effect;
[0061] S65. Use the basic defect detection model to compare the data set before and after expansion. By comparing the performance differences between the two in performance indicators, measure the impact of the generated images on the performance of the detection model, and further verify the effectiveness of the algorithm.
[0062] The beneficial effects of the present invention are as follows: Based on the idea of feature guidance and the StyleGAN2-ADA model, the present invention designs a multi-granularity feature extraction module to obtain feature vectors of different granularities, and fuses them with random potential vectors as the input of the generation network, thereby achieving fine control over the features of the generated defect image. At the same time, an improved intra-class mixing mechanism based on the Mixup strategy is introduced, and combined with the ADA technology, the application of the dynamic adjustment enhancement strategy is further optimized to further optimize the training effect of the model on a small sample data set, thereby improving the generalization ability of the model and the diversity of the generated steel surface defect images. The present invention can efficiently generate a large number of high-quality steel surface defect images for expanding the existing steel surface defect data set, alleviating the problem of the scarcity of currently publicly available steel surface defect data. BRIEF DESCRIPTION OF THE DRAWINGS
[0063] Figure 1 It is a flow chart of the steel surface defect image generation algorithm based on multi-granularity feature guidance of the present invention;
[0064] Figure 2 This is a network architecture diagram of the steel surface defect image generation algorithm based on multi-granularity feature guidance;
[0065] Figure 3 This is the structure diagram of the multi-granularity feature extraction module for steel surface defects;
[0066] Figure 4 The structure diagram after adding the IM module to StyleGAN2-ADA;
[0067] Figure 5 This is the experimental result of the steel surface defect image generation algorithm based on multi-granularity feature guidance;
[0068] Figure 6 This is the FID iteration curve of the steel surface defect image generation algorithm guided by multi-granularity features. DETAILED DESCRIPTION
[0069] The technical solution of the present invention is further described below in conjunction with the accompanying drawings.
[0070] like Figure 1As shown, the steel surface defect image generation algorithm based on multi-granularity feature guidance of the present invention comprises the following steps:
[0071] S1, obtaining a data set and performing preprocessing operations on the image data in the data set;
[0072] The specific steps include:
[0073] S11. In the experiment, the present invention uses the NEU steel surface defect public dataset of Northeastern University, which contains six types in total: cracks, inclusions, plaques, pits, scale indentations and scratches. Each type of defect sample contains 300 images, all of which are grayscale images. First, the image data in the dataset is subjected to image denoising by Gaussian filtering;
[0074] S12, performing an image enhancement operation of adaptive grayscale equalization on the image data in the NEU data set.
[0075] S2, based on the data set preprocessed in step S1, create a training data set;
[0076] The specific steps include:
[0077] S21, obtaining the data set preprocessed in step S1, and adjusting the resolution to 256×256;
[0078] S22. 210 images in each category of the resolution-adjusted NEU dataset are used as training sets, and the remaining part is used as validation sets; then the steel surface defect image generation model guided by multi-granularity features is trained and validated.
[0079] S3, build a multi-granularity feature extraction module, its structure diagram is as follows Figure 2 As shown, vectors of three different granularity features of the steel surface defect image from coarse to fine are obtained;
[0080] The specific steps include:
[0081] S31, using the ResNet50 network as the basic feature extraction layer, and taking the output of the first residual block conv2_x in the pre-trained ResNet50 network as the basis for feature extraction;
[0082] S32. Three parallel multi-granularity feature extraction branches are designed after the basic feature extraction layer. The size of the convolution kernel and the convolution step size are adjusted to achieve the extraction of features of different granularities. Coarse-grained branch: 5×5 convolution kernel and a larger step size of 2 are used for convolution to extract the rough features of the image, such as the overall shape and contour information; Medium-grained branch: medium-sized 3×3 convolution kernel and medium step size of 2 are used for convolution to extract medium-grained features of the image, such as local shape and texture information; Fine-grained branch: smaller 3×3 convolution kernel and smaller step size of 1 are used for convolution to capture subtle features in the image, such as fine changes in edges, tiny texture details, etc. In each branch, the number of channels of the two-layer convolution increases gradually to expand the expressive power of the features and provide richer and more detailed information for each feature level; in addition, batch normalization and ReLU activation function are introduced after each convolution operation to stabilize the training process while introducing nonlinearity to enhance the ability to capture complex features.
[0083] S33. The self-attention module is introduced after the multi-granularity feature extraction branch. The self-attention module first maps the input feature map to the query, key, and value spaces through three different 1×1 convolutional layers to obtain three new feature maps. Then, the query and key feature maps are matrix multiplied to obtain the attention score matrix, which represents the attention score of each position in the feature map to all other positions. Then, each row is normalized through the softmax function to obtain the attention weight matrix. Then, the attention weight matrix is matrix multiplied with the value feature map to obtain the weighted feature map. Finally, the weighted feature map is mapped back to the original number of channels through a 1×1 convolutional layer, and residually connected with the input feature map to obtain the final output feature map. The self-attention module effectively captures the relationship between each position and other positions in the feature map through the classic single-head attention mechanism, thereby highlighting important features and suppressing irrelevant information, making the model more focused and effective when processing complex defect features.
[0084] S34. After the self-attention module, a 1×1 convolutional layer is used to process the output feature map of each branch, reducing its number of channels to 512 to achieve dimensional matching. Subsequently, the feature map is further compressed through a global average pooling operation to obtain three 1×1×512-dimensional feature vectors v c 、v m 、v f , output the key feature information of steel surface defect images at three different granularity levels: coarse, medium and fine.
[0085] S4. Build a steel surface defect image generation module based on StyleGAN2-ADA network;
[0086] The specific steps include:
[0087] S41. The three feature vectors of different granularities obtained in step S3 are weightedly fused with the random initial latent vector of the StyleGAN2-ADA generation model to generate a new latent vector. The specific formulas are shown in formulas (1)-(3):
[0088]
[0089] Among them, v c 、v m 、v f They represent the coarse-grained, medium-grained, and fine-grained feature vectors output from the multi-granularity feature extraction module respectively; z is the random initial latent vector of the StyleGAN2-ADA model.
[0090] S42, the new potential vector z obtained after fusion c 、z m 、z f After being decoupled into three intermediate latent vectors w c 、w m 、w f , which is then converted into a style vector by affine transformation and input into different layers of the StyleGAN2-ADA synthesis network to control the feature expression of the generated image at different resolution layers. Specifically, the new latent vector w c The affine transformation is input to the 1st to 4th layers of the synthesis network to adjust the overall style and contour information of the image; the new latent vector w of the medium granularity is controlled m Input to the 5th to 8th layers of the synthesis network to adjust the texture and local morphology of the image; control the fine-grained new latent vector w f Input to the 9th to 14th layers of the synthesis network to refine the details and edge features of the image. The specific operation is as shown in formulas (4)-(6):
[0091]
[0092] Among them, w i is the style vector of the i-th layer; f style represents the affine transformation operation; w c 、w m 、w f is the new latent vector obtained after fusion.
[0093] Step S43: Add the designed intra-class mixing module (IM module) to the StyleGAN2-ADA network structure, and its structure changes as follows: Figure 4 As shown in the figure, (a) is the structure before adding the IM module, and (b) is the structure after adding the IM module. The key features of the IM module are as follows:
[0094] 1) Pixel-level mixing of intra-class images: The IM module randomly selects pairs of images of the same class in the training batch for pixel-level mixing, with a fixed mixing coefficient of 0.5, which ensures that each image contributes equally during the mixing process, thereby enhancing the diversity of the generation process.
[0095] 2) Integrated adaptive enhancement: The IM module is integrated with the data enhancement module in StyleGAN2-ADA, sharing the ADA adaptive adjustment mechanism. The application probability of the data enhancement module and the IM module is dynamically adjusted according to the ADA feedback system to optimize the training effect.
[0096] During the training process, the application intensity of the IM module is controlled by the ADA mechanism, and shares an adjustment probability p∈[0,1] with the image enhancement process. This probability is dynamically adjusted according to the overfitting degree of the discriminator to maintain the generalization ability of the model and prevent overfitting. Specifically, the average positive and negative value E(sign(D(x)) of the discriminator output value of 4 consecutive batches of images is used as the feedback signal for adjustment. The calculation formula of D(x) is as shown in formula (7):
[0097]
[0098] Where D is the output of the discriminator; x∈real means x is a real image; x∈fake means x is a generated image. When the E value is lower than the empirically set threshold (such as 0.6), it indicates that the discriminator is underfitting and does not need enhancement processing; when the E value exceeds the threshold, the enhancement probability p is activated and gradually increases, and two modules are applied to quickly adjust the model back to the ideal training state.
[0099] S5. Construct a loss function based on the feature vector obtained in step S3;
[0100] The specific steps include:
[0101] S51. Calculate the adversarial loss. The adversarial loss calculation formula is shown in formulas (8)-(10):
[0102] L adv =L G +L D (8)
[0103]
[0104]
[0105] Among them, x is the real image; z is the random initial latent vector; v c ,v m ,v f are the feature vectors of three different granularities extracted by the feature module; h is the fusion function.
[0106] S52. Calculate feature matching loss. The calculation formula of feature matching loss is shown in formula (11):
[0107] L FM =||v c -v c || 2 +||v m -v m || 2 +||v f -v f || 2 (11)
[0108] Where: v c 、v m 、v f are the coarse, medium and fine granularity feature vectors extracted by the feature extraction module from the real image x; v c 、v m 、v f is the corresponding feature vector extracted from the generated image by the feature extraction module.
[0109] S53. Calculate the final loss function, as shown in formula (12):
[0110] L=λ adv L adv +λ FM L FM (12)
[0111] Among them, L adv Indicates resistance loss; L FM represents feature matching loss; λ adv With λ FM They respectively represent the weight ratios of the two losses, which are used to balance the contributions of the two losses.
[0112] S6, combining the multi-granularity feature extraction module of step S3, the steel surface defect image generation module of S4, and the loss function of S5; constructing a steel surface defect image generation model, and conducting experiments and evaluation on the generation model;
[0113] The specific steps include:
[0114] S61, integrating the modules constructed in steps S3 to S5 with the loss function into a steel surface defect image generation model guided by multi-granularity features, the overall network architecture of which is shown in the figure below: Figure 2 As shown, experiments were conducted to verify the feasibility and reliability of the model;
[0115] S62, perform experiments on the data set in step S2 to obtain the generated steel surface defect image. The experimental results are as follows: Figure 5As shown, (a) is the real defect image, and (b) is the algorithm-generated image;
[0116] S63. Subjective qualitative evaluation of the generated steel surface defect images shows that the texture and details of the defect areas of the six types of defect images generated by the algorithm are very clear and realistic, and difficult to distinguish from the real defect images. At the same time, the defect areas are not completely consistent with the original images, maintaining rich feature diversity.
[0117] S64, use the FID value index to objectively evaluate the quality of the generated steel surface defect image and the model convergence effect;
[0118] FID is an indicator used to evaluate the quality of generated images, especially widely used in generative adversarial network research. It measures the similarity between the generated image and the real image by comparing the feature activation distribution of the generated image and the real image at a specific layer of the Inception v3 model. The lower the FID score, the higher the similarity between the generated image and the real image. Its calculation formula is shown in formula (13):
[0119]
[0120] Among them, x is the real image; g is the generated image; μ x , μ g are the mean of the feature vectors output by the Inception v3 network for the real image and the generated image respectively; Represent the covariance matrices of the feature vectors of the real image and the generated image respectively.
[0121] During the experiment, the FID value iteration curve of the algorithm in the six types of defect generation tasks is as follows: Figure 6 As shown in the figure, (a), (b), (c), (d), (e), and (f) are the training curves of the algorithm on six types of defects: inclusions, plaques, cracks, pits, oxide scale indentations, and scratches. The vertical axis represents the FID score, and the horizontal axis shows the total number of training samples, in kimg (thousand images). Figure 6 It can be seen that in the six types of defect image generation tasks, the training curve of the algorithm shows an excellent convergence speed, and the final FID value converges to an ideal smaller value.
[0122] S65. Use the basic defect detection model to compare the data set before and after expansion. By comparing the performance differences between the two in performance indicators, measure the impact of the generated images on the performance of the detection model, and further verify the effectiveness of the algorithm.
[0123] In order to verify the actual contribution of the images generated by the present invention to the steel surface defect detection task, the original data set before expansion and the data set expanded by the algorithm of the present invention were respectively put into the basic YOLOV5 detection model for training. By comparing the performance differences between the two in terms of performance indicators, the impact of the images generated by the algorithm on the performance of the detection model was measured, and the effectiveness of the algorithm was further verified.
[0124] The six models trained by the algorithm of the present invention were used to generate corresponding six categories of defect images respectively, expanding the original NEU dataset from 300 to 900 defect images of each category, with a total of 5,400 defect images of six categories. All newly generated images have been labeled using the LabelImg tool. Since the size of the expanded dataset is still limited, the experiment assigns most of the defect images to the training set to ensure that the model can fully learn the defect features, and finally divides the dataset into a training set, a validation set, and a test set in a ratio of 8:1:1. In order to ensure the accuracy of the test, the following guidelines should be followed when constructing the test set: (1) The images in the test set must not overlap with the input images of the defect image generation algorithm; (2) The test set can only contain real images; (3) The defect category distribution in the test set must be consistent with the distribution of the real dataset.
[0125] The yolov5s-6.0 network was used, and 200 iterations were performed on the datasets before and after the expansion. The evaluation was performed with 0.5 as the standard value of the IoU threshold. The comparison of the detection results is shown in Table 1.
[0126] Table 1 Comparative experimental results
[0127]
[0128] As shown in Table 1, the mAP value (mean average precision) of the YOLOv5s model on the expanded dataset is 2.9% higher than that of the original dataset. Among them, the AP values (mean average precision) of the six types of defects have all increased, and the most obvious gains are the two types of defects, cracks and iron oxide indentations, which had extremely unsatisfactory detection effects before expansion. This shows that the defect images generated by the algorithm of the present invention not only increase the scale of the dataset, but also increase the diversity of the dataset, especially for these two types of defects with poor detection effects due to unclear intra-class differences, the detection accuracy has been significantly improved.
[0129] In summary, the algorithm proposed in this invention can generate high-quality and diverse steel surface defect images, effectively solve the problem of too few defect samples, enrich the data set, and thus improve the performance of the detection model.
[0130] Those skilled in the art will appreciate that the embodiments described herein are intended to help readers understand the principles of the present invention, and should be understood that the protection scope of the present invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific variations and combinations that do not deviate from the essence of the present invention based on the technical revelations disclosed by the present invention, and these variations and combinations are still within the protection scope of the present invention.
Claims
1. A method for generating steel surface defect images based on multi-granularity feature guidance, characterized in that: The following steps are involved: S1, obtaining a data set and performing preprocessing operations on the image data in the data set; S2, based on the data set preprocessed in step S1, create a training data set; S3, construct a multi-granularity feature extraction module to obtain vectors of three different granularity features from coarse to fine of the steel surface defect image; S4. Build a steel surface defect image generation module based on StyleGAN2-ADA network; S5. Construct a loss function based on the feature vector obtained in step S3; S6. Combining the multi-granularity feature extraction module of step S3, the steel surface defect image generation module of S4, and the loss function of S5, a steel surface defect image generation model is constructed, and experiments and evaluations are conducted on the generation model.
2. The method for generating steel surface defect images based on multi-granularity feature guidance according to claim 1, characterized in that: The step S1 comprises the following sub-steps: S11, performing a Gaussian filtering image denoising operation on the image data in the public dataset of steel surface defects; S12. Perform an image enhancement operation of adaptive grayscale equalization on the image data in the public dataset of steel surface defects.
3. The method for generating steel surface defect images based on multi-granularity feature guidance according to claim 1, characterized in that: The step S2 comprises the following sub-steps: S21, obtaining the data set preprocessed in step S1, and adjusting the image resolution to 256×256; S22, using part of the dataset after adjusting the resolution as a training set, and the other part as a validation set; Subsequently, the steel surface defect image generation model guided by multi-granularity features was trained and verified.
4. The method for generating steel surface defect images based on multi-granularity feature guidance according to claim 1, characterized in that: The step S3 comprises the following sub-steps: S31, using the ResNet50 network as the basic feature extraction layer, and taking the output of the first residual block conv2_x in the pre-trained ResNet50 network as the basis for feature extraction; S32. Design three parallel multi-granularity feature extraction branches after the basic feature extraction layer, and extract features of different granularities by adjusting the size of the convolution kernel and the convolution step size; S33, introduce the self-attention module after the multi-granularity feature extraction branch to perform mapping and feature weight adjustment; S34. After the self-attention module, a 1×1 convolution layer and pooling operation are used to process the output feature map of each branch to obtain feature vectors of three different granularities.
5. The method for generating steel surface defect images based on multi-granularity feature guidance according to claim 1, characterized in that: The step S4 comprises the following sub-steps: S41, performing weighted fusion on the feature vectors of three different granularities obtained in step S3 and the random initial latent vector of the StyleGAN2-ADA generation model to generate a new latent vector; S42, the new latent vector obtained after fusion is converted into a style vector through affine transformation and input into different layers of the StyleGAN2-ADA synthesis network; S43. An intra-class mixing module (IM module) is added to the StyleGAN2-ADA network structure to perform pixel-level mixing of intra-class images and integrate an adaptive enhancement mechanism.
6. The method for generating steel surface defect images based on multi-granularity feature guidance according to claim 1, characterized in that: The step S5 comprises the following sub-steps: S51. Calculate the adversarial loss, which is used to guide the training process of the generator and the discriminator. S52, calculate feature matching loss, which focuses on the consistency at the feature level; S53. Perform a weighted summation of the adversarial loss and the feature matching loss to obtain the final loss function.
7. The method for generating steel surface defect images based on multi-granularity feature guidance according to claim 1, characterized in that: The step S6 comprises the following sub-steps: S61, integrating the modules constructed in steps S3 to S5 and the loss function into a steel surface defect image generation model guided by multi-granularity features; S62, conducting experiments on the preprocessed data set to obtain generated steel surface defect images; S63, performing subjective qualitative evaluation on the generated steel surface defect image; S64, use the FID value indicator to objectively evaluate the quality of generated images and model convergence effect; S65. Compare the data sets before and after expansion through the basic defect detection model to verify the impact of the generated images on the performance of the detection model.
Citation Information
Cited By
Multi-granularity prompting metal surface defect image synthesis method based on pre-training diffusion model
CN120451071A
Industrial defect sample generation method based on small sample fine tuning and controllable diffusion model
CN121169823A
A Method for Generating Industrial Defect Samples Based on Small Sample Fine-tuning and Controlled Diffusion Model
CN121169823B
