Unsupervised defect detection method and system based on transfer learning, storage medium
By employing an unsupervised defect detection method based on transfer learning and utilizing feature compression and fusion techniques, the problem of insufficient defect images is solved, enabling efficient and accurate defect detection in industrial production.
Patent Information
- Application Number
- CN202310085859.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-01-18
- Publication Date
- 2025-12-16
- Estimated Expiration
- 2043-01-18
AI Technical Summary
The limited number of defect images in existing technologies makes it difficult to apply supervised defect detection methods in practical industrial production.
An unsupervised defect detection method based on transfer learning is adopted. By acquiring the image of the object to be detected, a feature description map is extracted using a pre-trained defect detection model and compared with the core feature map of a pre-saved normal sample image to determine the defect region. No defect image is required during the training process. Feature compression and feature fusion techniques are used to enhance the feature representation capability of normal sample images.
It improves detection performance, reduces inference time, and enhances detection accuracy and real-time performance without the involvement of defective images, making it suitable for industrial defect detection.
Smart Images

Figure CN115994900B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of defect detection, and particularly relates to an unsupervised defect detection method and system based on transfer learning and a storage medium. BACKGROUND
[0002] In the prior art, when a machine learning method is used to detect defects of industrial products, defect images and normal images are usually obtained as training samples to train a machine learning model, so that the machine learning model learns the difference between the defect images and the normal images, and realizes detection and classification of defects. The defect images refer to images of defective products, and the normal images refer to images of normal products. This detection method is called supervised detection. In many real industrial production scenarios, the number of industrial images of defective products is small, and the proportion of normal product images is large, resulting in a large difference in the proportion of positive and negative samples. Moreover, the types of defects are complex and unpredictable. In terms of acquisition, it is very easy to obtain a large number of normal product images, but it is expensive to collect defect images of all defect types, which is beyond the reach of production enterprises. Therefore, in the defect detection scenario of industrial production, the supervised detection method is difficult to apply in practice. SUMMARY
[0003] The technical problem solved by the present application is that the number of defect images is small in reality, which makes it difficult to apply the supervised defect detection method in practice.
[0004] According to a first aspect, an embodiment provides an unsupervised defect detection method based on transfer learning, comprising:
[0005] obtaining a to-be-detected image of a measured object;
[0006] inputting the to-be-detected image into a trained defect detection model to obtain a feature description map of the to-be-detected image;
[0007] comparing the feature description map of the to-be-detected image with a core feature map of a pre-stored normal sample image, and determining a defect region of the to-be-detected image according to the difference between the two;
[0008] wherein the defect detection model is trained according to the following steps:
[0009] obtaining a training sample set composed of normal sample images;
[0010] The normal sample images of the training sample set are taken as current sample images in batches, each current sample image is input into the defect detection model with initial parameters to obtain a feature description map of each current sample image, the feature description map of each current sample image is subjected to feature compression processing to obtain a compressed feature map, and the compressed feature map is subjected to feature fusion with a fusion feature map obtained in a previous batch to obtain a new fusion feature map, and the fusion feature map obtained in the last batch is saved as a core feature map of the normal sample images, wherein the compressed feature map of the first batch of normal sample images is subjected to feature fusion with a 0-value image, and the core feature map has the same resolution as the feature description map;
[0011] The defect detection model is trained using the training sample set, and final model parameters are obtained, and the training target is to increase the difference between the feature description map of the normal sample image and the core feature map and to reduce the difference between similar parts.
[0012] In an embodiment, the defect detection model comprises a feature extraction module and a feature description module.
[0013] The input of the to-be-detected image into the trained defect detection model to obtain the feature description map of the to-be-detected image comprises:
[0014] The to-be-detected image is input into the feature extraction module to obtain n-layer feature sub-maps of the to-be-detected image, the last n-1-layer feature sub-maps are up-sampled to the same resolution as the first-layer feature sub-map, and then the first-layer feature sub-map and the other feature sub-maps after up-sampling are channel spliced to obtain an initial feature map, wherein n≥2.
[0015] The initial feature map is input into the feature description module to enhance the representation ability of the initial feature map for position information and improve the feature description ability, and the feature description map of the to-be-detected image is obtained.
[0016] The input of the current sample image into the defect detection model with initial parameters to obtain the feature description map of the current sample image comprises:
[0017] The current sample image is input into the feature extraction module with initial parameters to obtain n-layer feature sub-maps of the current sample image, the last n-1-layer feature sub-maps are up-sampled to the same resolution as the first-layer feature sub-map, and then the first-layer feature sub-map and the other feature sub-maps after up-sampling are channel spliced to obtain an initial feature map.
[0018] The initial feature map is input into the feature description module with initial parameters to enhance the representation ability of the initial feature map for position information and improve the feature description ability, and the feature description map of the current sample image is obtained.
[0019] In an embodiment, the feature extraction module is a pre-trained feature extraction network, and the network parameters of the feature extraction network are fixed during training, and / or the feature description module is a coordinate convolution network layer.
[0020] In an embodiment, the defect detection model is trained according to a preset loss function, and the loss function is determined by the following method:
[0021] The distance values between the feature vectors of each pixel point in the feature description graph of the normal sample image and the feature vectors of all pixel points of the core feature graph are calculated respectively;
[0022] For each pixel point of the feature description graph of the normal sample image, the smallest Y distance values among the distance values between the feature vector of the pixel point and the feature vectors of all pixel points of the core feature graph are selected, and the selected distance values are arranged in ascending order, and the feature vectors of the pixel points of the core feature graph corresponding to the smaller Y / 2 distance values are taken as positive contrast feature vectors, and the feature vectors of the pixel points of the core feature graph corresponding to the larger Y / 2 distance values are taken as negative contrast feature vectors, wherein Y is an even number not less than 2;
[0023] A first loss function is constructed according to the feature vectors of the pixel points of the feature description graph of the normal sample image and the corresponding positive contrast feature vectors, and the target of the first loss function is to reduce the distance between the feature vectors of the pixel points of the feature description graph of the normal sample image and the corresponding positive contrast feature vectors;
[0024] A second loss function is constructed according to the feature vectors of the pixel points of the feature description graph of the normal sample image and the corresponding negative contrast feature vectors, and the target of the second loss function is to increase the distance between the feature vectors of the pixel points of the feature description graph of the normal sample image and the corresponding negative contrast feature vectors;
[0025] The first loss function and the second loss function are added as the loss function.
[0026] In an embodiment, the loss function is specifically:
[0027] L total =L1+L2,
[0028] wherein L1 is the first loss function, L2 is the second loss function, and
[0029]
[0030]
[0031] Z represents the number of pixels of the feature description graph of the normal sample image, K=Y / 2, and β za feature vector of a zth pixel point of a feature description graph representing a normal sample image, a Euclidean distance between β z a corresponding kth positive contrast feature vector, a Euclidean distance between β z and P=Y / 2, a Euclidean distance between β z a corresponding pth negative contrast feature vector, a Euclidean distance between β z and R and λ are adaptive parameters to be obtained through learning.
[0032] In an embodiment, the feature compression processing on the feature description graph of the current sample image obtains a compressed feature graph, and the compressed feature graph is fused with a fusion feature graph obtained in a previous batch to serve as a new fusion feature graph, including:
[0033] performing an average operation on the feature description graph of the current sample image in a batch dimension to obtain a compressed feature graph g t :
[0034] g t =Mean(β),
[0035] wherein t represents an iteration batch and t≥1, g t represents a compressed feature graph of the tth batch, β represents a feature description graph of a current sample image, and Mean() represents an average operation performed in a batch dimension;
[0036] fuse the compressed feature graph g t with a fusion feature graph obtained in a previous batch to obtain a new fusion feature graph
[0037]
[0038] wherein represents a fusion feature graph obtained in the tth batch, and
[0039] In an embodiment, the comparison of the feature description graph of the to-be-detected image with the core feature graph of the normal sample image and the determination of a defect region of the to-be-detected image according to a difference between the two include:
[0040] calculating a distance value between a feature vector of each pixel point in the feature description graph of the to-be-detected image and a feature vector of all pixel points in the core feature graph;
[0041] For each pixel point of the feature description map of the image to be detected, select the minimum distance value in the distance values of the feature vector of the pixel point and the feature vectors of all pixel points of the core feature map, and compose a distance representation map;
[0042] The distance representation map is processed by a Sigmoid function to obtain a prediction score map of the image to be detected, and a pixel value of the prediction score map is used to represent the probability that the corresponding pixel point is an abnormal pixel;
[0043] The prediction score map of the image to be detected is up-sampled to have the same resolution as the image to be detected.
[0044] The prediction score map of the image to be detected after up-sampling is threshold segmented to obtain a defect region of the image to be detected.
[0045] In an embodiment, the threshold segmentation of the prediction score map of the image to be detected after up-sampling includes:
[0046] obtaining the average value of the pixel values of the prediction score map of the normal sample image and the standard deviation σ x ;
[0047] If the pixel value of the prediction score map of the image to be detected after up-sampling is located in the interval , the pixel is determined to be a normal pixel, otherwise it is an abnormal pixel, where k1 is a preset coefficient.
[0048] According to a second aspect, an embodiment provides an unsupervised defect detection system based on transfer learning, comprising:
[0049] An image to be detected acquisition module is configured to acquire an image to be detected of an object to be measured;
[0050] A feature description map acquisition module is configured to input the image to be detected into a trained defect detection model to obtain a feature description map of the image to be detected;
[0051] A feature comparison module is configured to compare the feature description map of the image to be detected with a core feature map of a normal sample image saved in advance, and determine a defect region of the image to be detected according to the difference between the two;
[0052] A model training module is configured to train the defect detection model by the following way:
[0053] A training sample set composed of normal sample images is acquired;
[0054] The normal sample images of the training sample set are taken as current sample images in batches, each current sample image is input into the defect detection model with initial parameters to obtain a feature description map of each current sample image, the feature description map of each current sample image is subjected to feature compression processing to obtain a compressed feature map, and the compressed feature map is subjected to feature fusion with a fusion feature map obtained in the last batch to obtain a new fusion feature map, and the fusion feature map obtained in the last batch is saved as a core feature map of the normal sample images, wherein the compressed feature map of the first batch of normal sample images is subjected to feature fusion with a 0-value image, and the core feature map has the same resolution as the feature description map;
[0055] The defect detection model is trained using the training sample set, and final model parameters are obtained, and the training target is to increase the difference between the feature description map of the normal sample image and the core feature map and to reduce the difference between similar parts.
[0056] According to a third aspect, a computer readable storage medium is provided in an embodiment, and the medium stores a program which can be executed by a processor to implement the unsupervised defect detection method according to the first aspect.
[0057] According to the unsupervised defect detection method / system based on transfer learning, the feature description map of the to-be-detected image is obtained by inputting the to-be-detected image of the measured object into the pre-trained defect detection model, the feature description map of the to-be-detected image is compared with the core feature map of the normal sample image which is pre-stored, and the defect region of the to-be-detected image is determined according to the difference between the two. The training of the defect detection model includes: taking the normal sample images of the training sample set as current sample images in batches, for each batch, inputting each current sample image into the defect detection model with initial parameters to obtain a feature description map of each current sample image, performing feature compression processing on the feature description map of the current sample image to obtain a compressed feature map, and performing feature fusion on the compressed feature map and a fusion feature map obtained in the last batch to obtain a new fusion feature map, saving the fusion feature map obtained in the last batch as a core feature map of the normal sample images, and training the defect detection model with the target of increasing the difference between the feature description map of the normal sample image and the core feature map and reducing the difference between similar parts. Since the feature description map of the normal sample image is subjected to feature compression and feature fusion, the core feature map obtained does not increase with the increase of the normal sample image, thereby avoiding long inference time and achieving high real-time performance. Based on transfer learning, the core feature map is extracted using the normal sample image to guide the training of the defect detection model, and the feature of the industrial image is self-adapted. In the training process, no defect image is needed, and the method is more suitable for practical application in industry compared with the supervised detection method. BRIEF DESCRIPTION OF DRAWINGS
[0058] Figure 1 FIG. 1 is a flowchart of a training process of a defect detection model according to an embodiment;
[0059] Figure 2 FIG. 2 is a schematic diagram of a defect detection model training process according to an embodiment;
[0060] Figure 3 FIG. 3 is a diagram according to an embodiment in which each pixel point of a feature description map is composed of distance values between a feature vector of each pixel point of the feature description map and a feature vector of each pixel point of a core feature map;
[0061] Figure 4 FIG. 4 is a flowchart of a defect detection process according to an embodiment;
[0062] Figure 5 FIG. 5 is a schematic diagram of a defect detection process according to an embodiment;
[0063] Figure 6 FIG. 6 is a schematic diagram of a structure of an unsupervised defect detection system based on transfer learning according to an embodiment. DETAILED DESCRIPTION
[0064] The application will be described in further detail below with reference to the drawings. Like elements in different embodiments are denoted by like reference numerals. In the following embodiments, many details are described in order to provide a more thorough description of the application. However, it will be apparent to those skilled in the art that some features can be omitted, or some elements, materials, or methods can be substituted, in different situations. In some cases, some operations related to the application are not shown or described in the specification, in order to avoid the core of the application being obscured by too much description, and it is not necessary for those skilled in the art to describe these operations in detail based on the description in the specification and general technical knowledge in the art.
[0065] In addition, the features, operations, or characteristics described in the specification can be combined in any appropriate manner to form various embodiments. Meanwhile, the steps or actions in the method description can also be adjusted in sequence or order as is apparent to those skilled in the art. Therefore, the order in the specification and the drawings is only for the purpose of clearly describing a certain embodiment, and does not mean that the order is necessary, unless otherwise stated that a certain order must be followed.
[0066] In this document, the serial numbers of components, such as "first", "second", etc., are used only to distinguish the described objects, and do not have any sequential or technical meaning. Unless otherwise specified, "connected" or "coupled" in this application includes direct and indirect connections (couplings).
[0067] As described in the background, there are some limitations in the supervised defect detection method, so some unsupervised defect detection methods are developed. In the actual application of industry, the unsupervised defect detection generally adopts the distance measurement method, and the specific processing method is that a pre-trained model is used to extract features of each normal image respectively, and all the features of the normal images are saved as normal features. During inference (i.e. during actual defect detection), the pre-trained model extracts the features of the to-be-detected image as detection features in the same way, then calculates the distance between the detection features and the normal features in a certain way, and finally compares with the preset threshold to distinguish whether the to-be-detected image has defects. The larger the distance is, the more defects there are, and the smaller the distance is, the less defects there are.
[0068] Essentially, the mechanism of action of this distance measurement method is that the feature similarity between normal images is high, and the feature difference between defect images and normal images is large, and through a suitable threshold, the detection purpose can be well achieved. However, this method has two major drawbacks, one is that the pre-trained model for extracting features of the image is trained on a large-scale natural data set, and has not realized the feature adaptation of the industrial image data, which to some extent, overestimates the normality of the defect features, and causes the phenomenon of missed detection; the second is that the detection performance of the model improves with the increase of the number of normal samples, the more normal images are extracted to obtain normal features, the higher the detection accuracy is, but the inference time also increases, and the detection accuracy and real-time performance cannot be well balanced. The above two aspects jointly act on the detection performance.
[0069] In view of the above problems, the present application proposes an unsupervised defect detection method based on transfer learning, which can complete the training of the model in an end-to-end manner without the participation of any defect image during training. The trained model can realize the feature adaptation of the industrial image, improve the feature representation ability of the normal sample, and the inference time is not limited by the number of normal samples, which greatly improves the detection performance and realizes the accurate detection of the industrial defect image.
[0070] One of the purposes of the present application is to solve the problem of defect segmentation of the to-be-detected image under the condition that only normal samples participate in the training. For this purpose, the present application builds a neural network structure based on the transfer learning technology of deep learning, obtains a defect detection model through training, and the defect detection model is used to extract features of the to-be-detected image to obtain a feature description map of the to-be-detected image. The feature description map of the to-be-detected image is compared with the normal features, and the defect area in the to-be-detected image can be segmented. The training process of the defect detection model can refer to Figure 1 and Figure 2 . As Figure 2As shown, the training includes two stages, an initial training stage (Initial) and a forward training stage (Forward). The initial training stage (Initial) needs to be performed only once for the same training sample set, and the forward training stage (Forward) can be performed multiple times. In terms of process sequence, the initial training stage (Initial) must be performed first, and then the forward training stage (Forward) can be performed. The training process is described in detail below. Please refer to Figure 1 The training process of the defect detection model in an embodiment includes steps 110-130, which are described in detail below.
[0071] Step 110: Obtain a training sample set composed of normal sample images.
[0072] The normal sample image, which is a normal image as a training sample, is an image of a normal product without defects corresponding to the measured object. The measured object can be a product on an industrial assembly line, a mechanical part in a box of objects, a tool on an operating table, etc., without specific limitation. The normal sample image can be obtained by photographing the normal product without defects corresponding to the measured object by any camera device. All normal sample images form a training sample set.
[0073] Step 120: Obtain the core feature map of the normal sample image.
[0074] Step 120 is the initial training stage, mainly for obtaining the core feature map g of the normal sample image. First, the normal sample images of the training sample set are taken as the current sample images in batches. For each batch, the current sample images therein are respectively input into the defect detection model with initial parameters to obtain the feature description map β of each current sample image. The feature description map of the current sample image is compressed to obtain a compressed feature map, and the compressed feature map is fused with the fusion feature map obtained in the last batch to obtain a new fusion feature map. Then, the fusion feature map obtained in the last batch is saved as the core feature map g of the normal sample image. The compressed feature map of the first batch of normal sample images is fused with a 0-value image, and the obtained core feature map g has the same resolution as the feature description map β.
[0075] Specifically, first, initial parameters are set for the defect detection model, normal sample images in the training sample set are batched, and each batch contains a plurality of normal sample images. A 0-value image is taken as an initial fusion feature map, and iteration is performed in batches. The fusion feature map is updated in each batch. Specifically, first, the normal sample images in the first batch are taken as current sample images, and the current sample images are respectively input into the defect detection model with the initial parameters set to obtain feature description maps β of the current sample images. The feature description maps of the current sample images are subjected to feature compression processing to compress the feature description maps of all the current sample images into one feature map, thereby obtaining a compressed feature map. The compressed feature map is subjected to feature fusion with the 0-value image to obtain a new fusion feature map. Then, the normal sample images in each subsequent batch are taken in turn as current sample images, and the same operation is performed to obtain a compressed feature map. The compressed feature map is subjected to feature fusion with the fusion feature map obtained in the previous batch to obtain a new fusion feature map, thereby realizing updating of the fusion feature map. The fusion feature map obtained in the last batch is saved as a core feature map g of the normal sample images.
[0076] For reference Figure 2 In an embodiment of the present application, the defect detection model constructed includes a feature extraction module M and a feature description module D. The feature extraction module M is mainly used to extract features of an input image to obtain feature sub-maps of multiple layers with different resolutions. The feature description module D is mainly used to enhance the representation ability of position information of the extracted features and better describe the extracted features to improve the feature description ability of the input image and realize feature self-adaptation. In this embodiment, the process of inputting a current sample image into the defect detection model with initial parameters set to obtain a feature description map β of the current sample image includes: inputting the current sample image into the feature extraction module M with initial parameters set to obtain feature sub-maps of the current sample image with n layers of resolution decreasing, upsampling the feature sub-maps of the last n-1 layers to the same resolution as the feature sub-map of the first layer, and then performing channel splicing on the feature sub-map of the first layer and the other feature sub-maps after upsampling to obtain an initial feature map α, where n≥2, for example, n can be 3; inputting the initial feature map into the feature description module D with initial parameters set to enhance the representation ability of position information of the initial feature map and improve the feature description ability, thereby obtaining the feature description map β of the current sample image.
[0077] The upsampling and channel concatenation of the feature sub-graphs are described below by an example. Assuming n=3, the shape of the feature sub-graphs is represented in the form of vector [B, C, H, W], wherein B represents the batch dimension value, i.e. the batch number, C represents the channel number of the feature sub-graph, H represents the height of the feature sub-graph, and W represents the width of the feature sub-graph. Assuming the shapes of the extracted 3-layer feature sub-graphs are [1, 256, 56, 56], [1, 512, 28, 28], and [1, 1024, 14, 14] respectively, firstly, the upsampling operation is performed on the extracted second-layer feature sub-graph and third-layer feature sub-graph respectively to improve the resolution to the same as the first-layer feature sub-graph, so as to obtain the shapes of the second-layer and third-layer feature sub-graphs as [1, 512, 56, 56] and [1, 1024, 56, 56] respectively, and then the concatenation operation is performed on the first-layer feature sub-graph and the two-layer feature sub-graphs after upsampling in the channel dimension, i.e. the feature sub-graphs with shapes of [1, 256, 56, 56], [1, 512, 56, 56], and [1, 1024, 56, 56] are concatenated into an initial feature map a with a shape of [1, 1792, 56, 56]. Figure 1
[0078] In an embodiment of the present application, a feature compression and feature fusion method is also provided. When performing feature compression, the average operation is performed on the feature description graph of the current sample image in the batch dimension to obtain a compressed feature graph g t :
[0079] g t = Mean (β),
[0080] wherein t represents the iteration batch and t≥1, g t represents the compressed feature graph of the t-th batch, β represents the feature description graph of the current sample image, here referring to the feature description graph of all current sample images, and Mean () represents the average operation performed in the batch dimension, i.e. the average of the feature description graphs of all current sample images in a batch.
[0081] When performing feature compression, the compressed feature graph g t is fused with the fusion feature graph obtained in the last batch according to the following formula to obtain a new fusion feature graph
[0082]
[0083] wherein g represents the fusion feature graph obtained in the t-th batch, and
[0084] It can be understood that the feature compression and feature fusion method of the embodiment can retain the features of each normal sample image and does not increase the core feature map by continuously compressing and fusing the features of the normal sample image, improves the feature density of the core feature map, and keeps the size of the core feature map representing the normal feature constant without reducing the detection accuracy.
[0085] The training initial stage only performs one iteration on the training sample set without repeated iteration, and the fusion feature map obtained after the iteration is completed is the core feature map g of the normal sample image. After the training initial stage ends, the core feature map g is saved and frozen and is no longer updated. Essentially, the purpose of the training initial stage is to obtain the compressed feature representation of the normal sample, that is, the core feature map g, which represents the overall normal feature of the normal sample image and is the target feature for reference during training.
[0086] Step 130: training the defect detection model using the training sample set to obtain the final model parameters, and the training target is to increase the difference between the dissimilar parts of the feature description map and the core feature map of the normal sample image and reduce the difference between the similar parts.
[0087] Step 130 is the training running stage, which mainly trains the defect detection model according to the preset loss function, and the training target is to increase the difference between the dissimilar parts of the feature description map and the core feature map of the normal sample image and reduce the difference between the similar parts, thereby enhancing the ability of the defect detection model to distinguish between defect features and normal features.
[0088] The feature description map of the normal sample image is also obtained by inputting the normal sample image into the defect detection model. If the defect detection model includes a feature extraction module M and a feature description module D, the normal sample image is also input into the feature extraction module M to obtain feature subgraphs of the normal sample image with n layers of resolution decreasing, the last n-1 layer feature subgraphs are upsampled to the same resolution as the first layer feature subgraph, and then the first layer feature subgraph and the other feature subgraphs after upsampling are channel spliced to obtain an initial feature map α, where n≥2, for example, it can be 3; the initial feature map is input into the feature description module D to enhance the representation ability of the position information of the initial feature map and improve the feature description ability, and the feature description map β of the normal sample image is obtained. The feature description map β is compared with the core feature map g, the loss function is calculated, and the parameters of the defect detection model are updated according to the gradient descent method. The training running stage can be performed multiple times, and the training sample set is used for multiple repeated iterations.
[0089] In an embodiment, the feature extraction module M can be a pre-trained feature extraction network, the network parameters of which remain unchanged during training, and the network parameters are loaded with pre-trained weights, and the parameters remain frozen during the whole process of training and inference of the overall network model. The feature extraction network can specifically use ResNet-50 or the like. In an embodiment, the feature description module D can be a coordinate convolution network layer (CoordConv), specifically a 1x1 coordinate convolution network layer. The purpose of using the coordinate convolution network layer in the feature description module D is to enable the convolution process to perceive the position information of the input feature map and realize accurate positioning of defects. The feature description module D is run with randomly initialized weight parameters in the initial training stage and does not need to update the weight parameters. In the training running stage, the weight parameters of the feature description module D will be updated.
[0090] In an embodiment, a special contrastive supervision loss function L is designed for training of the defect detection model total The contrastive supervision loss function L total The contrastive supervision loss function L is composed of two parts, namely a first loss function L1 and a second loss function L2. The construction of the contrastive supervision loss function is described in detail below.
[0091] As shown in Figure 2 The feature description graph β and the core feature graph g are subjected to TrainOp operation to obtain positive contrast feature vectors and negative contrast feature vectors. The TrainOp operation includes: calculating the distance value, for example, the Euclidean distance, between the feature vector of each pixel point in the feature description graph β of the normal sample image and the feature vectors of all pixel points of the core feature graph g, wherein the feature vector of a pixel point is a vector composed of pixel values corresponding to the position of the pixel point on each channel; for each pixel point of the feature description graph β of the normal sample image, select the smallest Y distance values from the distance values between the feature vector of the pixel point and the feature vectors of all pixel points of the core feature graph g, and arrange them in ascending order, and take the feature vectors of the pixel points of the core feature graph g corresponding to the smaller Y / 2 distance values as the positive contrast feature vectors, and take the feature vectors of the pixel points of the core feature graph g corresponding to the larger Y / 2 distance values as the negative contrast feature vectors, wherein Y is an even number not less than 2, for example, Y=6.
[0092] TrainOp operation is illustrated by an example below, where the shape of the image is also represented in the form of vector [B, C, H, W]. Assuming Y = 6, the shape of the core feature map g is [1, 1792, 56, 56], the shape of the feature description map β is [1, 1792, 56, 56], and the feature vector of each pixel point in the feature description map β is respectively calculated with the feature vector of all pixel points in the core feature map g to obtain distance values, then these distance values can form a graph j with only one column and the number of channels is 56x56 = 3136, and the shape of the graph j is [1, 3136, 3136], as shown in Figure 3 The smallest 6 distance values of each channel of the graph j are selected, and arranged in ascending order to obtain a distance representation graph h, and the shape of the distance representation graph h is [1, 6, 3136]. The distance representation graph h is separated in the channel dimension with the midpoint of the channel length as the separation point to obtain two feature distance representation graphs d + and d — , d + is composed of the smaller 3 distance values, and the shape is [1, 3, 3136], which is restored to the resolution of the feature description map β, i.e. [1, 3, 56, 56], and the feature vector of the pixel point of the core feature map g corresponding to the distance value in d + is the positive contrast feature vector; d — is composed of the larger 3 distance values, and the shape is [1, 3, 3136], which is restored to the resolution of the feature description map β, i.e. [1, 3, 56, 56], and the feature vector of the pixel point of the core feature map g corresponding to the distance value in d — is the negative contrast feature vector.
[0093] At the pixel point level, d + represents the distance between the pixel point of the feature description map β of the normal sample and the similar pixel point of the core feature map g, d — represents the distance between the pixel point of the feature description map β of the normal sample and the abnormal pixel point of the core feature map g, d + should be less than a certain value, and d — should be greater than a certain value, so as to reduce the distance between the similar pixel points while increasing the distance between the normal and abnormal pixel points, so as to achieve the purpose of distinguishing the normal sample from the defect sample.
[0094] Therefore, based on this idea, after obtaining the positive contrast feature vector and the negative contrast feature vector, a first loss function and a second loss function can be constructed. The first loss function can be constructed according to the feature vector of the pixel point of the feature description map of the normal sample image and the corresponding positive contrast feature vector, and the target is to reduce the distance between the feature vector of the pixel point of the feature description map of the normal sample image and the corresponding positive contrast feature vector, i.e. to reduce d +; the second loss function can be constructed according to the feature vectors of the pixel points of the feature description graph of the normal sample image and the corresponding negative contrast feature vectors, and the target is to increase the distance between the feature vectors of the pixel points of the feature description graph of the normal sample image and the corresponding negative contrast feature vectors, that is, to increase d — .
[0095] In an embodiment, the first loss function and the second loss function can be specifically:
[0096]
[0097]
[0098] wherein Z represents the number of pixels of the feature description graph of the normal sample image, and the core feature graph is usually the same size as the feature description graph, so Z also represents the number of pixels of the core feature graph, for example, the shape of the feature description graph of the normal sample image is [1, 1792, 56, 56], and the number of pixels Z of the feature description graph of the normal sample image is 56x56=3136; K=Y / 2, β z represents the feature vector of the zth pixel point of the feature description graph of the normal sample image, represents the kth positive contrast feature vector corresponding to β z . represents the pth negative contrast feature vector corresponding to β z . the Euclidean distance between and ; P=Y / 2, represents the pth negative contrast feature vector corresponding to β z . represents the pth negative contrast feature vector corresponding to β z . the Euclidean distance between and, and R and λ are adaptive parameters that need to be obtained through learning, that is, R and λ will also be updated according to the training process.
[0099] Then the contrastive supervision loss function L total can be:
[0100] L total = L1+L2.
[0101] Through the above contrastive supervision loss function, the training of the defect detection model completing the transfer learning can make each pixel point of the feature description graph of the normal sample image keep similar to the most similar pixel point in the core feature graph and pull away from the pixel points that are not similar in the core feature graph, so that the model greatly improves the discrimination degree of normal features and defect features, thereby completing the task of defect segmentation.
[0102] The defect detection process will be described in detail below. Figure 4 and Figure 5 Please refer to Figure 4In one embodiment, the flow of defect detection includes steps 210-230, which are described below.
[0103] Step 210: Obtain the image to be detected of the object to be detected.
[0104] For the acquisition of the image to be detected of the object to be detected, please refer to the acquisition of the normal sample image.
[0105] Step 220: Input the image to be detected into the trained defect detection model to obtain the feature description map of the image to be detected.
[0106] The process of obtaining the feature description map of the image to be detected is the same as the process of obtaining the feature description map of the normal sample image. Please refer to Figure 5 In the embodiment in which the defect detection model includes the feature extraction module M and the feature description module D, the process of inputting the image to be detected into the trained defect detection model to obtain the feature description map of the image to be detected includes: inputting the image to be detected x into the feature extraction module M to obtain n-layer feature sub-maps with decreasing resolution of the image to be detected, upsampling the last n-1 layer feature sub-maps to the same resolution as the first layer feature sub-map, and then channel splicing the first layer feature sub-map and the other feature sub-maps after upsampling to obtain an initial feature map α; inputting the initial feature map into the feature description module D to enhance the representation ability of the location information of the initial feature map and improve the feature description ability, and obtaining the feature description map β of the image to be detected. It can be understood that the feature description map obtained here has the same resolution as the feature description map obtained in the training process, and therefore has the same resolution as the core feature map.
[0107] Step 230: Compare the feature description map of the image to be detected with the core feature map of the pre-stored normal sample image, and determine the defect area of the image to be detected according to the difference between the two.
[0108] Please refer to Figure 5 In one embodiment, step 230 includes TestOp operation, Sigmoid function processing, upsampling, and threshold segmentation, which are described below.
[0109] As shown in Figure 5 , first, the feature description map β of the image to be detected is subjected to TestOp operation with the core feature map g to obtain a distance representation map l. The TestOp operation includes: calculating the distance value, such as the Euclidean distance, between the feature vector of each pixel point in the feature description map β of the image to be detected and the feature vectors of all pixel points of the core feature map g; for each pixel point of the feature description map β of the image to be detected, selecting the smallest distance value among the distance values between its feature vector and the feature vectors of all pixel points of the core feature map g to form the distance representation map l.
[0110] Then the distance representation graph l is processed by a Sigmoid function to obtain a prediction score graph u of the image to be detected, and the pixel value of the prediction score graph is used to represent the probability that the corresponding pixel point is an abnormal pixel. The Sigmoid function mainly maps the distance value in the distance representation graph l to between 0 and 1 to obtain a value representing the probability, and the smaller the value, the greater the normality, and vice versa, the greater the probability of defects.
[0111] Then the prediction score graph u of the image to be detected is up-sampled to have the same resolution as the image to be detected x. Finally, the prediction score graph u of the image to be detected after up-sampling is threshold segmented to obtain a detection result s, and the resolution of s is consistent with the image to be detected x. As shown in Figure 5 , the detection result s presents the defect area of the image to be detected x. The threshold segmentation of the prediction score graph u of the image to be detected after up-sampling can include the following steps: obtaining the average value and the standard deviation σ x of the pixel value of the prediction score graph of the normal sample image, if the pixel value of the prediction score graph u of the image to be detected after up-sampling is located in the interval , the pixel is determined to be a normal pixel, otherwise it is an abnormal pixel. The acquisition method of the prediction score graph of the normal sample image is the same as that of the prediction score graph of the image to be detected, and k1 is a preset coefficient, which can be set to 3 by default.
[0112] The following describes step 230 by an example. It is assumed that the shape of the image to be detected x is [1, 3, 224, 224], the shape of the core feature graph g is [1, 1792, 56, 56], and the shape of the feature description graph β is [1, 1792, 56, 56]. The feature vector of each pixel point in the feature description graph β is calculated with the feature vector of all pixel points in the core feature graph g to obtain a distance value, and then the distance values can form a graph j with only one column and a channel number of 56*56=3136, and the shape of the graph j is [1, 3136, 3136], as shown in Figure 3 . A minimum distance value is obtained in the channel dimension of the graph j to obtain a distance representation graph l, and the shape of the distance representation graph l is [1, 1, 3136], which is restored to the resolution of the feature description graph β, i.e., [1, 1, 56, 56]. The distance representation graph l is processed by a Sigmoid function to obtain a prediction score graph u, the prediction score graph u is up-sampled, and threshold segmentation is performed to obtain a detection result s. In order to restore the resolution of the image to be detected x, the up-sampling multiple is set to 4, i.e., 224 / 56=4, and then the shape of the obtained detection result s is [1, 1, 224, 224].
[0113] The application is based on the idea of transfer learning to design a contrastive supervision loss function for training the whole defect detection model, which effectively improves the final detection accuracy of the model. During inference, the defect segmentation map of the image to be detected can be directly output in an end-to-end manner.
[0114] Based on the above-mentioned unsupervised defect detection method based on transfer learning, the application also provides an unsupervised defect detection system based on transfer learning, please refer to Figure 6 In an embodiment, the system includes an image to be detected acquisition module 1, a feature description map acquisition module 2, a feature comparison module 3 and a model training module 4, which are described below.
[0115] The image to be detected acquisition module 1 is used to acquire the image to be detected of the measured object.
[0116] The feature description map acquisition module 2 is used to input the image to be detected into the trained defect detection model to obtain the feature description map of the image to be detected.
[0117] Please refer to Figure 5 The defect detection model of an embodiment includes a feature extraction module M and a feature description module D. The feature extraction module M is mainly used to extract the features of the input image to obtain feature subgraphs of multiple layers with different resolutions. The feature description module D is mainly used to enhance the representation ability of the position information of the extracted features, better describe the extracted features, improve the feature description ability of the input image, and realize feature adaptation. In this embodiment, the feature description map acquisition module 2 is specifically used to input the image to be detected x into the feature extraction module M to obtain feature subgraphs of n layers with decreasing resolutions, upsample the last n-1 layers of feature subgraphs to the same resolution as the first layer of feature subgraph, then concatenate the first layer of feature subgraph with the other upsampled feature subgraphs in the channel to obtain an initial feature map α, where n≥2, for example, it can be 3; input the initial feature map into the feature description module D to enhance the representation ability of the position information of the initial feature map and improve the feature description ability, and obtain the feature description map β of the image to be detected.
[0118] The feature comparison module 3 is used to compare the feature description map of the image to be detected with the core feature map of the pre-stored normal sample image, and determine the defect area of the image to be detected according to the difference between the two.
[0119] In an embodiment, the feature comparison module 3 can be specifically configured to: calculate distance values, such as Euclidean distances, between the feature vector of each pixel point in the feature description graph of the image to be detected and the feature vectors of all pixel points of the core feature graph, wherein the feature vector of a pixel point is a vector composed of pixel values on each channel corresponding to the position of the pixel point; for each pixel point of the feature description graph of the image to be detected, select the smallest distance value from the distance values of the feature vectors of all pixel points of the core feature graph, to form a distance representation graph; process the distance representation graph using a Sigmoid function to obtain a prediction score graph, wherein the pixel value of the prediction score graph is used to represent the probability that the corresponding pixel point is an abnormal pixel; perform up-sampling processing on the prediction score graph to make its resolution the same as that of the image to be detected; and perform threshold segmentation on the prediction score graph after up-sampling to obtain the defect region of the image to be detected. The specific working process of the feature comparison module 3 in this embodiment can refer to step 230, which will not be described here again.
[0120] The model training module 4 is configured to train the defect detection model by: obtaining a training sample set composed of normal sample images; taking the normal sample images of the training sample set as current sample images in batches, inputting each current sample image into the defect detection model with initial parameters to obtain a feature description graph of each current sample image, performing feature compression processing on the feature description graph of each current sample image to obtain a compressed feature graph, and performing feature fusion with the fusion feature graph obtained in the last batch to obtain a new fusion feature graph, saving the fusion feature graph obtained in the last batch as a core feature graph of the normal sample image, wherein the compressed feature graph of the first batch of normal sample images is fused with a 0-value image, and the obtained core feature graph has the same resolution as the feature description graph; training the defect detection model using the training sample set to obtain final model parameters, and the training target is to increase the difference between the dissimilar parts of the feature description graph and the core feature graph of the normal sample image and to reduce the difference between the similar parts.
[0121] Please refer to Figure 2 In the embodiment in which the defect detection model includes the feature extraction module M and the feature description module D, the model training module 4 is specifically configured to: input the current sample image into the feature extraction module M with initial parameters to obtain feature subgraphs of the current sample image with n layers of resolution decreasing, up-sample the last n-1 layer feature subgraphs to the same resolution as the first layer feature subgraph, and then perform channel splicing on the first layer feature subgraph and the up-sampled other feature subgraphs to obtain an initial feature graph a; input the initial feature graph into the feature description module D with initial parameters to further extract the position information of the features, to obtain the feature description graph β of the current sample image. For the feature extraction module M and the feature description module D, refer to the description in step 130, which will not be described here again.
[0122] In an embodiment, the model training module 4 performs feature compression processing on the feature description maps of the current sample images to obtain compressed feature maps, and performs feature fusion with the fusion feature maps obtained in the previous batch to obtain new fusion feature maps.
[0123] The feature description maps of the current sample images are subjected to an average operation in the batch dimension to obtain the compressed feature maps g t :
[0124] g t = Mean(β),
[0125] where t represents the iteration batch and t≥1, g t represents the compressed feature maps of the tth batch, β represents the feature description maps of the current sample images, which here refers to the feature description maps of all the current sample images, and Mean() represents an average operation in the batch dimension, i.e., an average operation on the feature description maps of all the current sample images in a batch; the compressed feature maps g t are fused with the fusion feature maps g t-1 obtained in the previous batch to obtain new fusion feature maps g
[0126]
[0127] where g represents the fusion feature maps obtained in the tth batch, and g
[0128] The acquisition of the feature description maps β and the core feature maps g can refer to step 120, which will not be described here.
[0129] In an embodiment, the model training module 4 is further configured to train the defect detection model according to a preset contrastive supervision loss function, wherein the contrastive supervision loss function is determined by calculating a distance value, such as an Euclidean distance, between the feature vector of each pixel point in the feature description map β of the normal sample image and the feature vector of all pixel points in the core feature map g; for each pixel point in the feature description map β of the normal sample image, selecting Y smallest distance values from the distance values between the feature vector of the pixel point and the feature vectors of all pixel points in the core feature map g, and arranging the Y smallest distance values in ascending order, and taking the feature vectors of the pixel points in the core feature map g corresponding to the smaller Y / 2 distance values as positive contrast feature vectors, and taking the feature vectors of the pixel points in the core feature map g corresponding to the larger Y / 2 distance values as negative contrast feature vectors; constructing a first loss function according to the feature vectors of the pixel points in the feature description map of the normal sample image and the corresponding positive contrast feature vectors, and the target of the first loss function is to reduce the distance between the feature vectors of the pixel points in the feature description map of the normal sample image and the corresponding positive contrast feature vectors; constructing a second loss function according to the feature vectors of the pixel points in the feature description map of the normal sample image and the corresponding negative contrast feature vectors, and the target of the second loss function is to increase the distance between the feature vectors of the pixel points in the feature description map of the normal sample image and the corresponding negative contrast feature vectors; and adding the first loss function and the second loss function as the contrastive supervision loss function.
[0130] The specific expressions of the first loss function, the second loss function and the contrastive supervision loss function can refer to step 130. By controlling the defect detection model to complete the training of the transfer learning through the contrastive supervision loss function, each pixel point in the feature description map of the normal sample image can be kept similar to the most similar pixel point in the core feature map, and the pixel points in the core feature map that are not similar can be pulled away, so that the model greatly improves the discrimination degree of the normal features and the defect features, thereby completing the task of defect segmentation.
[0131] According to the unsupervised defect detection method / system based on migration learning in the above embodiment, based on migration learning, core feature maps are extracted using normal sample images, and the defect detection model is guided to train, and the characteristics of the industrial images are self-adapted. In the training process, no defect image is involved, and compared with the supervised detection method, the method is more suitable for practical application in industry. In the inference stage, the feature description map of the to-be-detected image is compared with the core feature map for defect segmentation, wherein the core feature map is obtained by the defect detection model to obtain the feature description map of the normal sample image, and the feature compression and feature fusion are performed on the feature description map of the normal sample image to obtain the core feature map, so that the core feature map does not increase with the increase of the normal sample image, the feature density of the core feature map is improved, the size of the core feature map is kept constant without reducing the detection accuracy, the time for comparing the feature description map of the to-be-detected image with the core feature map in the inference stage can be reduced, thereby avoiding long inference time and high real-time performance. Since the defect detection model is trained to increase the difference between the feature description map of the normal sample image and the core feature map and to reduce the difference between the similar parts, the most similar parts in the feature description map of the normal sample image and the core feature map can be kept close, and the dissimilar parts in the core feature map can be far away, so that the model greatly improves the discrimination between normal features and defect features, thereby completing the defect segmentation task.
[0132] Those skilled in the art can understand that all or part of the functions of the various methods in the above embodiments can be realized by hardware or by a computer program. When all or part of the functions in the above embodiments are realized by a computer program, the program can be stored in a computer readable storage medium, which can include a read-only memory, a random access memory, a magnetic disk, an optical disk, a hard disk, etc. The above functions are realized by executing the program by a computer. For example, the program is stored in the memory of the device, and when the program in the memory is executed by the processor, the above functions are realized. In addition, when all or part of the functions in the above embodiments are realized by a computer program, the program can also be stored in a server, another computer, a disk, an optical disk, a flash disk or a mobile hard disk, etc. The program is saved in the memory of the local device by downloading or copying, or the system of the local device is updated, and when the program in the memory is executed by the processor, the above functions are realized.
[0133] The above application of specific examples is used to illustrate the present application, which is only used to help understand the present application, and does not limit the present application. According to the idea of the present application, those skilled in the art can make several simple deductions, deformations or substitutions.
Claims
1. A method for unsupervised defect detection based on transfer learning, characterized in that, The method comprises the following steps: obtaining a to-be-detected image of a measured object; inputting the to-be-detected image into a trained defect detection model to obtain a feature description map of the to-be-detected image; comparing the feature description map of the to-be-detected image with a core feature map of a pre-stored normal sample image, and determining a defect region of the to-be-detected image according to the difference between the two; wherein the defect detection model is trained according to the following steps: obtaining a training sample set composed of normal sample images; taking the normal sample images of the training sample set as current sample images in batches, for each batch, inputting each current sample image into the defect detection model with initial parameters to obtain a feature description map of each current sample image, performing feature compression processing on the feature description map of the current sample image to obtain a compressed feature map, and performing feature fusion with the fusion feature map obtained in the last batch to obtain a new fusion feature map, saving the fusion feature map obtained in the last batch as a core feature map of the normal sample image, wherein the compressed feature map of the first batch of normal sample images is fused with a 0-value image, and the core feature map has the same resolution as the feature description map; training the defect detection model using the training sample set to obtain final model parameters, and the training target is to increase the difference between the feature description map of the normal sample image and the core feature map, and to reduce the difference between similar parts.
2. The unsupervised defect detection method of claim 1, wherein, The defect detection model comprises a feature extraction module and a feature description module; the inputting of the to-be-detected image into the trained defect detection model to obtain the feature description map of the to-be-detected image comprises: inputting the to-be-detected image into the feature extraction module to obtain n-layer feature sub-maps of the to-be-detected image, upsampling the last n-1-layer feature sub-maps to the same resolution as the first-layer feature sub-map, then channel splicing the first-layer feature sub-map and the other feature sub-maps after upsampling to obtain an initial feature map, wherein n≥2; inputting the initial feature map into the feature description module to enhance the representation ability of the initial feature map for position information and improve the feature description ability, and obtaining the feature description map of the to-be-detected image; the inputting of the current sample image into the defect detection model with initial parameters to obtain the feature description map of the current sample image comprises: inputting the current sample image into the feature extraction module with initial parameters to obtain n-layer feature sub-maps of the current sample image, upsampling the last n-1-layer feature sub-maps to the same resolution as the first-layer feature sub-map, then channel splicing the first-layer feature sub-map and the other feature sub-maps after upsampling to obtain an initial feature map; inputting the initial feature map into the feature description module with initial parameters to enhance the representation ability of the initial feature map for position information and improve the feature description ability, and obtaining the feature description map of the current sample image.
3. The unsupervised defect detection method of claim 2, wherein, The feature extraction module is a pre-trained feature extraction network, and the network parameters of the feature extraction network remain unchanged during the training process, and / or the feature description module is a coordinate convolution network layer.
4. The unsupervised defect detection method of any one of claims 1 to 3, wherein, The defect detection model is trained according to a preset loss function, and the loss function is determined by the following method: The feature vectors of each pixel point in the feature description graph of the normal sample image are respectively calculated with the feature vectors of all pixel points in the core feature graph to obtain distance values; For each pixel point in the feature description graph of the normal sample image, the minimum Y distance values in the distance values of the feature vector of the pixel point and the feature vectors of all pixel points in the core feature graph are selected, and the distance values are arranged in ascending order, the feature vectors of the pixel points in the core feature graph corresponding to the smaller Y / 2 distance values are taken as positive contrast feature vectors, and the feature vectors of the pixel points in the core feature graph corresponding to the larger Y / 2 distance values are taken as negative contrast feature vectors, wherein Y is an even number not less than 2; A first loss function is constructed according to the feature vectors of the pixel points in the feature description graph of the normal sample image and the corresponding positive contrast feature vectors, and the target of the first loss function is to reduce the distance between the feature vectors of the pixel points in the feature description graph of the normal sample image and the corresponding positive contrast feature vectors; A second loss function is constructed according to the feature vectors of the pixel points in the feature description graph of the normal sample image and the corresponding negative contrast feature vectors, and the target of the second loss function is to increase the distance between the feature vectors of the pixel points in the feature description graph of the normal sample image and the corresponding negative contrast feature vectors; The first loss function and the second loss function are added to obtain the loss function.
5. The unsupervised defect detection method of claim 4, wherein, The loss function is specifically: L total = L1+ L2, Wherein L1 is the first loss function, L2 is the second loss function, and Z represents the pixel number of the feature description graph of the normal sample image, K=Y / 2, β z represents the feature vector of the zth pixel point of the feature description graph of the normal sample image, represents β z the kth positive contrast feature vector corresponding to, represents β z the Euclidean distance between and P=Y / 2, represents β z the pth negative contrast feature vector corresponding to, represents β z the Euclidean distance between and R and λ are adaptive parameters that need to be obtained through learning.
6. The unsupervised defect detection method of claim 1, wherein, The feature compression processing is performed on the feature description graph of the current sample image to obtain a compressed feature graph, and the compressed feature graph is fused with the fusion feature graph obtained in the previous batch to obtain a new fusion feature graph, which comprises: The feature description map of the current sample image is subjected to an average operation in the batch dimension to obtain a compressed feature map g t : g t = Mean(β), where t represents an iteration batch and t > 1, g t represents the compressed feature map of the t-th batch, β represents the feature description map of the current sample image, and Mean() represents performing an average operation in the batch dimension; The compressed feature map g is obtained according to the following formula t The new fusion feature map is obtained by performing feature fusion on the fusion feature map obtained in the previous batch wherein denotes the fusion feature map obtained in the t-th batch, and 7. The unsupervised defect detection method of claim 1, wherein, The feature description graph of the to-be-detected image is compared with the core feature graph of the normal sample image, and the defect region of the to-be-detected image is determined according to the difference between the two, which comprises: The feature vectors of each pixel point in the feature description graph of the to-be-detected image are respectively calculated with the feature vectors of all pixel points in the core feature graph to obtain distance values; For each pixel point in the feature description graph of the to-be-detected image, the minimum distance value in the distance values of the feature vector of the pixel point and the feature vectors of all pixel points in the core feature graph is selected to form a distance representation graph; The distance representation graph is processed by using a Sigmoid function to obtain a prediction score graph of the to-be-detected image, and the pixel value of the prediction score graph is used to represent the probability that the corresponding pixel point is an abnormal pixel; The prediction score graph of the to-be-detected image is up-sampled to have the same resolution as the to-be-detected image; The prediction score graph of the to-be-detected image after up-sampling is threshold segmented to obtain the defect region of the to-be-detected image.
8. The unsupervised defect detection method of claim 7, wherein, The prediction score graph of the to-be-detected image after up-sampling is threshold segmented, comprising: obtaining an average value of pixel values of a prediction score map of a normal sample image and a standard deviation σ x ; If the pixel value of the prediction score map of the up-sampled image to be detected is located in the interval , the pixel is determined as a normal pixel, otherwise as an abnormal pixel, wherein k1 is a preset coefficient.
9. A system for unsupervised defect detection based on transfer learning, characterized in that, Comprising: A to-be-detected image acquisition module is configured to acquire a to-be-detected image of a measured object. The feature description map acquisition module is configured to input the to-be-detected image into the trained defect detection model to obtain a feature description map of the to-be-detected image. The feature comparison module is configured to compare the feature description map of the to-be-detected image with a core feature map of a pre-stored normal sample image, and determine a defect region of the to-be-detected image according to a difference between the two. The model training module is configured to train the defect detection model in the following manner: obtain a training sample set composed of normal sample images; input the normal sample images of the training sample set as current sample images in batches, input each current sample image into the defect detection model with initial parameters to obtain a feature description map of each current sample image, perform feature compression processing on the feature description map of each current sample image to obtain a compressed feature map, perform feature fusion on the compressed feature map and a fusion feature map obtained in a previous batch to obtain a new fusion feature map, save the fusion feature map obtained in a last batch as a core feature map of the normal sample image, wherein the compressed feature map of the first batch of normal sample images is fused with a 0-value image, and the core feature map has the same resolution as the feature description map; train the defect detection model using the training sample set to obtain final model parameters, and the training target is to increase a difference in dissimilar places and reduce a difference in similar places between the feature description map of the normal sample image and the core feature map.
10. A computer-readable storage medium, characterized in that, The medium has a program stored thereon, and the program can be executed by a processor to implement the unsupervised defect detection method according to any one of claims 1-8.
Citation Information
Patent Citations
Two-stage mainboard image defect detecting and positioning method based on machine vision
CN114972213A
Attention-based anomaly detection method
CN115272958A