Defect detection method and device, electronic device and storage medium

By extracting the segmentation area features of the image to be tested in the image segmentation network and comparing it with the reference feature library, the problem of inaccurate detection by the PatchCore algorithm in complex backgrounds is solved, and high-accuracy defect detection is achieved.

CN117474917BActive Publication Date: 2024-08-30SUZHOU MEGAROBO TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311813975.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-12-27
Publication Date
2024-08-30
Estimated Expiration
2043-12-27

AI Technical Summary

Technical Problem

The existing PatchCore algorithm is difficult to work effectively when the background of the image to be tested is complex or changes greatly, resulting in inaccurate defect detection.

Method used

By obtaining the image to be tested and inputting it into the trained image segmentation network, the first position information is determined to indicate the segmented area in the image to be tested, the feature extraction network is used to extract the feature map of the segmented area, and it is compared with the reference feature library The feature maps are compared to determine whether there are defects in the segmented area.

Benefits of technology

This method does not need to consider the overall background information of the image to be tested, improves the accuracy and breadth of defect detection, and avoids inaccurate or undetectable detection results.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117474917B
    Figure CN117474917B
Patent Text Reader

Abstract

The embodiments of the present invention provide a defect detection method and device, an electronic device and a storage medium. The method includes: acquiring an image to be tested; inputting the image to be tested into a trained image segmentation network to determine first position information, the first position information being used to indicate the position of at least one first segmented area in the image to be tested; based on the first position information, using a feature extraction network to extract a feature map of the area to be tested corresponding to each first segmented area in at least one first segmented area; for each first segmented area in at least one first segmented area, comparing the feature map of the area to be tested corresponding to the first segmented area with a reference area feature map corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area. This solution does not need to consider the overall image information of the image to be tested, such as the background of the image to be tested, to avoid inaccurate detection results or undetectable situations.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of image processing technology, and more specifically to a defect detection method, a defect detection device, an electronic device and a storage medium. Background Art

[0002] The anomaly detection algorithms commonly used in the industrial field are usually unsupervised algorithms, that is, anomaly detection can be achieved without collecting labeled data sets. Existing anomaly detection methods, such as the PatchCore algorithm, extract mid-level features in the image to be tested through a trained image segmentation network model, and determine the feature library based on the extracted mid-level features. When inferring the image segmentation network model, the image features of the current image and the feature library are combined to generate an anomaly score, thereby achieving the detection of abnormal defects. However, since the PatchCore algorithm performs global feature matching, the PatchCore algorithm often cannot work effectively when the image background of the image to be tested is complex or changes greatly. Summary of the invention

[0003] The present invention is proposed in view of the above problems. The present invention provides a defect detection method, a defect detection device, an electronic device and a storage medium.

[0004] According to one aspect of the present invention, a defect detection method is provided, the method comprising: acquiring an image to be tested; inputting the image to be tested into a trained image segmentation network to determine first position information, the first position information being used to indicate the position of at least one first segmented area in the image to be tested, the at least one first segmented area corresponding one-to-one to at least one target image position; based on the first position information, extracting a feature map of the area to be tested corresponding to each first segmented area in the at least one first segmented area using a feature extraction network; for each first segmented area in the at least one first segmented area, comparing the feature map of the area to be tested corresponding to the first segmented area with a reference area feature map corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, the specific target image position being the target image position corresponding to the first segmented area.

[0005] Exemplarily, the image segmentation network includes a feature extraction module and a segmentation head, the feature extraction module is used to extract image features of the image to be tested, the segmentation head is used to determine the first position information based on the image features output by the feature extraction module, and the feature extraction network is a feature extraction module in a trained image segmentation network.

[0006] Exemplarily, based on the first position information, a feature extraction network is used to extract a feature map of the area to be tested corresponding to each first segmented area in at least one first segmented area, including: for each first segmented area in at least one first segmented area, based on the position of the first segmented area indicated by the first position information, pixel information of the image area other than the first segmented area is deleted from the image to be tested to obtain a regional image corresponding to the first segmented area, and the regional image is input into the feature extraction network to obtain the feature map of the area to be tested corresponding to the first segmented area; or, the first position information and the image to be tested are input into the feature extraction network to obtain the feature map of the area to be tested corresponding to the first segmented area.

[0007] Exemplarily, an image segmentation network is trained in the following manner: a sample data set is obtained, wherein the sample data set includes a plurality of sample images and annotated position information corresponding to each of the plurality of sample images, the annotated position information is used to indicate the position of at least one sample segmentation region in the corresponding sample image, and the at least one sample segmentation region corresponds one-to-one to at least one target image position; the plurality of sample images are input into the image segmentation network to be trained to obtain predicted position information corresponding to each of the plurality of sample images, the predicted position information is used to indicate the position of at least one sample segmentation region in the corresponding sample image; a prediction loss value is calculated based on an error between the predicted position information and the annotated position information; and parameters in the image segmentation network to be trained are optimized based on the predicted loss value to obtain a trained image segmentation network.

[0008] Exemplarily, obtaining a sample data set includes: obtaining an initial template image and partition annotation information corresponding to the initial template image, wherein the partition annotation information is used to indicate the position of each annotated partition in at least one annotated partition on the initial template image, and at least one annotated partition corresponds one-to-one to at least one target image position; based on the initial template image and the partition annotation information, generating at least one partition template image corresponding one-to-one to at least one annotated partition, wherein each partition template image contains pixel information within the corresponding annotated partition and does not contain pixel information within other annotated partitions; obtaining multiple sample images; for each sample image in the multiple sample images, matching the sample image with at least one partition template image respectively to obtain the annotation position information corresponding to the sample image, wherein at least one sample segmentation area is an image area that matches one-to-one with at least one annotated partition.

[0009] Exemplarily, after extracting the feature map of the region to be tested corresponding to each of the at least one first segmented region using a feature extraction network based on the first position information, the method further includes: for each of the at least one first segmented region, performing the following feature encoding operation: segmenting the feature map of the region to be tested corresponding to the first segmented region according to a preset size to obtain a plurality of sub-region feature maps corresponding one to one to the segmented plurality of coded regions; determining the region feature values ​​corresponding to each of the plurality of sub-region feature maps; obtaining a new feature map of the region to be tested corresponding to the first segmented region based on the region feature values ​​corresponding to each of the plurality of sub-region feature maps, the new feature map of the region to be tested including the region feature values ​​corresponding to the plurality of sub-region feature maps; Figure 1 A plurality of corresponding coding feature maps, the pixel value of each coding feature map is consistent with the regional feature value of the corresponding sub-region feature image; wherein, when performing an operation of comparing the feature map of the area to be tested corresponding to the first segmented area with the reference area feature map corresponding to the specific target image position in the reference feature library, the new feature map of the area to be tested corresponding to the first segmented area is compared with the reference area feature map corresponding to the specific target image position in the reference feature library.

[0010] Exemplarily, determining the regional feature values ​​corresponding to each of the multiple sub-region feature maps includes: for each pixel point in each of the multiple sub-region feature maps, taking the pixel point as the target feature point, and comparing the pixel values ​​corresponding to each of the first number of pixels in the neighborhood of the target feature point with the pixel value corresponding to the target feature point in turn; when the pixel value corresponding to any pixel point is less than or equal to the pixel value corresponding to the target feature point, determining the encoding value corresponding to the pixel point as the first value; when the pixel value corresponding to any pixel point is greater than the pixel value corresponding to the target feature point, determining the encoding value corresponding to the pixel point as the second value; summing the encoding values ​​corresponding to each of the first number of pixels in the neighborhood of the target feature point, and using the summation result as the pixel feature value corresponding to the target feature point, so as to obtain the regional feature value corresponding to the sub-region feature map, the regional feature value including the pixel feature values ​​corresponding to each pixel point in the sub-region feature map.

[0011] Exemplarily, based on the region feature values ​​corresponding to each of the multiple sub-region feature maps, obtaining a new feature map of the region to be tested corresponding to the first segmented region includes: merging the region feature values ​​corresponding to each of the multiple sub-region feature maps to obtain a new feature map of the region to be tested corresponding to the first segmented region.

[0012] Exemplarily, before comparing, for each of at least one first segmented area, a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, the method also includes: acquiring a reference image; inputting the reference image into a trained image segmentation network to determine second position information, the second position information being used to indicate the position of at least one second segmented area in the reference image, the at least one second segmented area corresponding one-to-one to at least one target image position; based on the second position information, extracting, using a feature extraction network, a reference area feature map corresponding to each second segmented area in at least one second segmented area; and acquiring a reference feature library based on the reference area feature map corresponding to each second segmented area in at least one second segmented area.

[0013] Exemplarily, obtaining a reference feature library based on a reference region feature map corresponding to each second segmented region in at least one second segmented region includes: performing a feature encoding operation on each second segmented region in at least one second segmented region to obtain a new reference region feature map corresponding to each second segmented region; and obtaining a reference feature library based on a new reference region feature map corresponding to each of the at least one second segmented regions.

[0014] Exemplarily, the reference feature library includes a reference feature description library corresponding to multiple position area groups one by one, the multiple position area groups are groups formed by combining at least one target image position and multiple coding areas, different position area groups correspond to different target image positions and at least one of the coding areas, and the number of reference images is multiple, wherein the reference feature library is obtained based on a new reference area feature map corresponding to each of the at least one second segmented areas, including: storing the sub-area feature maps corresponding to each position area group of the multiple reference images in the reference feature description library corresponding to the position area group.

[0015] Exemplarily, obtaining a reference feature library based on a new reference area feature map corresponding to each of at least one second segmented area also includes: for any position area group among the multiple position area groups, if there are sub-region feature maps that are identical to each other in the corresponding reference feature description library, then retaining any sub-region feature map that is identical to each other in the corresponding reference feature description library and deleting other sub-region feature maps.

[0016] Exemplarily, the feature map of the area to be tested corresponding to the first segmented area is compared with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, including: for each of the multiple coding areas, selecting the coding feature map corresponding to the maximum abnormal value from each coding feature map in the reference feature description library corresponding to the specific position area group, the specific position area group is a group formed by the combination of the specific target image position and the coding area; determining the difference between the pixel value of the coding feature map corresponding to the coding area of ​​the image to be tested and the pixel value of the coding feature map corresponding to the maximum abnormal value, and determining the difference as the pixel value of the sub-abnormal feature map corresponding to the coding area; comparing the pixel value of each pixel in the first abnormal feature map or the second abnormal feature map obtained by upsampling the first abnormal feature map with the abnormal threshold, and determining that the pixel whose pixel value is greater than the abnormal threshold is a defective pixel, wherein the first abnormal feature map includes multiple sub-abnormal feature maps corresponding to the coding areas one by one; mapping the defective pixels in the first abnormal feature map or the second abnormal feature map to the image to be tested to determine the defective area in the first segmented area.

[0017] Exemplarily, the feature map of the area to be tested corresponding to the first segmented area is compared with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, including: comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether each pixel point in the feature map of the area to be tested corresponding to the first segmented area belongs to the defect area; mapping the pixel points belonging to the defect area in the feature map of the area to be tested to the image to be tested to determine the defect area located in the first segmented area on the image to be tested; for each first segmented area in at least one first segmented area, comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, the method also includes: comprehensively determining the defect area in the image to be tested by combining the defect areas corresponding to each of the at least one first segmented area.

[0018] Exemplarily, before comparing, for each of at least one first segmented area, a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, the method also includes: acquiring a reference image; inputting the reference image into a trained image segmentation network to determine second position information, the second position information being used to indicate the position of at least one second segmented area in the reference image, the at least one second segmented area corresponding one-to-one to at least one target image position; based on the second position information, extracting, using a feature extraction network, a reference area feature map corresponding to each second segmented area in at least one second segmented area; and acquiring a reference feature library based on the reference area feature map corresponding to each second segmented area in at least one second segmented area.

[0019] According to another aspect of the present invention, a defect detection device is also provided, the device comprising: an acquisition module for acquiring an image to be tested; an input module for inputting the image to be tested into a trained image segmentation network to determine first position information, the first position information being used to indicate the position of at least one first segmented area in the image to be tested, the at least one first segmented area corresponding one-to-one to at least one target image position; an extraction module for extracting a feature map of the area to be tested corresponding to each first segmented area in the at least one first segmented area using a feature extraction network based on the first position information; and a comparison module for comparing, for each first segmented area in the at least one first segmented area, the feature map of the area to be tested corresponding to the first segmented area with a reference area feature map corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, the specific target image position being the target image position corresponding to the first segmented area.

[0020] According to another aspect of the present invention, there is also provided an electronic device, comprising a processor and a memory, wherein the memory stores computer program instructions, and the computer program instructions are used to execute the above-mentioned defect detection method when the processor is running.

[0021] According to yet another aspect of the present invention, there is further provided a storage medium storing a computer program / instruction, wherein the computer program / instruction is used to execute the above-mentioned defect detection method when running.

[0022] According to the defect detection method, defect detection device, electronic device and storage medium of the embodiment of the present invention, the image to be tested is input into a trained image segmentation network to determine the first position information. Based on the first position information, the feature extraction network can be used to extract the feature map of the area to be tested corresponding to each first segmented area. Then, the feature map of the area to be tested corresponding to each first segmented area is compared with the reference area feature map corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area. This scheme uses the image segmentation network to segment the image to be tested, and can realize defect detection for each area image. In this way, there is no need to consider the overall image information of the image to be tested, such as the background of the image to be tested, etc., to avoid the situation where the detection result is inaccurate or cannot be detected. This method has a wide range of applications and a high accuracy rate. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The above and other purposes, features and advantages of the present invention will become more apparent by describing the embodiments of the present invention in more detail in conjunction with the accompanying drawings. The accompanying drawings are used to provide a further understanding of the embodiments of the present invention and constitute a part of the specification. Together with the embodiments of the present invention, they are used to explain the present invention and do not constitute a limitation of the present invention. In the accompanying drawings, the same reference numerals generally represent the same components or steps.

[0024] Figure 1 A schematic flow chart of a defect detection method according to an embodiment of the present invention is shown;

[0025] Figure 2 A schematic diagram showing at least one first segmented area in an image to be tested according to an embodiment of the present invention is shown;

[0026] Figure 3 A schematic block diagram of a defect detection device according to an embodiment of the present invention is shown; and

[0027] Figure 4 A schematic block diagram of an electronic device according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0028] In order to make the purpose, technical scheme and advantages of the present invention more obvious, the exemplary embodiments according to the present invention will be described in detail with reference to the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, rather than all the embodiments of the present invention, and it should be understood that the present invention is not limited to the exemplary embodiments described herein. Based on the embodiments of the present invention described in the present invention, all other embodiments obtained by those skilled in the art without creative work should fall within the protection scope of the present invention.

[0029] In order to at least partially solve the above problems, an embodiment of the present invention provides a defect detection method. Figure 1 A schematic flow chart of a defect detection method 100 according to an embodiment of the present invention is shown. Figure 1 As shown, the method 100 may include the following steps S110, S120, S130 and S140.

[0030] Step S110, obtaining an image to be tested.

[0031] Exemplarily, the image to be tested may be any type of image including a target object. The target object may be any type of object such as a wafer, a character, an electronic component, etc. The image to be tested may be a static image or any video frame in a dynamic video. The image to be tested may be an original image captured by an image acquisition device (such as an image sensor in a camera), or may be an image obtained after preprocessing the original image (such as digitization, normalization, smoothing, etc.).

[0032] Step S120, input the image to be tested into the trained image segmentation network to determine first position information, where the first position information is used to indicate the position of at least one first segmentation area in the image to be tested, and the at least one first segmentation area corresponds one-to-one to at least one target image position.

[0033] Exemplarily, after the image to be tested is input into a trained image segmentation network, the first position information can be determined. Exemplarily and not restrictively, the image segmentation network can be implemented using one or more of the following networks: Fully Convolutional Networks (FCN), U-type network (Unet), DeepLab series, V-type network (Vnet), etc. The first position information may include the position of at least one first segmented area in the image to be tested. At least one first segmented area corresponds to at least one target image position one by one. Figure 2 FIG. 4 is a schematic diagram showing at least one first segmented area in an image to be tested according to an embodiment of the present invention. Figure 2As shown, if the image size of the image to be tested I is 512×512, after the image to be tested I is input into the trained image segmentation network, 4 first segmented areas can be obtained, and the size of each first segmented area is 256×256. The first position information may include the position information of each of the 4 first segmented areas in the image to be tested I. In the image to be tested I, starting from the first segmented area in the upper left corner and going in a clockwise direction, the 4 first segmented areas are I1, I2, I3 and I4, and each first segmented area corresponds to a target image position. The position information of each first segmented area can be represented by the image coordinates of the corresponding area vertex. For example, for the first segmented area I1, the image coordinates of the upper left vertex are (0, 0), and the image coordinates of the lower right vertex are (256, 256), then the position information of the first segmented area I1 can be expressed as [(0, 0), (256, 256)]. In a similar manner, the position information of the first segmented area I2 can be expressed as [(256, 0), (512, 256)], the position information of the first segmented area I3 can be expressed as [(256, 256), (512, 512)], and the position information of the first segmented area I4 can be expressed as [(0, 256), (256, 512)].

[0034] Step S130: Based on the first position information, a feature extraction network is used to extract a feature map of the region to be tested corresponding to each first segmented region in at least one first segmented region.

[0035] Exemplarily, based on the first position information, the regional images corresponding to each first segmented region can be respectively input into the feature extraction network. After the regional images corresponding to the first segmented regions are subjected to feature extraction by the feature extraction network, a feature map of the region to be tested corresponding to the first segmented region can be obtained. Exemplarily and not restrictively, the feature extraction network can be implemented using convolutional neural networks (CNN).

[0036] Step S140, for each first segmented area of ​​at least one first segmented area, compare the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, and the specific target image position is the target image position corresponding to the first segmented area.

[0037] Exemplarily, for each first segmented area in at least one first segmented area, such as the first segmented area I1, the feature map of the area to be tested corresponding to the first segmented area I1 can be compared with the feature map of the reference area corresponding to the reference feature library to obtain a comparison result. The feature map of the reference area corresponding to the first segmented area I1 in the reference feature library is a feature map at a specific target image position corresponding to the target image position corresponding to the first segmented area. The similarity between the reference area feature map in the feature library and the feature map of the area to be tested corresponding to the first segmented area I1 can be compared, and when the similarity does not meet the target similarity threshold, it is determined that there is a defect in the first segmented area I1. The distance between the reference area feature map in the feature library and the feature map of the area to be tested corresponding to the first segmented area I1 can also be compared, and when the distance is greater than the target distance threshold, it is determined that there is a defect in the first segmented area I1. The feature library can be a sample feature library obtained by clustering the multiple reference area feature maps obtained by the feature extraction network after processing the sample image according to the above method. In a similar manner, it can be determined whether there is a defect in each first segmented area, which will not be repeated here for the sake of brevity.

[0038] According to the defect detection method of an embodiment of the present invention, the image to be tested is input into a trained image segmentation network to determine the first position information. Based on the first position information, a feature extraction network can be used to extract a feature map of the area to be tested corresponding to each first segmented area. Then, the feature map of the area to be tested corresponding to each first segmented area is compared with the reference area feature map corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area. This scheme uses an image segmentation network to segment the image to be tested, and can realize defect detection for each area image. In this way, there is no need to consider the overall image information of the image to be tested, such as the background of the image to be tested, etc., to avoid inaccurate detection results or undetectable situations. This method has a wide range of applications and a high accuracy rate.

[0039] Exemplarily, the image segmentation network may include a feature extraction module and a segmentation head, the feature extraction module is used to extract image features of the image to be tested, the segmentation head is used to determine the first position information based on the image features output by the feature extraction module, and the feature extraction network is a feature extraction module in a trained image segmentation network.

[0040] In one embodiment, the image segmentation network may include a feature extraction module and a segmentation head. The feature extraction network in the above embodiment may be a feature extraction module in a trained image segmentation network. That is, the feature extraction network in the above embodiment may be included in the image segmentation network. The feature extraction module may extract image features of the image to be tested. The segmentation head may determine the first position information based on the image features output by the feature extraction module. In this way, by performing multiple processing operations through one network model, the resources of the network model may be saved while improving the training efficiency of the model.

[0041] Exemplarily, based on the first position information, using a feature extraction network to extract a feature map of the area to be tested corresponding to each first segmented area in at least one first segmented area may include: for each first segmented area in at least one first segmented area, based on the position of the first segmented area indicated by the first position information, deleting pixel information of the image area other than the first segmented area from the image to be tested to obtain a regional image corresponding to the first segmented area, and inputting the regional image into the feature extraction network to obtain a feature map of the area to be tested corresponding to the first segmented area; or, inputting the first position information and the image to be tested into the feature extraction network to obtain a feature map of the area to be tested corresponding to the first segmented area.

[0042] In one embodiment, when extracting the corresponding regional features of the image to be tested for each first segmented area in at least one first segmented area, the pixel information of the image area other than the first segmented area can be deleted from the image to be tested based on the position of the first segmented area in the image to be tested, so as to obtain the regional image corresponding to the first segmented area. For example, if the first segmented area I1 is located in the upper left quarter of the image to be tested, the pixel values ​​of the pixels corresponding to the first segmented areas I2, I3 and I4 can be set to 0 to obtain the regional image corresponding to the first segmented area I1. Then, the regional image is input into the feature extraction network, and the feature map of the region to be tested corresponding to the first segmented area I1 can be obtained. In a similar manner, the regional image corresponding to each first segmented area and the feature map of the region to be tested corresponding to the regional image can be determined, which will not be described here for the sake of brevity.

[0043] In another embodiment, for each first segmented area, such as the first segmented area I1, the position information corresponding to the first segmented area I1 and the image to be tested can be input into the feature extraction network, and the feature extraction network can extract the regional features corresponding to the current position prompt information in the image to be tested according to the current position prompt information, as the feature map of the area to be tested corresponding to the first segmented area I1. In a similar manner, the feature map of the area to be tested corresponding to each first segmented area can be determined, and for the sake of brevity, it will not be repeated here. In one embodiment of the present invention, the size of the feature map of the area to be tested corresponding to each first segmented area can be 64×64.

[0044] According to the above technical solution, for each first segmented area, based on the position of the first segmented area indicated by the first position information, the area image corresponding to the first segmented area is obtained. Then the area image is input into the feature extraction network to obtain the feature map of the area to be tested corresponding to the first segmented area. Alternatively, the first position information and the image to be tested can also be input into the feature extraction network to directly obtain the feature map of the area to be tested corresponding to the first segmented area. In this way, the feature map of the area to be tested corresponding to each first segmented area can be accurately obtained.

[0045] Exemplarily, an image segmentation network is trained in the following manner: a sample data set is obtained, wherein the sample data set includes a plurality of sample images and annotated position information corresponding to each of the plurality of sample images, the annotated position information is used to indicate the position of at least one sample segmentation region in the corresponding sample image, and the at least one sample segmentation region corresponds one-to-one to at least one target image position; the plurality of sample images are input into the image segmentation network to be trained to obtain predicted position information corresponding to each of the plurality of sample images, the predicted position information is used to indicate the position of at least one sample segmentation region in the corresponding sample image; a prediction loss value is calculated based on an error between the predicted position information and the annotated position information; and parameters in the image segmentation network to be trained are optimized based on the predicted loss value to obtain a trained image segmentation network.

[0046] In one embodiment, the sample data set may include multiple sample images and the annotated position information corresponding to each of the multiple sample images. The method for acquiring the sample image is similar to the method for acquiring the image to be tested. The method for acquiring the image to be tested has been described in detail in step S110, and for the sake of brevity, it will not be repeated here. Similar to the at least one first segmented area contained in the image to be tested, each sample image contains at least one sample segmented area. The annotated position information can be used to indicate the position of at least one sample segmented area in the corresponding sample image.

[0047] By inputting multiple sample images into the image segmentation network to be trained, the predicted position information corresponding to each of the multiple sample images can be obtained. The predicted position information can indicate the position of at least one sample segmentation area in the corresponding sample image. Based on the predicted position information, the predicted position information and the marked position information can be substituted into the preset loss function for loss calculation to obtain the predicted loss value. The preset loss function can be any loss function such as the KL divergence loss function, the cross entropy loss function, etc., and the present invention is not limited to this. Subsequently, the parameters in the initial image segmentation network can be optimized based on the predicted loss value using the back propagation and gradient descent algorithms. The optimization operation can be repeatedly performed until the image segmentation network reaches a convergence state. When the training is completed, the obtained image segmentation network can be used for subsequent image segmentation of the image to be tested.

[0048] In another embodiment of the present invention, the image segmentation network may include a feature extraction module and a segmentation head. When training the image segmentation network, the feature extraction module and the segmentation head may be trained separately to obtain a trained feature extraction module and a trained segmentation head. The feature extraction module and the segmentation head may be trained separately with reference to the method of training the image segmentation network in the previous embodiment, which will not be described in detail here for the sake of brevity. Based on the feature extraction module obtained through training and the segmentation head obtained through training, the image segmentation network is determined.

[0049] According to the above technical solution, by inputting multiple sample images in the sample data set into the image segmentation network to be trained, the predicted position information corresponding to each of the multiple sample images can be obtained. Based on the error between the predicted position information and the annotated position information, the prediction loss value is calculated, and the parameters in the image segmentation network to be trained are optimized based on the prediction loss value to obtain a trained image segmentation network. The image segmentation network obtained by such training can accurately segment the image to be tested and determine the position information of each first segmented area. Furthermore, it is convenient to determine whether there is a defect in each first segmented area, which can improve the reliability of the defect detection result.

[0050] Exemplarily, obtaining a sample data set may include: obtaining an initial template image and partition annotation information corresponding to the initial template image, wherein the partition annotation information is used to indicate the position of each annotated partition in at least one annotated partition on the initial template image, and at least one annotated partition corresponds one-to-one to at least one target image position; based on the initial template image and the partition annotation information, generating at least one partition template image corresponding one-to-one to at least one annotated partition, wherein each partition template image contains pixel information within the corresponding annotated partition and does not contain pixel information within other annotated partitions; obtaining multiple sample images; for each sample image in the multiple sample images, matching the sample image with at least one partition template image respectively to obtain the annotation position information corresponding to the sample image, wherein at least one sample segmentation area is an image area that matches one-to-one with at least one annotated partition.

[0051] In one embodiment, the acquisition method of the initial template image is similar to the acquisition method of the image to be tested. The acquisition method of the image to be tested has been described in detail in step S110, and for the sake of brevity, it will not be repeated here. Exemplarily, the initial template image can be an image randomly selected from the positive sample image. The initial template image includes at least one annotated partition and each annotated partition has corresponding partition annotation information. At least one annotated partition corresponds to at least one target image position. The partition annotation information can indicate the position of each annotated partition in at least one annotated partition. The positions of different annotated sub-regions can be represented by different pixel values. For example, if 4 annotated partitions are divided, the pixel values ​​of all pixels in the first annotated partition can be set to 0, the pixel values ​​of all pixels in the second annotated partition can be set to 1, the pixel values ​​of all pixels in the third annotated partition can be set to 2, and the pixel values ​​of all pixels in the fourth annotated partition can be set to 3. In one embodiment of the present invention, at least one annotated partition in the initial template image can be obtained by manual division. The partition annotation information corresponding to each annotated partition can be obtained by manual annotation, or can be annotated using an automatic annotation tool. Based on the initial template image and the partition annotation information, at least one partition template image corresponding to at least one annotated partition can be generated. The image size of each partition template image is the same as the image size of the initial template image. Each partition template image contains pixel information in the corresponding annotated partition and does not contain pixel information in other annotated partitions. Taking the partition template image M1 corresponding to the image position of the first segmented area I1 as an example, the image size of the partition template image M1 is 256×256. The pixel values ​​of each pixel in the partition template image M1 except for the partial area located in the upper left quarter can be set to 0.

[0052] Then, multiple sample images are obtained. The method for obtaining the sample images is similar to the method for obtaining the image to be tested. The method for obtaining the image to be tested has been described in detail in step S110, and for the sake of brevity, it will not be repeated here. For each sample image in the multiple sample images, the sample image can be matched with at least one partition template image to obtain the annotation position information corresponding to the sample image.

[0053] According to the above technical solution, at least one partition template image corresponding to at least one annotated partition can be generated through the initial template image and the partition annotation information corresponding to the initial template image. For each sample image in a plurality of sample images, the sample image is matched with at least one partition template image respectively, and the annotation position information corresponding to the sample image can be obtained. By matching the sample image with at least one partition template image respectively, the situation that the matching effect is affected by the position offset of the image information can be avoided, so as to ensure the accuracy of the matching result.

[0054] Exemplarily, after extracting the feature map of the region to be tested corresponding to each of the at least one first segmented regions using a feature extraction network based on the first position information, the method may further include: for each of the at least one first segmented regions, performing the following feature encoding operations: segmenting the feature map of the region to be tested corresponding to the first segmented region according to a preset size to obtain a plurality of sub-region feature maps corresponding one-to-one to the segmented plurality of coded regions; determining the region feature values ​​corresponding to each of the plurality of sub-region feature maps; obtaining a new feature map of the region to be tested corresponding to the first segmented region based on the region feature values ​​corresponding to each of the plurality of sub-region feature maps, the new feature map of the region to be tested including the region feature values ​​corresponding to the plurality of sub-region feature maps; Figure 1 A plurality of corresponding coding feature maps, the pixel value of each coding feature map is consistent with the regional feature value of the corresponding sub-region feature image; wherein, when performing an operation of comparing the feature map of the area to be tested corresponding to the first segmented area with the reference area feature map corresponding to the specific target image position in the reference feature library, the new feature map of the area to be tested corresponding to the first segmented area is compared with the reference area feature map corresponding to the specific target image position in the reference feature library.

[0055] In one embodiment, feature encoding operations may be performed on at least one first segmented region. For ease of description and understanding, the following description is made by taking the first segmented region I1 as an example. The feature map F1 of the region to be tested corresponding to the first segmented region I1 is segmented according to a preset size, and multiple sub-region feature maps corresponding to the multiple segmented coding regions (patches) can be obtained. The preset size can be arbitrary. For example, the size of the feature map F1 of the region to be tested is 64×64, and the feature map F1 of the region to be tested can be divided into 64 coding regions of 8×8 size. For another example, if the size of each coding region is 16×16, then the number of coding regions is 16. In one embodiment of the present invention, the size of the coding region is 8×8. Each coding region has a corresponding sub-region feature map. The pixel values ​​of each pixel in the regional feature map corresponding to each coding region can be added or averaged to serve as the regional feature value corresponding to the regional feature map. Based on the regional feature values ​​corresponding to each of the multiple sub-region feature maps, a new feature map of the region to be tested corresponding to the first segmented region can be obtained. The new feature map of the region to be tested may include features of multiple sub-regions Figure 1 A plurality of corresponding coding feature maps. The pixel value of each coding feature map is consistent with the regional feature value of the corresponding sub-region feature image. A new feature map of the region to be tested corresponding to each first segmented region can be determined by a similar method, which will not be described here for the sake of brevity. The feature map of the region to be tested in the operation of "comparing the feature map of the region to be tested corresponding to the first segmented region with the reference region feature map corresponding to the specific target image position in the reference feature library" in the previous embodiment can be a new feature map of the region to be tested.

[0056] According to the above technical solution, for each first segmented area, the feature map of the region to be tested corresponding to the first segmented area can be segmented according to a preset size to obtain multiple sub-region feature maps corresponding to the segmented multiple coding regions. Based on the region feature values ​​corresponding to each of the multiple sub-region feature maps, a new feature map of the region to be tested corresponding to the first segmented area can be obtained. The new feature map of the region to be tested includes the feature values ​​corresponding to the multiple sub-region feature maps. Figure 1 One corresponding to multiple coding feature maps. This solution can encode multiple sub-regions in each first segmented region to obtain a sub-region feature map corresponding to each sub-region, further improving the detection accuracy of the defective region.

[0057] Exemplarily, determining the regional feature values ​​corresponding to each of the multiple sub-region feature maps may include: for each pixel point in each of the multiple sub-region feature maps, taking the pixel point as the target feature point, and comparing the pixel values ​​corresponding to each of the first number of pixels in the neighborhood of the target feature point with the pixel value corresponding to the target feature point in turn; when the pixel value corresponding to any pixel point is less than or equal to the pixel value corresponding to the target feature point, determining the encoding value corresponding to the pixel point as the first value; when the pixel value corresponding to any pixel point is greater than the pixel value corresponding to the target feature point, determining the encoding value corresponding to the pixel point as the second value; summing the encoding values ​​corresponding to each of the first number of pixels in the neighborhood of the target feature point, and using the summation result as the pixel feature value corresponding to the target feature point, so as to obtain the regional feature value corresponding to the sub-region feature map, the regional feature value including the pixel feature values ​​corresponding to each pixel point in the sub-region feature map.

[0058] In one embodiment, for the obtained multiple sub-region feature maps of size 8×8, each sub-region feature map may include 64 feature points. For each of the 64 pixel points in each sub-region feature map, each pixel point may be used as a target feature point, and the pixel values ​​corresponding to the first number of pixel points in the neighborhood of the target feature point may be compared with the pixel values ​​corresponding to the target feature point in turn. The size of the neighborhood S×S may be arbitrary, where S may be equal to any integer value, such as 2, 3, or 4. In one embodiment of the present invention, the pixel values ​​corresponding to the 8 pixel points in the 3×3 domain window may be selected and compared with the pixel values ​​corresponding to the target feature point in turn. For example, for a pixel point among the 8 pixel points in the neighborhood P (1), if the pixel P (1) If the corresponding pixel value is less than or equal to the pixel value corresponding to the target feature point, then the pixel point P (1) The corresponding code value is determined as a first value. The first value and the second value in the following embodiments can be equal to any two different values. In the first embodiment of the present invention, the first value is equal to 0, and the second value in the following embodiments is equal to 1. If the pixel point P (1) If the corresponding pixel value is greater than the pixel value corresponding to the target feature point, then the pixel point P (1) The corresponding code value is determined to be 1. In a similar way, the pixel point P (1) P (2) ... P(8) The corresponding coding values ​​are not described here for brevity. The result of summing the coding values ​​corresponding to the eight pixels in the neighborhood of the target feature point can be used as the pixel feature value corresponding to the target feature point. Based on the pixel feature value corresponding to each target feature point in the sub-region feature map, the region feature value corresponding to the sub-region feature map can be obtained. The region feature value may include the pixel feature value corresponding to each pixel in the corresponding sub-region feature map.

[0059] The above method of determining the pixel feature value corresponding to the target feature point can be expressed by the following formula:

[0060]

[0061] in, i =1,2,...,8, E ( c , i ) represents the pixel feature value corresponding to the current target feature point, P ( i ) represents the pixel value of the pixel point in the neighborhood of the target feature point, P ( c ) represents the pixel value corresponding to the target feature point.

[0062] According to the above technical solution, for each pixel point in each sub-region feature map in multiple sub-region feature maps, the pixel point can be used as a target feature point, and the pixel values ​​corresponding to the first number of pixel points in the neighborhood of the target feature point are compared with the pixel values ​​corresponding to the target feature point in turn, to determine the encoding values ​​corresponding to the first number of pixel points in the neighborhood of the target feature point and sum the encoding values ​​corresponding to the first number of pixel points. The summation result can be used as the pixel feature value corresponding to the target feature point to obtain the regional feature value corresponding to the sub-region feature map. This method does not require a complex encoding method and can simply and quickly obtain the regional feature value corresponding to each sub-region feature map.

[0063] Exemplarily, obtaining a new feature map of the area to be tested corresponding to the first segmented area based on the area feature values ​​corresponding to each of the multiple sub-area feature maps may include: merging the area feature values ​​corresponding to each of the multiple sub-area feature maps to obtain a new feature map of the area to be tested corresponding to the first segmented area.

[0064] In one embodiment, the region feature values ​​corresponding to the multiple sub-region feature maps in each first segmented region are merged to obtain a new feature map of the region to be tested corresponding to the first segmented region. In this way, the new feature map of the region to be tested corresponding to each first segmented region can be obtained without complicated operations, which is highly efficient.

[0065] Exemplarily, before comparing, for each of at least one first segmented area, a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, the method may also include: acquiring a reference image; inputting the reference image into a trained image segmentation network to determine second position information, the second position information being used to indicate the position of at least one second segmented area in the reference image, the at least one second segmented area corresponding one-to-one to at least one target image position; based on the second position information, extracting, using a feature extraction network, a reference area feature map corresponding to each second segmented area in at least one second segmented area; and acquiring a reference feature library based on the reference area feature map corresponding to each second segmented area in at least one second segmented area.

[0066] In one embodiment, the method for acquiring the reference image is similar to the method for acquiring the image to be tested. The method for acquiring the image to be tested has been described in detail in step S110, and for the sake of brevity, it will not be repeated here. The reference image can be any image, and can be partially the same, completely the same, or completely different from the sample image when training the image segmentation network. The implementation method of "inputting the reference image into the trained image segmentation network to determine the second position information; based on the second position information, using the feature extraction network to extract the reference area feature map corresponding to each second segmentation area in at least one second segmentation area" is similar to step S120 and step S130. Ordinary technicians in this field can refer to the relevant descriptions of step S120 and step S130 to understand the implementation method of obtaining the reference area feature map corresponding to each second segmentation area. For the sake of brevity, it will not be repeated here. The reference area feature map corresponding to each second segmentation area in at least one second segmentation area can be clustered by any existing or upcoming clustering algorithm to obtain a reference feature library.

[0067] According to the above technical solution, the second position information can be determined by inputting the reference image into the trained image segmentation network. Based on the second position information, the reference region feature map corresponding to each second segmentation region in at least one second segmentation region is extracted using the feature extraction network. Then, a reference feature library is obtained based on the reference region feature map corresponding to each second segmentation region in at least one second segmentation region. This method accurately obtains a representative reference feature library to provide a guarantee for subsequent defect detection based on the reference feature library.

[0068] Exemplarily, obtaining a reference feature library based on a reference region feature map corresponding to each of at least one second segmented region may include: performing a feature encoding operation on each of the at least one second segmented region to obtain a new reference region feature map corresponding to each second segmented region; and obtaining a reference feature library based on a new reference region feature map corresponding to each of the at least one second segmented regions.

[0069] In one embodiment, a feature encoding operation may be performed on each of the at least one second segmented regions. The implementation method of the encoding operation may refer to the relevant description of the feature encoding operation performed on each first segmented region in the previous embodiment. For the sake of brevity, it will not be repeated here. By performing the feature encoding operation on each second segmented region, a new reference region feature map corresponding to each second segmented region may be obtained. By clustering the new reference region feature map corresponding to each second segmented region using an existing or upcoming clustering algorithm, a reference feature library may be obtained. The reference feature library thus obtained contains rich and representative reference region feature maps to ensure the reliability of defect detection based on the reference feature library.

[0070] Exemplarily, the reference feature library may include a reference feature description library corresponding one-to-one to multiple position area groups, the multiple position area groups are groups formed by combining at least one target image position and multiple coding areas, different position area groups correspond to different target image positions and at least one of the coding areas, and the number of reference images is multiple, wherein obtaining the reference feature library based on a new reference area feature map corresponding to each of at least one second segmented area may include: storing the sub-area feature maps corresponding to each position area group of the multiple reference images in the reference feature description library corresponding to the position area group.

[0071] In one embodiment, if the number of target image positions is 4, then for 1000 reference images, 4 second segmented regions corresponding to each of the 1000 reference images can be extracted respectively. Each second segmented region can obtain a 64×64 reference region feature map. Each 64×64 reference region feature map can be further divided into 64 8×8 coding regions (patch). For any target image position, each of the 64 8×8 coding regions can correspond to 1000 images, and then 1000 sub-region feature maps can be obtained. These 1000 sub-region feature maps can constitute a reference feature description library. The sub-region feature maps corresponding to each position region group of multiple reference images are stored in the reference feature description library corresponding to the position region group. In one embodiment, each reference feature description library can use the patch_bit: "key, map" dictionary to save the sub-region feature map. When 1000 sub-region feature maps need to be saved to the reference feature library, each coding region can obtain a dictionary consisting of 1000 64-bit numbers. The entire reference feature library can be represented by memory_bit〈idx, patch_bit〉.

[0072] According to the above technical solution, the reference feature library may include a reference feature description library corresponding to multiple position area groups. The reference feature description library corresponding to each position area group includes sub-region feature maps of multiple reference images corresponding to each position area group. This ensures that various defect conditions are fully detected to avoid missed detection or false detection.

[0073] Exemplarily, obtaining a reference feature library based on a new reference area feature map corresponding to each of at least one second segmented area may also include: for any position area group among the multiple position area groups, if there are sub-region feature maps that are identical to each other in the corresponding reference feature description library, then retaining any sub-region feature map that is identical to each other in the corresponding reference feature description library and deleting other sub-region feature maps.

[0074] In one embodiment, for any one of the multiple position area groups, when multiple sub-region feature maps in the reference feature description library corresponding to the area feature group are the same, any one of these identical sub-region feature maps can be retained and the other sub-region feature maps can be deleted. In one embodiment of the present invention, if multiple sub-region feature maps in the reference feature description library corresponding to any one of the area feature groups are the same, these identical sub-region feature maps can be merged into one in the feature description library. This can be represented in the reference feature library by "memory_bit《(idx1, idx2....), patch_bit》". This can increase the richness of the reference area feature maps in the reference feature library to improve the accuracy of defect detection.

[0075] Exemplarily, comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area may include: for each of the multiple coding areas, selecting the coding feature map corresponding to the maximum abnormal value from the coding feature maps in the reference feature description library corresponding to the specific position area group, the specific position area group being a group formed by the combination of the specific target image position and the coding area; determining the difference between the pixel value of the coding feature map corresponding to the coding area of ​​the image to be tested and the pixel value of the coding feature map corresponding to the maximum abnormal value, and determining the difference as the pixel value of the sub-abnormal feature map corresponding to the coding area; comparing the pixel value of each pixel in the first abnormal feature map or the second abnormal feature map obtained by upsampling the first abnormal feature map with the abnormal threshold, and determining that the pixel whose pixel value is greater than the abnormal threshold is a defective pixel, wherein the first abnormal feature map includes the sub-abnormal feature maps corresponding to the multiple coding areas one by one; mapping the defective pixels in the first abnormal feature map or the second abnormal feature map to the image to be tested to determine the defective area in the first segmented area.

[0076] In one embodiment, for each coding region in a plurality of coding regions, a coding feature map corresponding to the maximum outlier value can be selected from each coding feature map in a reference feature description library corresponding to a specific position region group. The specific position region group can represent a group formed by combining a specific target image position with the coding region. The specific image position is any one of at least one target image position. For any segmented region, 64 coding regions are obtained, and each coding region has a corresponding reference feature description library. For example, each reference feature description library contains 1000 coding feature maps (corresponding to 1000 reference images respectively). For the current coding region Q1, a coding feature map corresponding to the maximum outlier value can be selected from the 1000 coding feature maps in the reference feature description library corresponding to the coding region Q1. Exemplarily, the coding feature map corresponding to the coding region Q1 is subtracted from the 1000 coding feature maps in the reference feature description library to obtain 1000 differences. The 1000 differences can represent 1000 outliers respectively. The outlier with the largest value among the 1000 outliers is taken as the maximum outlier value. The first difference map can be obtained by taking the difference between the pixel value of the coding feature map corresponding to the coding area Q1 and the coding feature map corresponding to the maximum abnormal value. The first difference map can be used as the sub-abnormal feature map corresponding to the coding area Q1. The pixel value of each pixel in the sub-abnormal feature map is equal to the difference of the corresponding position in the first difference map. After obtaining the pixel values ​​of the sub-abnormal feature maps corresponding to each of the 64 coding areas, a first abnormal feature map of size 64×64 can be obtained. The first abnormal feature map is upsampled to obtain a second abnormal feature map. For example, the size of the second abnormal feature map can be 512×512. The pixel value of each pixel in the first abnormal feature map or the second abnormal feature map is compared with the abnormal threshold value. When the pixel value is greater than the abnormal threshold value, we can determine that the pixel point is a defective pixel. By determining the position of one or more defective pixels in the image to be tested, the defective area in the segmented area can be determined.

[0077] The abnormal threshold corresponding to each first segmented area can be calculated by the following method, which is described below by taking the first segmented area I1 as an example. In one embodiment, for example, the reference feature library corresponding to the first segmented area I1 includes 1000 reference area feature maps. For each reference area feature map in the 1000 reference area feature maps, the second difference map corresponding to the reference area feature map and the other 999 reference area feature maps is calculated. The first average value of the 999 second difference maps is calculated as the initial abnormal value corresponding to the reference image. After obtaining the initial abnormal values ​​corresponding to the 1000 reference images, the second average value of the initial abnormal values ​​corresponding to each of the 1000 reference area feature maps is calculated, and the second average value is used as the abnormal threshold corresponding to the first segmented area I1. In another embodiment, 2 reference feature maps can be randomly selected from the 1000 reference feature maps, and the third difference map of the two reference feature maps is calculated. Then this operation is repeated 1000 times to obtain 1000 third difference maps. The two reference feature maps selected each time are randomly selected. A third average value of the 1000 third difference images is calculated, and the third average value is used as the abnormal threshold corresponding to the first segmented area I1.

[0078] According to the above technical solution, for each coding area in the multiple coding areas, the pixel value of the sub-abnormal feature map corresponding to the coding area can be determined based on the difference between the pixel value of the coding feature map corresponding to the coding area of ​​the image to be tested and the pixel value of the coding feature map corresponding to the maximum abnormal value. Based on the pixel value of the sub-abnormal feature map corresponding to each coding area, the first abnormal feature map can be determined. By comparing the pixel value of each pixel in the first abnormal feature map or the second abnormal feature map with the abnormal threshold, it can be determined that the pixel whose pixel value is greater than the abnormal threshold is a defective pixel. Then, the defective pixel is mapped to the image to be tested to determine the defective area within the first segmented area. This solution can improve the detection accuracy of the defective area and avoid missed detection by judging whether each pixel is a defective pixel.

[0079] Exemplarily, comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area may include: comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether each pixel point in the feature map of the area to be tested corresponding to the first segmented area belongs to a defective area; mapping the pixel points belonging to the defective area in the feature map of the area to be tested to the image to be tested to determine the defective area located in the first segmented area on the image to be tested; for each first segmented area in at least one first segmented area, comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, the method may also include: determining the defective area in the image to be tested by combining the defective areas corresponding to each of the at least one first segmented area.

[0080] In one embodiment, for any first segmented area, the feature map of the area to be tested corresponding to the first segmented area is compared with the feature map of the reference area corresponding to the specific target image position in the reference feature library. For example, for the first segmented area I1, the feature map of the reference area corresponding to the upper left quarter area in the reference image can be selected for comparison. If there are some pixels whose pixel values ​​are greater than the abnormal threshold in the feature map of the area to be tested corresponding to the first segmented area, then the area where these pixels are located belongs to the defective area. The pixels belonging to the defective area in the feature map of the area to be tested are mapped to the image to be tested, and the defective area located in the first segmented area on the image to be tested can be determined. The defective area in each of the at least one first segmented area can be determined by a similar method, and for the sake of brevity, it will not be repeated here. The defective areas corresponding to each of the at least one first segmented area can be combined to determine the defective area in the image to be tested. For example, if there are 2 defective areas in the first segmented area I1, 1 defective area in the first segmented area I2, and no defective area in the first segmented areas I3 and I4, then it can be determined that the number of defective areas in the image to be tested is 3 and the position of each defective area in the image to be tested.

[0081] According to the above technical solution, for each first segmented area, the feature map of the area to be tested corresponding to the first segmented area can be compared with the corresponding feature map of the reference area to determine whether each pixel point in the feature map of the area to be tested corresponding to the first segmented area belongs to the defect area. Then, the pixel points belonging to the defect area in the feature map of the area to be tested are mapped to the image to be tested, and the defect area located in the first segmented area on the image to be tested can be determined. The defect area in the image to be tested can be determined by combining the defect areas corresponding to at least one first segmented area. This method can perform defect detection on each first segmented area on the image to be tested, thereby realizing defect detection of the image to be tested, with high detection accuracy and relatively accurate defect areas obtained by detection.

[0082] Exemplarily, before comparing, for each of at least one first segmented area, a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, the method may also include: acquiring a reference image; inputting the reference image into a trained image segmentation network to determine second position information, the second position information being used to indicate the position of at least one second segmented area in the reference image, the at least one second segmented area corresponding one-to-one to at least one target image position; based on the second position information, extracting, using a feature extraction network, a reference area feature map corresponding to each second segmented area in at least one second segmented area; and acquiring a reference feature library based on the reference area feature map corresponding to each second segmented area in at least one second segmented area.

[0083] In one embodiment, the implementation method of obtaining a reference feature library by determining the reference area feature map corresponding to each second segmented area in the reference image based on the reference image has been described in detail in the previous embodiments. Ordinary technicians in this field can understand the implementation method and its beneficial effects here by reading the relevant description in the previous text. For the sake of brevity, it will not be repeated here.

[0084] According to another aspect of the present invention, a defect detection device is also provided. Figure 3 A schematic block diagram of a defect detection device 300 according to an embodiment of the present invention is shown. Figure 3 As shown, the defect detection device 300 includes an acquisition module 310 , an input module 320 , an extraction module 330 and a comparison module 340 .

[0085] The acquisition module 310 is used to acquire the image to be tested.

[0086] The input module 320 is used to input the image to be tested into the trained image segmentation network to determine the first position information, where the first position information is used to indicate the position of at least one first segmentation area in the image to be tested, and the at least one first segmentation area corresponds one-to-one to at least one target image position.

[0087] The extraction module 330 is used to extract the feature map of the area to be tested corresponding to each first segmented area in at least one first segmented area by using a feature extraction network based on the first position information.

[0088] The comparison module 340 is used to compare, for each of the at least one first segmented area, a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, and the specific target image position is a target image position corresponding to the first segmented area.

[0089] A person skilled in the art may understand the specific implementation scheme and beneficial effects of the defect detection device by reading the above description of the defect detection method 100 , which will not be described in detail here for the sake of brevity.

[0090] According to yet another aspect of the present invention, an electronic device is provided. Figure 4 FIG. 2 shows a schematic block diagram of an electronic device according to an embodiment of the present invention. Figure 4 As shown, the electronic device 400 includes a processor 410 and a memory 420. The memory 420 stores a computer program. When the computer program instructions are executed by the processor 410, they are used to execute the above-mentioned defect detection method.

[0091] According to another aspect of the present invention, there is also provided a storage medium storing a computer program / instruction, the storage medium may include, for example, a storage component of a tablet computer, a hard disk of a personal computer, an erasable programmable read-only memory (EPROM), a portable read-only memory (CD-ROM), a USB memory, or any combination of the above storage media. The storage medium may be any combination of one or more computer-readable storage media. The computer program / instruction is used by a processor to execute the above defect detection method when it is running.

[0092] A person skilled in the art may understand the specific implementation scheme of the above-mentioned electronic device and storage medium by reading the above-mentioned description of the defect detection method, which will not be described here for the sake of brevity.

[0093] Although example embodiments have been described herein with reference to the accompanying drawings, it should be understood that the above example embodiments are merely exemplary and are not intended to limit the scope of the present invention thereto. Various changes and modifications may be made therein by one of ordinary skill in the art without departing from the scope and spirit of the present invention. All such changes and modifications are intended to be included within the scope of the present invention as required by the appended claims.

[0094] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of the present invention.

[0095] In the several embodiments provided by the present invention, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of the units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another device, or some features can be ignored or not executed.

[0096] In the description provided herein, a large number of specific details are described. However, it is understood that embodiments of the present invention can be practiced without these specific details. In some instances, well-known methods, structures and techniques are not shown in detail so as not to obscure the understanding of this description.

[0097] Similarly, it should be understood that in order to streamline the present invention and help understand one or more of the various inventive aspects, in the description of the exemplary embodiments of the present invention, the various features of the present invention are sometimes grouped together into a single embodiment, figure, or description thereof. However, the method of the present invention should not be interpreted as reflecting the following intention: the claimed invention requires more features than the features explicitly stated in each claim. More specifically, as reflected in the corresponding claims, the inventive point is that the corresponding technical problem can be solved with less than all the features of a single disclosed embodiment. Therefore, the claims following the specific embodiment are hereby expressly incorporated into the specific embodiment, wherein each claim itself serves as a separate embodiment of the present invention.

[0098] Those skilled in the art will understand that, except for mutually exclusive features, all features disclosed in this specification (including the accompanying claims, abstract and drawings) and all processes or units of any method or device disclosed in this specification may be combined in any combination. Unless otherwise explicitly stated, each feature disclosed in this specification (including the accompanying claims, abstract and drawings) may be replaced by an alternative feature that provides the same, equivalent or similar purpose.

[0099] In addition, those skilled in the art will appreciate that, although some embodiments described herein include certain features included in other embodiments but not other features, the combination of features of different embodiments is meant to be within the scope of the present invention and form different embodiments. For example, in the claims, any one of the claimed embodiments may be used in any combination.

[0100] The various component embodiments of the present invention may be implemented in hardware, or in software modules running on one or more processors, or in a combination thereof. Those skilled in the art should understand that a microprocessor or a digital signal processor (DSP) may be used in practice to implement some or all of the functions of some modules in the defect detection device according to an embodiment of the present invention. The present invention may also be implemented as a device program (e.g., a computer program and a computer program product) for executing part or all of the methods described herein. Such a program for implementing the present invention may be stored on a computer-readable medium, or may be in the form of one or more signals. Such a signal may be downloaded from an Internet website, or provided on a carrier signal, or provided in any other form.

[0101] It should be noted that the above embodiments illustrate the present invention rather than limit it, and that those skilled in the art may devise alternative embodiments without departing from the scope of the appended claims. In the claims, any reference symbol between brackets shall not be construed as a limitation on the claims. The word "comprising" does not exclude the presence of elements or steps not listed in the claims. The word "one" or "an" preceding an element does not exclude the presence of a plurality of such elements. The present invention may be implemented by means of hardware comprising a number of different elements and by means of a suitably programmed computer. In a unit claim enumerating a number of devices, several of these devices may be embodied by the same hardware item. The use of the words first, second, and third, etc., does not indicate any order. These words may be interpreted as names.

[0102] The above is only a specific embodiment of the present invention or an explanation of a specific embodiment. The protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. The protection scope of the present invention shall be based on the protection scope of the claims.

Claims

1. A defect detection method, It is characterized in that The method comprises: Acquire the image to be tested; Inputting the image to be tested into a trained image segmentation network to determine first position information, where the first position information is used to indicate the position of at least one first segmented region in the image to be tested, and the at least one first segmented region corresponds to at least one target image position in a one-to-one manner; Based on the first position information, using a feature extraction network to extract a feature map of the area to be tested corresponding to each of the at least one first segmented area; For each of the at least one first segmented area, comparing a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library to determine whether there is a defect in the first segmented area, wherein the specific target image position is a target image position corresponding to the first segmented area; Wherein, after extracting the feature map of the region to be tested corresponding to each of the at least one first segmented region by using a feature extraction network based on the first position information, the method further includes: For each of the at least one first segmented region, the following feature encoding operation is performed: The feature map of the region to be tested corresponding to the first segmented region is segmented according to a preset size to obtain a plurality of sub-region feature maps corresponding one by one to the segmented plurality of coding regions; Determine the region characteristic value corresponding to each of the plurality of sub-region characteristic maps; Based on the regional feature values ​​corresponding to the plurality of sub-region feature maps, a new feature map of the region to be tested corresponding to the first segmented region is obtained, wherein the new feature map of the region to be tested includes a plurality of coded feature maps corresponding to the plurality of sub-region feature maps one by one, and a pixel value of each coded feature map is consistent with a regional feature value of a corresponding sub-region feature image; Wherein, when performing the operation of comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library, the new feature map of the area to be tested corresponding to the first segmented area is compared with the feature map of the reference area corresponding to the specific target image position in the reference feature library.

2. The method according to claim 1, It is characterized in that The image segmentation network includes a feature extraction module and a segmentation head. The feature extraction module is used to extract image features of the image to be tested. The segmentation head is used to determine the first position information based on the image features output by the feature extraction module. The feature extraction network is the feature extraction module in the trained image segmentation network.

3. The method according to claim 1, It is characterized in that The extracting, based on the first position information, a feature extraction network corresponding to each first segmented area in the at least one first segmented area, a feature map of the area to be tested includes: For each of the at least one first segmented region, Based on the position of the first segmented area indicated by the first position information, pixel information of the image area other than the first segmented area is deleted from the image to be tested to obtain a regional image corresponding to the first segmented area, and the regional image is input into the feature extraction network to obtain a feature map of the region to be tested corresponding to the first segmented area; or The first position information and the image to be tested are input into the feature extraction network to obtain a feature map of the area to be tested corresponding to the first segmented area.

4. The method according to any one of claims 1 to 3, It is characterized in that The image segmentation network is trained in the following way: Acquire a sample data set, wherein the sample data set includes a plurality of sample images and annotated position information corresponding to each of the plurality of sample images, the annotated position information is used to indicate the position of at least one sample segmentation region in the corresponding sample image, and the at least one sample segmentation region corresponds one-to-one to the position of the at least one target image; Inputting the plurality of sample images into the image segmentation network to be trained to obtain predicted position information corresponding to each of the plurality of sample images, wherein the predicted position information is used to indicate the position of at least one sample segmentation region in the corresponding sample image; Calculating a predicted loss value based on an error between the predicted position information and the marked position information; Parameters in the image segmentation network to be trained are optimized based on the prediction loss value to obtain the trained image segmentation network.

5. The method according to claim 4, It is characterized in that The obtaining of the sample data set comprises: Acquire an initial template image and partition annotation information corresponding to the initial template image, wherein the partition annotation information is used to indicate the position of each annotated partition in at least one annotated partition on the initial template image, and the at least one annotated partition corresponds to the at least one target image position in a one-to-one manner; Based on the initial template image and the partition annotation information, generating at least one partition template image corresponding to the at least one annotated partition, wherein each partition template image includes pixel information in the corresponding annotated partition and does not include pixel information in other annotated partitions; acquiring the plurality of sample images; For each sample image among the multiple sample images, the sample image is matched with the at least one partition template image respectively to obtain the annotation position information corresponding to the sample image, wherein the at least one sample segmentation area is an image area that matches the at least one annotation partition one by one.

6. The method according to claim 1, It is characterized in that The determining of the region feature values ​​corresponding to each of the plurality of sub-region feature maps comprises: For each pixel point in each sub-region feature map of the multiple sub-region feature maps, Taking the pixel point as the target feature point, and sequentially comparing the pixel values ​​corresponding to the first number of pixel points in the neighborhood of the target feature point with the pixel value corresponding to the target feature point; When the pixel value corresponding to any pixel point is less than or equal to the pixel value corresponding to the target feature point, the encoding value corresponding to the pixel point is determined as the first value; When the pixel value corresponding to any pixel point is greater than the pixel value corresponding to the target feature point, the encoding value corresponding to the pixel point is determined as the second value; The encoding values ​​corresponding to the first number of pixel points in the neighborhood of the target feature point are summed, and the sum result is used as the pixel feature value corresponding to the target feature point to obtain the regional feature value corresponding to the sub-region feature map, and the regional feature value includes the pixel feature value corresponding to each pixel point in the sub-region feature map.

7. The method according to claim 1, It is characterized in that The obtaining, based on the region feature values ​​corresponding to each of the plurality of sub-region feature maps, a new feature map of the region to be tested corresponding to the first segmented region comprises: The region feature values ​​corresponding to each of the plurality of sub-region feature maps are merged to obtain a new feature map of the region to be tested corresponding to the first segmented region.

8. The method according to claim 1, It is characterized in that Before comparing, for each of the at least one first segmented area, the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, the method further includes: Get a reference image; Inputting the reference image into the trained image segmentation network to determine second position information, where the second position information is used to indicate the position of at least one second segmented region in the reference image, where the at least one second segmented region corresponds one-to-one with the at least one target image position; Based on the second position information, using the feature extraction network to extract a reference region feature map corresponding to each second segmented region in the at least one second segmented region; The reference feature library is acquired based on a reference region feature map corresponding to each second segmented region in the at least one second segmented region.

9. The method according to claim 8, It is characterized in that The acquiring the reference feature library based on the reference region feature map corresponding to each second segmented region of the at least one second segmented region comprises: Perform the feature encoding operation on each of the at least one second segmented region to obtain a new reference region feature map corresponding to each second segmented region; The reference feature library is obtained based on a new reference region feature map corresponding to each of the at least one second segmented regions.

10. The method according to claim 9, It is characterized in that The reference feature library includes a reference feature description library corresponding to a plurality of position area groups one by one, wherein the plurality of position area groups are groups formed by combining the at least one target image position and the plurality of coding areas, and at least one of the target image position and the coding area corresponding to different position area groups is different, and the number of the reference images is multiple, wherein: The acquiring the reference feature library based on the new reference region feature map corresponding to each of the at least one second segmented regions comprises: The sub-region feature maps corresponding to each position region group of the plurality of reference images are stored in a reference feature description library corresponding to the position region group.

11. The method according to claim 10, It is characterized in that The step of acquiring the reference feature library based on the new reference region feature map corresponding to each of the at least one second segmented regions further includes: For any position area group among the multiple position area groups, if there are identical sub-region feature maps in the corresponding reference feature description library, any sub-region feature map among the identical sub-region feature maps is retained in the corresponding reference feature description library and other sub-region feature maps are deleted.

12. The method according to claim 10, It is characterized in that The step of comparing the feature map of the region to be tested corresponding to the first segmented region with the feature map of the reference region corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented region includes: For each of the plurality of coding regions, Selecting a coding feature map corresponding to the maximum abnormal value from each coding feature map in a reference feature description library corresponding to a specific position area group, wherein the specific position area group is a group formed by combining the specific target image position and the coding area; Determine the difference between the pixel value of the coding feature map corresponding to the coding area of ​​the image to be tested and the pixel value of the coding feature map corresponding to the maximum abnormal value, and determine the difference as the pixel value of the sub-abnormal feature map corresponding to the coding area; Comparing the pixel value of each pixel in the first abnormal feature map or the second abnormal feature map obtained by upsampling the first abnormal feature map with the abnormal threshold, and determining that the pixel whose pixel value is greater than the abnormal threshold is a defective pixel, wherein the first abnormal feature map includes sub-abnormal feature maps corresponding to the multiple encoding regions one by one; Defective pixels in the first abnormal feature map or the second abnormal feature map are mapped to the image to be tested to determine a defective area within the first segmented area.

13. The method according to any one of claims 1 to 3, It is characterized in that The step of comparing the feature map of the region to be tested corresponding to the first segmented region with the feature map of the reference region corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented region includes: Comparing the feature map of the region to be tested corresponding to the first segmented region with the feature map of the reference region corresponding to the specific target image position in the reference feature library to determine whether each pixel point in the feature map of the region to be tested corresponding to the first segmented region belongs to the defect region; Mapping the pixel points belonging to the defective area in the feature map of the area to be tested onto the image to be tested, so as to determine the defective area on the image to be tested that is located within the first segmented area; After comparing, for each of the at least one first segmented area, the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, the method further includes: The defect area in the image to be tested is determined by combining the defect areas corresponding to the at least one first segmented area.

14. The method according to any one of claims 1 to 3, It is characterized in that Before comparing, for each of the at least one first segmented area, the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library to determine whether there is a defect in the first segmented area, the method further includes: Get a reference image; Inputting the reference image into the trained image segmentation network to determine second position information, where the second position information is used to indicate the position of at least one second segmented region in the reference image, where the at least one second segmented region corresponds one-to-one with the at least one target image position; Based on the second position information, using the feature extraction network to extract a reference region feature map corresponding to each second segmented region in the at least one second segmented region; The reference feature library is acquired based on a reference region feature map corresponding to each second segmented region in the at least one second segmented region.

15. A defect detection device, It is characterized in that The device comprises: An acquisition module, used for acquiring an image to be tested; An input module, used for inputting the image to be tested into a trained image segmentation network to determine first position information, wherein the first position information is used for indicating the position of at least one first segmented region in the image to be tested, and the at least one first segmented region corresponds to at least one target image position in a one-to-one manner; An extraction module, configured to extract, based on the first position information, a feature extraction network to extract a feature map of the region to be tested corresponding to each of the at least one first segmented region; A comparison module, configured to compare, for each of the at least one first segmented area, a feature map of the area to be tested corresponding to the first segmented area with a feature map of a reference area corresponding to a specific target image position in a reference feature library, so as to determine whether there is a defect within the first segmented area, wherein the specific target image position is a target image position corresponding to the first segmented area; Wherein, the defect detection device also includes a feature encoding module, The feature encoding module is used to perform the following feature encoding operation for each first segmented area in the at least one first segmented area after the extraction module performs an operation of extracting a feature map of the area to be tested corresponding to each first segmented area in the at least one first segmented area by using a feature extraction network based on the first position information: The feature map of the region to be tested corresponding to the first segmented region is segmented according to a preset size to obtain a plurality of sub-region feature maps corresponding one by one to the segmented plurality of coding regions; Determine the region characteristic value corresponding to each of the plurality of sub-region characteristic maps; Based on the regional feature values ​​corresponding to the plurality of sub-region feature maps, a new feature map of the region to be tested corresponding to the first segmented region is obtained, wherein the new feature map of the region to be tested includes a plurality of coded feature maps corresponding to the plurality of sub-region feature maps one by one, and a pixel value of each coded feature map is consistent with a regional feature value of a corresponding sub-region feature image; Wherein, when the input module is used to perform the operation of comparing the feature map of the area to be tested corresponding to the first segmented area with the feature map of the reference area corresponding to the specific target image position in the reference feature library, the new feature map of the area to be tested corresponding to the first segmented area is compared with the reference feature map of the reference area corresponding to the specific target image position in the reference feature library.

16. An electronic device comprising a processor and a memory, It is characterized in that The memory stores computer program instructions, which are used by the processor to execute the defect detection method according to any one of claims 1 to 14 when executed.

17. A storage medium storing a computer program / instructions, It is characterized in that The computer program / instructions are used to execute the defect detection method according to any one of claims 1 to 14 when running.

Citation Information

Patent Citations

  • Multistage ground wire defect identification method based on parallax auxiliary semantic segmentation

    CN116385364A