CN112508950B - Anomaly detection method and device - Google Patents
Anomaly detection method and device Download PDFInfo
- Publication number
- CN112508950B CN112508950B CN202110138926.7A CN202110138926A CN112508950B CN 112508950 B CN112508950 B CN 112508950B CN 202110138926 A CN202110138926 A CN 202110138926A CN 112508950 B CN112508950 B CN 112508950B
- Authority
- CN
- China
- Prior art keywords
- map
- acquiring
- segmentation
- workpiece
- score
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
- 238000001514 detection method Methods 0.000 title claims abstract description 119
- 230000011218 segmentation Effects 0.000 claims abstract description 100
- 238000010586 diagram Methods 0.000 claims abstract description 41
- 230000002159 abnormal effect Effects 0.000 claims abstract description 23
- 230000005856 abnormality Effects 0.000 claims description 26
- 238000009826 distribution Methods 0.000 claims description 21
- 238000004590 computer program Methods 0.000 claims description 8
- 238000003860 storage Methods 0.000 claims description 8
- 238000003709 image segmentation Methods 0.000 claims description 7
- 238000000034 method Methods 0.000 abstract description 12
- 239000000463 material Substances 0.000 abstract description 11
- 230000007547 defect Effects 0.000 description 9
- 230000006870 function Effects 0.000 description 4
- 238000013135 deep learning Methods 0.000 description 2
- 230000002950 deficient Effects 0.000 description 2
- 230000003287 optical effect Effects 0.000 description 2
- 238000012549 training Methods 0.000 description 2
- 230000003044 adaptive effect Effects 0.000 description 1
- 230000004075 alteration Effects 0.000 description 1
- 230000009286 beneficial effect Effects 0.000 description 1
- 238000005516 engineering process Methods 0.000 description 1
- 238000007689 inspection Methods 0.000 description 1
- 238000004519 manufacturing process Methods 0.000 description 1
- 239000011159 matrix material Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 239000013307 optical fiber Substances 0.000 description 1
- 238000012545 processing Methods 0.000 description 1
- 238000012216 screening Methods 0.000 description 1
- 238000006467 substitution reaction Methods 0.000 description 1
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/0002—Inspection of images, e.g. flaw detection
- G06T7/0004—Industrial image inspection
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/22—Matching criteria, e.g. proximity measures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/23—Clustering techniques
- G06F18/232—Non-hierarchical techniques
- G06F18/2321—Non-hierarchical techniques using statistics or function optimisation, e.g. modelling of probability density functions
- G06F18/23213—Non-hierarchical techniques using statistics or function optimisation, e.g. modelling of probability density functions with fixed number of clusters, e.g. K-means clustering
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F18/00—Pattern recognition
- G06F18/20—Analysing
- G06F18/29—Graphical models, e.g. Bayesian networks
- G06F18/295—Markov models or related models, e.g. semi-Markov models; Markov random fields; Networks embedding Markov models
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T5/00—Image enhancement or restoration
- G06T5/90—Dynamic range modification of images or parts thereof
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/11—Region-based segmentation
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/30—Subject of image; Context of image processing
- G06T2207/30108—Industrial image inspection
- G06T2207/30164—Workpiece; Machine component
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/30—Subject of image; Context of image processing
- G06T2207/30168—Image quality inspection
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Physics & Mathematics (AREA)
- Computer Vision & Pattern Recognition (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Evolutionary Biology (AREA)
- Evolutionary Computation (AREA)
- Bioinformatics & Computational Biology (AREA)
- General Engineering & Computer Science (AREA)
- Artificial Intelligence (AREA)
- Life Sciences & Earth Sciences (AREA)
- Probability & Statistics with Applications (AREA)
- Quality & Reliability (AREA)
- Image Analysis (AREA)
Abstract
The invention provides an anomaly detection method and device, wherein the method comprises the following steps: acquiring a target detection image of a workpiece to be detected and a good product image of a good product workpiece; acquiring a first characteristic diagram according to the target detection image, and acquiring a second characteristic diagram according to the good product image; cosine similarity is obtained according to the first characteristic diagram and the second characteristic diagram; performing first abnormity detection on a workpiece to be detected according to the cosine similarity; if the workpiece to be detected cannot be judged to be abnormal, acquiring a first gray scale map according to the target detection image, and acquiring a second gray scale map according to the good product image; acquiring a first segmentation drawing according to the first gray scale drawing, and acquiring a second segmentation drawing according to the second gray scale drawing; acquiring index scores according to the first segmentation chart and the second segmentation chart; and performing second abnormity detection on the workpiece to be detected according to the index score. The invention can accurately detect the abnormity of the workpiece to be detected, has wide application range and does not need to consume a large amount of manpower, material resources and time cost.
Description
Technical Field
The present invention relates to the field of target detection technologies, and in particular, to an anomaly detection method and an anomaly detection apparatus.
Background
In the field of industrial quality inspection, the abnormal detection of defects is a key link. Compared with the normal defect, the number of the abnormal defects is smaller, and the abnormal defect and the normal defect have a larger difference in morphology, such as: serious shape distortion, large-area material shortage and the like. Since the number of samples of an abnormal defect is very small, the defect cannot be learned by using a target detection model.
In the related art, the anomaly detection is generally implemented by using an open-source library operator such as OpenCV, or a GAN (generic adaptive Networks) network, or a deep learning algorithm, but the above-mentioned techniques have the following problems: (1) when the anomaly detection is realized by adopting operators of open source libraries such as OpenCV (open source computer vision library), the consumption of computing resources is large, the consumed time is long, and the application range is small; (2) when the GAN network is adopted to realize the anomaly detection, a large amount of time is consumed to train the GAN network before the anomaly detection, and different models are required to be trained aiming at different surfaces of the same workpiece, so that the time and the labor are consumed; (3) when the deep learning algorithm is adopted to realize the anomaly detection, a large amount of training data is needed, and the accuracy is low.
Disclosure of Invention
The invention provides an anomaly detection method for solving the technical problems, which can accurately detect the anomaly of a workpiece to be detected, has a wide application range, and does not need to consume a large amount of manpower, material resources and time cost.
The technical scheme adopted by the invention is as follows:
an abnormality detection method comprising the steps of: acquiring a target detection image of a workpiece to be detected and a good product image of a good product workpiece; acquiring a first characteristic diagram according to the target detection image, and acquiring a second characteristic diagram according to the good product image; obtaining cosine similarity according to the first characteristic diagram and the second characteristic diagram; performing first anomaly detection on the workpiece to be detected according to the cosine similarity; if the workpiece to be detected cannot be judged to be abnormal, acquiring a first gray scale map according to the target detection image, and acquiring a second gray scale map according to the good product image; acquiring a first segmentation chart according to the first gray-scale chart, and acquiring a second segmentation chart according to the second gray-scale chart; acquiring index scores according to the first segmentation chart and the second segmentation chart; and carrying out secondary abnormity detection on the workpiece to be detected according to the index score.
Acquiring the first characteristic diagram according to the target detection image and acquiring the second characteristic diagram according to the good product image, wherein the method comprises the following steps: inputting the target detection image into a convolution network ResNet-50 to obtain the first characteristic map, and inputting the good product image into the convolution network ResNet-50 to obtain the second characteristic map.
Obtaining the cosine similarity according to the first feature map and the second feature map, including: performing one-dimensional vectorization on the first feature map to obtain a first vector, and performing one-dimensional vectorization on the second feature map to obtain a second vector; and acquiring the cosine similarity according to the first vector and the second vector.
Acquiring the first segmentation map according to the first gray scale map, and acquiring the second segmentation map according to the second gray scale map, including: acquiring a first pixel cluster map according to the first gray scale map by adopting a K-means algorithm (K-mean algorithm), and acquiring a second pixel cluster map according to the second gray scale map; inputting the first pixel cluster map and the second pixel cluster map into an MRF (Markov Random Field) image segmentation model to respectively obtain the first segmentation map and the second segmentation map.
Acquiring the index score according to the first segmentation chart and the second segmentation chart, wherein the index score comprises the following steps: calculating the distribution difference of the pixel classes of the first segmentation map and the second segmentation map by using Wasserstein distance to obtain a first score; calculating a distribution difference of pixel categories of the first segmentation map and the second segmentation map by adopting JS (Jensen-Shannon) divergence to obtain a second score; and acquiring the index score according to the first score and the second score.
And performing second abnormity detection on the workpiece to be detected according to the index score, wherein the second abnormity detection comprises the following steps: judging whether the index score is larger than a score threshold value; if the index score is larger than a score threshold value, judging that the workpiece to be detected is abnormal; and if the index score is smaller than or equal to the score threshold value, judging that the workpiece to be detected is normal.
An abnormality detection device comprising: the first acquisition module is used for acquiring a target detection image of a workpiece to be detected and a good product image of a good product workpiece; the second acquisition module is used for acquiring a first characteristic diagram according to the target detection image and acquiring a second characteristic diagram according to the good product image; a third obtaining module, configured to obtain a cosine similarity according to the first feature map and the second feature map; the first detection module is used for carrying out first abnormality detection on the workpiece to be detected according to the cosine similarity; the fourth acquisition module is used for acquiring a first gray scale map according to the target detection image and acquiring a second gray scale map according to the good product image when the condition that whether the workpiece to be detected is abnormal cannot be judged; a fifth obtaining module, configured to obtain a first segmentation map according to the first grayscale map, and obtain a second segmentation map according to the second grayscale map; a sixth obtaining module, configured to obtain an index score according to the first segmentation map and the second segmentation map; and the second detection module is used for carrying out second abnormity detection on the workpiece to be detected according to the index score.
A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, the processor implementing the above-mentioned anomaly detection method when executing the computer program.
A non-transitory computer-readable storage medium, on which a computer program is stored, which when executed by a processor implements the above-described abnormality detection method.
The invention has the beneficial effects that:
the invention can accurately detect the abnormity of the workpiece to be detected, has wide application range and does not need to consume a large amount of manpower, material resources and time cost.
Drawings
FIG. 1 is a flow chart of an anomaly detection method according to an embodiment of the present invention;
FIG. 2 is a logic diagram of a first anomaly detection method according to one embodiment of the present invention;
FIG. 3 is a logic diagram of a second anomaly detection method according to one embodiment of the present invention;
fig. 4 is a block diagram of an abnormality detection apparatus according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a flowchart of an abnormality detection method according to an embodiment of the present invention.
As shown in fig. 1, the abnormality detection method according to the embodiment of the present invention may include the steps of:
and S1, acquiring a target detection image of the workpiece to be detected and a good-product image of a good-product workpiece.
Specifically, when the abnormality of the workpiece to be detected is detected, the first abnormality detection may be performed by using a similarity comparison method. Specifically, as shown in fig. 2, first, on the production line, a shooting device (e.g., a camera or the like) may be used to shoot a workpiece to be detected, so as to obtain a target detection image of the workpiece to be detected.
A certain good workpiece (or a certain group of good workpieces) can be selected and photographed and sampled by a photographing device to obtain a good image.
And S2, acquiring a first characteristic diagram according to the target detection image and acquiring a second characteristic diagram according to the good product image.
According to an embodiment of the present invention, acquiring a first feature map according to a target detection image and acquiring a second feature map according to a good product image includes: the target detection image is input into a convolution network ResNet-50 to obtain a first characteristic map, and the good product image is input into the convolution network ResNet-50 to obtain a second characteristic map.
Specifically, as shown in fig. 2, after the good product image and the target detection image are obtained, the good product image may be fed as input to the convolution network ResNet-50 (the ResNet-50 is derived from the pre-training result of ImageNet and has corresponding open source codes and weight parameters) to obtain the second feature map, and the target detection image may be fed as input to the convolution network ResNet-50 to obtain the first feature map. The convolution network ResNet-50 input by the target detection image and the convolution network ResNet-50 input by the non-defective image share parameters and have the same network structure.
And S3, obtaining cosine similarity according to the first characteristic diagram and the second characteristic diagram.
According to an embodiment of the present invention, obtaining cosine similarity according to a first feature map and a second feature map includes: performing one-dimensional vectorization on the first feature map to obtain a first vector, and performing one-dimensional vectorization on the second feature map to obtain a second vector; and obtaining cosine similarity according to the first vector and the second vector.
Specifically, as shown in fig. 2, after the first feature map and the second feature map are obtained, one-dimensional vectorization may be performed on the first feature map and the second feature map, that is, a two-dimensional matrix is stretched into a one-dimensional vector to obtain a first vector a and a second vector B, and a cosine similarity K is obtained according to the first vector a and the second vector B. The cosine similarity K can be generated by the following formula:
wherein,Kis cosine similarity degreeAA modulo of a first vector ABL is the modulus of the second vector B,A i for each element in the first vector a,B i is each element in the second vector B, wherein n is a positive integer larger than 1, and i is more than or equal to 1 and less than or equal to n.
And S4, performing first abnormality detection on the workpiece to be detected according to the cosine similarity.
Specifically, as shown in fig. 2, the cosine similarity is obtainedKThen, the cosine can beDegree of similarityKCompared with a first threshold T1 (which may be calibrated to the actual conditions, e.g., may be 0.7) and a second threshold T2 (which may be calibrated to the actual conditions, e.g., may be 0.95), wherein the first threshold T1 is less than the second threshold T2. If cosine similarityKIf the detected workpiece is smaller than the first threshold value T1, marking that the detected workpiece is abnormal, rejecting the detected workpiece, and detecting the next workpiece; if cosine similarityKIf the detection result is greater than the second threshold value T2, marking the workpiece to be detected as normal, and if the workpiece to be detected passes the abnormal detection, the system enters the detection of the next workpiece; if cosine similarityKAnd if the detected workpiece is between the first threshold value T1 and the second threshold value T2, the detected workpiece is marked as being incapable of judging whether the detected workpiece is abnormal or not, and the abnormal detection needs to be carried out continuously.
And S5, if the workpiece to be detected cannot be judged to be abnormal, acquiring a first gray-scale image according to the target detection image, and acquiring a second gray-scale image according to the good product image.
Specifically, as shown in fig. 2, cosine similarity is identified and confirmedKWhen the image is between the first threshold T1 and the second threshold T2, it cannot be determined whether the workpiece to be detected is abnormal, and at this time, the target detection image and the good product image may be sent to the MRF system for the second abnormality detection.
As shown in fig. 3, in the MRF system, the target detection image and the non-defective product image may be converted into grayscale images to obtain a first grayscale image and a second grayscale image, respectively.
And S6, acquiring a first segmentation map according to the first gray scale map, and acquiring a second segmentation map according to the second gray scale map.
According to an embodiment of the present invention, acquiring a first segmentation map according to a first gray scale map and acquiring a second segmentation map according to a second gray scale map includes: acquiring a first pixel cluster map according to the first gray scale map by adopting a K-means algorithm, and acquiring a second pixel cluster map according to the second gray scale map; and inputting the first pixel cluster map and the second pixel cluster map into an MRF image segmentation model to respectively obtain a first segmentation map and a second segmentation map.
Specifically, as shown in fig. 3, after the target detection image and the good product image are converted into a first gray scale map and a second gray scale map, the first gray scale map and the second gray scale map may be subjected to a K-means algorithm to obtain a first pixel cluster map and a second pixel cluster map, wherein the size of the cluster number K in the K-means algorithm may be calibrated according to the defect type.
Further, the first pixel cluster map and the second pixel cluster map may be input into the MRF image segmentation model to obtain the first segmentation map and the second segmentation map, respectively. The MRF image segmentation model can be written manually without the help of open source libraries such as OpenCV and the like, so that the loss of computing resources is effectively avoided, and the application range is wide.
And S7, acquiring index scores according to the first segmentation chart and the second segmentation chart.
According to one embodiment of the invention, acquiring the index score according to the first segmentation map and the second segmentation map comprises the following steps: calculating the distribution difference of the pixel categories of the first segmentation graph and the second segmentation graph by adopting a Wasserstein Distance (also called bulldozer Distance, Earth Mover's Distance) to obtain a first score; calculating the distribution difference of the pixel categories of the first segmentation graph and the second segmentation graph by adopting JS divergence so as to obtain a second score; and acquiring an index score according to the first score and the second score.
Specifically, as shown in fig. 3, after the first segmentation map and the second segmentation map are acquired, the distributions of the pixel classes of the first segmentation map and the second segmentation map may be counted respectively to acquire a first distribution and a second distribution. Then, the difference of the distribution of the pixel categories of the first segmentation map and the second segmentation map is calculated by respectively adopting the Wasserstein distance and the JS divergence so as to respectively obtain a first score and a second score.
When the first score is obtained by calculating the distribution difference of the pixel classes of the first segmentation map and the second segmentation map by using the Wasserstein distance (the Wasserstein distance can be defined as the cost required for converting from one distribution to another distribution), it can be assumed that the first segmentation map and the second segmentation map both have n pixel points, wherein the cost scores of the ith pixel of the second segmentation map and the first segmentation map can be obtained by the following formula:
wherein,C i is the class number of the ith pixel in the second segmentation map,D i is the class number of the ith pixel in the first segmentation map,δ i the cost scores for the second segmentation map and the first segmentation map at the ith pixel,。
thus, the first score, W, the Wasserstein distance, may be generated by the following equation:
when calculating the difference between the distribution of the pixel classes of the first segmentation map and the second segmentation map by adopting the divergence of JS to obtain the second score, the distribution of the pixel classes of the second segmentation map can be set asα(x) The pixel class distribution of the first segmentation map isβ(x) Second fraction ofJI.e., the JS divergence distribution can be generated by the following formula:
wherein,is composed ofα(x) To pairβ(x) The JS divergence of the beam is measured,is composed ofα(x) To pairThe relative entropy (KL divergence) of (c),is composed ofβ(x) To pairRelative entropy (KL divergence), wherein,
further, the first score may be dividedWAnd a second fractionJMerging to obtain the final index scoreS. Wherein the index score can be generated by the following formulaS:
Wherein,mandnand the weight parameter can be calibrated according to the actual condition.
And S8, performing second abnormity detection on the workpiece to be detected according to the index score.
According to one embodiment of the invention, the second abnormality detection of the workpiece to be detected according to the index score comprises the following steps: judging whether the index score is larger than a score threshold value; if the index score is larger than the score threshold value, judging that the workpiece to be detected is abnormal; and if the index score is less than or equal to the score threshold value, judging that the workpiece to be detected is normal.
Specifically, as shown in fig. 3, a score threshold T0 may be set for the second screening. If the index score S is larger than the score threshold value T0, marking that the workpiece to be detected is abnormal, removing the workpiece to be detected, and detecting the next workpiece; and if the index score S is less than or equal to the score threshold T0, marking that the workpiece to be detected is normal and directly entering the detection of the next workpiece. The score threshold T0 can be calibrated according to actual conditions, for example, the score threshold T0 can be between 0.8 and 0.9.
Therefore, the method can accurately detect the abnormity of the workpiece to be detected, does not need to use operators with non-commercial purposes, has wide application range, effectively avoids the loss of computing resources, simultaneously does not need to train a model, saves a large amount of manpower, material resources and time, has no requirement on defect quantity samples, and has universality.
In summary, according to the abnormality detection method of the embodiment of the invention, the target detection image of the workpiece to be detected and the good product image of the good product workpiece are obtained, and obtaining a first characteristic diagram according to the target detection image and a second characteristic diagram according to the good product image, and cosine similarity is obtained according to the first characteristic diagram and the second characteristic diagram, first abnormity detection is carried out on the workpiece to be detected according to the cosine similarity, and when the workpiece to be detected is not judged to be abnormal, obtaining a first gray-scale image according to the target detection image, obtaining a second gray-scale image according to the good product image, and obtaining a first segmentation map according to the first gray scale map and a second segmentation map according to the second gray scale map, and acquiring index scores according to the first segmentation chart and the second segmentation chart, and performing second abnormity detection on the workpiece to be detected according to the index scores. Therefore, the abnormity detection of the workpiece to be detected can be accurately carried out, the application range is wide, and a large amount of manpower, material resources and time cost are not required to be consumed.
Corresponding to the anomaly detection method of the above embodiment, the invention also provides an anomaly detection device.
As shown in fig. 4, the abnormality detection apparatus according to the embodiment of the present invention may include a first obtaining module 100, a second obtaining module 200, a third obtaining module 300, a first detecting module 400, a fourth obtaining module 500, a fifth obtaining module 600, a sixth obtaining module 700, and a second detecting module 800.
The first obtaining module 100 is configured to obtain a target detection image of a workpiece to be detected and a good product image of a good product workpiece; the second obtaining module 200 is configured to obtain a first feature map according to the target detection image, and obtain a second feature map according to the good product image; the third obtaining module 300 is configured to obtain a cosine similarity according to the first feature map and the second feature map; the first detection module 400 is configured to perform first anomaly detection on the workpiece to be detected according to the cosine similarity; the fourth obtaining module 500 is configured to obtain a first grayscale map according to the target detection image and obtain a second grayscale map according to the good product image when it is impossible to determine whether the workpiece to be detected is abnormal; the fifth obtaining module 600 is configured to obtain the first segmentation map according to the first grayscale map, and obtain the second segmentation map according to the second grayscale map; the sixth obtaining module 700 is configured to obtain an index score according to the first segmentation map and the second segmentation map; the second detection module 800 is configured to perform a second anomaly detection on the workpiece to be detected according to the index score.
According to an embodiment of the present invention, the second obtaining module 200 is specifically configured to input the target detection image into the convolution network ResNet-50 to obtain the first characteristic map, and input the good image into the convolution network ResNet-50 to obtain the second characteristic map.
According to an embodiment of the present invention, the third obtaining module 300 is specifically configured to perform one-dimensional vectorization on the first feature map to obtain a first vector, and perform one-dimensional vectorization on the second feature map to obtain a second vector; and obtaining cosine similarity according to the first vector and the second vector.
According to an embodiment of the present invention, the fifth obtaining module 600 is specifically configured to obtain a first pixel cluster map according to the first gray scale map by using a K-means algorithm, and obtain a second pixel cluster map according to the second gray scale map; and inputting the first pixel cluster map and the second pixel cluster map into an MRF image segmentation model to respectively obtain a first segmentation map and a second segmentation map.
According to an embodiment of the present invention, the sixth obtaining module 700 is specifically configured to calculate a distribution difference between pixel categories of the first segmentation map and the second segmentation map by using Wasserstein distance to obtain a first score; calculating the distribution difference of the pixel categories of the first segmentation graph and the second segmentation graph by adopting JS divergence so as to obtain a second score; and acquiring an index score according to the first score and the second score.
According to an embodiment of the present invention, the second detecting module 800 is specifically configured to: judging whether the index score is larger than a score threshold value; if the index score is larger than the score threshold value, judging that the workpiece to be detected is abnormal; and if the index score is less than or equal to the score threshold value, judging that the workpiece to be detected is normal.
It should be noted that, for a more specific implementation of the abnormality detection apparatus according to the embodiment of the present invention, reference may be made to the above-mentioned embodiment of the abnormality detection method, which is not described herein again.
According to the abnormality detection device of the embodiment of the invention, the target detection image of the workpiece to be detected and the good product image of the good product workpiece are obtained through the first obtaining module, the first characteristic diagram is obtained through the second obtaining module according to the target detection image, the second characteristic diagram is obtained according to the good product image, the cosine similarity is obtained through the third obtaining module according to the first characteristic diagram and the second characteristic diagram, the first abnormality detection is carried out on the workpiece to be detected according to the cosine similarity through the first detecting module, the first gray scale diagram is obtained according to the target detection image when the abnormality of the workpiece to be detected cannot be judged through the fourth obtaining module, the second gray scale diagram is obtained according to the good product image, the first segmentation diagram is obtained through the fifth obtaining module according to the first gray scale diagram, the second segmentation diagram is obtained according to the second gray scale diagram, and the score is obtained through the sixth obtaining module according to the first segmentation diagram and the second segmentation diagram, and performing second abnormity detection on the workpiece to be detected through a second detection module according to the index score. Therefore, the abnormity detection of the workpiece to be detected can be accurately carried out, the application range is wide, and a large amount of manpower, material resources and time cost are not required to be consumed.
The invention further provides a computer device corresponding to the embodiment.
The computer device of the embodiment of the invention comprises a memory, a processor and a computer program which is stored on the memory and can run on the processor, and when the processor executes the program, the abnormality detection method of the embodiment is realized.
According to the computer equipment provided by the embodiment of the invention, the abnormity of the workpiece to be detected can be accurately detected, the application range is wide, and a large amount of manpower, material resources and time cost are not required to be consumed.
The invention also provides a non-transitory computer readable storage medium corresponding to the above embodiment.
A non-transitory computer-readable storage medium of an embodiment of the present invention stores thereon a computer program that, when executed by a processor, implements the above-described abnormality detection method.
According to the non-transitory computer-readable storage medium provided by the embodiment of the invention, the abnormity of the workpiece to be detected can be accurately detected, the application range is wide, and a large amount of manpower, material resources and time cost are not required to be consumed.
In the description of the present invention, the terms "first" and "second" are used for descriptive purposes only and are not to be construed as indicating or implying relative importance or implying any number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of that feature. The meaning of "plurality" is two or more unless specifically limited otherwise.
In the present invention, unless otherwise expressly stated or limited, the terms "mounted," "connected," "secured," and the like are to be construed broadly and can, for example, be fixedly connected, detachably connected, or integrally formed; can be mechanically or electrically connected; either directly or indirectly through intervening media, either internally or in any other relationship. The specific meanings of the above terms in the present invention can be understood by those skilled in the art according to specific situations.
In the present invention, unless otherwise expressly stated or limited, the first feature "on" or "under" the second feature may be directly contacting the first and second features or indirectly contacting the first and second features through an intermediate. Also, a first feature "on," "over," and "above" a second feature may be directly or diagonally above the second feature, or may simply indicate that the first feature is at a higher level than the second feature. A first feature being "under," "below," and "beneath" a second feature may be directly under or obliquely under the first feature, or may simply mean that the first feature is at a lesser elevation than the second feature.
In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of the invention. In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, the particular features, structures, materials, or characteristics described may be combined in any suitable manner in any one or more embodiments or examples. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction.
Any process or method descriptions in flow charts or otherwise described herein may be understood as representing modules, segments, or portions of code which include one or more executable instructions for implementing specific logical functions or steps of the process, and alternate implementations are included within the scope of the preferred embodiment of the present invention in which functions may be executed out of order from that shown or discussed, including substantially concurrently or in reverse order, depending on the functionality involved, as would be understood by those reasonably skilled in the art of the present invention.
The logic and/or steps represented in the flowcharts or otherwise described herein, e.g., an ordered listing of executable instructions that can be considered to implement logical functions, can be embodied in any computer-readable medium for use by or in connection with an instruction execution system, apparatus, or device, such as a computer-based system, processor-containing system, or other system that can fetch the instructions from the instruction execution system, apparatus, or device and execute the instructions. For the purposes of this description, a "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transport the program for use by or in connection with the instruction execution system, apparatus, or device. More specific examples (a non-exhaustive list) of the computer-readable medium would include the following: an electrical connection (electronic device) having one or more wires, a portable computer diskette (magnetic device), a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disc read-only memory (CDROM). Additionally, the computer-readable medium could even be paper or another suitable medium upon which the program is printed, as the program can be electronically captured, via for instance optical scanning of the paper or other medium, then compiled, interpreted or otherwise processed in a suitable manner if necessary, and then stored in a computer memory.
It should be understood that portions of the present invention may be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, the various steps or methods may be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one or combination of the following techniques, which are known in the art, may be used: a discrete logic circuit having a logic gate circuit for implementing a logic function on a data signal, an application specific integrated circuit having an appropriate combinational logic gate circuit, a Programmable Gate Array (PGA), a Field Programmable Gate Array (FPGA), or the like.
It will be understood by those skilled in the art that all or part of the steps carried by the method for implementing the above embodiments may be implemented by hardware related to instructions of a program, which may be stored in a computer readable storage medium, and when the program is executed, the program includes one or a combination of the steps of the method embodiments.
In addition, functional units in the embodiments of the present invention may be integrated into one processing module, or each unit may exist alone physically, or two or more units are integrated into one module. The integrated module can be realized in a hardware mode, and can also be realized in a software functional module mode. The integrated module, if implemented in the form of a software functional module and sold or used as a stand-alone product, may also be stored in a computer readable storage medium. The storage medium mentioned above may be a read-only memory, a magnetic or optical disk, etc.
Although embodiments of the present invention have been shown and described above, it is understood that the above embodiments are exemplary and should not be construed as limiting the present invention, and that variations, modifications, substitutions and alterations can be made to the above embodiments by those of ordinary skill in the art within the scope of the present invention.
Claims (6)
1. An abnormality detection method characterized by comprising the steps of:
acquiring a target detection image of a workpiece to be detected and a good product image of a good product workpiece;
acquiring a first characteristic diagram according to the target detection image, and acquiring a second characteristic diagram according to the good product image;
obtaining cosine similarity according to the first characteristic diagram and the second characteristic diagram;
performing first anomaly detection on the workpiece to be detected according to the cosine similarity;
if the workpiece to be detected cannot be judged to be abnormal, acquiring a first gray scale map according to the target detection image, and acquiring a second gray scale map according to the good product image;
acquiring a first segmentation map according to the first gray scale map and acquiring a second segmentation map according to the second gray scale map, wherein acquiring the first segmentation map according to the first gray scale map and acquiring the second segmentation map according to the second gray scale map comprises:
acquiring a first pixel cluster map according to the first gray scale map by adopting a K-means algorithm, and acquiring a second pixel cluster map according to the second gray scale map;
inputting the first pixel cluster map and the second pixel cluster map into an MRF image segmentation model to respectively obtain the first segmentation map and the second segmentation map;
obtaining an index score according to the first segmentation map and the second segmentation map, wherein obtaining the index score according to the first segmentation map and the second segmentation map comprises:
calculating the distribution difference of the pixel classes of the first segmentation map and the second segmentation map by using Wasserstein distance to obtain a first score;
calculating the distribution difference of the pixel categories of the first segmentation graph and the second segmentation graph by adopting JS divergence so as to obtain a second score;
acquiring the index score according to the first score and the second score;
performing second anomaly detection on the workpiece to be detected according to the index score, wherein the second anomaly detection on the workpiece to be detected according to the index score comprises the following steps:
judging whether the index score is larger than a score threshold value;
if the index score is larger than a score threshold value, judging that the workpiece to be detected is abnormal;
and if the index score is smaller than or equal to the score threshold value, judging that the workpiece to be detected is normal.
2. The abnormality detection method according to claim 1, wherein acquiring the first feature map from the target detection image and acquiring the second feature map from the good product image includes:
inputting the target detection image into a convolution network ResNet-50 to obtain the first characteristic map, and inputting the good product image into the convolution network ResNet-50 to obtain the second characteristic map.
3. The abnormality detection method according to claim 1 or 2, wherein obtaining the cosine similarity from the first feature map and the second feature map includes:
performing one-dimensional vectorization on the first feature map to obtain a first vector, and performing one-dimensional vectorization on the second feature map to obtain a second vector;
and acquiring the cosine similarity according to the first vector and the second vector.
4. An abnormality detection device characterized by comprising:
the first acquisition module is used for acquiring a target detection image of a workpiece to be detected and a good product image of a good product workpiece;
the second acquisition module is used for acquiring a first characteristic diagram according to the target detection image and acquiring a second characteristic diagram according to the good product image;
a third obtaining module, configured to obtain a cosine similarity according to the first feature map and the second feature map;
the first detection module is used for carrying out first abnormality detection on the workpiece to be detected according to the cosine similarity;
the fourth acquisition module is used for acquiring a first gray scale map according to the target detection image and acquiring a second gray scale map according to the good product image when the condition that whether the workpiece to be detected is abnormal cannot be judged;
a fifth obtaining module, configured to obtain a first segmentation map according to the first grayscale map, and obtain a second segmentation map according to the second grayscale map, where the fifth obtaining module is specifically configured to obtain a first pixel cluster map according to the first grayscale map by using a K-means algorithm, and obtain a second pixel cluster map according to the second grayscale map; inputting the first pixel cluster map and the second pixel cluster map into an MRF image segmentation model to respectively obtain a first segmentation map and a second segmentation map;
a sixth obtaining module, configured to obtain an index score according to the first segmentation map and the second segmentation map, where the sixth obtaining module is specifically configured to calculate a distribution difference between pixel categories of the first segmentation map and the second segmentation map by using a Wasserstein distance, so as to obtain a first score; calculating the distribution difference of the pixel categories of the first segmentation graph and the second segmentation graph by adopting JS divergence so as to obtain a second score; acquiring an index score according to the first score and the second score;
the second detection module is used for carrying out second abnormity detection on the workpiece to be detected according to the index score, wherein the second detection module is specifically used for judging whether the index score is larger than a score threshold value; if the index score is larger than a score threshold value, judging that the workpiece to be detected is abnormal; and if the index score is smaller than or equal to the score threshold value, judging that the workpiece to be detected is normal.
5. A computer device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the processor implements the anomaly detection method according to any one of claims 1-3 when executing the computer program.
6. A non-transitory computer-readable storage medium having stored thereon a computer program, characterized in that the program, when executed by a processor, implements the anomaly detection method according to any one of claims 1-3.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110138926.7A CN112508950B (en) | 2021-02-02 | 2021-02-02 | Anomaly detection method and device |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202110138926.7A CN112508950B (en) | 2021-02-02 | 2021-02-02 | Anomaly detection method and device |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112508950A CN112508950A (en) | 2021-03-16 |
CN112508950B true CN112508950B (en) | 2021-05-11 |
Family
ID=74952643
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202110138926.7A Active CN112508950B (en) | 2021-02-02 | 2021-02-02 | Anomaly detection method and device |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112508950B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113435485A (en) * | 2021-06-15 | 2021-09-24 | 北京百度网讯科技有限公司 | Picture detection method and device, electronic equipment and storage medium |
CN113554645B (en) * | 2021-09-17 | 2022-01-11 | 常州微亿智造科技有限公司 | Industrial anomaly detection method and device based on WGAN |
CN115274093B (en) * | 2022-07-26 | 2023-06-23 | 华东师范大学 | Method and system for generating reference pathology data set containing automatic labeling file |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101666616A (en) * | 2008-09-01 | 2010-03-10 | 比亚迪股份有限公司 | Appearance detecting method |
CN111951237A (en) * | 2020-08-04 | 2020-11-17 | 上海微亿智造科技有限公司 | Visual appearance detection method |
-
2021
- 2021-02-02 CN CN202110138926.7A patent/CN112508950B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101666616A (en) * | 2008-09-01 | 2010-03-10 | 比亚迪股份有限公司 | Appearance detecting method |
CN111951237A (en) * | 2020-08-04 | 2020-11-17 | 上海微亿智造科技有限公司 | Visual appearance detection method |
Non-Patent Citations (1)
Title |
---|
Evaluation of modified adaptive k-means segmentation algorithm;Taye Girma Debelee 等;《Computational Visual Media》;20191215;第5卷(第4期);第347-361页 * |
Also Published As
Publication number | Publication date |
---|---|
CN112508950A (en) | 2021-03-16 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN112508950B (en) | Anomaly detection method and device | |
CN107507173B (en) | No-reference definition evaluation method and system for full-slice image | |
CN109870461B (en) | Electronic components quality detection system | |
CN109871895B (en) | Method and device for detecting defects of circuit board | |
CN110036279B (en) | Inspection apparatus and inspection method | |
US11715190B2 (en) | Inspection system, image discrimination system, discrimination system, discriminator generation system, and learning data generation device | |
CN109671078B (en) | Method and device for detecting product surface image abnormity | |
CN106920219A (en) | Article defect detection method, image processing system and computer readable recording medium | |
KR100598381B1 (en) | in-line typed apparatus for auto wafer-defect classification and control method thereof | |
Liu et al. | A multi-metric fusion approach to visual quality assessment | |
Liu et al. | AI-facilitated coating corrosion assessment system for productivity enhancement | |
CN113554645B (en) | Industrial anomaly detection method and device based on WGAN | |
CN113012157A (en) | Visual detection method and system for equipment defects | |
CN113066088A (en) | Detection method, detection device and storage medium in industrial detection | |
CN116778520B (en) | Mass license data quality inspection method | |
CN113139963A (en) | Defect detection method and device | |
CN115861315B (en) | Defect detection method and device | |
CN116721096A (en) | New energy harness quality online detection method based on artificial intelligence | |
CN114998346B (en) | Waterproof cloth quality data processing and identifying method | |
CN113256607B (en) | Defect detection method and device | |
CN116109543A (en) | Method and device for quickly identifying and reading data and computer readable storage medium | |
CN113326749A (en) | Target detection method and device, storage medium and electronic equipment | |
US20200167908A1 (en) | Determination device and determining method thereof | |
CN112700446A (en) | Algorithm model training method and device for industrial quality inspection | |
CN112767400B (en) | Defect detection method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |