Industrial defect detection method, device, equipment and storage medium
By calculating the similarity between the image feature vector to be detected and the text feature library and image feature library in the industrial defect detection method, and weighting the process, the accurate detection of industrial defect categories is achieved, and the dependence on annotation data and the problem in the existing technology are solved. The problem of insufficient generalization ability improves detection accuracy and adaptability.
Patent Information
- Application Number
- CN202410889043.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2044-07-04
AI Technical Summary
Existing industrial defect detection methods, especially supervised learning methods, are highly dependent on annotated data and have limited generalization capabilities, and cannot adapt to unknown defect types. Unsupervised learning methods have poor detection accuracy and cannot adapt to changes in the production environment.
By obtaining the target abnormal area and its feature vector of the image to be detected, calculating the similarity with the pre-established text feature library and image feature library, and using the abnormal score weighting to achieve accurate detection of industrial defect categories and adapt to the production environment change.
It improves the accuracy of industrial defect detection, can adapt to changes in the production environment, reduces dependence on annotated data, and enhances the ability to identify unknown defect types.
Smart Images

Figure CN118429344B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer vision technology, and in particular to an industrial defect detection method, device, equipment and storage medium. Background Art
[0002] Industrial defect detection is an indispensable part of modern manufacturing. It plays a vital role in ensuring product quality, reducing production costs and improving production efficiency.
[0003] At present, the existing industrial defect detection methods mainly include supervised learning industrial defect detection methods and unsupervised learning industrial defect detection methods. Among them, the supervised learning industrial defect detection method uses a large amount of labeled data to train the deep learning model, so that the system can effectively identify various defect types that have appeared in the training set and perform accurate detection, including some complex features, such as tiny cracks or subtle color changes. By training different data sets to adapt to various production lines and product types, it plays an important role in a variety of industrial scenarios. However, the supervised learning industrial defect detection method is highly dependent on a large amount of labeled data, and the labeling cost is high, and there are limitations in generalization ability, and it cannot adapt to unknown defect types that appear randomly.
[0004] Unsupervised learning industrial defect detection methods can automatically identify distinctive abnormal patterns by learning the data distribution of normal samples, thereby realizing the detection of industrial defects. Although it can get rid of the dependence on a large amount of labeled data and reveal unknown or unexpected defect types, the detection accuracy is poor, and when the production environment changes, the model may need to be adjusted by re-analyzing the data, which often leads to delays in the implementation process and increased costs. Moreover, it is impossible to give specific defect types and cannot meet the needs of most actual industrial scenarios. Summary of the invention
[0005] The present invention provides an industrial defect detection method, device, equipment and storage medium, which can realize accurate detection of industrial defect categories, improve the accuracy of industrial defect detection, and adapt to changes in the production environment.
[0006] According to one aspect of the present invention, there is provided a method for detecting industrial defects, comprising:
[0007] Acquire an image to be detected, and acquire a target abnormal region corresponding to the image to be detected, and an abnormality score corresponding to the target abnormal region;
[0008] Acquire a feature vector corresponding to the target abnormal area, and calculate the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library;
[0009] The anomaly score is used to weight each of the image-text similarities and each of the image similarities to obtain each weighted image-text similarity and each weighted image similarity, and the industrial defect category corresponding to the image to be detected is obtained according to each of the weighted image-text similarities and each of the weighted image similarities.
[0010] According to another aspect of the present invention, there is provided an industrial defect detection device, comprising:
[0011] An abnormal region acquisition module is used to acquire an image to be detected, and acquire a target abnormal region corresponding to the image to be detected, and an abnormal score corresponding to the target abnormal region;
[0012] A similarity calculation module is used to obtain a feature vector corresponding to the target abnormal area, and calculate the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library;
[0013] The industrial defect category acquisition module is used to use the abnormality score to weight each of the image-text similarities and each of the image similarities to obtain each weighted image-text similarity and each weighted image similarity, and obtain the industrial defect category corresponding to the image to be detected based on each of the weighted image-text similarities and each of the weighted image similarities.
[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0015] at least one processor; and
[0016] a memory communicatively connected to the at least one processor; wherein,
[0017] The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can execute the industrial defect detection method described in any embodiment of the present invention.
[0018] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, wherein the computer program is used to enable a processor to implement the industrial defect detection method described in any embodiment of the present invention when executed.
[0019] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, wherein when the computer program is executed by a processor, the method for detecting industrial defects according to any one of the embodiments of the present invention is implemented.
[0020] The technical solution of the embodiment of the present invention obtains an image to be detected, and obtains a target abnormal area corresponding to the image to be detected, and an abnormality score corresponding to the target abnormal area; obtains a feature vector corresponding to the target abnormal area, and calculates the image-text similarity between the feature vector and each text feature in a text feature library, and the image similarity between the feature vector and each image feature in an image feature library; uses the abnormality score to weight each image-text similarity and each image similarity to obtain each weighted image-text similarity and each weighted image similarity, and obtains the industrial defect category corresponding to the image to be detected according to each weighted image-text similarity and each weighted image similarity; by pre-establishing a text feature library and an image feature library, and determining the industrial defect category based on the image-text similarity between the feature vector corresponding to the image to be detected and the text feature, and the image similarity between the feature vector and the image feature, accurate detection of the industrial defect category can be achieved, the accuracy of industrial defect detection can be improved, and changes in the production environment can be adapted.
[0021] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 is a flow chart of an industrial defect detection method provided according to Embodiment 1 of the present invention;
[0024] Figure 2 is a flow chart of another industrial defect detection method provided according to Embodiment 1 of the present invention;
[0025] Figure 3 is a schematic structural diagram of an industrial defect detection device provided according to Embodiment 2 of the present invention;
[0026] Figure 4 It is a schematic diagram of the structure of an electronic device for implementing the industrial defect detection method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0027] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0028] It should be noted that the terms "first", "second", "target", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] Embodiment 1
[0030] Figure 1 A flowchart of an industrial defect detection method is provided for the first embodiment of the present invention. This embodiment is applicable to the case of detecting and identifying industrial defects during the manufacture of industrial products. The method can be performed by an industrial defect detection device, which can be implemented in the form of hardware and / or software. Typically, the industrial defect detection device can be configured in an electronic device, such as a computer device or a server. Figure 1 As shown, the method includes:
[0031] S110, obtaining an image to be detected, and obtaining a target abnormal region corresponding to the image to be detected, and an abnormality score corresponding to the target abnormal region.
[0032] In this embodiment, a product image can be captured by a camera pre-deployed in an industrial scene as an image to be detected. Then, an unsupervised anomaly detection algorithm, such as the PatchCore method, can be used to identify a target abnormal region and its corresponding abnormality score (i.e., the probability of an abnormality) from the image to be detected, and the target abnormal region can be segmented from the image to be detected to obtain a target abnormal region image.
[0033] S120, obtaining a feature vector corresponding to the target abnormal area, and calculating the image-text similarity between the feature vector and each text feature in a text feature library, and the image similarity between the feature vector and each image feature in an image feature library.
[0034] It should be noted that in the actual scenario of industrial defect detection, the defect categories that need to be detected are diverse, and multiple defect categories may appear even in a single image. Some current detection models introduce text supervision through cross-attention to learn more image information. Although text supervision can help the model better understand the details in the image that are difficult to directly identify, the model trained in this way requires the joint input of the image and the corresponding text during reasoning.
[0035] In order to avoid the tedious input of the corresponding text description every time an image is input, this embodiment uses a vision-language alignment model to extract features from the target abnormal area to obtain a feature vector that can effectively describe the joint representation of vision-language under the abnormal area. Based on the format of its pre-trained samples and the setting of the loss function, the image branch of this type of model can capture rich visual concepts and corresponding semantic information to obtain a joint representation of vision-language, so no text input is required in the reasoning stage.
[0036] In this embodiment, a text feature library and an image feature library may be pre-established, wherein the text feature library may store text features and corresponding industrial defect categories in the form of key-value pairs, and the image feature library may store image features and corresponding industrial defect categories in the form of key-value pairs. After obtaining the feature vector corresponding to the image to be detected, the image-text similarity between the feature vector and each text feature (i.e., image-text similarity) and the image similarity between the feature vector and each image feature (i.e., image-image similarity) may be calculated respectively. This embodiment does not specifically limit the method for calculating feature similarity.
[0037] Among them, the image-text similarity represents the matching degree between the abnormal region features and the text features, while the image similarity represents the matching degree between the abnormal region features and the image features.
[0038] Optionally, obtaining the feature vector corresponding to the target abnormal area may include:
[0039] Inputting the target abnormal area into the image branch of the pre-trained image-text multimodal model, and obtaining a feature vector corresponding to the target abnormal area output by the image-text multimodal model;
[0040] The image-text multimodal model is established based on the contrastive language-image pretraining (CLIP) method.
[0041] In this embodiment, first, an initial image-text multimodal model can be established based on the CLIP method and the set initial model parameters. The initial image-text multimodal model can include a text branch and an image branch, which are used for text feature extraction and image feature extraction, respectively; then, the initial image-text multimodal model can be trained using image sample data and text sample data to obtain a trained image-text multimodal model.
[0042] In a specific example, the image branch of the image-text multimodal model established based on the CLIP method can be used to extract image features of the target abnormal area to obtain its corresponding feature vector.
[0043] Optionally, before calculating the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library, the following may also be included:
[0044] Obtaining descriptive prompts corresponding to each industrial defect category, and inputting each of the descriptive prompts into the text branch of the pre-trained image-text multimodal model to obtain text features corresponding to each of the industrial defect categories;
[0045] A first mapping relationship between the industrial defect category and the corresponding text feature is established, and a text feature library is generated based on the first mapping relationship.
[0046] In this embodiment, a retrieval library including a text feature library and an image feature library can be pre-established based on RAG (Retrieval-Augmented Generation) technology. The elements of the text feature library are dictionaries, the keys are all industrial defect categories in a specific industrial field, and the values are the text features obtained after the prompt (descriptive prompt) corresponding to each industrial defect category is input into the text branch of the CLIP model, such as "a defect region image of'label'".
[0047] In a specific example, when establishing a text feature library, first, define descriptive prompts for each industrial defect category, and input these prompts into the text branch of the CLIP model to extract the corresponding text features; then, store these text features in a dictionary with the category name as the key and the text feature as the value, thereby establishing a text feature library.
[0048] Optionally, before calculating the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library, the following may also be included:
[0049] Acquire multiple industrial defect images corresponding to each industrial defect category, and input each of the industrial defect images into an image branch of a pre-trained image-text multimodal model to obtain multiple initial image features corresponding to each of the industrial defect categories;
[0050] Average pooling is performed on a plurality of initial image features corresponding to each of the industrial defect categories to obtain an image feature corresponding to each of the industrial defect categories;
[0051] A second mapping relationship between the industrial defect category and the corresponding image feature is established, and an image feature library is generated based on the second mapping relationship.
[0052] In this embodiment, the elements in the image feature library are also dictionaries, the keys are all industrial defect categories in the specific industrial field, and the values are the image features corresponding to each industrial defect category. For known industrial defect categories in the model training set, some representative images can be selected from the training set; and for industrial defect categories that have not been seen in the model training set, some representative defect images can be selected from public general data.
[0053] Specifically, when constructing an image feature library, first, representative images of known industrial defect categories can be collected, and representative images of unknown industrial defect categories can be obtained from public general data; then, these images are subjected to feature extraction through the image branch of the CLIP model to obtain initial image features; further, for multiple initial image features extracted under the same industrial defect category, average pooling is used to fuse them to obtain an image feature; finally, the fused image features are stored in a dictionary, with the industrial defect category as the key and the image feature as the value.
[0054] S130, using the abnormality score to weight each of the image-text similarities and each of the image similarities to obtain each weighted image-text similarity and each weighted image similarity, and obtaining the industrial defect category corresponding to the image to be detected according to each of the weighted image-text similarities and each of the weighted image similarities.
[0055] Specifically, the anomaly score corresponding to the target abnormal area can be used as a weight value, and multiplied by each image-text similarity to obtain a weighted image-text similarity, and multiplied by each image similarity to obtain a weighted image similarity. Subsequently, the weighted image-text similarity and weighted image similarity corresponding to the same industrial defect category can be weighted summed according to the industrial defect categories corresponding to each text feature and each image feature, and the industrial defect category corresponding to the maximum sum value is used as the industrial defect category corresponding to the image to be detected; or, the weighted image-text similarity and weighted image similarity corresponding to the same industrial defect category can be averaged, and the industrial defect category corresponding to the maximum average value is used as the industrial defect category corresponding to the image to be detected.
[0056] The technical solution of the embodiment of the present invention obtains an image to be detected, and obtains a target abnormal area corresponding to the image to be detected, and an abnormality score corresponding to the target abnormal area; obtains a feature vector corresponding to the target abnormal area, and calculates the image-text similarity between the feature vector and each text feature in a text feature library, and the image similarity between the feature vector and each image feature in an image feature library; uses the abnormality score to weight each image-text similarity and each image similarity to obtain each weighted image-text similarity and each weighted image similarity, and obtains the industrial defect category corresponding to the image to be detected according to each weighted image-text similarity and each weighted image similarity; by pre-establishing a text feature library and an image feature library, and determining the industrial defect category based on the image-text similarity between the feature vector corresponding to the image to be detected and the text feature, and the image similarity between the feature vector and the image feature, accurate detection of the industrial defect category can be achieved, the accuracy of industrial defect detection can be improved, and changes in the production environment can be adapted.
[0057] In an optional implementation of this embodiment, obtaining the target abnormal region corresponding to the image to be detected and the abnormality score corresponding to the target abnormal region may include:
[0058] Inputting the image to be detected into a pre-trained abnormal region detection model, and obtaining at least one candidate abnormal region corresponding to the image to be detected output by the abnormal region detection model, and an abnormality score corresponding to each candidate abnormal region;
[0059] If it is detected that the abnormality score corresponding to the current candidate abnormal area is greater than the preset score threshold, the current candidate abnormal area is determined to be the target abnormal area;
[0060] Among them, the abnormal area detection model is established based on the patch core method.
[0061] Specifically, when performing target abnormal region detection, first, the image to be detected can be input into the trained PatchCore model, and the model will identify candidate abnormal regions in the image and assign an abnormality score to each candidate abnormal region; then, through the pre-set score threshold, the target abnormal region with an abnormality score greater than the score threshold is selected from the candidate abnormal regions, and the target abnormal region can be segmented from the image to be detected to obtain the target abnormal region image. If the abnormality scores of all candidate abnormal regions are lower than the preset score threshold, the image to be detected is determined to be normal.
[0062] It should be noted that the generation of general abnormal regions, that is, these proposed regions are not specific to any known or unknown category objects, is particularly important for industrial defect detection under open vocabulary. This embodiment uses the PatchCore model to locate the proposed regions, which has low data requirements and only requires normal (defect-free) samples in specific industrial fields to complete the model training. Moreover, model training often only requires one cycle to achieve good abnormal region detection results.
[0063] Specifically, the model training process may include: (1) data preparation, collecting and preparing normal sample images in specific industrial fields; (2) data preprocessing, preprocessing the normal sample images, such as resizing and normalization; (3) model initialization, initializing the model weights pre-trained on a general public dataset; (4) model training, inputting the preprocessed normal samples into the PatchCore model for a training cycle.
[0064] The advantage of the above setting is that it can realize the identification and location of unknown defect categories and can adapt to changes in the production environment.
[0065] In another optional implementation of this embodiment, obtaining the industrial defect category corresponding to the image to be detected according to each weighted image-text similarity and each weighted image similarity may include:
[0066] According to the industrial defect categories corresponding to the text features, the industrial defect categories corresponding to the weighted image-text similarities are obtained, and according to the industrial defect categories corresponding to the image features, the industrial defect categories corresponding to the weighted image similarities are obtained;
[0067] The sum of the weighted graphic similarity and the weighted image similarity corresponding to each of the industrial defect categories is calculated to obtain the comprehensive similarity corresponding to each of the industrial defect categories, and the industrial defect category corresponding to the maximum comprehensive similarity is used as the industrial defect category corresponding to the image to be detected.
[0068] In this embodiment, the industrial defect category corresponding to the text feature used in calculating each weighted image-text similarity can be used as the industrial defect category corresponding to the weighted image-text similarity. At the same time, the industrial defect category corresponding to the image feature used in calculating each weighted image similarity can be used as the industrial defect category corresponding to the weighted image similarity; then, the weighted image-text similarity and the weighted image similarity corresponding to the same industrial defect category can be directly added, and the sum can be used as the comprehensive similarity corresponding to the industrial defect category; finally, all comprehensive similarities can be sorted in descending order, and the industrial defect category corresponding to the maximum comprehensive similarity (Top-1) can be selected as the industrial defect category corresponding to the target abnormal area, and its corresponding comprehensive similarity can be used as the confidence score.
[0069] Optionally, after obtaining the industrial defect category corresponding to the image to be detected, the location information of the target abnormal area, the industrial defect category and the confidence score can be used as the inference result and visualized to the user.
[0070] It is worth noting that among the samples collected in actual industrial scenarios, normal samples account for the vast majority, while defective samples are relatively few. The size of the sample is proportional to time and cost, and some defect categories are difficult to collect, or only a small number of samples can be collected. In addition, new unknown class defects may be encountered after product deployment. The open vocabulary industrial defect detection method proposed in this embodiment, by using unsupervised anomaly detection algorithms, such as PatchCore, can locate and identify object categories that have been seen or unseen in existing samples, thereby better adapting to the needs of industrial defect detection in actual scenarios; secondly, by adopting a vision-language alignment model, such as CLIP, a joint representation of Vision-Language can be extracted, which allows the model to perform real-time reasoning in complex scenarios without the need for text input to assist in image feature extraction.
[0071] In a specific implementation of this embodiment, the process of detecting industrial defects can be as follows: Figure 2 First, the image to be detected is input into the pre-trained PatchCore model to identify candidate abnormal regions in the image and assign an abnormality score to each candidate abnormal region; then, it is determined whether there is a candidate abnormal region with an abnormality score greater than or equal to the preset score threshold. If so, the candidate abnormal region is used as the target abnormal region; and if the abnormality scores of all candidate abnormal regions are less than the preset score threshold, the image is determined to be normal.
[0072] Furthermore, the target abnormal region image is input into the image branch of the CLIP model, and the feature vector is extracted from it. The feature vector is respectively calculated for similarity with the text feature library and the image feature library in the retrieval library to obtain the image-text similarity and image similarity. Subsequently, for each similarity calculation result, it is multiplied by the abnormality score of the target abnormal region to obtain the weighted image-text similarity and weighted image similarity. Finally, the weighted image-text similarity and weighted image similarity corresponding to the same industrial defect category are summed to obtain the comprehensive similarity, and the comprehensive similarity is sorted, and the industrial defect category corresponding to the highest score (Top-1) is selected as the industrial defect category of the target abnormal region image, and the comprehensive similarity is used as the confidence score, and the location information, industrial defect category and confidence score of the target abnormal region are output.
[0073] Embodiment 2
[0074] Figure 3 This is a schematic diagram of the structure of an industrial defect detection device provided in Embodiment 2 of the present invention. Figure 3 As shown, the device includes: an abnormal area acquisition module 210, a similarity calculation module 220 and an industrial defect category acquisition module 230; wherein,
[0075] The abnormal region acquisition module 210 is used to acquire the image to be detected, and acquire the target abnormal region corresponding to the image to be detected, and the abnormality score corresponding to the target abnormal region;
[0076] A similarity calculation module 220 is used to obtain a feature vector corresponding to the target abnormal area, and calculate the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library;
[0077] The industrial defect category acquisition module 230 is used to use the abnormality score to weight each of the image-text similarities and each of the image similarities to obtain each weighted image-text similarity and each weighted image similarity, and obtain the industrial defect category corresponding to the image to be detected based on each of the weighted image-text similarities and each of the weighted image similarities.
[0078] The technical solution of the embodiment of the present invention obtains an image to be detected, and obtains a target abnormal area corresponding to the image to be detected, and an abnormality score corresponding to the target abnormal area; obtains a feature vector corresponding to the target abnormal area, and calculates the image-text similarity between the feature vector and each text feature in a text feature library, and the image similarity between the feature vector and each image feature in an image feature library; uses the abnormality score to weight each image-text similarity and each image similarity to obtain each weighted image-text similarity and each weighted image similarity, and obtains the industrial defect category corresponding to the image to be detected according to each weighted image-text similarity and each weighted image similarity; by pre-establishing a text feature library and an image feature library, and determining the industrial defect category based on the image-text similarity between the feature vector corresponding to the image to be detected and the text feature, and the image similarity between the feature vector and the image feature, accurate detection of the industrial defect category can be achieved, the accuracy of industrial defect detection can be improved, and changes in the production environment can be adapted.
[0079] Optionally, the abnormal region acquisition module 210 is specifically used to input the image to be detected into a pre-trained abnormal region detection model, and obtain at least one candidate abnormal region corresponding to the image to be detected output by the abnormal region detection model, and an abnormality score corresponding to each candidate abnormal region;
[0080] If it is detected that the abnormality score corresponding to the current candidate abnormal area is greater than the preset score threshold, the current candidate abnormal area is determined to be the target abnormal area;
[0081] Among them, the abnormal area detection model is established based on the patch core method.
[0082] Optionally, the industrial defect detection device also includes:
[0083] A text feature acquisition module, used to acquire descriptive prompts corresponding to each industrial defect category, and input each of the descriptive prompts into the text branch of the pre-trained image-text multimodal model to obtain text features corresponding to each of the industrial defect categories;
[0084] The text feature library generation module is used to establish a first mapping relationship between the industrial defect category and the corresponding text feature, and generate a text feature library based on the first mapping relationship.
[0085] Optionally, the industrial defect detection device also includes:
[0086] An initial image feature acquisition module is used to acquire multiple industrial defect images corresponding to each industrial defect category, and input each of the industrial defect images into an image branch of a pre-trained image-text multimodal model to obtain multiple initial image features corresponding to each of the industrial defect categories;
[0087] An image feature acquisition module, used for averaging and pooling a plurality of initial image features corresponding to each of the industrial defect categories to obtain an image feature corresponding to each of the industrial defect categories;
[0088] The image feature library generation module is used to establish a second mapping relationship between the industrial defect category and the corresponding image feature, and generate an image feature library based on the second mapping relationship.
[0089] Optionally, the similarity calculation module 220 is specifically used to input the target abnormal area into the image branch of the pre-trained image-text multimodal model, and obtain the feature vector corresponding to the target abnormal area output by the image-text multimodal model;
[0090] Wherein, the image-text multimodal model is established based on a contrastive learning language-image pre-training method.
[0091] Optionally, the industrial defect category acquisition module 230 is specifically used to acquire the industrial defect category corresponding to each weighted image-text similarity according to the industrial defect category corresponding to each text feature, and acquire the industrial defect category corresponding to each weighted image similarity according to the industrial defect category corresponding to each image feature;
[0092] The sum of the weighted graphic similarity and the weighted image similarity corresponding to each of the industrial defect categories is calculated to obtain the comprehensive similarity corresponding to each of the industrial defect categories, and the industrial defect category corresponding to the maximum comprehensive similarity is used as the industrial defect category corresponding to the image to be detected.
[0093] The industrial defect detection device provided in the embodiment of the present invention can execute the industrial defect detection method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0094] In the technical solution of the present disclosure, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals.
[0095] Embodiment 3
[0096] Figure 4A schematic diagram of the structure of an electronic device 30 that can be used to implement an embodiment of the present invention is shown. The electronic device 30 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device 30 can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0097] like Figure 4 As shown, the electronic device 30 includes at least one processor 31, and a memory connected to the at least one processor 31, such as a read-only memory (ROM) 32, a random access memory (RAM) 33, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 31 can perform various appropriate actions and processes according to the computer program stored in the read-only memory 32 or the computer program loaded from the storage unit 38 to the random access memory 33. In the RAM 33, various programs and data required for the operation of the electronic device 30 can also be stored. The processor 31, the ROM 32 and the RAM 33 are connected to each other through a bus 34. The input / output (I / O) interface 35 is also connected to the bus 34.
[0098] A number of components in the electronic device 30 are connected to the I / O interface 35, including: an input unit 36, such as a keyboard, a mouse, etc.; an output unit 37, such as various types of displays, speakers, etc.; a storage unit 38, such as a disk, an optical disk, etc.; and a communication unit 39, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 39 allows the electronic device 30 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0099] The processor 31 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 31 include, but are not limited to, a central processing unit, a graphics processing unit, various special artificial intelligence computing chips, various processors running machine learning model algorithms, digital signal processors, and any appropriate processors, controllers, microcontrollers, etc. The processor 31 executes the various methods and processes described above, such as the detection method of industrial defects.
[0100] In some embodiments, the method for detecting industrial defects may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 38. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 30 via the ROM 32 and / or the communication unit 39. When the computer program is loaded into the RAM 33 and executed by the processor 31, one or more steps of the method for detecting industrial defects described above may be performed. Alternatively, in other embodiments, the processor 31 may be configured to perform the method for detecting industrial defects in any other appropriate manner (e.g., by means of firmware).
[0101] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays, application specific integrated circuits, application specific standard products, systems on a chip, load programmable logic devices, computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0102] Computer programs for implementing the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0103] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory, a read-only memory, an erasable programmable read-only memory, an optical fiber, a portable compact disk read-only memory, an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0104] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device 30 having: a display device (e.g., a cathode ray tube or a liquid crystal display) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which the user can provide input to the electronic device 30. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0105] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local area networks, wide area networks, blockchain networks, and the Internet.
[0106] A computing system may include clients and servers. Clients and servers are generally remote from each other and typically interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other. The server may be a cloud server.
[0107] This embodiment may also include a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the industrial defect detection method provided by any embodiment of the present invention.
[0108] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0109] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for detecting industrial defects, characterized in that: include: Acquire an image to be detected, and acquire a target abnormal region corresponding to the image to be detected, and an abnormality score corresponding to the target abnormal region; Acquire a feature vector corresponding to the target abnormal area, and calculate the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library; Using the anomaly score as a weight value to weight each of the image-text similarities and each of the image similarities, to obtain each weighted image-text similarity and each weighted image similarity; According to the industrial defect categories corresponding to the text features, the industrial defect categories corresponding to the weighted image-text similarities are obtained, and according to the industrial defect categories corresponding to the image features, the industrial defect categories corresponding to the weighted image similarities are obtained; The sum of the weighted graphic similarity and the weighted image similarity corresponding to each of the industrial defect categories is calculated to obtain the comprehensive similarity corresponding to each of the industrial defect categories, and the industrial defect category corresponding to the maximum comprehensive similarity is used as the industrial defect category corresponding to the image to be detected.
2. The method according to claim 1, characterized in that Obtaining a target abnormal region corresponding to the image to be detected and an abnormality score corresponding to the target abnormal region, including: Inputting the image to be detected into a pre-trained abnormal region detection model, and obtaining at least one candidate abnormal region corresponding to the image to be detected output by the abnormal region detection model, and an abnormality score corresponding to each candidate abnormal region; If it is detected that the abnormality score corresponding to the current candidate abnormal area is greater than the preset score threshold, the current candidate abnormal area is determined to be the target abnormal area; Among them, the abnormal area detection model is established based on the patch core method.
3. The method according to claim 1, characterized in that Before calculating the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library, the method further includes: Obtaining descriptive prompts corresponding to each industrial defect category, and inputting each of the descriptive prompts into the text branch of the pre-trained image-text multimodal model to obtain text features corresponding to each of the industrial defect categories; A first mapping relationship between the industrial defect category and the corresponding text feature is established, and a text feature library is generated based on the first mapping relationship.
4. The method according to claim 1, characterized in that Before calculating the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library, the method further includes: Acquire multiple industrial defect images corresponding to each industrial defect category, and input each of the industrial defect images into an image branch of a pre-trained image-text multimodal model to obtain multiple initial image features corresponding to each of the industrial defect categories; Average pooling is performed on a plurality of initial image features corresponding to each of the industrial defect categories to obtain an image feature corresponding to each of the industrial defect categories; A second mapping relationship between the industrial defect category and the corresponding image feature is established, and an image feature library is generated based on the second mapping relationship.
5. The method according to claim 1, characterized in that Obtaining a feature vector corresponding to the target abnormal area includes: Inputting the target abnormal area into the image branch of the pre-trained image-text multimodal model, and obtaining a feature vector corresponding to the target abnormal area output by the image-text multimodal model; Wherein, the image-text multimodal model is established based on a contrastive learning language-image pre-training method.
6. An industrial defect detection device, characterized in that: include: An abnormal region acquisition module is used to acquire an image to be detected, and acquire a target abnormal region corresponding to the image to be detected, and an abnormal score corresponding to the target abnormal region; A similarity calculation module is used to obtain a feature vector corresponding to the target abnormal area, and calculate the image-text similarity between the feature vector and each text feature in the text feature library, and the image similarity between the feature vector and each image feature in the image feature library; An industrial defect category acquisition module, used to use the anomaly score as a weight value to weight each of the image-text similarities and each of the image similarities, to obtain each weighted image-text similarity and each weighted image similarity, and to obtain the industrial defect category corresponding to each of the weighted image-text similarities according to the industrial defect category corresponding to each of the text features, and to obtain the industrial defect category corresponding to each of the weighted image-text similarities according to the industrial defect category corresponding to each of the image features; The sum of the weighted graphic similarity and the weighted image similarity corresponding to each of the industrial defect categories is calculated to obtain the comprehensive similarity corresponding to each of the industrial defect categories, and the industrial defect category corresponding to the maximum comprehensive similarity is used as the industrial defect category corresponding to the image to be detected.
7. An electronic device, characterized in that: The electronic device comprises: at least one processor, and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the industrial defect detection method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is used to enable a processor to implement the industrial defect detection method according to any one of claims 1 to 5 when executed.
9. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the industrial defect detection method according to any one of claims 1 to 5.
