An industrial product anomaly detection method

By constructing a surface feature memory model for industrial products and using GPU parallel computing, the problems of low efficiency and insufficient accuracy in traditional detection methods are solved, achieving efficient and accurate detection of surface defects in industrial products.

CN122222951APending Publication Date: 2026-06-16WUXI MCTIFFIN ARTIFICIAL INTELLIGENCE TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
WUXI MCTIFFIN ARTIFICIAL INTELLIGENCE TECHNOLOGY CO LTD
Filing Date
2026-03-13
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

Traditional industrial product surface defect detection relies on manual visual inspection, which is inefficient and the results are greatly affected by experience. Existing automated detection methods have high computational complexity when defect samples are scarce, making it difficult to meet the requirements of high efficiency and high accuracy detection.

Method used

A GPU-based parallel computing approach is adopted. By constructing a memory bank model of industrial product surface features, feature vectors are extracted using a convolutional neural network, and cosine similarity calculation and redundancy removal are performed. Anomaly detection is then combined with overlapping sliding regions.

Benefits of technology

It significantly improves detection efficiency while ensuring detection accuracy, and is suitable for detecting surface defects in industrial products with complex textures and structures, and is suitable for real-time or near-real-time detection needs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122222951A_ABST
    Figure CN122222951A_ABST
Patent Text Reader

Abstract

The application provides an industrial product anomaly detection method, only a small amount of good product samples are needed for training, a memory bank model of industrial product surface characteristics is constructed, and the extraction, storage and similarity matrix operation process of the characteristic vector are accelerated based on GPU parallel computing, efficient and accurate identification of abnormal characteristics is realized, so that the detection efficiency is significantly improved while the detection accuracy is ensured, and rapid detection of the surface defects of the industrial product is completed.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial visual inspection and image recognition technology, specifically to a method for detecting surface defects in industrial products based on training with a small number of good product samples and accelerating the process with GPU parallel computing and matrix operations. It is applicable to surface quality inspection scenarios for various industrial products such as building materials, textiles, footwear, and metals. Background Technology

[0002] In industrial production, industrial products typically undergo molding, processing, or surface treatment. To ensure product quality, it is necessary to inspect the surface quality of industrial products after processing to promptly identify and remove defective products with flaws such as breakage, dirt, scratches, holes, or missing parts.

[0003] Traditional industrial surface defect inspection mainly relies on manual visual inspection, which is not only labor-intensive and inefficient, but also highly susceptible to the influence of the inspector's experience and subjective factors, making it difficult to meet the requirements of modern industry for high-efficiency, high-consistency, and high-stability quality inspection. With the development of automation and intelligent manufacturing, image recognition-based automated inspection technology is gradually being applied to the field of industrial surface quality inspection.

[0004] However, in real-world industrial scenarios, defect samples are often few in number and diverse in type, and the morphology of defects varies greatly between different batches and processes, making it difficult for traditional defect detection methods based on supervised learning to construct a comprehensive training dataset.

[0005] Furthermore, existing defect detection methods based on feature matching, similarity calculation, or high-dimensional vector distance measurement often rely on serial or low-parallel computation when dealing with high-resolution images, multi-scale feature fusion, and large-scale feature vector comparison. The computation process involves a large number of matrix operations and similarity calculations, resulting in high overall computational complexity. This makes it difficult to complete real-time or near-real-time detection under limited computing resources and time constraints, thus limiting its practical application in industrial production line scenarios.

[0006] Therefore, there is a need for a method that can fully utilize the parallel computing power of GPUs to accelerate the feature vector extraction, matrix operation, and similarity calculation processes when there are very few or no defect samples, thereby significantly improving detection efficiency while ensuring detection accuracy and meeting the high-precision and high-efficiency defect detection requirements of complex textures and structures in industrial products. Summary of the Invention

[0007] To address the aforementioned problems, this invention proposes an industrial product anomaly detection method that requires only a small number of good product samples for training. By constructing a memory bank model of industrial product surface features and accelerating the extraction, storage, and similarity matrix operations of feature vectors based on GPU parallel computing, it achieves efficient and accurate identification of abnormal features. This significantly improves detection efficiency while ensuring detection accuracy, enabling rapid detection of surface defects in industrial products.

[0008] The method of this invention can effectively distinguish between complex textures, structural patterns and real defects, and solves the problems of scarce defect samples, insufficient detection accuracy and low detection efficiency. It has strong versatility and industrial application value.

[0009] To achieve the above objectives, the present invention adopts the following technical solution: A method for defect detection of industrial products, characterized by comprising the following steps: S1: Image acquisition and feature generation; Images are acquired from the industrial products to be inspected, and training images containing only normal samples are obtained. The training images are input into a preset convolutional neural network model to generate a feature map that represents the local structural information of the images. S2: Grid-based window partitioning, feature vector generation, and window memory construction; The feature map is spatially divided according to a preset G×G grid method to obtain multiple window regions, denoted as: Window; Perform dimensional transformation on the feature map within each window area to generate a Feature Vector that corresponds one-to-one with the spatial location. The feature vectors of all images in the training set are aggregated according to their corresponding window regions. For each window region, the cosine similarity between feature vectors is calculated on the GPU based on parallel matrix operations. By batch similarity comparison and threshold filtering, the feature vectors in the same window region are processed to remove redundancy, thereby constructing a corresponding window memory bank for each window region.

[0010] S3: Generation of feature vectors for the image to be detected; The image to be detected is input into the same convolutional neural network as in step S1 to generate a feature map, and the same dimension transformation operation as in step S2 is performed to obtain the feature vector of the image to be detected.

[0011] S4: Construct overlapping sliding regions; An overlapping sliding region is constructed in the feature space of the image to be detected to cover the feature vectors of the image to be detected. The feature vectors within each overlapping sliding region are determined from the feature map by using their corresponding spatial positions as indices.

[0012] S5: Exception reasoning based on window memory; The corresponding window memory is determined based on the spatial center position of each overlapping sliding region; On the GPU, the feature vectors within the overlapping sliding region are organized into a matrix form, and cosine similarity calculation is performed in parallel with the corresponding window memory to obtain the maximum similarity value of each feature vector relative to the window memory. Based on the maximum similarity value, the corresponding anomaly score is calculated.

[0013] S6: Abnormal score fusion, mapping, and result output; The abnormal scores are mapped back to the image space to generate an abnormal score map; Calculate the corresponding abnormal color based on the abnormal score at each position in the abnormal score graph; The anomaly score map is normalized and smoothed to output the anomaly detection results of industrial products and a visual heatmap of the anomaly area.

[0014] Its further features are: In step S2, for all feature vectors obtained within the same window, deduplication based on cosine similarity is performed, specifically including the following steps: a1: Feature vector preprocessing; Obtain the set of feature vectors within the current window (Window), and perform cosine L2 normalization on each feature vector in the set on the GPU to make the magnitude of each feature vector equal to 1.

[0015] a2: Construction of the initial set of retained feature vectors; According to a preset number, the first feature vector corresponding to the preset number is selected sequentially from the feature vector set, and the selected feature vector is directly used as the initial value and placed into the reserved feature vector set, denoted as: reserved feature vector set R.

[0016] a3: Process the remaining feature vectors in sequence; The remaining feature vectors, excluding the reserved feature vector set R, are selected sequentially in multiple batches according to their original arrangement in the feature vector set, and each selected feature vector is organized into a matrix form as the current feature vector set to be processed, denoted as: feature vector set to be processed B.

[0017] a4: Cosine similarity calculation; For each feature vector in the set of feature vectors to be processed, cosine similarity is calculated on the GPU with all feature vectors in the set of retained feature vectors through parallel matrix operations, and the corresponding maximum cosine similarity value is obtained.

[0018] a5: Similarity threshold determination; The maximum cosine similarity value is compared with a preset similarity threshold: If the maximum cosine similarity value is greater than or equal to the similarity threshold, the feature vector is determined to be a redundant feature vector and discarded.

[0019] If the maximum cosine similarity value is less than the similarity threshold, the feature vector is determined to be a non-redundant feature vector, retained and added to the set of retained feature vectors to update the set of retained feature vectors R. a6: When the number of feature vectors retained in the retained feature vector set R reaches the preset maximum number of retained feature vectors, stop the deduplication process for subsequent feature vectors; otherwise, return to step a3 and continue processing the next batch of the feature vector set B to be processed until the feature vector set within the current window is traversed.

[0020] a7: Store the set of retained feature vectors R after deduplication as the set of deduplicated feature vectors corresponding to the window Window, and store it in the feature memory using the grid space position corresponding to the window Window as the index.

[0021] In step S4, the overlapping sliding area Overlap block slides in a specified order and with a preset step size; each slide uses a number to mark the area covered by the Overlap block, until all areas in the feature map to be detected are completely covered by at least one Overlap block, then the sliding stops.

[0022] In step S5, for the overlapping block coverage area in the feature map to be detected, similarity calculation is performed based on the window memory corresponding to its geometric center in the G×G grid. This specifically includes the following steps: b1: For each numbered Overlap block, calculate the geometric center position of its overlapping area, and determine its corresponding Window MemoryBank based on the position of the geometric center in the G×G grid.

[0023] When the geometric center of an overlap block is located on the common boundary of two adjacent grid spatial locations, it is assigned to the Window location with the larger row index or column index. b2: For the currently numbered Overlap block, obtain the set of feature vectors to be detected within its coverage area, and organize the set of feature vectors to be detected into a matrix form; Based on the Window Memory Bank corresponding to the Overlap block, a set of feature vectors for comparison is obtained. On the GPU, cosine similarity calculation is performed on the set of feature vectors to be detected and the set of feature vectors for comparison through parallel matrix operations, so as to obtain a set of similarity comparison results corresponding to each feature vector to be detected in the current Overlap block.

[0024] b3: For each of the aforementioned feature vectors to be detected, perform a parallel reduction operation on the GPU on the corresponding similarity comparison result, and select the maximum cosine similarity value as the local similarity result of the feature vector to be detected within the coverage area of ​​the Overlap block.

[0025] b4: Determine whether the feature vector to be detected is covered by multiple overlapping blocks with different numbers: When the feature vector to be detected is covered by only one overlap block, the local similarity result obtained within that overlap block is used as the cosine similarity data for scoring. max ; When the feature vector to be detected is covered by multiple overlapping blocks with different numbers, the local similarity result is calculated within the coverage area of ​​each overlapping block, and the maximum value among all local similarity results is selected as the cosine similarity data for scoring. max .

[0026] b5: Based on the aforementioned rating similarity data cosine max The anomaly score corresponding to the feature vector to be detected is calculated using the following formula: Anomaly Score = 1 - cosine max ; In step S6, the abnormal color is calculated as follows: color = JET((AnomalyScore - v) min ) / (v max - v min ) ); In the formula, color is the RGB value corresponding to the abnormal color, JET() is a predefined pseudo-color mapping function; AnomalyScore is the anomaly score corresponding to the feature vector to be detected; v min v is the minimum of all anomaly scores included in the image to be detected; max This is the maximum value among all anomaly scores included in the image to be detected.

[0027] This application provides a surface defect detection method for industrial products that meets the real-time or near-real-time detection needs of industrial production lines. This method significantly improves overall detection efficiency while ensuring detection accuracy. It relies on only a small number of defect samples or none at all, and can extract features from the surface of industrial products under normal conditions and construct a memory database through window perception. Specifically, by spatially dividing the surface of the industrial product, corresponding window memories are constructed within different spatial windows, ensuring that the features stored in each spatial window can characterize the local statistical distribution characteristics of that area under normal conditions. During the detection process, the surface features of the industrial product to be detected are compared with the corresponding window memories, and anomaly determination is achieved by calculating the anomaly score between feature vectors. Compared to detection methods based on overall feature similarity, this application transforms the defect detection problem into a judgment based on the consistency of local statistical distribution, effectively reducing the risk of mismatches between different areas due to similar surface structures or textures, and improving the reliability of the detection results. Furthermore, by dividing the spatial windows into regions, the normal feature distribution within each window tends to be unimodal or low-complexity, thereby enhancing the anomaly discrimination capability based on feature similarity. For industrial products with complex surface structures or rich texture variations, even minor anomalies can produce significant distribution differences within the corresponding local window, thus enabling effective detection. This application further constructs overlapping sliding regions and combines them with a feature memory database built based on spatial windows to perform region-by-region comparisons of the surface features of the industrial product to be detected, achieving refined detection of local anomalies. Since the dispersion of normal feature distribution within a local window is significantly lower than the overall distribution, even minor damage, slight surface anomalies, or local foreign objects can form significant similarity differences within the local area, thereby improving the detection accuracy and stability of complex surface defects. Based on the above method, this application can achieve high-precision and high-efficiency detection of surface defects in industrial products under complex texture and structure scenarios, and is suitable for industrial production environments with high requirements for real-time performance and consistency. Attached Figure Description

[0028] Figure 1 This is a schematic diagram of the abnormal product detection method in this application; Figure 2 Examples of training images for the corrected standard samples; Figure 3 Here is an example of dividing a single Feature Map into Windows; Figure 4 Example of performing a dimension transformation operation on a feature map; Figure 4 a and Figure 4 b is an example of a feature vector obtained after dimensionality transformation of the feature map in the window; Figure 5 This is an example of how overlapping sliding blocks slide in a specified order and with a preset step size. Figure 6 After sliding the Overlap block 25 times, the FeatureMap is overwritten, with each slide corresponding to a numbered example. Figure 7 This example demonstrates the correspondence between a window and its overlapping blocks. For instance, the four overlapping blocks 0, 1, 5, and 6 are compared and calculated with the window (0, 0). Figure 8 Example of the process of calculating scores using similarity data; Figure 9 This is a comparison chart of the anomaly scoring charts; Figure 9 Example 'a' is an anomaly rating chart; Figure 9 b is an example of an anomaly rating chart. Detailed Implementation

[0029] like Figure 1 As shown, this application includes a method for detecting anomalies in industrial products, which includes the following steps.

[0030] S1: Acquire images of the industrial products to be detected, obtain training images containing only normal samples, and input the training images into a preset convolutional neural network model for feature extraction.

[0031] This embodiment uses training images of footwear product components. When constructing standard sample training images, preprocessing of the sample data is required, specifically including the following steps: Raw images of standard components are captured using a camera.

[0032] Image correction algorithms are used to correct the angles of all acquired raw images, aligning them to a single standard pose. The specific standard pose is adaptively set based on the shape of the component itself. The correction algorithm is implemented based on existing technologies. Figure 2The image shown is an example of a portion of standard component images after correction. The angles and positions of the standard components in the images differ slightly, but they all exist in the same standard posture. Each original image is a 500px × 500px square image. In practical applications, to find subtle defects, the resolution of industrial cameras used on production lines is much larger than 500px × 500px. This embodiment only uses a 500px × 500px size to illustrate the calculation process.

[0033] Standard sample training images are constructed using calibrated standard component images. In this embodiment, the training set includes 20 standard sample training images, each 500px × 500px.

[0034] In this embodiment, the convolutional neural network model is ResNet18, from which feature map outputs of the L2 and L3 layers are extracted to characterize the local structure and texture features of the input image at different scales.

[0035] Since the feature maps output by L2 and L3 layers may differ in spatial resolution, this embodiment selects the spatial size of the L2 layer feature map as the target size and aligns the L3 layer feature map spatially through interpolation so that the two have the same height and width dimensions in spatial dimension, where H and W represent the height and width of the feature map, respectively; in this embodiment, the feature map size is 73x73 (H×W).

[0036] After completing the spatial size alignment, the feature maps of the L2 layer and the L3 layer are stitched together along the channel dimension to obtain a feature map set with C channels, where C is the total number of channels after stitching, 1500. The feature map set consists of 1500 73x73 feature maps.

[0037] Subsequently, the feature map set is smoothed along the channel dimension to reduce the impact of local noise on the feature distribution, thereby improving the stability of the feature representation.

[0038] This method uses feature maps extracted from mid-to-high-level convolutional layers of the convolutional neural network backbone model as the basis for subsequent techniques. This is because the feature maps extracted from mid-to-high-level convolutional layers take into account both local texture details and mesoscale structural information, thus improving the accuracy of subsequent calculations. By aligning the feature maps extracted from different convolutional layers and performing channel concatenation, the inconsistency problem in the multi-scale feature space is eliminated. Simultaneously, concatenation ensures sufficient feature information, improving the completeness of subsequent feature representation.

[0039] S2: After completing the feature extraction and feature vector generation described in step S1, the feature vectors are organized regionally according to their spatial location to construct a window memory library.

[0040] First, the feature map is divided into multiple non-overlapping windows according to a preset G×G grid. Each window corresponds to a sub-region in the feature map space and has a unique window index in the grid. In this embodiment, a 3x3 grid is used for division, resulting in 9 windows with 9 positions: (0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2). The first window in the upper left corner is denoted as (0,0). Figure 3 As shown, a single 73x73 Feature Map is divided into 9 windows. Each window corresponds to a spatial location (0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1), (2,2). The size of the Feature Map after being divided by windows is 24x24.

[0041] Based on this, a dimension transformation operation is performed on the feature map. The entire spatial location of the feature map is traversed in the order of the first direction and the last direction. The feature patches (spatial location 1x1) corresponding to all spatial locations are arranged sequentially, resulting in a feature patch set (H×W)×C. Each row of the patches corresponds to a feature vector (dimension 1×1500). Figure 4 a and Figure 4 As shown in b, each window position of an image has 1500 24x24 feature maps. For example, the feature map of the (1,1) window has 1500 24x24 maps. After dimensionality transformation, it becomes 576x1500 patches. A patch is a 1x1 spatial unit, and each row of patches corresponds to a feature vector.

[0042] In this embodiment, the feature map is described using a two-dimensional spatial coordinate system.

[0043] The coordinate system is established with the upper left corner of the feature map as the origin O, forming a two-dimensional discrete coordinate system, wherein: The horizontal direction is the x-axis, which increases from left to right along the width of the image; The vertical direction is the y-axis, and it increases from top to bottom along the image height direction; The coordinates (y, x) are used to represent the row and column indices of the feature vector in the feature map.

[0044] When (x, y) is used to represent the grid space position of a window, its meaning is the same as that of (y, x) coordinates, only the index order is different. Both are based on the same feature map coordinate system.

[0045] Therefore, the feature map is mapped to a set of feature patches consisting of 5329 (73×73) feature vectors, with an overall dimension of 5329×1500.

[0046] Simultaneously, the spatial coordinates (y, x) of each feature vector in the feature map are recorded, and an index relationship of the feature vector in patches is established based on the spatial coordinates; the position of the feature vector in the feature map can be uniquely determined through the spatial coordinates (y, x), thereby determining the window to which it belongs.

[0047] Subsequently, the feature vectors generated from all normal sample images in the training set are aggregated according to their corresponding windows, so that each window corresponds to a set of feature vectors to represent the normal feature distribution in that spatial region.

[0048] After feature vector aggregation is completed, a similarity-based redundancy removal process is performed on the feature vector set within the same window to reduce the redundant impact of highly similar feature vectors on subsequent calculations. Specifically, the feature vectors within the window are normalized, and the similarity between any two feature vectors is calculated based on cosine similarity. When the similarity between two feature vectors is higher than a preset threshold, only one feature vector is retained, thus obtaining a redundancy-removed subset of feature vectors.

[0049] Through the above processing, a corresponding feature memory unit is constructed for each window, and the feature memory units of all windows together constitute the Window Memory Bank. The Window Memory Bank is organized using window indexes and is used to store representative normal feature vectors in different spatial regions.

[0050] In this embodiment, the training set includes 20 standard sample training images.

[0051] For each standard sample training image, under the G×G grid division, each grid position (x, y) corresponds to a window. After performing dimensionality transformation and aggregation on the FeatureMap generated by the Window of the same grid position (x, y) of 20 training images, we can obtain patches consisting of 11520 feature vectors, each with a dimension of 1500. The patches are the window memory banks that constitute the corresponding grid positions (x, y).

[0052] In this embodiment, a total of 9 window positions are formed, corresponding to (0,0), (0,1), (0,2), (1,0), (1,1), (1,2), (2,0), (2,1) and (2,2), respectively, thereby constructing a complete window memory library.

[0053] In this method, each feature map is divided into local regions by using a window, so that subsequent comparisons are not based on global comparisons, but on local region comparisons. This can effectively preserve spatial semantic consistency and avoid feature pollution caused by global mixing.

[0054] In practical applications, the resolution of standard component images may be very high, and the local texture of the image may be simple or the color variation may be small. In order to reduce the computational complexity of the subsequent anomaly detection stage, this method performs cosine similarity-based deduplication on the feature vectors in each spatial window region, removes highly similar redundant features, and retains only the feature vectors with large differences, thereby significantly compressing the memory size while ensuring the representation ability.

[0055] Specifically, the deduplication operation performed on the feature vector of each window includes the following steps: a1: Feature vector preprocessing; Obtain the set of feature vectors within the current window (Window), and perform cosine L2 normalization on each feature vector in the set on the GPU to make the magnitude of each feature vector equal to 1.

[0056] a2: Construction of the initial set of retained feature vectors; According to a preset number, the first feature vector corresponding to the preset number is selected sequentially from the feature vector set, and the selected feature vector is directly used as the initial value and placed into the reserved feature vector set, denoted as: reserved feature vector set R.

[0057] a3: Process the remaining feature vectors in sequence; The remaining feature vectors, excluding the reserved feature vector set R, are selected sequentially in multiple batches according to their original arrangement in the feature vector set, and each selected feature vector is organized into a matrix form as the current feature vector set to be processed, denoted as: feature vector set to be processed B.

[0058] a4: Cosine similarity calculation; For each feature vector in the set of feature vectors to be processed, cosine similarity is calculated on the GPU with all feature vectors in the set of retained feature vectors through parallel matrix operations, and the corresponding maximum cosine similarity value is obtained.

[0059] a5: Similarity threshold determination; The maximum cosine similarity value is compared with a preset similarity threshold: If the maximum cosine similarity value is greater than or equal to the similarity threshold, the feature vector is determined to be a redundant feature vector and discarded.

[0060] If the maximum cosine similarity value is less than the similarity threshold, the feature vector is determined to be a non-redundant feature vector, retained and added to the set of retained feature vectors to update the set of retained feature vectors R. a6: When the number of feature vectors retained in the retained feature vector set R reaches the preset maximum number of retained feature vectors, stop the deduplication process for subsequent feature vectors; otherwise, return to step a3 and continue processing the next batch of the feature vector set B to be processed until the feature vector set within the current window is traversed.

[0061] a7: Store the set of retained feature vectors R after deduplication as the set of deduplicated feature vectors corresponding to the window Window, and store it in the feature memory using the grid space position corresponding to the window Window as the index.

[0062] This method uses cosine linear velocity to calculate the similarity between two vectors. The formula for calculating cosine similarity is as follows: cosine similarity = A·B / (||A||×||B||); where A and B are the two vectors being compared. A·B is the dot product of the two vectors; and ||A|| and ||B|| are their magnitudes. The specific cosine similarity calculation method can be implemented using existing technology.

[0063] The feature vector in this application is [f1, f2, ..., f 1500The calculation becomes quite complex when the dimension is too large. The following uses a 3-dimensional vector F to illustrate the specific calculation process.

[0064] Each feature vector is uploaded to the GPU, and the calculation process is as follows; F = [f1, f2, f3] = [10, 5, 3]; Calculate the norm: ||F||² = sqrt(f1) 2 + f2 2 + f3 2 = sqrt(100+25+9) = sqrt(134); Where sqrt() is the square root function; Normalization: F' = F / || F ||2 = [10 / sqrt(134), 5 / sqrt(134), 3 / sqrt(134)]; Calculate the norm again: ||F'||2 = sqrt((100+25+9) / 134) = 1; Suppose that after cosine normalization, F1, F2, and F3 are obtained as follows: F1=[0.80,0.60,0.00]; F2=[0.81,0.59,0.01]; F3=[0.00,1.00,0.00].

[0065] Using F1 as the vector to be processed, and F2 and F3 as the vectors to be compared; the cosine similarity calculation process is as follows: Initialize KEEP = [ ] to be empty; Add F1 to KEEP, KEEP = [F1]; Calculate the F1 and cosine similarity between the vectors to be compared; Feature vectors are all L2 normalized before similarity calculation to ensure their magnitude is 1. Therefore, the cosine similarity between vectors can be directly calculated using the vector dot product. cos(F2,F1)=F2·F1≈0.81×0.80+0.59×0.60+0.00×0.00≈1.000; cos(F3,F1)=0.60; In this embodiment, the similarity threshold is set to 0.95; therefore: If 1.000 > 0.95, it means that F1 and F2 are highly similar, so the vector to be compared, F2, is deleted. 0.60 < 0.95 indicates that F1 and F3 have low similarity. In this round of calculation, F1 and F3 are retained, and F3 is also included in KEEP. KEEP=[ F1, F3] In this embodiment, after deduplication based on pre-similarity, the size change of the memory in a certain Window location is shown below. The area before the arrow "→" is before deduplication, and the area after the arrow is the size after deduplication.

[0066] Memory Bank After Dedup: Window (0, 0): 11520 → 1024; Window (0, 1): 11520 → 1031; Window (0, 2): 11520 → 1027; Window (1, 0): 11520 → 1227; Window (1, 1): 11520 → 2090; Window (1, 2): 11520 → 1341; Window (2, 0): 11520 → 1102; Window (2, 1): 11520 → 1024; Window (2, 2): 11520 → 1024; Before deduplication, the number of patches in the Window location was 103680, and after deduplication, it became 10890, with a compression ratio of 0.09.

[0067] In this method, multiple standard sample training images are segmented through spatial window regions with the same grid coordinates, and a window memory bank is constructed. The memory bank modeling idea based on spatial statistical coupling is introduced to establish the relationship between the feature space and position of the image. The distribution characteristics of feature vectors are statistically analyzed and modeled based on spatial position to construct a memory bank of standard samples, providing stable and accurate reference sample data for subsequent detection calculations.

[0068] S3: For the image to be detected, input the image to be detected into the same convolutional neural network as in step S1 to generate a feature map, perform the same dimension transformation operation as in step S2, and obtain the feature vector of the image to be detected to ensure the consistency between the training features and the features to be detected in the feature space.

[0069] S4: Construct an overlap block that allows for overlapping sliding regions.

[0070] In this embodiment, the size of the overlap block is the same as the size of the window.

[0071] The overlapping sliding region slides across the feature map to be detected in a left-to-right and top-to-bottom order, with a sliding step size SL of 12. Each slide uses a number to mark the area covered by the Overlap block, and sliding stops when all areas in the feature map to be detected are completely covered by at least one Overlap block.

[0072] The step size SL is greater than 0 and less than the side length of any edge of the window. The step size SL controls the size of the overlapping area between adjacent Overlap blocks. If the step size SL is set too small, the overlapping area between adjacent Overlap blocks will be large. This means that the image in the center region will be covered by the overlapping sliding area more often. More coverage within the same region means more comparisons, making it more sensitive to small defects, but increasing the computational load. The specific value of the step size SL is set according to the shape of the product being inspected and the angle and position of standard components in the image.

[0073] In this embodiment, the part is located at the center of the image, and there are no part images to be compared at the edge. Therefore, the step size SL is set to 12, which means that the areas covered by adjacent overlap blocks overlap each other by 50%. This means that the image closer to the center will be compared more often, while the areas at the edge will be compared less often.

[0074] like Figure 5 As shown, overlapping sliding regions of size 24×24 are used. Based on a step size of 12, they slide from the top left corner to the right and from top to bottom, for a total of 25 slides, ensuring that all overlapping block coverage areas cover the entire feature map to be detected. The specific arrangement of each overlapping block coverage area is as follows. Figure 6 As shown, the Overlap Blocks covering the area are numbered 0-24. Note that in this embodiment, the size of the Overlap Block is the same as the Window, but to accurately see the positional changes of the Overlap Block, the dimensions are... Figure 5 and Figure 6 The slightly larger red box in the middle indicates the overlap block, which can be slid over.

[0075] S5: For the overlapping block coverage area in the feature map to be detected, similarity calculation is performed based on the window memory corresponding to its geometric center in the G×G grid. The specific steps include: b1: For each numbered Overlap block, calculate the geometric center position of its covered area, and determine the corresponding Window MemoryBank based on the position of the geometric center in the G×G grid.

[0076] When the geometric center of an overlap block is located on the common boundary of two adjacent grid spatial locations, it is assigned to the Window location with the larger row index or column index.

[0077] b2: For the currently numbered Overlap block, obtain the set of feature vectors to be detected within its coverage area, and organize the set of feature vectors to be detected into a matrix form; Based on the Window Memory Bank corresponding to the Overlap block, a set of feature vectors for comparison is obtained. On the GPU, cosine similarity calculation is performed on each feature vector in the set of feature vectors to be detected and the set of feature vectors for comparison through parallel matrix operations. This allows each feature vector to be detected to be compared with multiple feature vectors in the set of feature vectors for comparison, resulting in a set of similarity comparison results for each feature vector to be detected.

[0078] The set of similarity comparison results includes the cosine similarity values ​​between the feature vector to be detected and all feature vectors in the set of feature vectors for comparison.

[0079] b3: For each of the aforementioned feature vectors to be detected, perform a parallel reduction operation on the GPU on the corresponding similarity comparison result, and select the maximum cosine similarity value as the local similarity result of the feature vector to be detected within the coverage area of ​​the Overlap block.

[0080] b4: Determine whether the feature vector to be detected is covered by multiple overlapping blocks with different numbers: When the feature vector to be detected is covered by only one overlap block, the local similarity result obtained within that overlap block is used as the cosine similarity data for scoring. max ; When the feature vector to be detected is covered by multiple overlapping blocks with different numbers, the local similarity result is calculated within the coverage area of ​​each overlapping block, and the maximum value among all local similarity results is selected as the cosine similarity data for scoring. max .

[0081] By using the above method, the similarity results obtained by the same feature vector to be detected under multiple spatial window constraints are fused in a conservative manner, avoiding misjudgments caused by the inconsistency between the coverage of the overlap block and the boundary of the spatial window.

[0082] b5: Based on the aforementioned rating similarity data cosine max The anomaly score corresponding to the feature vector to be detected is calculated using the following formula: Anomaly Score = 1 - cosine max ; Among them, cosine max The larger the value, the closer the detected feature vector is to the normal feature distribution of the corresponding spatial window, and the lower its degree of abnormality. cosine max The smaller the value, the higher the degree of anomaly, indicating that the feature vector to be detected cannot be interpreted by the normal feature distribution in all spatial window contexts it covers.

[0083] like Figure 8 In the example shown, the feature map to be detected, with a size of 73×73, contains 576x4 deduplicated feature vectors within the four overlap blocks covering the (0,0) window. The corresponding grid coordinates in the Memory Bank correspond to 1024 deduplicated feature vectors for comparison from the 20 original images. Therefore, each feature vector to be detected needs to have its cosine similarity calculated with each of the 1024 comparison feature vectors, resulting in 1024 similarity comparison results.

[0084] Figure 8 In the example, among the 1024 similarity comparison results corresponding to the feature vector to be detected, the maximum value is 0.97; therefore, 0.97 is used as the similarity data for scoring. max .

[0085] Because in this application, the feature vectors for comparison are obtained by mapping the grid coordinates of the geometric center of each Overlap block coverage area to the memory; some feature vectors to be detected in the Overlap block coverage area do not actually belong to the corresponding spatial window area Window in the memory, so the calculated similarity value may be very small, that is, the outlier score will be very large.

[0086] like Figure 7 In the example shown, when the geometric centers of the overlapping blocks labeled 0, 1, 5, and 6 all fall within the spatial window region (0,0) of the grid coordinates, some of the feature vectors to be detected in the overlapping blocks 1, 5, and 6 will have very low similarity values ​​because their actual positions are not within the (0,0) grid coordinate window. However, this low similarity is due to the position of the feature vector, not because of any defects. Therefore, in this method, when the feature vector to be detected belongs to the coverage area of ​​multiple overlapping blocks, the maximum value is selected from the similarity comparison results calculated in all overlapping block coverage areas. This maximum similarity value represents the abnormal state of the feature vector to be detected. This is because if the maximum similarity value of the feature vector to be detected in a certain spatial window region is in line with the normal state, it means that the feature vector to be detected conforms to the state characteristics of a certain standard sample training image. However, if the similarity of the feature vector to be detected is very low (abnormal) in all spatial window regions, it means that its height may be due to defects causing the low similarity value (abnormal). Therefore, this method selects the maximum similarity value (corresponding to the minimum outlier score) as the similarity data for scoring.

[0087] By employing the above method, this approach does not simply divide feature vectors physically based on spatial coordinates. Instead, it uses a spatial window (Window) as a local statistical constraint domain, implicitly characterizing the feature statistical distribution of that region under normal conditions using the feature memory corresponding to each window. This transforms anomaly detection from a global feature similarity judgment to a local statistical distribution deviation judgment. Compared to existing methods that use a single global feature memory, this method effectively avoids multimodal distribution interference caused by the mixing of features from different structural regions, improves the discriminative power of feature distance in anomaly determination, and enhances sensitivity to subtle structural anomalies without increasing feature dimensionality. It is particularly suitable for detecting surface defects in industrial products with complex structures and textures.

[0088] S6: Reconstruct the anomaly score Anomaly Score corresponding to each detected feature vector into an anomaly score map according to its spatial position in the feature map space. After smoothing the anomaly score map, map it to the same spatial size as the detected image, and generate a corresponding anomaly heat map on the detected image, which is output as the detection result.

[0089] Specifically, based on the minimum value v of all valid anomaly scores in the current detected image min and the maximum value v max , normalize the anomaly scores, and generate anomaly colors through a predefined pseudo-color mapping function. The calculation method is as follows: color = JET( (Anomaly Score - v min ) / (v max - v min ) ); where JET() represents the pseudo-color mapping function, which is used to map the normalized anomaly scores to a continuous color space; v min and v max are respectively the minimum and maximum values of the anomaly scores in the current detected image.

[0090] Since there are differences in the numerical distribution ranges of anomaly scores in different detected images, the same anomaly score may correspond to different color performances in different anomaly score maps. By normalizing based on the range of anomaly scores within a single detected image, it helps to reduce the sensitivity of the anomaly score visualization results to changes in imaging conditions, thus obtaining a more stable and contrastive anomaly heat map.

[0091] In this method, when calculating the anomaly color color corresponding to each detected feature vector, it is calculated according to the maximum value v of the anomaly value scores in the detected image to which the detected feature vector belongs max and the minimum value v min . As shown in Figure 9 , it is a comparison diagram of two anomaly score maps. Figure 9 v in a max is 0.2062. Figure 9 v in b max is 0.0768. Therefore, the same anomaly value score Anomaly Score may correspond to different colors in the two anomaly score maps.

[0092] In this method, according to the maximum value v of the anomaly value scores in each detected image max and the minimum value v minInstead of using a fixed threshold to generate anomaly rating maps, this method avoids the influence of external environmental conditions such as image acquisition equipment and lighting on the anomaly rating maps. min and v max As a boundary for the reliability of outlier scoring, it ensures that the calculated outlier scoring map is more in line with the design goal of industrial anomaly detection: "It is better to miss an edge than to misjudge a normal value," and is therefore more practical.

Claims

1. A method for defect detection of industrial products, characterized in that, Includes the following steps: S1: Image acquisition and feature generation; Images are acquired from the industrial products to be inspected, and training images containing only normal samples are obtained. The training images are input into a preset convolutional neural network model to generate a feature map that represents the local structural information of the images. S2: Grid-based window partitioning, feature vector generation, and window memory construction; The feature map is spatially divided according to a preset G×G grid method to obtain multiple window regions, denoted as: Window; Perform dimensional transformation on the feature map within each window area to generate a Feature Vector that corresponds one-to-one with the spatial location. The feature vectors of all images in the training set are aggregated according to their corresponding window regions. For each window region, the cosine similarity between feature vectors is calculated on the GPU based on parallel matrix operations. By batch similarity comparison and threshold filtering, the feature vectors in the same window region are processed to remove redundancy due to similarity, thereby building a corresponding window memory bank for each window region. S3: Feature vector generation of the image to be detected; The image to be detected is input into the same convolutional neural network as in step S1 to generate a feature map, and the same dimension transformation operation as in step S2 is performed to obtain the feature vector of the image to be detected. S4: Construct overlapping sliding regions; An overlapping sliding region is constructed in the feature space of the image to be detected to cover the feature vector of the image to be detected, wherein the feature vector of each overlapping sliding region is determined from the feature map by its corresponding spatial position as an index; S5: Exception reasoning based on window memory; The corresponding window memory is determined based on the spatial center position of each overlapping sliding region; On the GPU, the feature vectors within the overlapping sliding region are organized into a matrix form, and cosine similarity calculation is performed in parallel with the corresponding window memory to obtain the maximum similarity value of each feature vector relative to the window memory. Based on the maximum similarity value, the corresponding anomaly score is calculated. S6: Abnormal score fusion, mapping, and result output; The abnormal scores are mapped back to the image space to generate an abnormal score map; Calculate the corresponding abnormal color based on the abnormal score at each position in the abnormal score graph; The anomaly score map is normalized and smoothed to output the anomaly detection results of industrial products and a visual heatmap of the anomaly area.

2. The defect detection method for industrial products according to claim 1, characterized in that: In step S2, for all feature vectors obtained within the same window, deduplication based on cosine similarity is performed, specifically including the following steps: a1: Feature vector preprocessing; Get the set of feature vectors within the current window Window, and perform cosine L2 normalization on each feature vector in the set on the GPU so that the magnitude of each feature vector is 1; a2: Construction of the initial set of retained feature vectors; According to a preset number, the first feature vector corresponding to the preset number is selected sequentially from the feature vector set, and the selected feature vector is directly used as the initial value and placed into the reserved feature vector set, denoted as: reserved feature vector set R; a3: Process the remaining feature vectors in sequence; The remaining feature vectors, excluding the reserved feature vector set R, are selected sequentially in multiple batches according to their original arrangement in the feature vector set, and the selected feature vectors are organized into a matrix form each time, which is used as the current feature vector set to be processed, denoted as: feature vector set to be processed B. a4: Cosine similarity calculation; For each feature vector in the set of feature vectors to be processed, the cosine similarity is calculated with all feature vectors in the set of retained feature vectors R through parallel matrix operations on the GPU, and the corresponding maximum cosine similarity value is obtained. a5: Similarity threshold determination; The maximum cosine similarity value is compared with a preset similarity threshold: If the maximum cosine similarity value is greater than or equal to the similarity threshold, the feature vector is determined to be a redundant feature vector and discarded. If the maximum cosine similarity value is less than the similarity threshold, the feature vector is determined to be a non-redundant feature vector, retained and added to the set of retained feature vectors to update the set of retained feature vectors R. a6: When the number of feature vectors retained in the retained feature vector set R reaches the preset maximum number of retained feature vectors, stop the deduplication process for subsequent feature vectors; otherwise, return to step a3 and continue processing the next batch of the feature vector set B to be processed until the feature vector set within the current window is traversed. a7: Store the set of retained feature vectors R after deduplication as the set of deduplicated feature vectors corresponding to the window Window, and store it in the feature memory using the grid space position corresponding to the window Window as the index.

3. The defect detection method for industrial products according to claim 1, characterized in that: In step S4, the overlapping sliding area Overlap block slides in a specified order and with a preset step size; each slide uses a number to mark the area covered by the Overlap block, until all areas in the feature map to be detected are completely covered by at least one Overlap block, then the sliding stops.

4. The defect detection method for industrial products according to claim 1, characterized in that: In step S5, for the overlapping block coverage area in the feature map to be detected, similarity calculation is performed based on the window memory corresponding to its geometric center in the G×G grid. This specifically includes the following steps: b1: For each numbered Overlap block, calculate the geometric center position of its overlapping area, and determine the corresponding Window Memory Bank based on the position of the geometric center in the G×G grid as an index; When the geometric center of an overlap block is located on the common boundary of two adjacent grid spatial locations, it is assigned to the Window location with the larger row index or column index. b2: For the currently numbered Overlap block, obtain the set of feature vectors to be detected within its coverage area, and organize the set of feature vectors to be detected into a matrix form; Based on the Window Memory Bank corresponding to the Overlap block, a set of feature vectors for comparison is obtained. On the GPU, cosine similarity calculation is performed on the set of feature vectors to be detected and the set of feature vectors for comparison through parallel matrix operations to obtain a set of similarity comparison results corresponding to each feature vector to be detected in the current Overlap block. b3: For each of the aforementioned feature vectors to be detected, a parallel reduction operation is performed on the GPU to determine the corresponding similarity comparison result, and the maximum cosine similarity value is selected as the local similarity result of the feature vector to be detected within the coverage area of ​​the Overlap block. b4: Determine whether the feature vector to be detected is covered by multiple overlapping blocks with different numbers: When the feature vector to be detected is covered by only one overlap block, the local similarity result obtained within that overlap block is used as the cosine similarity data for scoring. max ; When the feature vector to be detected is covered by multiple overlapping blocks with different numbers, the local similarity result is calculated within the coverage area of ​​each overlapping block, and the maximum value among all local similarity results is selected as the cosine similarity data for scoring. max ; b5: Based on the aforementioned rating similarity data cosine max The anomaly score corresponding to the feature vector to be detected is calculated using the following formula: Anomaly Score= 1- cosine max 。 5. The defect detection method for industrial products according to claim 4, characterized in that: In step S6, the abnormal color is calculated as follows: color = JET((AnomalyScore - v) min ) / (v max - v min ) ); In the formula, color is the RGB value corresponding to the abnormal color, JET() is a predefined pseudo-color mapping function; AnomalyScore is the anomaly score corresponding to the feature vector to be detected; v min v is the minimum of all anomaly scores included in the image to be detected; max This is the maximum value among all anomaly scores included in the image to be detected.