A weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasing

CN122966539APending Publication Date: 2026-10-23ZHEJIANG UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611018832.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-09
Publication Date
2026-10-23

AI Technical Summary

Technical Problem

然而,这类方法仍存在以下不足:1)模型易过度编辑图像,导致分割结果超出实际缺陷区域;2)需要训练两个生成器和两个判别器,资源消耗大、训练难度高,且推理时依赖额外的后处理步骤

Benefits of technology

1)本发明设计了一种像素擦除生成对抗网络,生成器输出的缺陷概率图具有与输入图像相同的空间尺寸,能够保留缺陷的精细结构,显著改善了对细小缺陷的分割效果。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122966539A_ABST
    Figure CN122966539A_ABST
Patent Text Reader

Abstract

The application discloses a kind of weak supervision surface defect segmentation methods based on knowledge transfer and pixel erasing.The method comprises the following steps: obtaining defect image and defect-free image and labeling image-level label to construct training set;Establish pixel erasing generative adversarial network, the generator of network generates defect probability map for defect image, defect and defect-free image are synchronously executed pixel erasing, then input discriminator to classify, on this basis, the total generation loss comprising generator loss, auxiliary loss and morphological constraint loss is constructed, and the total discriminant loss comprising discriminator loss and knowledge distillation loss is alternately trained;The image to be segmented is input into the trained generator to obtain the defect probability map, and the final segmentation result is obtained by threshold processing.The present application only uses image-level label for training, can efficiently and accurately output pixel-level defect segmentation result, while ensuring high segmentation accuracy, has lower computational complexity.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a surface defect segmentation method, which falls within the field of defect detection technology, and specifically to a weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure. Background Technology

[0002] Surface defect detection is a crucial step in industrial product quality control. In recent years, deep learning-based defect segmentation methods have made significant progress; however, these methods typically rely on fully supervised learning, requiring pixel-level annotation of the training dataset, which is costly. To alleviate this problem, weakly supervised surface defect segmentation methods have been proposed. These methods only require image-level annotation to train the model and achieve defect segmentation, significantly reducing annotation costs.

[0003] Currently, weakly supervised defect segmentation methods mainly utilize class activation maps in classification networks to locate defects. However, class activation maps are derived from low-resolution feature maps that have undergone multiple downsampling, resulting in low spatial resolution and poor localization of small defects, easily leading to the loss of details or incomplete predictions. To address this issue, some methods leverage CycleGANs, which learn to transform defect images into defect-free images to indirectly locate defect regions, demonstrating better performance compared to methods based on class activation maps. However, these methods still suffer from the following drawbacks: 1) the model is prone to over-editing images, causing segmentation results to exceed the actual defect region; 2) they require training two generators and two discriminators, resulting in high resource consumption, high training difficulty, and reliance on additional post-processing steps during inference. These shortcomings limit their application in real-world industrial scenarios. Summary of the Invention

[0004] To address the problems existing in the background art, the present invention provides a weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure.

[0005] The technical solution adopted in this invention is: The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure of the present invention includes: Step S1: Obtain several defective and non-defective images and label them with image-level labels to construct a training set.

[0006] Step S2: Establish a pixel erasure generative adversarial network including a generator and a discriminator. Train the pixel erasure generative adversarial network using the training set. The generator processes the defective images in the training set and outputs the corresponding defect probability map. Perform synchronous pixel erasure operation on the corresponding defective and non-defective images using the defect probability map to obtain defective and non-defective erased images, which are then input into the discriminator for classification. Based on this, construct a total generation loss including generator loss, auxiliary loss, and morphological constraint loss, and a total discriminant loss including discriminator loss and knowledge distillation loss. Train the pixel erasure generative adversarial network alternately until the total generation loss and the total discriminant loss converge, and obtain the trained generator.

[0007] Step S3: During testing, the image to be segmented is input into the trained generator, which then processes and outputs a defect probability map of the image to be segmented. Thresholding is applied to the defect probability map to obtain the final segmentation result, thus achieving weakly supervised surface defect segmentation.

[0008] In step S1, each defective image is labeled with an image-level label indicating the defect, and each defect-free image is labeled with an image-level label indicating the absence of defects. No pixel-level labels are used, meaning there is no need to label the outline of the defect.

[0009] In step S2, the defect erasure image and defect-free erased images as follows: in, and Defect images and defect-free images Corresponding to the defect-erased image and the defect-free erased image obtained through pixel erasure operation, These are the spatial coordinates of the pixel. Represents the color channels of an image; For defect images The corresponding defect probability map is obtained after processing by the generator. , and These are the height and width of the defect probability map, respectively. and Defect images and defect-free images In image color channels The weighted average pixel value on the surface. This represents summation over all spatial locations; It is a very small constant greater than 0.

[0010] In step S2, the total generation loss Specifically as follows: in, and These are the first and second loss weights, respectively; , and These are generator loss, morphological constraint loss, and auxiliary loss, respectively.

[0011] Total discriminant loss Specifically as follows: in, To determine the loss weight; and These are discriminator loss and knowledge distillation loss, respectively.

[0012] During training, the parameters of the discriminator and the generator are updated alternately. The discriminator is used to distinguish between the two types of erased images and is only used during the training phase.

[0013] The aforementioned morphological constraint loss as follows: in, , and The defect probability map generated by the generator, along with its height and width, are shown below. , and These are the shape constraint weights and their first and second preset values, respectively; and These are defect probability maps. Binarized images and temporary labeled images.

[0014] Defect probability map Thresholding is performed to obtain a binarized image. Then, a morphological closing operation is performed, followed by an erosion operation to obtain a temporary label image. .

[0015] The knowledge distillation loss During construction, a teacher classification model is first pre-trained using a training set. After training, the weights are frozen to obtain the pre-trained teacher classification model. This model consists of a backbone feature extractor, convolutional layers, a global average pooling layer, and a sigmoid layer connected in sequence. Defect images are input into both the pre-trained model and the discriminator. The convolutional layers of the pre-trained model output class activation maps corresponding to the defect images, while the last convolutional layer in the discriminator outputs feature maps corresponding to the defect images. The class activation maps and feature maps are spatially aligned to obtain aligned class activation maps and aligned feature maps. Normalization is then performed, and the mean squared error between the normalized aligned class activation maps and aligned feature maps is calculated as the knowledge distillation loss. .

[0016] The aforementioned auxiliary loss During construction, based on the defect probability map output by the generator after processing the defect-free image, the mean square error between the defect probability map and the all-zero probability map is calculated as an auxiliary loss. .

[0017] The electronic device of the present invention includes: a memory and a processor coupled to each other, wherein the memory stores program data, and the processor invokes the program data to execute the method described above.

[0018] The present invention provides a computer-readable storage medium having program data stored thereon, which, when executed by a processor, implements the method described above.

[0019] The beneficial effects of this invention are: 1) This invention designs a pixel erasure generative adversarial network. The defect probability map output by the generator has the same spatial size as the input image, which can preserve the fine structure of the defect and significantly improve the segmentation effect of small defects.

[0020] 2) This invention proposes a morphological constraint loss, which shrinks the high-probability region in the defect probability map by generating a temporary label constraint generator, so that the segmentation result output by the model more accurately matches the actual defect boundary.

[0021] 3) This invention introduces knowledge distillation loss, which uses a pre-trained teacher classification model to generate class activation maps and guides the discriminator's feature maps to match them. This enables the discriminator to continuously have the ability to perceive defect features throughout the training process, thereby providing continuous and effective feedback to the generator, avoiding training oscillations, and accelerating the convergence speed.

[0022] 4) This invention constructs an auxiliary loss that directly constrains the generator to output a defect probability map for defect-free images that approaches zero, effectively suppressing false positive predictions and improving the reliability of the model in actual industrial inspection.

[0023] 5) The pixel erasure generative adversarial network of the present invention contains only one generator and one discriminator. Compared with the CycleGAN-based method, it has lower training complexity and does not require complex post-processing during inference, thereby reducing the computational burden and deployment difficulty.

[0024] In summary, this invention utilizes only image-level labels for training, achieving high-precision pixel-level defect segmentation while maintaining low computational complexity. Attached Figure Description

[0025] Figure 1 This is a flowchart of the method of the present invention; Figure 2 This is a schematic diagram of the generator and discriminator in an embodiment of the present invention, wherein, Figure 2 (a) is a schematic diagram of the generator structure. Figure 2 (b) is a schematic diagram of the discriminator structure; Figure 3 This is an example diagram of the segmentation result in an embodiment of the present invention, wherein, Figure 3 (a) is an image of the surface defect to be tested. Figure 3 (b) is the binary segmentation result output by the method of the present invention. Detailed Implementation

[0026] The present invention will be further described in detail below with reference to the accompanying drawings and specific embodiments. These embodiments are implemented based on the technical solution of the present invention, providing detailed implementation methods and specific operating procedures; however, the scope of protection of the present invention is not limited to the following embodiments.

[0027] like Figure 1 As shown, the weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure of the present invention is as follows: Step S1: Obtain several defective and non-defective images and label them with image-level labels to construct a training set; specifically, each defective image is labeled with an image-level label indicating that it is defective, specifically labeled as 0, and each non-defective image is labeled with an image-level label indicating that it is non-defective, specifically labeled as 1. No pixel-level labels are labeled, that is, there is no need to label the outline of the defect, etc.

[0028] Step S2: Establish a pixel erasure generative adversarial network (GAN) including a generator and a discriminator. Train the GAN using a training set. The generator processes the defective images in the training set and outputs the corresponding defect probability map. Perform synchronous pixel erasure operations on the corresponding defective and non-defective images using the defect probability map to obtain the defect-erased image. and defect-free erased images as follows: in, and Defect images and defect-free images Corresponding to the defect-erased image and the defect-free erased image obtained through pixel erasure operation, These are the spatial coordinates of the pixel. Represents the color channels of an image; For defect images The corresponding defect probability map is obtained after processing by the generator. , and These represent the height and width of the defect probability map, respectively. The value of each element in the graph represents the probability that the corresponding spatial location belongs to a defect area; using the defect probability map... complement As pixel-level weights and Defect images and defect-free images In image color channels The weighted average pixel value on the surface. This represents summation over all spatial locations; It is a very small constant greater than 0, to prevent division by zero, in specific implementation. -8.

[0029] Image with defects erased and defect-free erased images The input is classified in the discriminator. Based on this, a total generation loss is constructed, which includes generator loss, auxiliary loss, and morphological constraint loss. A total discriminant loss is constructed, which includes discriminator loss and knowledge distillation loss. The total generation loss of the generator is also constructed. Specifically as follows: in, and These are the first and second loss weights, which are fixed weights; in specific implementation... , ; , and These are generator loss, morphological constraint loss, and auxiliary loss, respectively.

[0030] Total discrimination loss of the discriminator Specifically as follows: in, To determine the loss weight; and These are discriminator loss and knowledge distillation loss, respectively.

[0031] Discriminating loss weights As the dynamic weight of the knowledge distillation loss, in specific implementation, , This is the current epoch number. is the total number of epochs. The initial value of 40 was determined experimentally, which allows knowledge distillation to effectively guide the discriminator in the early stages of training; the decay rate of exponent 10 allows the impact of knowledge distillation to decrease rapidly in the later stages of training, allowing the discriminator to focus on adversarial tasks, while mitigating the misleading effects of potential errors in the teacher model's class activation graph.

[0032] Generator loss and discriminator loss The original adversarial loss that constitutes the pixel erasure generative adversarial network. The details are as follows: in, Expressing expectations; This represents the output of the discriminator, i.e., a value between 0 and 1.

[0033] During training, the parameters of the discriminator and the generator are updated alternately. The discriminator is used to distinguish between two types of erased images and outputs a probability value between 0 and 1. It is only used during the training phase.

[0034] During training, the discriminator minimizes the discriminator loss. To enhance its ability to distinguish between the two types of erased images, the generator minimizes the generator loss. To generate a more complete defect probability map, so that it can maximize the classification error of the discriminator, so that the erased... It is difficult for discriminators to recognize.

[0035] Shape constraint loss as follows: in, , and The defect probability map generated by the generator, along with its height and width, are shown below. , and These are the shape constraint weights and their first and second preset values, respectively, both of which are positive numbers. The specific values ​​to be used in implementation will be... , ; and These are defect probability maps. Binarized images and temporary labeled images.

[0036] Defect probability map Thresholding is performed to obtain a binarized image. Then, a morphological closing operation is performed to fill the holes and gaps in the foreground region, followed by an erosion operation to shrink the foreground region, resulting in a temporary label image. .

[0037] To suppress the excessive erasure problem of the generator, a morphological constraint loss is constructed. Used to generate a defect probability map from the generator output. Apply morphological constraints to reduce the defect probability map of the generator. The high-probability regions in the data are identified, resulting in segmentation results that better reflect the actual defects.

[0038] Knowledge distillation loss During construction, a teacher classification model is first pre-trained using a training set. After training, the weights are frozen to obtain the pre-trained teacher classification model. The teacher classification model consists of a backbone feature extractor, a convolutional layer with 1 channel and a 1×1 kernel, a global average pooling layer, and a sigmoid layer, connected in sequence. Defect images are input into the pre-trained teacher classification model and the discriminator, respectively. The convolutional layer of the pre-trained teacher classification model outputs the class activation map corresponding to the defect image. The last convolutional layer in the discriminator outputs the feature map corresponding to the defect image. Spatial alignment is performed on the class activation map and feature map to obtain an aligned class activation map. and alignment feature map Then, normalization is performed, and the mean squared error between the normalized aligned class activation map and the aligned feature map is calculated as the knowledge distillation loss. The details are as follows: in, and These represent the height and width of the class activation map after spatial dimension alignment; It is the Frobenius norm; This is a normalization operation.

[0039] Knowledge distillation loss This is used to transfer knowledge from a pre-trained teacher classification model to the discriminator, stabilize discriminator training, and enhance its perception of defect features, thereby improving the discriminator's ability to extract defect features; this is achieved by minimizing the knowledge distillation loss. The discriminator can mimic the teacher's classification model's focus on defect areas, thereby maintaining a stable defect feature extraction capability during dynamic training.

[0040] Auxiliary loss During construction, a defect probability map is output based on the generator after processing the defect-free image. The mean square error between the defect probability map and the all-zero probability map is calculated as an auxiliary loss. The details are as follows: in, and These represent the height and width of the defect probability map, respectively.

[0041] Constructing auxiliary loss This is used to suppress false positive predictions by the generator for defect-free images. It directly penalizes non-zero predictions, forcing the generator to output a probability map close to all zeros for defect-free images.

[0042] The pixel erasure generative adversarial network (GAN) is trained alternately until the total generation loss and total discriminant loss converge, resulting in a trained generator. The generator in the pixel erasure GAN employs an encoder-decoder structure to map the input image to a defect probability map; the discriminator uses a PatchGAN Markov discriminator to classify and distinguish the input image.

[0043] Step S3: During testing, the image to be segmented is input into the trained generator. After processing, the generator outputs a defect probability map of the image to be segmented. Thresholding is then applied to the defect probability map to obtain the final segmentation result, achieving weakly supervised surface defect segmentation. During the testing phase, the image to be processed should come from the same data acquisition environment as the training set images, such as using the same type of industrial camera and acquiring images of the same type of object under the same lighting conditions. The thresholding process includes: setting threshold parameters. θ Defect probability maps with probability values ​​greater than a threshold parameter θ Pixels that are not defective are identified as defective pixels; otherwise, they are identified as background pixels.

[0044] Specific embodiments of the present invention are as follows: 1. Dataset preparation: This embodiment is based on the publicly available surface defect dataset DAGM 2007. This dataset contains defective and non-defective images, with the image resolution uniformly adjusted to 256×256 pixels. Six hundred images were selected from the DAGM 2007 dataset: 300 for training, 100 for validation, and 200 for testing, with an equal number of defective and non-defective images in each subset. The training set only provides image-level labels: each defective image corresponds to an image-level label "0", and each non-defective image corresponds to an image-level label "1". To evaluate the model's segmentation performance, pixel-level annotations were created for all images in the validation and test sets; that is, each pixel in the image was manually labeled, with defective pixels labeled "1" and background pixels labeled "0".

[0045] 2. Construct a pixel erasure generative adversarial network: The pixel erasure generative adversarial network constructed in this embodiment includes a generator and a discriminator. The generator adopts an encoder-decoder architecture, such as... Figure 2 As shown in (a), the encoder consists of four layers with output channels of 64, 128, 256, and 384 respectively. Each layer includes two convolutional blocks followed by a max-pooling layer with a stride of 2. Each convolutional block consists of a 3×3 convolutional layer, a batch normalization layer, and a ReLU activation function connected sequentially. The deepest layer of the encoder is connected to the deepest layer of the decoder through a bottleneck layer, which consists of two convolutional blocks and has 384 output channels. The decoder consists of four layers. In each layer, the input feature map is first upsampled to twice its size using bilinear interpolation, then concatenated with the feature map of the corresponding layer of the encoder along the channel dimension via skip connections, and then passed through two convolutional blocks sequentially. The number of output channels is the same as that of the corresponding layer of the encoder. The decoder is finally connected to a 1×1 convolutional layer and a sigmoid activation function, outputting a defect probability map of the same size as the input image.

[0046] The discriminator employs a PatchGAN design, consisting of four stacked convolutional modules with output channels of 32, 64, 128, and 256, respectively. Each convolutional module comprises a convolutional layer, an instance normalization layer, and a LeakyReLU activation function, all connected sequentially. The convolutional kernels of the convolutional layers are 3×3 with a stride of 2. The output of the last convolutional module is passed through a 1×1 convolutional layer to reduce the number of channels to 1, then through a global average pooling layer to obtain scalar features, and finally through a sigmoid activation function to output the discriminant probability.

[0047] 3. Generate a defect probability map: A defect image is randomly selected from the training set. Input it into the generator to obtain the defect probability map. Probability graph The value of each element represents the probability that the corresponding pixel location belongs to a defect area.

[0048] 4. Perform synchronous pixel erasure operation: Select a defect-free image from the training set. Using defect probability maps right and Perform a synchronous pixel erasure operation to obtain the erased image. and The basic idea of ​​this operation is to replace the pixels in the defective area with the average pixel value of the non-defective area in the image, thereby achieving the purpose of erasing the defect.

[0049] 5. Discriminator discrimination: Erase image and Input the discriminator, and the discriminator outputs the judgment result.

[0050] 6. Construct the loss function: This embodiment constructs the above four loss functions: adversarial loss, morphological constraint loss, knowledge distillation loss, and auxiliary loss.

[0051] 6.1 Combating Losses : Define adversarial loss Includes discriminator loss and generator loss During training, the discriminator minimizes... To enhance its ability to distinguish between the two types of erased images, the generator minimizes... To generate a more complete defect probability map, so that the erased... It is difficult for discriminators to recognize.

[0052] 6.2. Shape constraint loss: To suppress the excessive erasure problem of the generator, this embodiment constructs a morphological constraint loss. The specific steps are as follows: Thresholding: Set the threshold to 0.5 and adjust the defect probability map. Binarization .

[0053] Morphological closing operation: using a structuring element of size 11×11 Perform a closing operation to fill the holes and small gaps inside the defective area.

[0054] Erosion operation: Further erosion is performed using a 3×3 structuring element to obtain a temporary label image. This shrinks the foreground area.

[0055] Shape constraint loss Reduce the defect probability map of the generator The high-probability regions in the data are identified, resulting in segmentation results that more closely resemble actual defect boundaries.

[0056] 6.3 Knowledge distillation loss: To stabilize the training of the discriminator and enhance its ability to perceive defect features, this embodiment constructs a knowledge distillation loss function. This is used to transfer knowledge from a pre-trained teacher classification model to the discriminator. The specific steps are as follows: Pre-trained teacher classification model: A binary classification model is trained using unerased original defective images and defect-free images. The model structure includes a backbone feature extractor (using ResNet50 in this embodiment, with the last fully connected layer removed), a convolutional layer with 1 channel and a 1×1 kernel, a global average pooling layer, and a sigmoid layer, all connected in sequence. During training, the Adam optimizer is used with a learning rate of 0.0005, a batch size of 4, and 50 epochs of training. After training, the teacher model parameters are fixed.

[0057] Obtain class activation maps and discriminator feature maps: [This refers to] defect images. The input teacher model is used, and the output of the convolutional layer serves as the class activation map. Images of the same defect Input the discriminator and obtain the feature map output from the last convolutional layer of the discriminator. .

[0058] Spatial Dimension Alignment: Class Activation Map Alignment via Bilinear Interpolation Adjust to the discriminator feature map The same spatial dimensions are denoted as .

[0059] Knowledge distillation loss Calculation: For and L2 normalization was performed separately, and then the knowledge distillation loss was calculated. .

[0060] By minimizing The discriminator can mimic the teacher model's focus on defect regions, thereby maintaining a stable defect feature extraction capability during dynamic training.

[0061] 6.4 Auxiliary Losses: To suppress false positive predictions by the generator for defect-free images, this embodiment constructs an auxiliary loss. This loss directly penalizes non-zero predictions, forcing the generator to output a probability map close to all zeros for defect-free images.

[0062] 7. Joint training: This embodiment employs an alternating training strategy. In each iteration batch, the total discriminant loss is first used. Update the discriminator, then apply the total generation loss. The generator is updated. The hyperparameters in the loss function are all determined optimally based on validation set experiments. Those skilled in the art will understand that the above hyperparameters can be adaptively adjusted for different datasets or application scenarios, which does not exceed the scope of protection of this invention.

[0063] During model training, the optimizer used was Adam, with a learning rate of 0.0001. The batch size was set to 4. The total number of training epochs was [not specified]. It is 100.

[0064] 8. Defect segmentation during the testing phase: During the testing phase, the image of the surface to be tested is input into the trained generator to obtain a defect probability map. This embodiment sets a threshold. θ =0.5, the value in the defect probability graph is greater than 0.5. θ If the pixels are identified as defects, the final segmentation result can be obtained, such as... Figure 3 (a) and Figure 3 As shown in (b).

[0065] The above description is merely a preferred embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure, characterized in that, include: Step S1: Obtain several defective and non-defective images and label them with image-level labels to construct a training set; Step S2: Establish a pixel erasure generative adversarial network including a generator and a discriminator. Train the pixel erasure generative adversarial network using the training set. The generator processes the defective images in the training set and outputs a defect probability map. Perform synchronous pixel erasure operations on defective and non-defective images using the defect probability map to obtain defective and non-defective erased images. Then input them into the discriminator for classification. Construct a total generation loss including generator loss, auxiliary loss and morphological constraint loss, and a total discriminant loss including discriminator loss and knowledge distillation loss. Train the pixel erasure generative adversarial network alternately until the total generation loss and the total discriminant loss converge, and obtain the trained generator. Step S3: Input the image to be segmented into the trained generator, process it, and output the defect probability map of the image to be segmented. Perform threshold processing on the defect probability map to obtain the final segmentation result, thus realizing weakly supervised surface defect segmentation.

2. The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure according to claim 1, characterized in that: In step S1, each defective image is labeled with a defective image-level label, and each defect-free image is labeled with a defect-free image-level label. No pixel-level labels are used.

3. The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure according to claim 1, characterized in that: In step S2, the defect erasure image and defect-free erased images as follows: ; ; ; ; in, and Defect images and defect-free images Defect-erased images and defect-free erased images obtained through pixel erasure operations. These are the spatial coordinates of the pixel. Represents the color channels of an image; For defect images The defect probability map obtained after processing by the generator , and These are the height and width of the defect probability map, respectively. and Defect images and defect-free images In image color channels The weighted average pixel value; It is a constant greater than 0.

4. The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure according to claim 1, characterized in that: In step S2, the total generation loss Specifically as follows: ; in, and These are the first and second loss weights, respectively; , and These are the generator loss, shape constraint loss, and auxiliary loss, respectively. Total discriminant loss Specifically as follows: ; in, To determine the loss weight; and These are discriminator loss and knowledge distillation loss, respectively. The discriminator and generator are updated alternately during training.

5. The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure according to claim 4, characterized in that: The aforementioned morphological constraint loss as follows: ; ; in, , and These are the defect probability maps generated by the generator, along with their height and width; , and These are the shape constraint weights and their first and second preset values, respectively; and These are defect probability maps. Binarized images and temporary labeled images; Defect probability map Thresholding is performed to obtain a binarized image. Then, a morphological closing operation is performed, followed by an erosion operation to obtain a temporary label image. .

6. The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure according to claim 4, characterized in that: The knowledge distillation loss During construction, a teacher classification model is first pre-trained using a training set. After the teacher classification model is trained, the weights are frozen to obtain the pre-trained teacher classification model. The teacher classification model includes a backbone feature extractor, a convolutional layer, a global average pooling layer, and a sigmoid layer connected in sequence. The defect image is input into the pre-trained teacher classification model and the discriminator, respectively. The convolutional layer of the pre-trained teacher classification model outputs the class activation map of the defect image, and the last convolutional layer in the discriminator outputs the feature map of the defect image. Spatial alignment is performed on the class activation map and feature map to obtain aligned class activation maps and aligned feature maps. Then, normalization is performed, and the mean squared error between the normalized aligned class activation map and aligned feature map is calculated as the knowledge distillation loss. .

7. The weakly supervised surface defect segmentation method based on knowledge transfer and pixel erasure according to claim 4, characterized in that: The aforementioned auxiliary loss During construction, based on the defect probability map output by the generator after processing the defect-free image, the mean square error between the defect probability map and the all-zero probability map is calculated as an auxiliary loss. .

8. An electronic device, characterized in that, include: A memory and a processor are coupled to each other, wherein the memory stores program data, and the processor invokes the program data to perform the method as described in any one of claims 1-7.

9. A computer-readable storage medium storing program data thereon, characterized in that, When the program data is executed by the processor, the method as described in any one of claims 1-7 is implemented.