Flexible material few-sample anomaly detection-oriented method and system
By extracting the global and local features of flexible material images through a pre-trained model, and combining linear layer adjustment and loss function optimization, an anomaly detection framework is constructed. This solves the problem of low accuracy caused by limited samples in flexible material detection and achieves efficient recognition of complex anomalies.
Patent Information
- Application Number
- CN202510747651.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-05
- Publication Date
- 2025-09-23
AI Technical Summary
Existing technologies for abnormality detection in flexible materials are difficult to adapt to diverse defects due to limited samples, resulting in low detection accuracy.
A pre-trained image processing model is used to extract the global features of flexible material images and divide them into local sub-images. The local features are adjusted through a pre-built linear layer, the anomaly score is calculated, and iterative optimization is performed using a preset loss function to construct an anomaly detection framework that combines local and global features.
The accuracy of anomaly detection in flexible materials is improved, and complex anomalies can be effectively identified when samples are relatively limited.
Smart Images

Figure CN120689668A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to a method, system, electronic device, and storage medium for detecting anomalies in a small number of samples of flexible materials. Background Art
[0002] With the rapid development of the global flexible materials industry, product quality control, particularly in flexible materials production, has become increasingly important. Ensuring product quality, particularly detecting defects in flexible materials, continues to gain importance in the modern flexible materials industry. Early detection of defects in flexible materials not only prevents inferior products from entering the market but also significantly reduces costs and losses for manufacturers.
[0003] Currently, existing methods for detecting anomalies in flexible materials using a small sample size primarily rely on various image processing algorithms, such as edge detection and texture analysis, to identify and classify defects in flexible materials. However, in practical applications, due to the limited number of samples of normal flexible materials, existing image processing methods alone are often unable to adapt to the diverse defects encountered when detecting anomalies in complex flexible materials, resulting in low accuracy. Summary of the Invention
[0004] The present application provides a method and system for detecting anomalies of flexible materials using a small number of samples, which has the effect of improving the accuracy of anomaly detection of flexible materials.
[0005] In a first aspect, the present application provides a method for detecting anomalies in a small number of samples of flexible materials, comprising:
[0006] Acquire a normalized flexible material image, and input the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image;
[0007] Dividing the flexible material image into a preset number of local sub-images, and determining a local feature of each of the local sub-images based on the global feature;
[0008] Performing feature adjustment on the local features of each of the local sub-images through a pre-constructed linear layer to obtain an adjusted first target local feature;
[0009] Calculating anomaly scores between each of the first target local features and the standard sample features, and calculating a total loss value corresponding to each of the anomaly scores and the global features according to a preset loss function;
[0010] Iteratively optimizing the pre-built linear layer and the pre-trained image processing model according to the total loss value to obtain an iteratively optimized target linear layer and a target image processing model;
[0011] determining second target local features of the flexible material image through the iteratively optimized target linear layer and target image processing model, and calculating a target anomaly score between each of the second target local features and the sample feature;
[0012] Among the local sub-images, a local sub-image having the target anomaly score greater than an anomaly score threshold is selected as an anomaly detection result.
[0013] In a second aspect of the present application, a system for detecting anomalies of a small number of samples of flexible materials is provided, the system comprising:
[0014] An image acquisition module is used to acquire a normalized flexible material image and input the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image;
[0015] a feature extraction module, configured to divide the flexible material image into a preset number of local sub-images, and determine local features of each of the local sub-images based on the global features; and perform feature adjustment on the local features of each of the local sub-images using a pre-constructed linear layer to obtain adjusted first target local features;
[0016] an anomaly score calculation module, configured to calculate an anomaly score between each of the first target local features and the standard sample features, and calculate a total loss value corresponding to each of the anomaly scores and the global features according to a preset loss function;
[0017] an iterative optimization module, configured to iteratively optimize the pre-built linear layer and the pre-trained image processing model according to the total loss value to obtain an iteratively optimized target linear layer and a target image processing model;
[0018] An anomaly detection module is configured to determine, using the iteratively optimized target linear layer and target image processing model, a second target local feature of the flexible material image, and calculate a target anomaly score between each of the second target local features and the sample feature; and select, from each of the local sub-images, a local sub-image having a target anomaly score greater than an anomaly score threshold as an anomaly detection result.
[0019] In a third aspect of the present application, an electronic device is provided, comprising a memory, a processor, and a program stored in the memory and executable on the processor, wherein the program can implement a method for detecting anomalies in a small number of samples of flexible materials when loaded and executed by the processor.
[0020] In a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program. When the computer program is executed by a processor, the processor implements a small-sample anomaly detection method for flexible materials.
[0021] In summary, one or more technical solutions provided in the embodiments of the present application have at least the following technical effects or advantages:
[0022] By adopting the above technical solution, a pre-trained image processing model is used to extract global features of flexible material images and divide them into multiple local sub-image regions. Based on the global features, a first local feature is determined for each local sub-image. This first local feature is then adjusted using a pre-built linear layer to obtain a first target local feature. An anomaly score is calculated between the first target local feature and the standard sample feature, and a preset loss function is designed to calculate the total loss. The linear layer and image processing model are then iteratively optimized based on the total loss value to obtain a target model. The optimized target model is then used to extract a second target local feature and calculate the corresponding target anomaly score. Finally, anomaly regions are identified based on a threshold. By constructing an anomaly detection framework that combines local and global features, an adaptive feature adjustment and loss function-driven model optimization method are introduced. This fully integrates local details and global structural information, continuously improving the model's representation of features. This improves the detection capability of complex anomalies even with relatively limited sample sizes, thereby enhancing the accuracy of flexible material anomaly detection. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 This is a flow chart of a method for detecting anomalies in a small number of samples of flexible materials provided in an embodiment of the present application;
[0024] Figure 2 This is a schematic diagram of the structure of a small sample anomaly detection system for flexible materials provided in an embodiment of the present application;
[0025] Figure 3 This is a structural diagram of an electronic device provided in an embodiment of the present application.
[0026] Figure 4 This is a comparison of the thermal map results of locating anomalies using different methods provided in Example 1 of the present application.
[0027] Description of reference numerals: 300, electronic device; 301, processor; 302, communication bus; 303, user interface; 304, network interface; 305, memory. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments.
[0029] In the description of the embodiments of this application, words such as "for example" or "for instance" are used to indicate examples, illustrations, or explanations. Any embodiment or design described as "for example" or "for instance" in the embodiments of this application should not be construed as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "for example" or "for instance" is intended to present the relevant concepts in a concrete manner.
[0030] In the description of the embodiments of the present application, the term "multiple" means two or more. For example, multiple systems refer to two or more systems, and multiple screen terminals refer to two or more screen terminals. In addition, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as indicating or implying relative importance or implicitly indicating the indicated technical features. Thus, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized.
[0031] The present application embodiment provides a method for detecting anomalies of a small number of samples of flexible materials. In one embodiment, please refer to Figure 1 , Figure 1 This is a flow chart of a method for detecting anomalies in a small number of samples for flexible materials provided in an embodiment of the present application. This method can be implemented using a computer program that can be integrated into an application or run as a standalone tool application. This method can also be implemented using a single-chip microcomputer or run on a small number of samples for detecting anomalies in flexible materials based on a von Neumann architecture. Specifically, this method can include the following steps:
[0032] Step 101: Obtain a normalized flexible material image, and input the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image.
[0033] The pre-trained image processing model refers to an image feature extraction model trained on a large-scale dataset, which can learn to extract semantic features from images. In the embodiments of the present application, the pre-trained image processing model can be understood as a CLIP model. The CLIP model is an image encoding model pre-trained on a multimodal image dataset, which acquires the ability to extract image semantic information through comparative learning between images and text.
[0034] Global features refer to semantic information extracted from the entire image and can express the overall content of the image. In the embodiments of the present application, global features can be understood as feature vectors extracted from the flexible material image using the CLIP model. Among them, the feature vector is a 512-dimensional vector that contains an expression of the entire image content and represents the overall semantic information of the image. Global features are used to describe the overall pattern and structure of the image, that is, global information such as the weaving style and pattern design of the flexible material.
[0035] Specifically, to address the image complexity and limited sample size issues in flexible material production, image preprocessing and feature extraction are necessary to effectively extract feature expression data distribution from limited samples. First, an RGB image of the flexible material is acquired. Next, the image is normalized, adjusting each pixel value to the range [0, 1] to enhance the model's robustness to varying brightness and contrast. This results in a normalized image. The preprocessed image is then fed into a pretrained image processing model, CLIP, which has been pretrained on a large-scale image semantic dataset and is capable of extracting semantically rich image features. After inputting the flexible material image, the CLIP model outputs a global feature vector. This pretrained model-based feature extraction approach is primarily due to the strong expressive power of the features learned by the CLIP model, which contains rich semantic information and facilitates subsequent anomaly detection. Furthermore, compared to training a feature extractor layer by layer, using a pretrained model significantly reduces the number of training samples and computational costs. Therefore, this global feature extraction approach ensures effective feature expression while meeting the constraints of scarce samples and limited computing resources in industrial applications.
[0036] Based on the above embodiment, as an optional embodiment, in step 101: inputting the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image, this step may further include the following steps:
[0037] Step 201: extract global features from the flexible material image using the CLIP model to generate an initial global feature vector.
[0038] Specifically, after obtaining a normalized flexible material image, global features need to be extracted based on the CLIP model in order to obtain a feature expression that expresses the global semantic information of the image. The flexible material image is input into a pre-trained CLIP model. The CLIP model contains a convolutional network as an encoder and is pre-trained on a large-scale multimodal dataset to learn the ability to extract semantic features from images. After inputting the flexible material image, the CLIP model outputs an initial global feature vector. The purpose of extracting initial global features through the CLIP model is to obtain a semantic feature expression that fully includes the global pattern and structural information of the flexible material image, such as high-level semantic features such as pattern and weave. This feature extraction method based on a pre-trained model not only ensures the expression effect, but also greatly reduces the sample size and computational requirements. Therefore, by performing global feature extraction on the flexible material image through the CLIP model, initial global features rich in semantic information can be efficiently obtained, which provides global information support for subsequent feature fusion and anomaly judgment.
[0039] Step 202: Input the initial global feature vector into a preset feature alignment network for feature fusion to obtain the global features of the flexible material image.
[0040] Among them, the preset feature alignment network refers to a predefined network structure used for feature fusion and refinement, which can acquire the ability to transform the feature space through training. In the embodiments of the present application, the preset feature alignment network can be understood as a neural network that integrates convolutional layers, multi-head self-attention mechanisms, and linear mappings. The network accepts initial global features as input and outputs refined global features. The preset feature alignment network is used to fuse the initial global features output by the CLIP model. Through the network's feature transformation and alignment operations, the ability of global features to express and depict subtle differences in flexible materials can be improved.
[0041] Specifically, the initial global features are input into a pre-set feature alignment network for processing. This network comprises convolutional layers, a multi-head attention mechanism, and a linear alignment layer. The convolutional layers extract local features, while the attention mechanism models global contextual information. Finally, the linear layer aligns and fuses the different features. The feature alignment network uses eight attention heads, each of which outputs 64-dimensional features. After multi-head attention extraction and fusion of different sub-feature spaces, the network outputs 512-dimensional global features. Compared to the initial features, these global features enhance the ability to express the global style and structure of the flexible material. This feature fusion based on the initial features is intended to improve the depiction of subtle differences in flexible materials and enhance the ability of global features to distinguish different styles. The pre-set feature alignment network is pre-trained and can adapt to different datasets for feature extraction.
[0042] Step 102: Divide the flexible material image into a preset number of local sub-images, and determine the local features of each local sub-image based on the global features.
[0043] A local sub-image refers to an image block obtained by dividing the entire image into multiple local regions. In the embodiments of the present application, a local sub-image can be understood as dividing the entire flexible material image into several small image blocks, for example, 16 128x128 pixel image blocks. A local sub-image is used to represent and extract features of a local region of the image. Compared to the overall image, a local sub-image focuses more on a small local region within the flexible material image and can represent local texture and structural features.
[0044] Local features refer to features extracted from a local area of an image that represent the semantic information of that area. In the embodiments of this application, local features can be understood as 512-dimensional local feature vectors extracted based on a local sub-image using an attention mechanism or a local convolutional network. The local feature vector expresses the semantic information of the corresponding local sub-image area.
[0045] Specifically, after obtaining a feature vector representing global semantic information, the image needs to be segmented and features extracted for each local region to more precisely model the local regions within the image. First, the flexible material image X is divided into a predetermined number of blocks. For example, a 256x256 image can be divided into 16 128x128 local sub-images. Then, based on the previously obtained global features F, an attention mechanism or feature fusion network can be guided to determine the local features of each local sub-image. The local features are also represented by a 512-dimensional feature vector. This division into local sub-images and the extraction of corresponding local features aim to focus more on local regions within the image and identify local defects or abnormal patterns. Compared to a single global feature, combining global and local features can provide representations of different image regions, which is more conducive to subsequent anomaly detection. Therefore, this process divides the image into local regions and extracts local features based on global features, resulting in feature tables of varying granularity. This provides both global and local information support for subsequent few-shot anomaly detection.
[0046] Step 103: perform feature adjustment on the local features of each local sub-image through a pre-built linear layer to obtain the adjusted first target local features.
[0047] Among them, the first target local feature refers to the local feature expression after linear adjustment, which has stronger expressive power than the original local feature. In the embodiment of the present application, the first target local feature can be understood as the local feature adjusted by the linear layer. The first target local feature is a new local feature obtained by linear mapping based on the initial local feature.
[0048] Specifically, in order to enhance the expressive power of local features, after obtaining the initial local feature expression of each local sub-image, feature adjustment is required to refine the expressive power of the features. A pre-constructed linear fully connected layer is defined, where the pre-constructed linear fully connected layer is a d*d dimensional matrix, where d represents the feature dimension. Each initial local feature vector is used as input, and the adjusted first target local feature is obtained through matrix multiplication. This linear transformation is performed to refine the initial local feature's ability to depict the local pattern of the flexible material and enhance the distinguishing expression of different local styles. Performing feature transformation through a pre-constructed linear layer not only ensures the controllability of the conversion process, but also reduces the computational requirements of network training. The adjusted first target local feature has a stronger feature expression capability than the initial feature. Therefore, the process rationally uses a linear layer to adjust the local features, which can obtain a better first target local feature expression, which provides information-rich local feature support for subsequent small-sample anomaly detection.
[0049] Based on the above embodiment, as an optional embodiment, in step 103, the step of performing feature adjustment on the local features of each local sub-image by using a pre-built linear layer to obtain the adjusted first target local features may further include the following steps:
[0050] Step 301: Substitute the local features of each local sub-image into a pre-constructed linear layer to obtain the first target local features after adjustment of each local feature; wherein the pre-constructed linear layer is:
[0051]
[0052] Where, is the first target local feature after adjustment of the i-th local feature, W is the weight matrix corresponding to the pre-built linear layer, represents the i-th local feature.
[0053] Among them, the pre-constructed linear layer refers to a pre-defined linear mapping layer for feature transformation, which realizes feature transformation through matrix multiplication. In the embodiment of the present application, the pre-constructed linear layer can be understood as a linear fully connected layer, which is a d*d matrix, where d represents the feature dimension. The pre-constructed linear layer is used to map the initial local features to the first target local features to realize linear transformation in the feature space. Compared with the nonlinear layer, the linear layer is simple to calculate and can also play the role of feature transformation.
[0054] Specifically, after obtaining the initial local feature expression of each local sub-image, in order to improve the distinguishing expression ability of the features, it is necessary to adjust the features through the pre-built linear layer. Define the parameter matrix of the linear layer. Take each 512-dimensional local feature as input and implement linear mapping through matrix multiplication: here The first target local feature after adjustment by the linear layer, with its dimension remaining unchanged at 512. This linear transformation allows for the refinement of local features, enhancing their ability to depict texture and structure. The use of a pre-built linear layer for feature adjustment enables fast and simple feature transformation, ensuring controllability of the conversion process while reducing computational effort. The adjusted first target local feature is more expressive than the original local feature. Therefore, this process rationally utilizes a linear layer to adjust local features, resulting in a better first target local feature. This further enhances the modeling representation of local regions of flexible materials and provides critical support for subsequent anomaly identification.
[0055] It should be noted that the parameter matrix W of the pre-constructed linear layer is used to adjust local features. To adapt the parameter matrix to a specific dataset, the following steps can be taken: Collect a small number of images of normal flexible materials, such as 50 images of crocheted blankets with different patterns. Preprocess the images and use the CLIP model to extract initial local features Fi with a dimension of 512. Set the linear layer to a randomly initialized matrix of 512×512. Input the features into the linear layer and optimize the pre-constructed linear layer to enhance the discriminability of the output features between different patterns. Contrastive learning can be used to increase the distance between features between different patterns. Fine-tune the linear layer and repeat the steps of optimizing the pre-constructed linear layer until the features are more sensitive to changes in the flexible material pattern. The resulting linear layer weight matrix W is the pre-constructed linear layer suitable for the current dataset and can be used in subsequent steps to adjust local features and enhance the representation of new samples. During training, optimizing the parameter matrix W of the linear layer can better refine local features, thereby enhancing the model's sensitivity to and ability to depict subtle changes in local regions of the flexible material.
[0056] Step 104: Calculate the anomaly score between each first target local feature and the standard sample feature, and calculate the total loss value corresponding to each anomaly score and the global feature according to a preset loss function.
[0057] Specifically, after obtaining the first target local feature expression, it is necessary to establish an abnormality detection judgment mechanism to evaluate whether each local area has defects. Set the feature set S = {F1, F2, ... Fn} containing normal standard samples, where Fi is the pre-extracted global feature of the i-th standard sample. For each first target local feature, calculate its distance or similarity with all standard sample features, and take the highest distance or minimum similarity as the abnormality score of the local area. Afterwards, connect the abnormality scores of all local areas with the global features, and use a preset loss function, such as contrast loss, to calculate the total loss corresponding to the abnormality score and the global feature. By minimizing the loss, the discriminative expression of the normal standard sample can be learned. In this way, the degree of abnormality between the local area and the standard sample is calculated and optimized in combination with the global feature. The purpose is to establish an evaluation mechanism for abnormal judgment so that the model has the ability to distinguish between abnormal and normal features.
[0058] Based on the above embodiment, as an optional embodiment, in step 104: calculating the anomaly score between each first target local feature and the standard sample feature, this step may further include the following steps:
[0059] Step 401: performing dot product calculations on each first target local feature and the standard sample feature to obtain the similarity between each first target local feature and the standard sample feature.
[0060] The standard sample feature refers to a feature expression pre-extracted from a normal standard sample, which is used to represent a normal feature distribution range. In the embodiment of the present application, the standard sample feature can be understood as a set of standard features.
[0061] Similarity refers to a value indicating the degree of numerical correlation between two feature vectors. In the embodiment of the present application, similarity can be understood as the value between the first target local feature and each standard sample feature obtained by dot product calculation.
[0062] Specifically, to evaluate the normality of each first target local feature region, it is necessary to compare it with a standard normal sample. Let S = {F1, F2, ..., Fm}, containing m standard sample features, where Fi is the pre-extracted text feature of the i-th sample, and its dimension is the same as that of the first target local feature. For each first target local feature, perform a dot product operation with all the standard features in S: Here sim_i represents the first target local feature The similarity between the local features and the i-th standard sample Fi is calculated using a dot product calculation to measure the degree of correlation between two feature vectors. This similarity comparison with the standard sample serves as a reference for anomaly determination, enabling the model to distinguish abnormal patterns that do not match the standard sample distribution. Therefore, this step rationally uses a dot product operation to compare the similarity between local features and standard features, resulting in a similarity matrix representing the degree of anomaly.
[0063] Step 402: normalize each similarity using a preset Softmax function to obtain anomaly scores between each first target local feature and the standard sample feature.
[0064] Among them, the preset Softmax function refers to a predefined Softmax activation function for normalizing the similarity. In the embodiment of the present application, the preset Softmax function can be understood as the applied Softmax operation, with the input being the similarity and the output being the normalized probability. The preset Softmax function is used to normalize the similarity matrix between each first target local feature and the standard sample feature to a probability distribution ranging from 0 to 1. Its maximum value is defined as the anomaly score.
[0065] The anomaly score is a numerical value that indicates the degree of mismatch between a local region of a sample and the normal pattern. A higher value indicates a greater likelihood of a defect or flaw. In the embodiments of this application, the anomaly score can be understood as the maximum probability value obtained through Softmax normalization, reflecting the degree of mismatch between the corresponding first target local feature and the standard normal feature set. The anomaly score is used to directly determine the degree of anomaly and possible defects in each local region.
[0066] Specifically, after obtaining the similarity matrix between the first target local feature and each standard sample feature, these similarities need to be further processed to obtain a score representing the degree of abnormality. The similarity matrix is processed column by column. For each first target local feature, there are m similarities with the standard sample {sim1, sim2, ..., simm}. These m similarities are used as input to the preset Softmax function, and m abnormal probabilities {p1, p2, ..., pm} are obtained as output. Finally, the value with the largest probability pk is taken as the abnormality score ek of the first target local feature. The purpose of applying the Softmax function to normalize the similarity is to obtain a probability value in the range of 0 to 1, which can directly represent the possibility of abnormality. The maximum value is used as the abnormality score ek. The larger the ek, the more mismatched the first target local feature is with the normal standard. Therefore, this step rationally uses the Softmax function to obtain the abnormality score, providing an important basis for subsequent abnormality judgment.
[0067] Based on the above embodiment, as an optional embodiment, in step 104: calculating the total loss value corresponding to each anomaly score and the global feature according to a preset loss function, this step may also include the following steps:
[0068] Step 403: Calculate pixel-level loss values based on each anomaly score, and calculate a global loss value based on the global features.
[0069] The pixel-level loss value refers to a loss function calculated based on the anomaly scores of each local area of the image, reflecting the anomaly of the local sample features. In the embodiments of the present application, the pixel-level loss value can be understood as the value of the anomaly scores of all first target local feature areas after the pixel-level loss calculation. The pixel-level loss value is used to provide an optimization target, enabling the model to enhance its ability to recognize local anomaly patterns, and it takes into account the detailed conditions of each local area.
[0070] The global loss value refers to the loss function calculated based on the classification results of the entire sample, which reflects the discriminative expression of the global sample features. In the embodiments of this application, the global loss value can be understood as the classification loss value calculated using the global features as input. The global loss value is used to provide an optimization target, enabling the model to enhance its ability to distinguish and recognize the entire sample, and it takes into account the discriminative information of the global features.
[0071] Specifically, after obtaining the anomaly scores for each first-target local feature region, an optimization objective needs to be established so that the model can learn from these scores and enhance its ability to recognize abnormal patterns. A pixel-level loss calculation is performed on the anomaly scores of all local regions to obtain the pixel-level loss value of the image. Simultaneously, a global loss function is set up, using global features as input to learn the ability to discriminate against normal samples and obtain a global loss value. This combination of pixel-level and global loss functions takes into account both local details and global classification, enhancing the model's anomaly recognition capabilities.
[0072] Based on the above embodiment, as an optional embodiment, in step 403: calculating the pixel-level loss value according to each anomaly score, this step may further include the following steps:
[0073] Step 413: Substitute each anomaly score into a preset pixel-level loss formula to obtain a pixel-level loss value; wherein the preset pixel-level loss formula is:
[0074]
[0075] Where, L pixel is the pixel-level loss value, A i is the i-th anomaly score, G i is the actual anomaly label corresponding to the i-th anomaly score.
[0076] Among them, the preset pixel-level loss formula refers to a predefined formula for calculating pixel-level loss values. In the embodiments of the present application, the preset pixel-level loss formula can be understood as a mathematical formula for calculating pixel-level loss based on each anomaly score and the corresponding actual label. The preset pixel-level loss formula is used to provide a method for calculating pixel-level loss, establish an optimization target based on the difference between the predicted score and the actual label, and improve the model's detection accuracy for local anomalies.
[0077] Specifically, after obtaining the anomaly scores of each first target local feature, it is necessary to establish a pixel-level loss function to optimize the model's prediction of these scores. The preset pixel-level loss formula is defined as this formula, where Ai represents the i-th anomaly score and Gi represents the actual anomaly label (0 or 1) corresponding to the local area. This formula calculates the degree of match between the predicted anomaly score and the actual anomaly label. By constructing a form similar to cross entropy, the effect of anomaly detection can be effectively reflected. The anomaly scores of each local area are substituted into the loss function in turn for calculation, and a pixel-level loss value can be obtained. In this way, the pixel-level loss can be directly constructed based on the anomaly score through the preset formula, providing a model optimization goal so that its prediction results are more in line with the actual anomaly distribution. Therefore, this step reasonably designs the pixel-level loss function, provides a good optimization target for subsequent model training, and can improve the detection effect of local anomalies.
[0078] For example, suppose there is a detection image of cloth. After the model prediction, the abnormality scores of four local areas are obtained: A1 = 0.2, A2 = 0.8, A3 = 0.1, A4 = 0.7. The actual abnormality label corresponding to each area (0 indicates normal, 1 indicates abnormal) is annotated by the detection system as: G1 = 0, G2 = 1, G3 = 0, G4 = 1. The predicted score and the actual label are substituted into the preset pixel-level loss formula for calculation:
[0079]
[0080] ≈0.2105. Calculation result L pixel The value is approximately 0.2105, a positive number, indicating that there is some, but relatively small, difference between the algorithm and the actual label. This result conforms to conventional similarity metrics, where values closer to 0 indicate greater similarity, while larger values indicate greater difference. In practical applications, this metric can help us understand the effectiveness of the algorithm in detecting defects in flexible materials at the pixel level.
[0081] Based on the above embodiment, as an optional embodiment, in step 403: calculating the global loss value according to the global features, this step may further include the following steps:
[0082] Step 423: Substitute the global features into the preset global loss formula to obtain the global loss value;
[0083] Among them, the preset global loss formula is:
[0084]
[0085] Where, L global is the global loss value, M is the total number of local sub-images, and F fusion is the global feature of the flexible material image, F normal is the global feature of the standard flexible material image.
[0086] The preset global loss formula refers to a predefined formula for calculating the global loss value. In the embodiments of the present application, the preset global loss formula can be understood as a mathematical formula for obtaining the global loss by calculating the Euclidean distance between the predicted global features and the standard normal features. The preset global loss formula is used to provide a method for calculating the global loss, establish an optimization target based on the deviation of the global feature expression from the normal standard, and improve the model's characterization of the overall pattern.
[0087] Specifically, after extracting the global feature vector of the flexible material image, it is necessary to establish a global loss function to optimize it. The global loss function is defined as the above formula, in which the Euclidean distance between the predicted global feature and the standard normal feature is calculated. This distance can directly reflect the degree of deviation between the global feature and the normal standard. By minimizing this distance, the global feature predicted by the model can be made closer to the standard normal feature. Here, M represents the total number of local sub-images of the flexible material image. The global feature vector is constructed by traversing all sub-images to ensure that the feature contains global information. The extracted global feature is substituted into the preset formula for calculation to obtain the global loss value. In this way, the global loss can be directly constructed based on the global feature through the preset formula, providing the goal of model optimization so that its prediction results are more in line with the standard normal features.
[0088] For example, suppose a flexible material factory is producing a batch of patterned fabrics. The global features of the standard samples of the patterned fabric images are known. Now it is necessary to detect whether the batch of flexible materials meets these standards. For example, the global features of the standard samples include color uniformity: 0.95, pattern symmetry: 0.98, and color saturation: 0.90. The global features of the tested flexible material A include color uniformity: 0.92, pattern symmetry: 0.95, and color saturation: 0.85. The global features of the tested flexible material B include color uniformity: 0.93, pattern symmetry: 0.96, and color saturation: 0.82. The difference calculation of the global features of flexible material A is as follows: Color uniformity difference: (0.92-0.95) 2=0.0009, pattern symmetry difference: (0.95-0.98) 2 =0.0009, color saturation difference: (0.85-0.90) 2
[0089] =0.0025, the loss value corresponding to the global characteristics of flexible material A is 0.0009+0.0009+0.0025=0.0043. The difference calculation of the global characteristics of flexible material B is as follows: Color uniformity difference: (0.93-0.95) 2 =0.0004, pattern symmetry difference: (0.96-0.98) 2 = 0.0004, color saturation difference: (0.82-0.90)² = 0.0064, the corresponding loss value for the global features of flexible material B is 0.0004+0.0004+0.0064=0.0072, and the global loss value is 0.0072+0.0043=0.0115. Using this specific numerical value to calculate the global loss, the main purpose of the global loss is to ensure that the fused global features are consistent with the global features of normal samples. This helps the model learn the feature distribution of normal samples, allowing it to more accurately identify deviations from the normal distribution when detecting anomalies. By minimizing the global loss, the model is constrained to maintain consistency with normal samples at the global feature level. This global constraint helps improve the overall stability and robustness of anomaly detection and prevents deviations in the model's processing of local features. The global loss encourages the model to learn more comprehensive and consistent image features, avoids overfitting to local anomalies, and enhances the model's generalization ability across different images and anomaly types.
[0090] Step 404: Substitute the pixel-level loss value and the global loss value into a preset loss function to obtain the total loss value corresponding to each anomaly score and the global feature; wherein the preset loss function is:
[0091] L total =λ1×L pixel +λ2×L global ;
[0092] Where, L total is the total loss value, λ1 is the preset pixel-level loss weight, L poxel is the pixel-level loss value, λ2 is the preset global loss weight, L global is the global loss value.
[0093] The preset loss function refers to a predefined loss calculation method used to integrate multiple loss values. In the embodiments of the present application, the preset loss function can be understood as a mathematical formula that obtains the final total loss by weightedly combining pixel-level loss and global loss. The preset loss function is used to provide an optimization target that takes into account local and global information, and is used to train the model to improve the overall effectiveness of anomaly detection.
[0094] Specifically, in order to optimize the model's expression of local and global features simultaneously, it is necessary to establish a loss function that integrates both pixel-level and global loss. The total loss function is defined as the weighted sum of pixel-level loss and global loss:
[0095] L total =λ1×L pixel +λ2×L global , where L pixel represents the pixel-level loss value calculated by the abnormal score of each first target local feature area, reflecting the pixel-level details; L global λ represents the classification loss calculated using global features as input, reflecting global discrimination. λ1 and λ2 are preset weight coefficients. This custom loss function combines both local and global considerations, focusing on the detailed expression of local features while also optimizing global discrimination. Therefore, this process rationally designs the loss function, providing a good optimization target for subsequent model training, resulting in improvements in both local and global aspects of the model.
[0096] For example, suppose that in a certain model training, the calculated loss values are: pixel-level loss L pixel =0.35, global loss L global =0.15. To balance the effects of pixel-level loss and global loss, the preset loss function sets the following weights: pixel-level loss weight λ1 = 0.7, global loss weight λ2 = 0.3. Substitute the loss value and weight into the preset loss function: L total =λ1×L pixel +λ2×L global =0.7×0.35+0.3×0.15=0.245+0.045=0.2, and the total loss L is finally obtained total = 0.29. As can be seen, the weighted calculation of the preset loss function places a greater weight on pixel-level loss, resulting in model training that prioritizes optimization of local details. Global loss also plays a role, allowing the model to balance global classification performance. This integrated local and global loss function allows the model to enhance local feature expression without neglecting global classification performance, achieving a balanced approach to anomaly detection.
[0097] It should be noted that in the preset loss function, the weights λ1 and λ2 reflect the importance of pixel-level loss and global loss. The process of setting the weight coefficients includes: initialization, setting the initial values of λ1 and λ2, for example, λ1 = λ2 = 0.5, that is, the pixel-level loss and global loss weights are the same. Observe the loss: After a certain number of training iterations, record the current two loss values L pixel and L global Comparison loss: If L pixel >>L global , indicating that the current model is not good at learning local features, then increase λ1 and reduce λ2, for example, set λ1 = 0.7, λ2 = 0.3. On the contrary, if L global >>L pixel , then decrease λ1 and increase λ2. Repeat the training, continuously observe the two loss values, and dynamically adjust λ1 and λ2 until the losses reach equilibrium. This dynamic weighting method balances the effects of pixel-level loss and global loss based on the actual model conditions, allowing the model to prioritize local feature expression while also balancing global classification, achieving optimal anomaly detection results.
[0098] Step 105: Iteratively optimize the pre-built linear layer and the pre-trained image processing model according to the total loss value to obtain the iteratively optimized target linear layer and target image processing model.
[0099] The target linear layer and target image processing model refer to the linear layer and image processing model ultimately used for anomaly detection, obtained through iterative optimization. In the embodiments of this application, the target linear layer can be understood as the optimized linear layer used to fuse information; the target image processing model can be understood as an optimized image feature extraction model, such as a CNN model. Both the target linear layer and the target image processing model are obtained through iterative optimization driven by a loss function, and their network parameters have been adjusted to make them more suitable for anomaly detection tasks.
[0100] Specifically, after calculating the total loss function that integrates pixel-level loss and global loss, it is necessary to optimize the model based on this loss function to improve the final anomaly detection effect. The designed total loss function is used as the optimization target. According to the size of the loss value, the network parameters in the linear layer and image processing model (such as CNN) are gradually adjusted through the backpropagation algorithm. For example, the Adam optimization algorithm is used for model iterative optimization. For example, the learning rate is set to (1×10 -4), the batch size is 8, and the model converges after 50 epochs. During the training process, a small number of normal samples are used for model optimization. Through the adaptive feature alignment mechanism and loss function design, the detection of flexible material anomalies can be effectively realized. After repeated iterative optimization, the parameters of the linear layer and CNN model will gradually have better discrimination capabilities, and finally the optimized target linear layer and image processing model can be obtained. In this way, through the optimization iteration driven by the loss function, the model can make the judgment of the input image more accurate, thereby improving the effect of anomaly detection. Therefore, this step is the key to achieving model performance improvement and the significance of designing the loss function. In summary, this process reasonably adopts the iterative optimization of the model based on the loss function, so that the final trained model is more efficient and accurate for anomaly detection.
[0101] Step 106: Determine the second target local features of the flexible material image through the iteratively optimized target linear layer and target image processing model, and calculate the target anomaly score between each second target local feature and the sample feature.
[0102] The target anomaly score refers to a score reflecting the probability of anomaly calculated using the optimized model. The target anomaly score is calculated in the same manner as the anomaly score. In the embodiments of this application, the target anomaly score can be understood as an anomaly probability score calculated based on the local features of the second target. The target anomaly score is calculated using the optimized model and is more accurate in identifying anomalies and has greater sensitivity than the original score.
[0103] Specifically, after obtaining the optimized target linear layer and target image processing model, they are used to detect anomalies in flexible material images. By inputting the flexible material image into the target image processing model, the image's second target local features can be extracted—local features that are more sensitive and discriminative after model optimization. The extracted second target local features are then passed into the target linear layer for processing, yielding target anomaly scores corresponding to each feature. These scores, after model optimization, more accurately reflect the probability of anomaly. The final target anomaly score is then calculated by comparing the scores with the sample features. Thus, by processing the flexible material image using the optimized model, key second target features and scores reflecting anomaly information can be obtained, providing a basis for subsequent anomaly determination. Through model optimization, the second target features and scores possess greater discriminative and discriminative capabilities than the original ones, allowing for more accurate indication of anomalies.
[0104] Step 107: Among the local sub-images, select the local sub-images whose target anomaly scores are greater than the anomaly score threshold as the anomaly detection results.
[0105] Specifically, after obtaining the target anomaly score for each local sub-image area, it is necessary to determine which areas have anomalies based on the threshold. For each local sub-image, its target anomaly score is compared with the preset anomaly score threshold. If the target anomaly score is greater than the threshold, it can be determined that the local sub-image has an anomaly of the type of defect or flaw. Finally, all local sub-image areas with target anomaly scores higher than the threshold are extracted as the final anomaly detection results. In this way, through threshold filtering, the target anomaly score can be effectively used for judgment, and the areas where abnormalities are truly present can be accurately detected. The threshold setting can also be adjusted according to actual needs to achieve the desired detection sensitivity or accuracy.
[0106] Reference Figure 2 , is a flexible material small sample anomaly detection system provided in an embodiment of the present application, the system comprising: an image acquisition module, a feature extraction module, an anomaly score calculation module, and an iterative optimization module, wherein:
[0107] An image acquisition module is used to acquire a normalized flexible material image and input the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image;
[0108] a feature extraction module for dividing the flexible material image into a preset number of local sub-images and determining local features of each local sub-image based on the global features; and performing feature adjustment on the local features of each local sub-image through a pre-constructed linear layer to obtain a first target local feature after adjustment;
[0109] Anomaly score calculation module, used to calculate the anomaly score between each first target local feature and the standard sample feature, and calculate the total loss value corresponding to each anomaly score and the global feature according to a preset loss function;
[0110] An iterative optimization module is used to iteratively optimize the pre-built linear layer and the pre-trained image processing model according to the total loss value to obtain the iteratively optimized target linear layer and target image processing model;
[0111] The anomaly detection module is used to determine the second target local features of the flexible material image through the iteratively optimized target linear layer and target image processing model, and calculate the target anomaly score between each second target local feature and the sample feature; in each local sub-image, the local sub-image with a target anomaly score greater than the anomaly score threshold is screened out as the anomaly detection result.
[0112] Based on the above embodiment, the image acquisition module is also used to extract global features of the flexible material image through the CLIP model to generate an initial global feature vector; the initial global feature vector is input into a preset feature alignment network for feature fusion to obtain the global features of the flexible material image.
[0113] Based on the above embodiment, the feature extraction module is further used to substitute the local features of each local sub-image into a pre-constructed linear layer to obtain the first target local features after the local features are adjusted; wherein the pre-constructed linear layer is:
[0114]
[0115] Where, is the first target local feature after adjustment of the i-th local feature, W is the weight matrix corresponding to the pre-built linear layer, represents the i-th local feature.
[0116] Based on the above embodiment, the anomaly score calculation module is further used to perform dot product calculations on each first target local feature and the standard sample feature to obtain the similarity between each first target local feature and the standard sample feature; each similarity is normalized by a preset Softmax function to obtain the anomaly score between each first target local feature and the standard sample feature.
[0117] Based on the above embodiment, the anomaly score calculation module is further used to calculate the pixel-level loss value according to each anomaly score, and calculate the global loss value according to the global feature; the pixel-level loss value and the global loss value are substituted into the preset loss function to obtain the total loss value corresponding to each anomaly score and the global feature; wherein the preset loss function is:
[0118] L total =λ1×L pixel +λ2×L global ;
[0119] Where, L total is the total loss value, λ1 is the preset pixel-level loss weight, L pixel is the pixel-level loss value, λ2 is the preset global loss weight, L global is the global loss value.
[0120] Based on the above embodiment, the anomaly score calculation module is further used to substitute each anomaly score into a preset pixel-level loss formula to obtain a pixel-level loss value; wherein the preset pixel-level loss formula is:
[0121]
[0122] Where, L pixel is the pixel-level loss value, Ai is the i-th anomaly score, G i is the actual anomaly label corresponding to the i-th anomaly score.
[0123] Based on the above embodiment, the anomaly score calculation module is further used to substitute the global features into a preset global loss formula to obtain a global loss value; wherein the preset global loss formula is:
[0124]
[0125] Where, L global is the global loss value, M is the total number of local sub-images, and F fusion is the global feature of the flexible material image, F normal is the global feature of the standard flexible material image.
[0126] It should be noted that the above embodiments provide devices that implement their functions using only the division of the above functional modules as examples. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.
[0127] This application also discloses an electronic device. Figure 3 , Figure 3 The electronic device 300 may include: at least one processor 301 , at least one network interface 304 , a user interface 303 , a memory 305 , and at least one communication bus 302 .
[0128] The communication bus 302 is used to implement the connection and communication between these components.
[0129] The user interface 303 may include a display interface and a camera interface. Optionally, the user interface 303 may also include a standard wired interface and a wireless interface.
[0130] The network interface 304 may optionally include a standard wired interface or a wireless interface (such as a WI-FI interface).
[0131] The processor 301 may include one or more processing cores. The processor 301 utilizes various interfaces and circuits to connect various components within the server. It executes instructions, programs, code sets, or instruction sets stored in the memory 305, as well as accesses data stored in the memory 305, to perform various server functions and process data. Optionally, the processor 301 may be implemented using at least one hardware form selected from the group consisting of a digital signal processing (DSP), a field-programmable gate array (FPGA), and a programmable logic array (PLA). The processor 301 may integrate one or a combination of a central processing unit (CPU), a graphics processing unit (GPU), and a modem. The CPU primarily processes the operating system, user interface graphics, and applications; the GPU is responsible for rendering and drawing the content displayed on the display screen; and the modem handles wireless communications. It is understood that the modem may not be integrated into the processor 301 and may be implemented separately on a separate chip.
[0132] Among them, the memory 305 may include a random access memory (RAM) or a read-only memory (Read-Only Memory). Optionally, the memory 305 includes a non-transitory computer-readable storage medium. The memory 305 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 305 may include a program storage area and a data storage area, wherein the program storage area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the above-mentioned various method embodiments, etc.; the data storage area may store data involved in the above-mentioned various method embodiments, etc. The memory 305 may also be optionally at least one storage device located away from the aforementioned processor 301. Refer to Figure 3 , as a computer storage medium, the memory 305 may include an operating system, a network communication module, a user interface module, and an application program for a small sample anomaly detection method for flexible materials.
[0133] exist Figure 3In the electronic device 300 shown, the user interface 303 is mainly used to provide an input interface for the user and obtain the data input by the user; and the processor 301 can be used to call an application program stored in the memory 305 for a method for detecting anomalies of a small number of samples of flexible materials. When executed by one or more processors 301, the electronic device 300 executes one or more methods in the above-mentioned embodiments. It should be noted that for the aforementioned method embodiments, for the sake of simplicity of description, they are all expressed as a series of action combinations, but those skilled in the art should know that this application is not limited to the order of the actions described, because according to this application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required for this application.
[0134] In the above embodiments, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.
[0135] In the several embodiments provided in this application, it should be understood that the disclosed devices can be implemented in other ways. For example, the device embodiments described above are merely schematic, such as the division of units, which is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some service interface, and the indirect coupling or communication connection of devices or units can be electrical or other forms.
[0136] Units described as separate components may or may not be physically separate, and 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 these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0137] In addition, the functional units in the various embodiments of the present application may be integrated into a single processing unit, or each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.
[0138] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a memory and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned memory includes various media that can store program codes, such as USB flash drives, mobile hard drives, magnetic disks or optical disks.
[0139] Example 1
[0140] In the performance evaluation of few-shot anomaly detection, the inventors conducted a comprehensive comparison between the proposed method (Ours) and two existing methods, PromptAD[1] and WinCLIP[2], in three scenarios: 1-shot, 2-shot, and 4-shot. In the 1-shot scenario, the AUROC of the proposed method is 68.7, which is better than PromptAD's 59.8 and WinCLIP's 59.6. At the same time, in terms of pixel-level localization index pAUROC, the method scored 79.4, which is also higher than PromptAD's 78.9 and WinCLIP's 71.9. When the number of samples is increased to 2-shot, the performance advantage of the proposed method is further expanded, and its AUROC is improved to 72.6, which is significantly higher than PromptAD's 60.5 and WinCLIP's 58.9. The pAUROC score also exceeds PromptAD's 79.1 and WinCLIP's 73.1 with a score of 81.2. In the 4-shot setting, the leading position of this method is consolidated, with AUROC and pAUROC reaching 73.2 and 80.5 respectively. In comparison, the corresponding indicators of PromptAD and WinCLIP are lower. Overall, regardless of the few-shot setting, the method proposed in this study outperforms PromptAD and WinCLIP in the four key indicators of AUROC, F1-max, pAUROC and pF1-max, demonstrating its effectiveness and robustness in few-shot industrial anomaly detection tasks. Figure 4 As shown in Table 1, the heat map in the experimental results also shows that the positioning ability of this method exceeds that of existing methods.
[0141] Table 1: Performance comparison of mainstream methods on multi-category anomaly detection tasks
[0142]
[0143] The above are merely exemplary embodiments of the present disclosure and are not intended to limit the scope of the present disclosure. In other words, any equivalent variations and modifications made in accordance with the teachings of the present disclosure are still within the scope of the present disclosure. Those skilled in the art will readily conceive of other embodiments of the present disclosure after considering the disclosure in this specification and practice.
[0144] This application is intended to cover any variations, uses, or adaptations of the present disclosure that follow the general principles of the present disclosure and include common knowledge or customary techniques in the art not described in this disclosure. The description and examples are to be considered as illustrative only.
[0145] References
[0146] [1] PromptAD: Li, X.; Zhang, Z.; Tan, X.; Chen, C.; Qu, Y.;
[0147] [2]WinCLIP: Jeong, J.; Zou, Y.; Kim, T.; Zhang, D.; Ravichandran, A.; and Dabeer, O. 2023. Winclip: Zero- / few-shot anomaly classification and segmentation. In Proceedings of the IEEE / CVF Conference on Computer Vision and Pattern Recognition, 19606-19616.
Claims
1. A method for detecting anomalies in a small number of samples of flexible materials, characterized by: include: Acquire a normalized flexible material image, and input the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image; Dividing the flexible material image into a preset number of local sub-images, and determining a local feature of each of the local sub-images based on the global feature; Performing feature adjustment on the local features of each of the local sub-images through a pre-constructed linear layer to obtain an adjusted first target local feature; Calculating anomaly scores between each of the first target local features and the standard sample features, and calculating a total loss value corresponding to each of the anomaly scores and the global features according to a preset loss function; Iteratively optimizing the pre-built linear layer and the pre-trained image processing model according to the total loss value to obtain an iteratively optimized target linear layer and a target image processing model; The second target local features of the flexible material image are determined using the iteratively optimized target linear layer and target image processing model, and a target anomaly score between each of the second target local features and the sample features is calculated; and in each of the local sub-images, a local sub-image having a target anomaly score greater than an anomaly score threshold is screened out as an anomaly detection result.
2. The method for detecting anomalies of flexible materials using a small number of samples according to claim 1, characterized in that: The pre-trained image processing model is a CLIP model, and the flexible material image is input into the pre-trained image processing model to obtain the global features of the flexible material image, including: The CLIP model is used to extract global features of the flexible material image to generate an initial global feature vector; the initial global feature vector is input into a preset feature alignment network for feature fusion to obtain the global features of the flexible material image.
3. The method for detecting anomalies of flexible materials using a small number of samples according to claim 1, characterized in that: The feature adjustment of the local features of each of the local sub-images by using a pre-constructed linear layer to obtain the adjusted first target local features includes: Substituting the local features of each of the local sub-images into the pre-constructed linear layer to obtain first target local features after adjustment of each of the local features; Among them, the pre-built linear layer is: Where, is the first target local feature after adjustment of the i-th local feature, W is the weight matrix corresponding to the pre-constructed linear layer, represents the i-th local feature.
4. The method for detecting anomalies of flexible materials using a small number of samples according to claim 1, characterized in that: The calculating of anomaly scores between each of the first target local features and the standard sample features includes: Performing dot product calculations on each of the first target local features and the standard sample features to obtain similarities between each of the first target local features and the standard sample features; Each of the similarities is normalized using a preset Softmax function to obtain an anomaly score between each of the first target local features and the standard sample features.
5. The method for detecting anomalies of flexible materials using a small number of samples according to claim 1, characterized in that: Calculating the total loss value corresponding to each of the anomaly scores and the global feature according to a preset loss function includes: Calculating a pixel-level loss value based on each of the anomaly scores, and calculating a global loss value based on the global features; Substituting the pixel-level loss value and the global loss value into a preset loss function to obtain a total loss value corresponding to each of the anomaly scores and the global feature; Wherein, the preset loss function is: L total =λ1×L pixel +λ2×L global ; Where, L total is the total loss value, λ1 is the preset pixel-level loss weight, L pixel is the pixel-level loss value, λ2 is the preset global loss weight, L global is the global loss value.
6. The method for detecting anomalies of flexible materials using a small number of samples according to claim 5, characterized in that: Calculating the pixel-level loss value according to each of the anomaly scores includes: Substituting each of the anomaly scores into a preset pixel-level loss formula to obtain the pixel-level loss value; The preset pixel-level loss formula is: Where, L pixel is the pixel-level loss value, A i is the i-th anomaly score, G i is the actual anomaly label corresponding to the i-th anomaly score.
7. The method for detecting anomalies of flexible materials using a small number of samples according to claim 5, characterized in that: Calculating the global loss value according to the global features includes: Substituting the global feature into a preset global loss formula to obtain the global loss value; Among them, the preset global loss formula is: Where, L global is the global loss value, M is the total number of local sub-images, and F fusion is the global feature of the flexible material image, F normal is the global feature of the standard flexible material image.
8. A small sample anomaly detection system for flexible materials, characterized by: The system comprises: An image acquisition module is used to acquire a normalized flexible material image and input the flexible material image into a pre-trained image processing model to obtain global features of the flexible material image; a feature extraction module, configured to divide the flexible material image into a preset number of local sub-images, and determine local features of each of the local sub-images based on the global features; and perform feature adjustment on the local features of each of the local sub-images using a pre-constructed linear layer to obtain adjusted first target local features; an anomaly score calculation module, configured to calculate an anomaly score between each of the first target local features and the standard sample features, and calculate a total loss value corresponding to each of the anomaly scores and the global features according to a preset loss function; an iterative optimization module, configured to iteratively optimize the pre-built linear layer and the pre-trained image processing model according to the total loss value to obtain an iteratively optimized target linear layer and a target image processing model; An anomaly detection module is configured to determine, using the iteratively optimized target linear layer and target image processing model, a second target local feature of the flexible material image, and calculate a target anomaly score between each of the second target local features and the sample feature; and select, from each of the local sub-images, a local sub-image having a target anomaly score greater than an anomaly score threshold as an anomaly detection result.
9. An electronic device, characterized in that: It includes a processor, a memory, a user interface and a network interface, the memory is used to store instructions, the user interface and the network interface are used to communicate with other devices, and the processor is used to execute the instructions stored in the memory so that the electronic device performs the method for small-sample anomaly detection of flexible materials as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores instructions, and when the instructions are executed, the method for small-sample anomaly detection for flexible materials according to any one of claims 1 to 7 is executed.