Uniform material workpiece anomaly detection method, system, equipment and medium
By extracting visual features from workpiece images using a pre-trained image coding model and combining global and local anomaly scores, efficient anomaly detection of uniformly made workpieces without the need for labeled samples is achieved. This solves the problem of high data acquisition and labeling costs in existing technologies and improves the efficiency and adaptability of detection.
Patent Information
- Application Number
- CN202511556406.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-29
- Publication Date
- 2026-01-13
AI Technical Summary
Existing technologies for automated anomaly detection of workpieces with uniform materials suffer from problems such as difficulty in data acquisition, high annotation costs, and poor model adaptability. In particular, when the product model or material changes, re-annotation and retraining are required, leading to a waste of costs and resources.
A pre-trained image coding model is used to extract visual feature vectors from workpiece images. By weighted fusion of global difference scores and local anomaly scores, combined with median and absolute deviation calculations, efficient anomaly detection without labeled samples is achieved.
It reduces the cost of data preparation and labeling, improves the efficiency and adaptability of detection, and can accurately identify workpiece anomalies under zero-sample conditions, reducing misjudgments and missed detections.
Smart Images

Figure CN121329949A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of industrial anomaly detection, specifically to a method, system, equipment, and medium for detecting anomalies in workpieces of uniform material. Background Technology
[0002] In the industrial manufacturing sector, homogeneous material workpieces refer to industrial products with a consistent surface material and no significant texture or pattern structure, such as glass panels, ceramic blanks, polished metal surfaces, plastic shells, and monitor screens. Because of their uniform surface, minute defects are difficult for the human eye to detect directly. However, in actual production, factors such as raw materials, processes, and the environment can still lead to various types of abnormalities, including scratches, dents, dirt, bubbles, and impurities. These defects not only directly affect the product's appearance and quality but can also impair its mechanical properties, safety, and lifespan. Therefore, efficient and accurate quality inspection before shipment is crucial.
[0003] Currently, supervised deep learning algorithms are widely used for automated anomaly detection of such workpieces. These include classification models based on convolutional neural networks, object detection networks like YOLO, and image segmentation models like U-Net. These methods typically rely on a large number of labeled samples for model training, requiring the collection of positive and negative samples covering various defect types, accurately labeled by professionals, to learn feature representations of normal and abnormal regions. However, existing methods are costly to implement: firstly, defect samples occur infrequently and are of variable types in actual production, making it very difficult to collect a sufficient number and diversity of defect samples; secondly, the labeling process requires the participation of professional quality inspectors, which is time-consuming and labor-intensive, and the labeling quality directly affects model performance. Furthermore, when product models, materials, or defect patterns change, the model needs to be re-labeled and retrained, further increasing the costs of manpower, time, and computing resources. Summary of the Invention
[0004] To address the aforementioned problems, this invention provides a method, system, equipment, and medium for detecting anomalies in workpieces made of uniform material.
[0005] The first aspect of this invention discloses a method for detecting anomalies in a workpiece made of uniform material, comprising: Obtain the workpiece image of the target workpiece; The workpiece image is divided into multiple sub-images; Visual feature vectors for each sub-image are extracted using a pre-trained image coding model; Anomaly score is calculated for each sub-image based on the visual feature vector, and the anomaly score includes a global difference score and a local anomaly score. Based on the anomaly scores of all subgraphs, determine whether the target workpiece is abnormal.
[0006] Furthermore, the step of calculating the anomaly score for each sub-image based on the visual feature vector includes: The degree of difference between the visual feature vector of each sub-image and the visual feature vector of other sub-images is calculated to obtain the global difference score; Based on the similarity between subgraphs, similar subgraphs corresponding to each subgraph are selected from all subgraphs according to a preset number of nearest neighbors; Based on the similarity, the difference between each sub-image and its corresponding similar sub-image is calculated to obtain the local anomaly score corresponding to the sub-image; The global difference score and the local anomaly score are weighted and summed to obtain the anomaly score for each subgraph.
[0007] Furthermore, the step of calculating the degree of difference between the visual feature vector of each sub-image and the visual feature vector of other sub-images to obtain the global difference score includes: Calculate the Euclidean distance between the visual feature vector of the subgraph and the visual feature vectors of the corresponding other subgraphs; Based on the Euclidean distance, and according to a preset adjacent ratio, the set of adjacent subgraphs corresponding to the subgraph is obtained by filtering from other subgraphs; The global difference score is calculated using the following formula. : ; in, This indicates the number of subgraphs in the set of adjacent subgraphs corresponding to the given subgraph. This indicates that the subgraph and the set of adjacent subgraphs are in the [missing information]. The Euclidean distance between adjacent subgraphs.
[0008] Furthermore, the step of selecting similar subgraphs for each subgraph from all subgraphs based on the similarity between subgraphs and according to a preset number of nearest neighbors includes: The similarity between the subgraph and other subgraphs is calculated based on the vector dot product; For each number of nearest neighbors corresponding to each subgraph, select the subgraph with the highest similarity from all subgraphs. A number of similar subgraphs are used as the similar subgraphs corresponding to the number of nearest neighbors of the subgraph, wherein... The number of nearest neighbors.
[0009] Furthermore, the step of calculating the difference between each sub-image and its corresponding similar sub-image based on the similarity, and obtaining the local anomaly score corresponding to the sub-image, includes: The local anomaly score is calculated using the following formula: ; in, This represents the number of nearest neighbors corresponding to the subgraph. This represents the set of the nearest neighbors corresponding to the subgraph. This represents the number of nearest neighbors corresponding to the subgraph. Represents the subgraph and its corresponding first... The similarity of similar subgraphs.
[0010] Furthermore, the step of determining whether the target workpiece is abnormal based on the anomaly scores of all subgraphs includes: Calculate the median of the outlier scores for all subgraphs to obtain the first median; Calculate the absolute deviation of the outlier score for each subplot from the first median; Calculate the median of all absolute deviations to obtain the second median; The robust outlier score for each subgraph is calculated based on the absolute deviation and the second median; Determine whether the robust anomaly scores of all subgraphs are less than a preset anomaly score threshold: If so, the target workpiece is determined to be normal; Otherwise, the target workpiece is determined to be abnormal.
[0011] Furthermore, the step of calculating the robust outlier score for each subgraph based on the absolute deviation and the second median includes: The scaling deviation is obtained by multiplying the absolute deviation corresponding to each subgraph by a preset adjustment coefficient. The ratio of the scaling deviation to the second median is calculated to obtain the robust anomaly score of the subgraph.
[0012] A second aspect of this invention discloses an anomaly detection system for a workpiece made of uniform material, comprising: The acquisition module is used to acquire the workpiece image of the target workpiece; A segmentation module is used to divide the workpiece image into multiple sub-images; The extraction module is used to extract the visual feature vector of each sub-image using a pre-trained image coding model; The calculation module is used to calculate the anomaly score for each sub-image based on the visual feature vector, wherein the anomaly score includes a global difference score and a local anomaly score; The judgment module is used to determine whether the target workpiece is abnormal based on the abnormality scores of all sub-graphs.
[0013] A third aspect of the present invention discloses an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that the processor, when executing the computer program, implements the steps of any of the uniform material workpiece anomaly detection methods disclosed in the first aspect of the present invention.
[0014] The fourth aspect of the present invention discloses a storage medium storing a computer program, characterized in that, when the computer program is executed by a processor, it implements the steps of any of the anomaly detection methods for uniform material workpieces disclosed in the first aspect of the present invention.
[0015] This invention extracts sub-graph features by employing a pre-trained image coding model and integrates global difference and local anomaly evaluation mechanisms, achieving efficient anomaly detection without any labeled samples or retraining. This significantly reduces the high costs incurred by traditional supervised methods in data preparation, labeling, and model iteration. Attached Figure Description
[0016] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0017] Figure 1 This is a schematic flowchart of an anomaly detection method for a workpiece made of uniform material disclosed in an embodiment of the present invention; Figure 2 This is a schematic diagram of the structure of a workpiece anomaly detection system of uniform material disclosed in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of the electronic device disclosed in the embodiments of the present invention. Detailed Implementation
[0018] To enable those skilled in the art to better understand the present invention, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0019] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this invention are used to distinguish different objects, not to describe a specific order. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion. For example, a process, method, apparatus, or product comprising a series of steps or units is not limited to the listed steps or units, but may optionally include steps or units not listed, or may optionally include other steps or units inherent to these processes, methods, apparatus, or products.
[0020] In this document, the term "embodiment" means that a particular feature, structure, or characteristic described in connection with an embodiment may be included in at least one embodiment of the invention. The appearance of this phrase in various places throughout the specification does not necessarily refer to the same embodiment, nor is it a separate or alternative embodiment mutually exclusive with other embodiments. It will be explicitly and implicitly understood by those skilled in the art that the embodiments described herein can be combined with other embodiments.
[0021] Please see Figure 1 As shown, Figure 1 This is a schematic flowchart of a method for detecting anomalies in a workpiece made of uniform material, as disclosed in an embodiment of the present invention. Figure 1 As shown, the anomaly detection method for uniformly made workpieces may include the following operations: S101. Obtain the workpiece image of the target workpiece; In this optional embodiment, the workpiece image refers to visual data obtained by photographing the surface of the target workpiece, used for analyzing and inspecting the quality of the target workpiece. In industrial manufacturing, workpiece images need to meet requirements such as high clarity, strong contrast, and uniform illumination to ensure effective capture of subtle surface defects or anomalies. Simultaneously, the workpiece image should have sufficient resolution for subsequent image processing and feature extraction. In this embodiment of the invention, workpiece images can be acquired using a high-resolution camera, industrial camera, or laser scanning equipment, combined with appropriate lighting conditions, such as ring lights or uniform illumination, to ensure that the captured images accurately reflect the surface features of the workpiece.
[0022] S102. Divide the workpiece image into multiple sub-images; In this optional embodiment, the workpiece image can be divided according to a predetermined grid or scale, such as dividing the workpiece image into several equal rectangular areas to ensure that each sub-image evenly covers the surface of the workpiece.
[0023] In an optional embodiment, the dividing line of the segmented image is more than a preset boundary distance threshold from the edge of the workpiece image.
[0024] S103. Use a pre-trained image coding model to extract the visual feature vector of each sub-image; In this optional embodiment, the image encoding model can be a Contrastive Language–Image Pre-training (CLIP), a Self-Distillation with No Labels (DINOv2), a Convolutional Neural Networks for the 2020s (ConvNeXt), etc., and this embodiment of the invention is not limited thereto. CLIP aligns image and text features through contrastive learning, is trained on ultra-large-scale image-text pairs, and can extract high-quality visual semantic features without domain-specific annotations. It has extremely strong generalization ability, can be directly transferred to industrial scenarios, and is sensitive to texture and structural changes in uniformly made workpieces, making it suitable as a backbone network for zero-shot anomaly detection. DINOv2 is based on a self-supervised learning framework and learns general representations from unlabeled images through a teacher-student model distillation mechanism. It excels at capturing local details and global context, exhibits strong robustness to lighting changes and minor defects, and is particularly suitable for feature extraction of uniformly material workpieces in industrial settings where labeled data is lacking. ConvNeXt upgrades traditional convolutional structures to near-Transformer performance, optimizing feature extraction efficiency through layered design (such as depthwise separable convolution and large kernel convolution). It consumes fewer computational resources than Transformer-like models, has low deployment costs, and can achieve real-time detection on edge devices, making it suitable for power-sensitive industrial production line environments. This embodiment of the invention uses a pre-trained CLIP model as the image encoding model.
[0025] S104. Calculate the anomaly score for each sub-image based on the visual feature vector, wherein the anomaly score includes a global difference score and a local anomaly score; In this optional embodiment, the global difference score represents the average degree of difference between the visual feature vector of a subgraph and the visual feature vectors of other subgraph groups; the local anomaly score represents the inconsistency between a subgraph and its most similar subgraph.
[0026] In an optional embodiment, the step of calculating the anomaly score for each sub-image based on the visual feature vector includes: The degree of difference between the visual feature vector of each sub-image and the visual feature vector of other sub-images is calculated to obtain the global difference score; Based on the similarity between subgraphs, similar subgraphs corresponding to each subgraph are selected from all subgraphs according to a preset number of nearest neighbors; Based on the similarity, the difference between each sub-image and its corresponding similar sub-image is calculated to obtain the local anomaly score corresponding to the sub-image; The global difference score and the local anomaly score are weighted and summed to obtain the anomaly score for each subgraph.
[0027] In this optional embodiment, the visual feature vector is a set of values obtained by extracting features from each sub-image through an image coding model. It describes the key features of the sub-image in mathematical form, such as color, texture, shape, and edges, and can effectively capture and express the visual information of the image.
[0028] Weighted summation refers to the process of multiplying multiple values by their corresponding weights and then summing the results. Weights can be used to emphasize the importance or influence of certain values. In this embodiment, the anomaly score is calculated according to the following formula. : ; in, These are the preset weight parameters.
[0029] As can be seen, this optional embodiment, by separately calculating and weighting the global difference score and the local anomaly score, can comprehensively evaluate the degree of anomaly in a sub-image at different scales. The global difference score reflects the degree of deviation of the sub-image from the overall image features, which helps to capture obvious anomalies; the local anomaly score assesses local consistency through similar nearest neighbor relationships, and is more sensitive to subtle anomalies. Combining the two can adaptively balance the influence of global and local features without relying on prior knowledge, improve the overall performance and generalization ability of anomaly recognition, and reduce the probability of misjudgment or missed detection caused by a single indicator.
[0030] In an optional embodiment, the step of calculating the degree of difference between the visual feature vector of each sub-graph and the visual feature vector of other sub-graphs to obtain the global difference score includes: Calculate the Euclidean distance between the visual feature vector of the subgraph and the visual feature vectors of the corresponding other subgraphs; Based on the Euclidean distance, and according to a preset adjacent ratio, the set of adjacent subgraphs corresponding to the subgraph is obtained by filtering from other subgraphs; The global difference score is calculated using the following formula. : ; in, This indicates the number of subgraphs in the set of adjacent subgraphs corresponding to the given subgraph. This indicates that the subgraph and the set of adjacent subgraphs are in the [missing information]. The Euclidean distance between adjacent subgraphs.
[0031] In this optional embodiment, Euclidean distance is the most fundamental and intuitive geometric metric in multidimensional space, characterizing the linear distance between two points in a Cartesian coordinate system. Its core idea is to naturally extend the Pythagorean theorem from plane geometry to high-dimensional data space, quantifying the strength of the difference by taking the square root of the sum of the squares of the coordinate differences in each dimension. In image analysis, it maps complex high-dimensional feature vectors into comparable scalar difference values, enabling algorithms to accurately perceive minute shifts in the feature space. In this embodiment, a sharp jump in the Euclidean distance value may reveal data points that deviate from the main distribution.
[0032] As can be seen, this optional embodiment quantifies feature differences using Euclidean distance and calculates the average distance as the global difference score by selecting a representative set of neighboring subgraphs based on the adjacent ratio, which can effectively reduce the interference of outliers on the overall estimation. This optional embodiment focuses on characterizing the relative distribution relationship of subgraphs in the feature space, making the scores of normal regions tend to be stable, while outlier regions show significant distance deviations, thereby enhancing the ability to distinguish outlier regions and improving the robustness and interpretability of the global evaluation.
[0033] In an optional embodiment, the step of selecting similar subgraphs for each subgraph from all subgraphs based on the similarity between subgraphs and according to a preset number of nearest neighbors includes: The similarity between the subgraph and other subgraphs is calculated based on the vector dot product; For each number of nearest neighbors corresponding to each subgraph, select the subgraph with the highest similarity from all subgraphs. A number of similar subgraphs are used as the similar subgraphs corresponding to the number of nearest neighbors of the subgraph, wherein... The number of nearest neighbors.
[0034] In this optional embodiment, the vector dot product is used to quantify the synergy between two visual feature vectors in terms of direction and intensity. It is calculated by multiplying the corresponding dimensions of the two visual feature vectors one by one and then summing the results. Geometrically, this can be understood as the product of the projected length of one vector in the direction of the other vector and the magnitude of the target vector. This operation reveals the angular relationship between the vectors: the dot product reaches its maximum positive value when the two vectors are in the same direction, its maximum negative value when they are in opposite directions, and zero when they are perpendicular.
[0035] In workpiece anomaly detection scenarios, the visual feature vectors encoded by the pre-trained model of the subgraphs essentially map visual information into directional semantic expressions in a high-dimensional space. In this case, the magnitude of the vector inner product directly reflects the "semantic angle" between the visual feature vectors of the two subgraphs: If two sub-images have highly similar textures and structures (e.g., both are normal uniform regions), their visual feature vectors tend to be in the same direction, and their inner product values are significantly larger. If a subgraph has defects (such as scratches or stains), its visual feature vector will deviate from the distribution direction of a normal subgraph, causing the inner product value to drop sharply. In extreme cases (such as when the defect differs greatly from the normal area), the vectors are nearly orthogonal and the inner product approaches zero.
[0036] As can be seen, this optional embodiment calculates similarity based on the inner product of vectors and selects the most similar subgraphs for each number of nearest neighbors. It can accurately construct the local context of each subgraph, fully consider the directional consistency between feature vectors, and is sensitive to changes in the local structure of the image. It helps to identify abnormal patterns that are not obvious in the global features but have subtle inconsistencies with the neighboring regions, providing a reliable basis for subsequent calculation of local anomaly scores.
[0037] In an optional embodiment, the step of calculating the difference between each sub-graph and its corresponding similar sub-graph to obtain the local anomaly score corresponding to the sub-graph based on the similarity includes: The local anomaly score is calculated using the following formula: ; in, This represents the number of nearest neighbors corresponding to the subgraph. This represents the set of the nearest neighbors corresponding to the subgraph. This represents the number of nearest neighbors corresponding to the subgraph. Represents the subgraph and its corresponding first... The similarity of similar subgraphs.
[0038] In this optional embodiment, introducing multiple sets of neighbor numbers at different scales to calculate local anomaly scores can construct a multi-granularity sensing mechanism. A single neighbor number can only capture local consistency within a specific range, but its sensitivity to defects of different sizes varies significantly: a smaller neighbor number is sensitive to tiny point-like anomalies but is easily affected by noise, while a larger neighbor number is stable for regional anomalies but may smooth out subtle defects. By setting a set of incrementally increasing neighbor numbers, the similarity between the subgraph and its neighbors can be evaluated simultaneously at three scales: micro, meso, and macro. The micro scale focuses on extremely local consistency to capture subtle anomalies, the macro scale evaluates regional consistency to identify larger defects, and finally, averaging the results at multiple scales can effectively suppress the risk of misjudgment at a single scale. In this embodiment of the invention, The value is 3. .
[0039] As can be seen, this optional embodiment aggregates the inverse mean of similarity under multiple different numbers of nearest neighbors as the local anomaly score. It takes into account the strong correlation of nearest neighbors and introduces the background constraint of slightly more distant neighbors, which enhances the robustness of the evaluation to noise. Anomaly regions obtain higher anomaly values because their similarity with the surrounding areas is generally low, while normal regions have lower scores because their similarity with neighboring subgraphs is high. This effectively captures local inconsistency features and improves the detection sensitivity of subtle anomalies and gradual defects.
[0040] S105. Determine whether the target workpiece is abnormal based on the abnormality scores of all sub-graphs.
[0041] In an optional embodiment, the step of determining whether the target workpiece is abnormal based on the anomaly scores of all subgraphs includes: Calculate the median of the outlier scores for all subgraphs to obtain the first median; Calculate the absolute deviation of the outlier score for each subplot from the first median; Calculate the median of all absolute deviations to obtain the second median; The robust outlier score for each subgraph is calculated based on the absolute deviation and the second median; Determine whether the robust anomaly scores of all subgraphs are less than a preset anomaly score threshold: If so, the target workpiece is determined to be normal; Otherwise, the target workpiece is determined to be abnormal.
[0042] In anomaly detection scenarios, a few anomalous subgraphs may generate extremely high anomalous scores. These extreme values significantly inflate the overall score average, distorting the estimation of "normal" levels and leading to an overestimation of the judgment threshold, potentially resulting in missed anomalies. The median, as the middle value of the dataset, depends only on the order of values rather than their specific magnitude. It is less affected by extreme anomalous scores than the mean and can stably represent the typical score level of the vast majority of normal subgraphs. This provides a reliable and uncontaminated benchmark for subsequent calculations of absolute bias and robust anomalous scores. This characteristic ensures the stability of the anomaly judgment logic, enabling it to accurately distinguish normal backgrounds from real defects even with zero-sample conditions and without prior knowledge.
[0043] Absolute deviation reflects the dispersion of data by calculating the absolute difference between the outlier score and the first median for each subplot. Specifically, absolute deviation can be used to assess the position of a particular outlier score within the overall dataset; a larger deviation value indicates a greater gap between the outlier score and the first median, which may suggest the outlier score of that subplot is an anomaly or peculiarity in the data distribution.
[0044] In this optional embodiment, the anomaly score threshold can be set by combining statistical distribution characteristics with domain prior knowledge: based on a large sample of normal workpieces, the distribution range of their robust anomaly scores is calculated, and the initial threshold benchmark is determined by statistical quantiles; subsequently, the tolerance for false positives and false negatives is fine-tuned according to the specific application scenario. If strict control of false alarms is required, the threshold is appropriately increased; if zero defects are to be ensured, the threshold is appropriately decreased. In this embodiment of the invention, the anomaly score threshold is set to 3.5.
[0045] As can be seen, this optional embodiment effectively suppresses the impact of outliers or skewed distributions that may exist in the outlier scores themselves on the final judgment by using robust statistics such as the median and median absolute deviation to perform secondary processing on the outlier scores of the subgraph. The robust outlier scores based on statistical deviation weaken the interference of extreme values, making the outlier determination process more adaptable to the uncertainty of score distribution in practical applications, and improving the stability and reliability of the overall method in complex scenarios.
[0046] In an optional embodiment, the step of calculating the robust outlier score for each subplot based on the absolute deviation and the second median includes: The scaling deviation is obtained by multiplying the absolute deviation corresponding to each subgraph by a preset adjustment coefficient. The ratio of the scaling deviation to the second median is calculated to obtain the robust anomaly score of the subgraph.
[0047] In this optional embodiment, the adjustment coefficient is preset to... .
[0048] As can be seen, this optional embodiment scales the absolute deviation by introducing an adjustment coefficient and then compares it with the second median, resulting in a standardized distribution scale for the final robust outlier score, making it easy to uniformly set the threshold. This calculation method draws on the idea of outlier detection in robust statistics, amplifying the deviation signal in the outlier region while maintaining the stability of the score in the normal region. This enables efficient and adaptive outlier decision-making without human intervention, improving the overall accuracy of the system.
[0049] Please see Figure 2 As shown, Figure 2 This is a schematic diagram of the structure of a uniform material workpiece anomaly detection system disclosed in an embodiment of the present invention, comprising: The acquisition module 201 is used to acquire the workpiece image of the target workpiece; The segmentation module 202 is used to divide the workpiece image into multiple sub-images; Extraction module 203 is used to extract the visual feature vector of each sub-image using a pre-trained image coding model; Calculation module 204 is used to calculate the anomaly score of each sub-image based on the visual feature vector, wherein the anomaly score includes a global difference score and a local anomaly score; The judgment module 205 is used to determine whether the target workpiece is abnormal based on the abnormality scores of all sub-graphs.
[0050] Specific limitations regarding the anomaly detection system for homogeneous material workpieces can be found in the limitations of the anomaly detection method for homogeneous material workpieces described above, and will not be repeated here. Each module in the aforementioned anomaly detection system for homogeneous material workpieces can be implemented entirely or partially through software, hardware, or a combination thereof. These modules can be embedded in the processor of the electronic device in hardware format or independent of it, or stored in the memory of the electronic device in software format, so that the processor can call the corresponding operations of each module.
[0051] It should be noted that, in order to highlight the innovative aspects of this invention, this embodiment does not include modules that are not closely related to solving the technical problems proposed by this invention, but this does not mean that there are no other modules in this embodiment.
[0052] like Figure 3 As shown, the electronic device 1 provided by the present invention may include a memory 12, a processor 13 and a bus, and may also include a computer program stored in the memory 12 and executable on the processor 13, such as a uniform material workpiece anomaly detection program.
[0053] The memory 12 includes at least one type of readable storage medium, such as flash memory, portable hard drive, multimedia card, card-type memory (e.g., SD or DX memory), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 12 can be an internal storage unit of the electronic device 1, such as a portable hard drive. In other embodiments, the memory 12 can be an external storage device of the electronic device 1, such as a plug-in portable hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the electronic device 1. Furthermore, the memory 12 can include both internal and external storage units of the electronic device 1. The memory 12 can be used not only to store application software and various types of data installed on the electronic device 1, such as code for detecting anomalies in uniformly made workpieces, but also to temporarily store data that has been output or will be output.
[0054] In some embodiments, the processor 13 may be composed of integrated circuits, such as a single packaged integrated circuit or multiple integrated circuits with the same or different functions, including combinations of one or more central processing units (CPUs), microprocessors, digital processing chips, graphics processors, and various control chips. The processor 13 is the control unit of the electronic device 1, connecting various components of the electronic device 1 through various interfaces and lines. It executes programs or modules stored in the memory 12 (e.g., a uniform material workpiece anomaly detection program) and calls data stored in the memory 12 to perform various functions and process data of the electronic device 1.
[0055] The processor 13 executes the operating system of the electronic device 1 and various installed applications. The processor 13 executes the applications to implement the steps in the above-described method for detecting anomalies in uniform material workpieces.
[0056] For example, the computer program may be divided into one or more modules, which are stored in the memory 12 and executed by the processor 13 to complete this application. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which describe the execution process of the computer program in the electronic device 1. For example, the computer program may be divided into an acquisition module 201, a segmentation module 202, an extraction module 203, a calculation module 204, and a judgment module 205.
[0057] The integrated unit implemented as a software functional module described above can be stored in a computer-readable storage medium, which can be non-volatile or volatile. The software functional module stored in the storage medium includes several instructions to cause a computer device (which may be a personal computer, computer equipment, or network device, etc.) or processor to execute some functions of the uniform material workpiece anomaly detection method described in the various embodiments of this application.
[0058] In summary, the present invention discloses a method, system, device, and medium for anomaly detection in uniformly made workpieces. By employing a pre-trained image coding model to extract sub-image features and integrating global difference and local anomaly evaluation mechanisms, it achieves efficient anomaly detection without any labeled samples or retraining, significantly reducing the high costs associated with data preparation, labeling, and model iteration in traditional supervised methods. Therefore, the present invention effectively overcomes the various shortcomings of existing technologies and possesses high industrial application value.
[0059] The above embodiments are merely illustrative of the principles and effects of the present invention and are not intended to limit the invention. Any person skilled in the art can modify or alter the above embodiments without departing from the spirit and scope of the present invention. Therefore, all equivalent modifications or alterations made by those skilled in the art without departing from the spirit and technical concept disclosed in the present invention should still be covered by the claims of the present invention.
Claims
1. A method for detecting anomalies in a workpiece made of uniform material, characterized in that, The method includes: Obtain the workpiece image of the target workpiece; The workpiece image is divided into multiple sub-images; Visual feature vectors for each sub-image are extracted using a pre-trained image coding model; Anomaly score is calculated for each sub-image based on the visual feature vector, and the anomaly score includes a global difference score and a local anomaly score. Based on the anomaly scores of all subgraphs, determine whether the target workpiece is abnormal.
2. The method for detecting anomalies in a workpiece of uniform material according to claim 1, characterized in that, The steps for calculating the anomaly score for each sub-image based on the visual feature vector include: The degree of difference between the visual feature vector of each sub-image and the visual feature vector of other sub-images is calculated to obtain the global difference score; Based on the similarity between subgraphs, similar subgraphs corresponding to each subgraph are selected from all subgraphs according to a preset number of nearest neighbors; Based on the similarity, the difference between each sub-image and its corresponding similar sub-image is calculated to obtain the local anomaly score corresponding to the sub-image; The global difference score and the local anomaly score are weighted and summed to obtain the anomaly score for each subgraph.
3. The method for detecting anomalies in a workpiece of uniform material according to claim 2, characterized in that, The step of calculating the degree of difference between the visual feature vector of each sub-image and the visual feature vector of other sub-images to obtain the global difference score includes: Calculate the Euclidean distance between the visual feature vector of the subgraph and the visual feature vectors of the corresponding other subgraphs; Based on the Euclidean distance, and according to a preset adjacent ratio, the set of adjacent subgraphs corresponding to the subgraph is obtained by filtering from other subgraphs; The global difference score is calculated using the following formula. : ; in, This indicates the number of subgraphs in the set of adjacent subgraphs corresponding to the given subgraph. This indicates that the subgraph and the set of adjacent subgraphs are in the [missing information]. The Euclidean distance between adjacent subgraphs.
4. The method for detecting anomalies in a workpiece of uniform material according to claim 2, characterized in that, The steps for selecting similar subgraphs for each subgraph from all subgraphs based on the similarity between subgraphs and according to a preset number of nearest neighbors include: The similarity between the subgraph and other subgraphs is calculated based on the vector dot product; For each number of nearest neighbors corresponding to each subgraph, select the subgraph with the highest similarity from all subgraphs. A number of similar subgraphs are used as the similar subgraphs corresponding to the number of nearest neighbors of the subgraph, wherein... The number of nearest neighbors.
5. The method for detecting anomalies in a workpiece of uniform material according to claim 4, characterized in that, The steps for calculating the difference between each sub-image and its corresponding similar sub-image, and obtaining the local anomaly score corresponding to the sub-image based on the similarity, include: The local anomaly score is calculated using the following formula: ; in, This represents the number of nearest neighbors corresponding to the subgraph. This represents the set of the nearest neighbors corresponding to the subgraph. This represents the number of nearest neighbors corresponding to the subgraph. Represents the subgraph and its corresponding first... The similarity of similar subgraphs.
6. The method for detecting anomalies in a workpiece of uniform material according to claim 1, characterized in that, The step of determining whether the target workpiece is abnormal based on the anomaly scores of all subgraphs includes: Calculate the median of the outlier scores for all subgraphs to obtain the first median; Calculate the absolute deviation of the outlier score for each subplot from the first median; Calculate the median of all absolute deviations to obtain the second median; The robust outlier score for each subgraph is calculated based on the absolute deviation and the second median; Determine whether the robust anomaly scores of all subgraphs are less than a preset anomaly score threshold: If so, the target workpiece is determined to be normal; Otherwise, the target workpiece is determined to be abnormal.
7. The method for detecting anomalies in a workpiece of uniform material according to claim 6, characterized in that, The steps for calculating the robust outlier score for each subplot based on the absolute deviation and the second median include: The scaling deviation is obtained by multiplying the absolute deviation corresponding to each subgraph by a preset adjustment coefficient. The ratio of the scaling deviation to the second median is calculated to obtain the robust anomaly score of the subgraph.
8. A system for detecting anomalies in workpieces of uniform material, characterized in that, include: The acquisition module is used to acquire the workpiece image of the target workpiece; A segmentation module is used to divide the workpiece image into multiple sub-images; The extraction module is used to extract the visual feature vector of each sub-image using a pre-trained image coding model; The calculation module is used to calculate the anomaly score for each sub-image based on the visual feature vector, wherein the anomaly score includes a global difference score and a local anomaly score; The judgment module is used to determine whether the target workpiece is abnormal based on the abnormality scores of all sub-graphs.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method for detecting anomalies in a uniform material workpiece as described in any one of claims 1 to 7.
10. A storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the method for detecting anomalies in a uniform material workpiece as described in any one of claims 1 to 7.