A pseudo-anomaly enhancement method based on a SegAug visual segmentation model and related devices
By generating pseudo-anomalies using the SegAug visual segmentation model and combining self-supervised learning with a multi-class classifier, the limitations of logical anomaly detection in visual anomaly detection are solved, and efficient global anomaly detection for multi-component products is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XI AN JIAOTONG UNIV
- Filing Date
- 2024-07-19
- Publication Date
- 2026-08-04
AI Technical Summary
Existing visual anomaly detection methods have limitations in handling logical anomalies, especially in multi-component products, where they struggle to detect high-level semantic global differences and violations of logical or geometric constraints.
A pseudo-anomaly enhancement method based on the SegAug visual segmentation model is adopted. By generating component masks and background masks, a multi-class classifier is constructed for self-supervised learning to generate paste-type, fill-type, and scar-type pseudo-anomalies. Combining local and global feature detection, local and global anomaly scores are calculated.
It significantly improves the detection performance of global high-level semantic and logical anomalies, effectively identifies structural and logical anomalies, and enhances the model's detection capabilities.
Smart Images

Figure CN118823002B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of visual anomaly detection technology, specifically relating to a pseudo-anomaly enhancement method and related apparatus based on the SegAug visual segmentation model. Background Technology
[0002] Visual anomaly detection is crucial for automated industrial quality inspection systems, aiming to identify anomalies or abnormal patterns in images. In actual industrial manufacturing, most products are typical normal products, making it extremely difficult to collect a sufficient variety and quantity of anomaly samples within a short timeframe. Therefore, supervised models that rely on anomaly samples are unsuitable for anomaly detection. In contrast, unsupervised models focus solely on the distribution of normally distributed samples. Ideally, any deviation from this distribution can be classified as anomaly, thus being less constrained by unknown anomaly forms. Therefore, unsupervised models are more suitable for anomaly detection scenarios in industry.
[0003] While unsupervised methods are better suited for anomaly detection, in practice, the lack of supervision over real anomalies often makes it difficult for models to automatically extract meaningful features. Therefore, it is necessary to incorporate domain-specific prior knowledge into the model to improve its performance. There are two main approaches to industrial visual anomaly detection: reconstruction-based and feature-based methods.
[0004] In reconstruction-based methods, models trained on normal samples can successfully reconstruct normal patterns, but when dealing with anomalous parts, these parts are difficult to reconstruct as normal patterns. Therefore, reconstruction error can be used as an anomaly indicator. However, the network's broad generalization ability to anomalies may lead to the reconstruction of anomalies, thereby reducing the discriminability of anomalies. Considering that anomalies in previous industrial inspections often manifest as structural anomalies, i.e., the appearance of entirely new local structures, such as scratches or stains, which do not exist in the training dataset, researchers have found that by introducing synthetic textures as pseudo-anomalies into normal samples and then using denoising techniques to train the reconstruction network, the performance of anomaly detection can be significantly improved.
[0005] For feature-based methods, current industrial anomaly detection methods primarily use pre-trained networks supervised on ImageNet as feature extractors. The pre-trained network projects training set samples into a feature space, then establishes a normal distribution. This distribution is typically represented using a Gaussian distribution, a feature library, or Normalized Flow (NF). Anomaly scores are then calculated by evaluating the distance between the features of test samples and the established normal distribution. Another feature-based anomaly detection method utilizes self-supervised learning, avoiding direct feature extraction using pre-trained networks on ImageNet. Instead, the network learns features of normal samples using synthetic textures. This network is then used as a feature extractor to establish a feature distribution for normal samples.
[0006] While using synthetic textures as pseudo-anomalies can significantly improve anomaly detection performance, these methods have limitations when handling logical anomalies. Logical anomalies typically do not manifest as local texture variations but rather as high-level, global semantic differences, such as images violating certain fundamental logical or geometric constraints present in the training dataset. Figure 1 As shown. Furthermore, while previous research has yielded promising results in detecting structural anomalies in single objects, in multi-component products, each component exhibits a degree of rotational variation. When these components combine, they produce numerous different patterns and textures. Texture differences between normal samples within the same category can be significant, making it difficult to determine product normality based solely on texture variations. In practical applications, many standard forms are often composed of multiple components, rendering structural anomaly detection using synthetic textures ineffective. Summary of the Invention
[0007] The technical problem this invention aims to solve is to address the shortcomings of the prior art by providing a pseudo-anomaly enhancement method and related apparatus based on the SegAug visual segmentation model. By introducing pseudo-anomalies, the model's detection capability can be effectively improved. This invention proposes a pseudo-anomaly enhancement method based on the SegAug visual segmentation model, which can effectively enhance the model's ability to detect global high-level semantic logic anomalies, thus solving the technical problem of low model performance due to the lack of real anomaly samples in visual anomaly detection tasks.
[0008] The present invention adopts the following technical solution:
[0009] A pseudo-anomaly enhancement method based on the SegAug visual segmentation model includes the following steps:
[0010] S1. The training set samples composed of normal images are segmented using the SegAug visual segmentation model to obtain component masks and background masks. Using the component masks and background masks of each training set sample, three types of pseudo-anomalies are generated by pasting, filling, and introducing scars.
[0011] S2. Construct a multi-class classifier to promote self-supervised learning. Mix normal samples and pseudo-abnormal samples for training and extract deep feature information containing local texture features and global high-level semantic features.
[0012] S3. Based on the deep feature information obtained in step S2, construct a local feature distribution for local anomaly detection to identify structural anomalies, construct a global feature distribution for global information capture to identify logical anomalies, and calculate the local anomaly score and the global anomaly score.
[0013] S4. Based on the local anomaly score and global anomaly score obtained in step S3, define the anomaly score of the test image to complete the pseudo-anomaly enhancement.
[0014] Preferably, in step S1, the component mask and the background mask are respectively:
[0015] Given a training set X of normal images, use the training samples X i Adjust the value to h×w and input it into the SegAug visual segmentation model for segmentation to obtain the mask set.
[0016] Based on the area of the minimum bounding rectangle, the mask set By filtering the masks with smaller areas, we obtain M. i ;
[0017] Background mask B i At least one pair of diagonals in each of the four corners contains pixel distributions, and the remaining masks constitute a component mask set. For mask set Each mask in the array is subjected to morphological opening operations, resulting in C. i For C i Each mask in Calculate the area of the minimum bounding rectangle of the s-th contour, and express the maximum area as... Finally, the mask with the largest area... Specify the background mask, apply the above operation to each training set sample, and obtain the background mask B and the component mask set C.
[0018] Preferably, in step S1, generating three types of pseudo-anomalies—paste-type, fill-type, and scar-type—using the component mask and background mask of each training set sample specifically involves:
[0019] In each iteration, a mask is randomly selected from the component mask set C of each training sample X; then, the region corresponding to the mask is segmented in the original image, and the edges of the segmented region are smoothed. Subsequently, x is determined by the minimum bounding rectangle of the background mask B. seg The new coordinates of the center within X, and finally x seg Pasting it into the original image yields a pasted pseudo-anomaly X. pasting ;
[0020] For each sample in each iteration, a mask is randomly selected from the component mask set; then, the region corresponding to the mask is filled with image patches randomly selected from the image, resulting in a filled X. filling False anomalies;
[0021] For each sample in each iteration, a component mask is randomly selected from set C, its minimum bounding rectangle is calculated, and a parallelogram of random shape is generated. Image patches are then filled within this region to obtain the scar-type pseudo-anomaly X. scar .
[0022] Preferably, the pseudo-abnormalities of the pasting type, the pseudo-abnormalities of the filling type, and the pseudo-abnormalities of the scar type are as follows:
[0023] X pasting =Q1(X, B, C)
[0024] X filling =Q2(X, C)
[0025] X scar =Q3(X, C)
[0026] Where X represents a training sample, B represents a background mask, C represents a component mask, Q1 represents pasting the original image region X corresponding to the random component mask C at its coordinates relative to the background mask B, Q2 represents filling the region corresponding to the random component mask C with random image blocks from the original image X, and Q3 represents generating a random parallelogram in the minimum bounding rectangle of the random component mask C and filling the region with image blocks.
[0027] Preferably, in step S2, ResNet-18 is used as the feature extractor for a multi-class classifier, and a multilayer perceptron with two hidden layers is combined for classification, with multi-class cross-entropy used as the loss function.
[0028] Preferably, the training objective of self-supervised learning is defined as follows:
[0029] L=E X∈X {L(I(X),0)+L(I(Q1(X)),1)+L(I(Q2(X)),2)+L(I(Q3(X)),3)}
[0030] Where L(·,·) represents the multi-class cross-entropy loss function, and I(·) represents image preprocessing.
[0031] Preferably, in step S3, the local branch uses the PatchCore anomaly detection structure, the global branch uses the feature extractor trained in the self-supervised learning task to extract global features, and the anomaly score is determined by the Mahalanobis distance between each test image and the normal distribution.
[0032] Preferably, the test image X test Local anomaly score A local (X test )for:
[0033]
[0034] Where, N k (X * ) indicates that the test patch feature X in M is related to this. * The k nearest patch features, where θ represents the corresponding nearest neighbor of the patch feature in the test image in M, X * To test patch features;
[0035] Global anomaly score A global (X test )for:
[0036]
[0037] in, This indicates that global adaptive average pooling is used to preserve global information, where μ is the mean of the global information and ∑ is the covariance.
[0038] Preferably, in step S4, the anomaly score A(X) of the test image is... test )for:
[0039] A(X test )=αA local (X test )+βA global (X test )
[0040] Where α=β=1, A local (X test ) represents the local anomaly score, A global (X test ) represents the global anomaly score.
[0041] Secondly, embodiments of the present invention provide a pseudo-anomaly enhancement system based on the SegAug visual segmentation model, comprising:
[0042] The segmentation module segments the training set samples composed of normal images using the SegAug visual segmentation model to obtain component masks and background masks. Using the component masks and background masks of each training set sample, three types of pseudo-anomalies are generated through pasting, filling, and introducing scars.
[0043] The learning module constructs a multi-class classifier based on three types of pseudo-anomalies: paste, fill, and scar, to promote self-supervised learning. Normal samples and pseudo-anomaly samples are mixed and fed into the training to extract deep feature information containing local texture features and global high-level semantic features.
[0044] The distribution module constructs a local feature distribution for local anomaly detection to identify structural anomalies based on deep feature information, and constructs a global feature distribution for global information capture to identify logical anomalies, and calculates the local anomaly score and the global anomaly score.
[0045] The output module defines the anomaly score of the test image based on the local anomaly score and the global anomaly score, and completes the pseudo-anomaly enhancement.
[0046] Thirdly, a computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the pseudo-anomaly enhancement method based on the SegAug visual segmentation model described above.
[0047] Fourthly, embodiments of the present invention provide a computer-readable storage medium including a computer program, which, when executed by a processor, implements the steps of the above-described pseudo-anomaly enhancement method based on the SegAug visual segmentation model.
[0048] Compared with the prior art, the present invention has at least the following beneficial effects:
[0049] A pseudo-anomaly augmentation method based on the SegAug visual segmentation model is proposed. By introducing a novel data augmentation method and combining it with a self-supervised learning task, a new anomaly detection framework is put forward. This framework comprehensively detects anomalies from both local and global perspectives. While effectively detecting structural anomalies, it significantly improves the detection performance of global and high-level semantic logic anomalies that violate certain basic logical or geometric constraints.
[0050] Furthermore, component masks can highlight specific components or regions in an image, allowing the model to focus on learning the features of these regions. Background masks can allow the model to mask or ignore background regions in the image that are irrelevant to the features, thereby focusing attention on component features and improving the model's ability to detect component defects.
[0051] Furthermore, pasted pseudo-anomalies simulate repetitive or foreign object phenomena that may occur on the surface of components in reality by pasting a part of a normal component to other parts, which can enhance the model's sensitivity to local anomalies and increase the diversity of training samples. Filled pseudo-anomalies simulate damage or contamination that may occur on the surface of components by filling a part of the component with other patterns, which can improve the model's ability to detect destructive anomalies and reduce overfitting. Scar-like pseudo-anomalies simulate scratches or cracks that may occur on the surface of components by generating scar-like lines or patterns on the surface of components, which can enhance the model's sensitivity to linear anomalies and also increase the diversity of anomalous samples.
[0052] Furthermore, in self-supervised learning tasks, the residual structure of the ResNet-18 feature extractor helps alleviate the vanishing gradient problem, allowing the network to be trained deeper and capture more complex features. Using a multilayer perceptron with two hidden layers allows the features extracted by ResNet-18 to be further mapped to a higher-dimensional feature space, facilitating the capture of more complex patterns and relationships and improving the classifier's expressive power. The multi-class cross-entropy loss function effectively handles multi-class classification problems, enabling the model to have higher accuracy in distinguishing different categories. Self-supervised learning tasks can effectively utilize unlabeled data to train the model to learn discriminative features.
[0053] Furthermore, setting the training objectives for self-supervised learning is crucial for the model to effectively learn and extract useful features even without a large amount of labeled data. Self-supervised learning, by designing specific pre-training tasks, enables the model to train on unlabeled data, thereby reducing the need for large amounts of labeled data; it allows the model to learn general representations of the data, enhancing its generalization ability; and it helps the model learn more diverse feature representations, improving the accuracy of anomaly detection.
[0054] Furthermore, in the local branch, the PatchCore anomaly detection structure captures fine-grained local anomaly features by segmenting the image locally and analyzing each small patch. It utilizes a memory-based method to store feature representations of normal samples, efficiently storing a large number of normal sample features in memory and reducing computational resource consumption. In the global branch, the Mahalanobis distance metric performs well in high-dimensional spaces, capturing the correlation and distribution characteristics between samples. Obtaining anomaly scores through this method improves detection accuracy. The feature extractor trained on a self-supervised learning task can learn global features including overall structure and high-level semantic information, which is significant for detecting logical anomalies.
[0055] Furthermore, the anomaly score of the test image represents the degree of deviation of the test image from the normal sample. This quantification makes anomaly detection more intuitive and interpretable.
[0056] It is understandable that the beneficial effects of the second aspect mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here.
[0057] In summary, this invention overcomes the shortcomings of previous studies that relied solely on synthetic textures to enhance the local representation of the model while neglecting the global representation, and provides a novel and effective method for detecting complex industrial anomalies that simultaneously contain structural and logical defects.
[0058] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0059] Figure 1 This is a diagram comparing logical anomalies and structural anomalies.
[0060] Figure 2 A schematic diagram of morphological opening operations;
[0061] Figure 3 Diagram showing mask selection;
[0062] Figure 4 This is a diagram illustrating a pseudo-anomaly.
[0063] Figure 5 A schematic diagram of the SegAug visual segmentation model;
[0064] Figure 6 A schematic diagram of a computer device provided in an embodiment of the present invention;
[0065] Figure 7 This is a block diagram of an electronic device according to an embodiment of the present invention;
[0066] Figure 8 This is a flowchart of the method of the present invention. Detailed Implementation
[0067] 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, not all, of the embodiments of the present invention. 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.
[0068] In the description of this invention, it should be understood that the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.
[0069] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.
[0070] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Additionally, the character " / " in this invention generally indicates that the preceding and following objects have an "or" relationship.
[0071] It should be understood that although terms such as first, second, third, etc., may be used in the embodiments of the present invention to describe the preset range, these preset ranges should not be limited to these terms. These terms are only used to distinguish the preset ranges from one another. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.
[0072] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."
[0073] The accompanying drawings illustrate various structural schematic diagrams according to embodiments disclosed in this invention. These drawings are not to scale, and some details have been enlarged for clarity, and some details may have been omitted. The shapes of the various regions and layers shown in the drawings, as well as their relative sizes and positional relationships, are merely exemplary and may deviate from reality due to manufacturing tolerances or technical limitations. Furthermore, those skilled in the art can design regions / layers with different shapes, sizes, and relative positions as needed.
[0074] This invention provides a pseudo-anomaly enhancement method based on the SegAug visual segmentation model. It establishes local and global feature distributions of training samples based on embedding information extracted from the network through self-supervised learning. Then, it comprehensively evaluates the anomaly score of the test sample by calculating the distance between the embedding of the test sample and the local and global normal distributions established through self-supervised learning. This method overcomes the shortcomings of previous methods that relied solely on synthetic textures to enhance local model representations while neglecting global representations, providing a novel approach for anomaly detection in more complex industrial scenarios. This invention achieved state-of-the-art performance in the challenging industry anomaly detection benchmark MVTecLocoAD, demonstrating its effectiveness.
[0075] Please see Figure 8This invention discloses a pseudo-anomaly enhancement method based on the SegAug visual segmentation model, comprising the following steps:
[0076] S1. The training set samples composed of normal images are segmented using the SegAug visual segmentation model to obtain component masks and background masks. The component masks and background masks of each training set sample are used to generate three types of pseudo-anomalies: paste, fill, and scar.
[0077] S101. Select component mask and background mask.
[0078] Given a training set of normal images First, the training sample X... i Adjust the value to h×w and input it into the SegAug visual segmentation model for segmentation to obtain the mask set.
[0079] The following criteria are used to determine the component mask set and background mask:
[0080] 1) Adjust the mask set according to the area of the minimum bounding rectangle. By filtering the masks with smaller areas, we obtain M. i ;
[0081] x m ,y m ,w m ,h m =F(m) (1)
[0082] w m ·h m >α (2)
[0083] Wherein, F(·) is used to calculate the coordinates of the minimum boundary rectangle in the mask. In this invention, the hyperparameter α is set to 500.
[0084] 2) In background mask B i In the middle, at least one pair of pixels exists in the two corners of the diagonal;
[0085] The pixel distribution is as follows:
[0086]
[0087] Where v(i,j) represents the pixel value at (i,j), and in this invention, the hyperparameters d and β are set to 15 and 150, respectively. Meanwhile, the remaining masks constitute the component mask set.
[0088] 3) In some cases, the SegAug visual segmentation model may fail to effectively separate the background mask of a specific image. The method of this invention primarily relies on obtaining approximate object locations in the image, rather than requiring an accurate background mask. When the background mask B is not selected according to condition 2), i At that time, for the set Each mask in the array is subjected to morphological opening operations, and the result is obtained. This smooths the object's outline, separates narrow necks, and eliminates elongated protrusions, such as Figure 2 As shown.
[0089] Therefore, for C i Each mask in Calculate the minimum bounding rectangle of the s-th contour. The area is given, and the largest area is represented as... Finally, the largest area mask Specifying it as the background mask, it is represented as:
[0090]
[0091] Where A(·) is used to calculate the area of the minimum boundary rectangle of the contour, for example as follows: Figure 3 As shown.
[0092] Subsequently, these operations are applied to each training set sample to obtain the background mask B = {B1, B2, ..., B}. n} and component mask set C = {C1, C2, ..., C n}, to generate pseudo-exceptions.
[0093] S102, Data Augmentation
[0094] For each training sample, three types of pseudo-anomalies are generated using its component mask set and background mask.
[0095] S1021, Paste
[0096] In each iteration, a mask is randomly selected from the component mask set C of each training sample X; then the region corresponding to the mask is segmented in the original image, and the edges of the segmented region are smoothed.
[0097] x seg =S(X, R(C)) (5)
[0098] Where R(·) represents randomly selecting a component mask from C, and S(·,·) represents segmenting the object corresponding to the mask in the sample X.
[0099] Subsequently, x is determined using the minimum bounding rectangle of the background mask B. segThe new coordinates of the center within X.
[0100] x b y b w b h b =F(B) (6)
[0101] x p ∈[x b +x bias x b +w b -x bias (7)
[0102] y p ∈[y b +y bias y b +h b -y bias (8)
[0103] Among them, (x p y p () represents the coordinates of the component's center, x bias and y bias These represent the offsets of the x and y coordinates, respectively.
[0104] Finally, x seg Pasting it into the original image will result in the following:
[0105] X pasting =Q1(X, B, C) (9)
[0106] S1022, Filling
[0107] Similar to the paste-type pseudo-anomaly, for each sample in each iteration, a mask is randomly selected from its component mask set; subsequently, the region corresponding to the mask is filled with an image patch randomly selected from the image, represented as:
[0108] X filling =Q2(X, C) (10)
[0109] S1023, Scars
[0110] Introducing minute anomalies facilitates fine-grained learning; therefore, this invention proposes a component mask-guided method. For each sample in each iteration, a component mask is randomly selected from set C, its minimum bounding rectangle is calculated, and a parallelogram of random shape is generated. Image patches are then filled within this region, as shown below:
[0111] X scar =Q3(X, C) (11)
[0112] Please see Figure 4 The three types of pseudo-anomalies are: paste-type pseudo-anomalies, fill-type pseudo-anomalies, and scar-type pseudo-anomalies. The first line displays the input normal sample and the selected component mask, while lines 2, 3, and 4 show the three types of pseudo-anomaly samples generated under this input sample.
[0113] S2. Construct a multi-class classifier to promote self-supervised learning and extract representative deep features;
[0114] Extracting representative deep features is crucial for anomaly detection, thus requiring a well-defined pre-training task for self-supervised representation learning. In this invention, a multi-class classifier is constructed to facilitate self-supervised learning within this task.
[0115] Using ResNet-18 as the feature extractor and combining it with a multilayer perceptron (MLP) with two hidden layers for classification, and employing multi-class cross-entropy as the loss function, the training objective of the proposed self-supervised learning is defined as follows:
[0116] L=E X∈X {L(I(X),0)+L(I(Q1(X)),1)+L(I(Q2(X)),2)+L(I(Q3(X)),3)} (12)
[0117] Where L(·,·) is the multi-class cross-entropy loss function, and I(·) represents image preprocessing, including resizing, normalization and other operations.
[0118] S3. Based on the feature information obtained from self-supervised learning, construct the local feature distribution for local anomaly detection to identify structural anomalies and the global feature distribution for global information capture to identify logical anomalies, and calculate the local and global anomaly scores.
[0119] Structural anomalies are novel visual structures that appear within local regions and are not present in anomaly-free data. In contrast, logical anomalies typically violate underlying logical constraints in the data, requiring the establishment of long-range data modeling. Therefore, this invention constructs two branches: a local branch and a global branch.
[0120] Local branch modeling utilizes local sample information for local anomaly detection.
[0121] Global branches capture global data information to identify anomalies caused by violations of logical constraints.
[0122] S301, Local Branch
[0123] Please see Figure 5For the design of local branches, this invention adopts the anomaly detection structure of PatchCore. PatchCore utilizes a feature extractor to extract features from the training set X = {X1, X2, ..., X...}. n Patch-level features are extracted from normal samples in the dataset. Because patch-level features are very rich, core set subsampling is applied to the memory M. During anomaly detection, the test image X... test Image-level anomaly score test The test patch feature P(φ) in its patch set l (X test The maximum distance score s between the nearest neighbor θ in memory M and the corresponding nearest neighbor θ is s. test,* Determined, where φ l (·) indicates that features are extracted from the l-th layer.
[0124]
[0125] s test,* =||X test,* -X * ||2 (14)
[0126] According to PatchCore, for s test,* Perform a scaling test:
[0127]
[0128] Where, N k (X * ) indicates that the test patch feature X in M is related to this. * The k nearest patch features.
[0129] The method of this invention can effectively identify local anomalies. This invention uses a self-supervised learning network instead of a feature extractor to extract more discriminative features. In this task, the test image X... test The local anomaly score is represented as s test .
[0130]
[0131] Where, N k (X * ) indicates that the test patch feature X in M is related to this. * The k nearest patch features.
[0132] S302, Global Branch
[0133] The global branch represents the global features of the sample. The feature extractor extracts global features from the training samples and establishes a Gaussian distribution for these features, such as... Figure 5As shown. During the test, the anomaly score is calculated by measuring the distance between the features of the test sample and the Gaussian distribution.
[0134] The specific approach involves using a feature extractor trained on a self-supervised task to extract global features, such as... Figure 5 As shown:
[0135] Feature information is extracted from each normal sample in the training set from layer 4; global adaptive average pooling is used to preserve global information. The Gaussian distribution G(μ,∑) is used to model the global information of normal samples, where μ is the mean of the global information, and the covariance ∑ is estimated as follows:
[0136]
[0137] The outlier score is determined using the Mahalanobis distance between each test image and the normal distribution, where D(X) test The calculation is as follows:
[0138]
[0139] And this abnormal score will be treated as a global abnormal score:
[0140]
[0141]
[0142] in, This indicates that global adaptive average pooling is used to preserve global information.
[0143] S4. Define the anomaly score of the test image based on local and global anomaly scores.
[0144] Based on the above, the corresponding global and local anomaly scores are calculated respectively. The anomaly score of the test image is defined as follows:
[0145] A(X test )=αA local (X test )+βA global (X test ) (twenty one)
[0146] In this invention, α = β = 1.
[0147] Those skilled in the art will understand that various aspects of the present invention can be implemented as systems, methods, or program products. Therefore, various aspects of the present invention can be specifically implemented in the following forms: a completely hardware implementation, a completely software implementation (including firmware, microcode, etc.), or a combination of hardware and software aspects, collectively referred to herein as a "circuit," "module," or "platform."
[0148] In another embodiment of the present invention, a pseudo-anomaly enhancement system based on the SegAug visual segmentation model is provided. This system can be used to implement the above-mentioned pseudo-anomaly enhancement method based on the SegAug visual segmentation model. Specifically, the pseudo-anomaly enhancement system based on the SegAug visual segmentation model includes a segmentation module, a learning module, a distribution module, and an output module.
[0149] The segmentation module segments the training set samples composed of normal images using the SegAug visual segmentation model to obtain component masks and background masks. Using the component masks and background masks of each training set sample, three types of pseudo-anomalies are generated through pasting, filling, and introducing scars.
[0150] The learning module constructs a multi-class classifier based on three types of pseudo-anomalies: paste, fill, and scar, to promote self-supervised learning. Normal samples and pseudo-anomaly samples are mixed and fed into the training to extract deep feature information containing local texture features and global high-level semantic features.
[0151] The distribution module constructs a local feature distribution for local anomaly detection to identify structural anomalies based on deep feature information, and constructs a global feature distribution for global information capture to identify logical anomalies, and calculates the local anomaly score and the global anomaly score.
[0152] The output module defines the anomaly score of the test image based on the local anomaly score and the global anomaly score, and completes the pseudo-anomaly enhancement.
[0153] In another embodiment of the present invention, a terminal device is provided, comprising a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to implement a corresponding method flow or corresponding function. The processor described in this embodiment can be used for the operation of a pseudo-anomaly enhancement method based on the SegAug visual segmentation model, including:
[0154] The SegAug visual segmentation model is used to segment training set samples composed of normal images to obtain component masks and background masks. Using the component and background masks of each training set sample, three types of pseudo-anomalies are generated through pasting, filling, and introducing scars. A multi-class classifier is constructed to promote self-supervised learning. Normal samples and pseudo-anomaly samples are mixed and fed into the training to extract deep feature information containing local texture features and global high-level semantic features. Based on the deep feature information, a local feature distribution for local anomaly detection to identify structural anomalies and a global feature distribution for global information capture to identify logical anomalies are constructed. Local anomaly scores and global anomaly scores are calculated. Based on the local and global anomaly scores, anomaly scores are defined for the test image to complete the pseudo-anomaly enhancement.
[0155] In another embodiment of the present invention, a storage medium is provided, specifically a computer-readable storage medium (Memory), which is a memory device in a terminal device for storing programs and data. It is understood that the computer-readable storage medium here can include both built-in storage media in the terminal device and extended storage media supported by the terminal device; it can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium provides storage space that stores the terminal's operating system. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor, which can be one or more computer programs (including program code). It should be noted that more specific examples (a non-exhaustive list) of the computer-readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0156] Computer-readable storage media also include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium can also be any readable medium other than a readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination thereof.
[0157] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages such as Java and C++, and conventional procedural programming languages such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0158] One or more instructions stored in a computer-readable storage medium can be loaded and executed by a processor to implement the corresponding steps of the pseudo-anomaly enhancement method based on the SegAug visual segmentation model in the above embodiments; one or more instructions in the computer-readable storage medium are loaded and executed by the processor to perform the following steps:
[0159] The SegAug visual segmentation model is used to segment training set samples composed of normal images to obtain component masks and background masks. Using the component and background masks of each training set sample, three types of pseudo-anomalies are generated through pasting, filling, and introducing scars. A multi-class classifier is constructed to promote self-supervised learning. Normal samples and pseudo-anomaly samples are mixed and fed into the training to extract deep feature information containing local texture features and global high-level semantic features. Based on the deep feature information, a local feature distribution for local anomaly detection to identify structural anomalies and a global feature distribution for global information capture to identify logical anomalies are constructed. Local anomaly scores and global anomaly scores are calculated. Based on the local and global anomaly scores, anomaly scores are defined for the test image to complete the pseudo-anomaly enhancement.
[0160] Please see Figure 6 The terminal device is a computer device. In this embodiment, the computer device 60 includes a processor 61, a memory 62, and a computer program 63 stored in the memory 62 and executable on the processor 61. When executed by the processor 61, the computer program 63 implements the fluid composition calculation method in the reservoir stimulation wellbore of this embodiment. To avoid repetition, these details are not elaborated here. Alternatively, when executed by the processor 61, the computer program 63 implements the functions of each model / unit in the fluid composition calculation system in the reservoir stimulation wellbore of this embodiment. To avoid repetition, these details are not elaborated here.
[0161] Computer device 60 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. Computer device 60 may include, but is not limited to, a processor 61 and a memory 62. Those skilled in the art will understand that... Figure 6 This is merely an example of computer device 60 and does not constitute a limitation on computer device 60. It may include more or fewer components than shown, or combine certain components, or different components. For example, computer device may also include input / output devices, network access devices, buses, etc.
[0162] The processor 61 may be a central processing unit (CPU), or other general-purpose processors, CPUs, graphics processing units (GPUs), digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, quantum computing-based data processing logic units, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0163] The memory 62 can be an internal storage unit of the computer device 60, such as a hard disk or RAM of the computer device 60. The memory 62 can also be an external storage device of the computer device 60, such as a plug-in hard disk, Smart Media Card (SMC), Secure Digital (SD) card, Flash Card, etc., equipped on the computer device 60.
[0164] Furthermore, the memory 62 may include both internal storage units of the computer device 60 and external storage devices. The memory 62 is used to store computer programs and other programs and data required by the computer device. The memory 62 can also be used to temporarily store data that has been output or will be output.
[0165] Any references to memory, databases, or other media used in the embodiments provided in this application may include at least one of non-volatile and volatile memory. Non-volatile memory may include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetic random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory may include random access memory (RAM) or external cache memory, etc. By way of illustration and not limitation, RAM may be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM), etc.
[0166] The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.
[0167] Please see Figure 7 The terminal device 600 is an electronic device, which takes the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different platform components (including storage unit 620 and processing unit 610), a display unit 640, etc.
[0168] The storage unit stores program code, which can be executed by the processing unit 610 to perform the steps described in the method section of this specification according to various exemplary embodiments of the present invention. For example, the processing unit 610 can perform actions such as... Figure 1 The steps are shown in the figure.
[0169] Storage unit 620 may include a readable medium in the form of a volatile storage unit, such as random access memory (RAM) 6201 and / or cache memory 6202, and may further include a read-only memory (ROM) 6203.
[0170] Storage unit 620 may also include a program / utility 6204 having a set (at least one) program module 6205, such program module 6205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.
[0171] Bus 630 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the multiple bus structures.
[0172] Electronic device 600 can also communicate with one or more external devices 700 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 600, and / or with any device that enables electronic device 600 to communicate with one or more other computing devices (e.g., router, modem, etc.). This communication can be performed via input / output (I / O) interface 650. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 660. Network adapter 660 can communicate with other modules of electronic device 600 via bus 630. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.
[0173] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, 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, not all, of the embodiments of the present invention. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.
[0174] Example
[0175] The operation of the pseudo-anomaly enhancement method based on the SegAug visual segmentation model includes the following steps:
[0176] 1. Data Preprocessing
[0177] Data loading: Load raw image data and corresponding labels from memory.
[0178] Data augmentation: Performing various data augmentation operations on images, such as rotation, scaling, and flipping, to increase the diversity of the data.
[0179] 2. Generate pseudo-anomaly data
[0180] Generate component and background masks: Using the SegAug visual segmentation model, generate component and background masks to identify important regions and background regions in the image based on the input image.
[0181] Generate pseudo-exceptions:
[0182] Paste-type pseudo-exception: Copy and paste certain parts of the component mask to random positions in the component mask to simulate a paste-type pseudo-exception.
[0183] Fill-type pseudo-anomalies: Randomly fill the component mask with other image blocks to simulate fill-type pseudo-anomalies.
[0184] Scar-type pseudo-anomaly: Add randomly shaped scars to the component mask to simulate a scar-type pseudo-anomaly.
[0185] 3. Feature Extraction
[0186] Feature extraction: The processor uses a pre-trained ResNet-18 feature extractor to process the original image and the pseudo-anomaly image to extract feature representations.
[0187] 4. Model Training
[0188] Loss function calculation: Calculate the multi-class cross-entropy loss function to guide model training.
[0189] Backpropagation and optimization: Execute the backpropagation algorithm to update the model parameters based on the gradient of the loss function.
[0190] 5. Model Evaluation and Optimization
[0191] Performance evaluation: The processor evaluates the model's performance based on the validation set data, calculating metrics such as accuracy, recall, and F1 score.
[0192] Model optimization: Based on the evaluation results, adjust the model structure or training parameters to further optimize model performance.
[0193] 6. Reasoning and Detection
[0194] Load and execute the model: Load the trained anomaly detection model and perform inference on the new input image.
[0195] Anomaly detection: The processor calculates the anomaly scores of local and global branches to obtain the anomaly score of the test image, and determines whether the input image contains anomalies.
[0196] 7. Results Output
[0197] Generate report: Generate a detection report, including anomaly score, anomaly type, location information, etc.
[0198] Visualization displays bring the test results to life, making them easy for users to view and analyze.
[0199] experiment
[0200] Dataset
[0201] To evaluate the method of this invention, the selected dataset covered both logical and structural anomalies. The area under the receiver operating characteristic (ROC) curve (AUC) was used as the evaluation metric.
[0202] MVTecLOCOAD
[0203] The MVTecLOCOAD dataset was introduced primarily to address the problem of simultaneous occurrence of structural and logical anomalies in industrial anomaly detection. To clearly illustrate the difference between logical and structural anomalies, some examples are provided below. Figure 1 As shown. This dataset contains five categories and a total of 1772 normal images for training. The test set includes 57 normal images, 432 images with structural abnormalities, and 56 images with logical abnormalities. For each category, the test set contains normal, logically abnormal, and structurally abnormal images.
[0204] Co-occurrence anomaly detection screw dataset (CAD-SD)
[0205] Logical anomalies in CAD-SD are referred to as "co-occurrence anomalies." This dataset contains 400 normal training images, while the test set includes 21 normal images and 8 images with structural anomalies, primarily showing scratches and paint problems. Additionally, 84 images depict logical anomalies, which can be categorized into two types: over-coupling and missing elements. Some examples are shown below. Figure 1 As shown.
[0206] Experimental conditions
[0207] Image sizes were resized to 256×256. The SAM model “ViT_h” was used for image segmentation. For each class dataset, the model was trained for 200 epochs using an SGD optimizer with a learning rate of 0.03 and a batch size of 32. All experiments were implemented on PyTorch 1.13.0 with an NVIDIA 3050.
[0208] Experimental results
[0209] The SegAug visual segmentation model of this invention was compared with reconstruction-based models DRAEM, THF, AST, feature-based models PatchCore, self-supervised model CutPaste, and the model GCAD specifically designed for logical anomaly detection. Results from the MVTecLOCOAD and CAD-SD datasets are shown in Tables 1 and 2, respectively.
[0210] Table 1. Quantitative comparison of image-level detection results (AUROC%) on the MVTecLOCOAD dataset
[0211]
[0212]
[0213] Table 1 compares the results of the proposed method with other existing models on the MVTecLOCOAD dataset for anomaly detection tasks, i.e., image-level detection results. It can be seen that the proposed method outperforms existing methods by 34.6% in the detection of logical anomalies and by 18.3% in the detection of structural anomalies.
[0214] Table 2. Quantitative comparison of image-level detection results (AUROC%) on the CAD-SD dataset
[0215]
[0216] Table 2 compares the results of the method of the present invention with those of other existing models on the CAD-SD dataset for image-level detection. As can be seen, the method of the present invention achieves better results in the image-level detection task.
[0217] This invention solves the problem of generating pseudo-anomalies from logical anomaly types; by introducing a new data augmentation method and combining it with a self-supervised learning task, it proposes an anomaly detection framework that comprehensively detects anomalies from both local and global perspectives; it overcomes the limitations of previous studies that relied solely on synthetic textures to enhance local model representations while ignoring global representations, providing a new method for anomaly detection in more complex real-world industrial scenarios; and it achieves state-of-the-art results on the MVTECLOCOAD dataset, confirming its effectiveness.
[0218] In summary, this invention presents a pseudo-anomaly enhancement method and related apparatus based on the SegAug visual segmentation model, incorporating three different pseudo-anomalies. The proposed pseudo-anomaly data augmentation method breaks away from previous research that relied solely on synthetic texture enhancement of local model representations while neglecting global representations, providing a new approach for anomaly detection in more complex real-world industrial scenarios. Furthermore, it proposes an anomaly detection framework combining local and global features to perform local and global anomaly detection on samples. This method, through comprehensive evaluation of local and global anomalies, more closely approximates anomaly detection in real-world industrial scenarios. The method effectively improves the joint detection performance of structural and logical anomalies. State-of-the-art results were achieved on the challenging industry anomaly detection benchmark MVTECLOCOAD dataset, demonstrating the effectiveness of the proposed method.
[0219] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0220] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0221] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0222] In the embodiments provided by this invention, it should be understood that the disclosed devices / terminals and methods can be implemented in other ways. For example, the device / terminal embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0223] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0224] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0225] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0226] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0227] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0228] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0229] The above content is only for illustrating the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. Any modifications made to the technical solution based on the technical concept proposed in this invention shall fall within the scope of protection of the claims of this invention.
Claims
1. A pseudo-anomaly enhancement method based on the SegAug visual segmentation model, characterized in that, Includes the following steps: S1. The training set samples composed of normal images are segmented using the SegAug visual segmentation model to obtain component masks and background masks. Using the component masks and background masks of each training set sample, three types of pseudo-anomalies are generated by pasting, filling, and introducing scars. The component mask and background mask are as follows: Given a training set of normal images , training samples Adjusted to The data is then fed into the SegAug visual segmentation model for segmentation to obtain a mask set. ; Based on the area of the minimum bounding rectangle, the mask set By filtering the masks with small areas, we can obtain... ; Background mask At least one pair of diagonals in each of the four corners contains pixel distributions, and the remaining masks constitute a component mask set. ; For mask set Each mask in the array is subjected to morphological opening operations, and the result is obtained. ,for Each mask in Calculate the area of the minimum bounding rectangle of the s-th contour, and express the maximum area as... , Finally, use the mask with the largest area. Specify the background mask, apply the above operations to each training set sample, and obtain the background mask. and component mask ; The three types of pseudo-anomalies—paste-type, fill-type, and scar-type—are generated using the component mask and background mask of each training set sample, specifically as follows: In each iteration, from each training sample X Component mask C Randomly select a mask from the middle; Then, the region corresponding to the mask is segmented in the original image, and the edges of the segmented region are smoothed, followed by the background mask. B Determining the minimum boundary rectangle The center is X The new coordinates within will eventually be Pasting it into the original image produces a pasted pseudo-anomaly. ; For each sample in each iteration, a mask is randomly selected from the component masks; Then, image patches randomly selected from the image are used to fill the areas corresponding to the mask, resulting in a filled mask. False anomalies; For each sample in each iteration, from the component mask C A component mask is randomly selected, its minimum bounding rectangle is calculated, and a parallelogram of random shape is generated. Image patches are then filled within this region to obtain a scar-like pseudo-anomaly. ; The pseudo-abnormalities of adhesive type, filler type, and scar type are as follows: in, Indicates training samples, Indicates the background mask. Indicates the component mask. Indicates the random component mask Corresponding original image The region is pasted relative to its background mask. On the coordinates, This indicates the original image Fill random image blocks into a random component mask The corresponding area Indicates the random component mask Random parallelograms are generated within the minimum bounding rectangle, and image patches are filled in that region. S2. Construct a multi-class classifier to promote self-supervised learning. Mix normal samples and pseudo-abnormal samples for training to extract deep feature information containing local texture features and global high-level semantic features. Use ResNet-18 as the feature extractor of the multi-class classifier, and combine it with a multilayer perceptron with two hidden layers for classification. Use multi-class cross-entropy as the loss function. S3. Based on the deep feature information obtained in step S2, construct a local feature distribution for local anomaly detection to identify structural anomalies, construct a global feature distribution for global information capture to identify logical anomalies, and calculate the local anomaly score and the global anomaly score. S4. Based on the local anomaly score and global anomaly score obtained in step S3, define the anomaly score of the test image to complete the pseudo-anomaly enhancement.
2. The pseudo-anomaly enhancement method based on the SegAug visual segmentation model according to claim 1, characterized in that, The training objective of self-supervised learning is defined as follows: in, Represents the multi-class cross-entropy loss function. This indicates image preprocessing.
3. The pseudo-anomaly enhancement method based on the SegAug visual segmentation model according to claim 1, characterized in that, In step S3, the local branch uses the PatchCore anomaly detection structure, while the global branch uses the feature extractor trained in the self-supervised learning task to extract global features. The anomaly score is determined by the Mahalanobis distance between each test image and the normal distribution.
4. The pseudo-anomaly enhancement method based on the SegAug visual segmentation model according to claim 3, characterized in that, Test image Local anomaly score for: in, express Features of test patches The k nearest patch features, Indicates the patch features of the test image in The corresponding nearest neighbor, To test patch features; Global anomaly score for: in, This indicates that global adaptive average pooling is used to preserve global information. The mean of global information. For covariance.
5. The pseudo-anomaly enhancement method based on the SegAug visual segmentation model according to claim 1, characterized in that, In step S4, the anomaly score of the test image is... for: in, , Indicates the score of local anomalies. This represents the global anomaly score.
6. A pseudo-anomaly enhancement system based on the SegAug visual segmentation model, characterized in that, include: The segmentation module segments the training set samples composed of normal images using the SegAug visual segmentation model to obtain component masks and background masks. Using the component masks and background masks of each training set sample, three types of pseudo-anomalies are generated through pasting, filling, and introducing scars. The component mask and background mask are as follows: Given a training set of normal images , training samples Adjusted to The data is then fed into the SegAug visual segmentation model for segmentation to obtain a mask set. ; Based on the area of the minimum bounding rectangle, the mask set By filtering the masks with small areas, we can obtain... ; Background mask At least one pair of diagonals in each of the four corners contains pixel distributions, and the remaining masks constitute a component mask set. ; For mask set Each mask in the array is subjected to morphological opening operations, and the result is obtained. ,for Each mask in Calculate the area of the minimum bounding rectangle of the s-th contour, and express the maximum area as... , Finally, use the mask with the largest area. Specify the background mask, apply the above operations to each training set sample, and obtain the background mask. and component mask ; The three types of pseudo-anomalies—paste-type, fill-type, and scar-type—are generated using the component mask and background mask of each training set sample, specifically as follows: In each iteration, from each training sample X Component mask C Randomly select a mask from the middle; Then, the region corresponding to the mask is segmented in the original image, and the edges of the segmented region are smoothed, followed by the background mask. B Determining the minimum boundary rectangle The center is X The new coordinates within will eventually be Pasting it into the original image produces a pasted pseudo-anomaly. ; For each sample in each iteration, a mask is randomly selected from the component masks; Then, image patches randomly selected from the image are used to fill the areas corresponding to the mask, resulting in a filled mask. False anomalies; For each sample in each iteration, from the component mask C A component mask is randomly selected, its minimum bounding rectangle is calculated, and a parallelogram of random shape is generated. Image patches are then filled within this region to obtain a scar-like pseudo-anomaly. ; The pseudo-abnormalities of adhesive type, filler type, and scar type are as follows: in, Indicates training samples, Indicates the background mask. Indicates the component mask. Indicates the random component mask Corresponding original image The region is pasted relative to its background mask. On the coordinates, This indicates the original image Fill random image blocks into a random component mask The corresponding area Indicates the random component mask Random parallelograms are generated within the minimum bounding rectangle, and image patches are filled in that region. The learning module constructs a multi-class classifier based on three types of pseudo-anomalies: paste, fill, and scar, to promote self-supervised learning. Normal samples and pseudo-anomaly samples are mixed and fed into the training to extract deep feature information containing local texture features and global high-level semantic features. ResNet-18 is used as the feature extractor of the multi-class classifier, and a multilayer perceptron with two hidden layers is combined for classification. Multi-class cross-entropy is used as the loss function. The distribution module constructs a local feature distribution for local anomaly detection to identify structural anomalies based on deep feature information, and constructs a global feature distribution for global information capture to identify logical anomalies, and calculates the local anomaly score and the global anomaly score. The output module defines the anomaly score of the test image based on the local anomaly score and the global anomaly score, and completes the pseudo-anomaly enhancement.