A cable surface anomaly detection method and system based on invariant features
By using an invariant feature-based cable surface anomaly detection method, a multi-level invariant feature vector is generated using the RealNVP normalized flow model and a customized feature vector constraint network. This solves the problems of low efficiency, high false negative rate and strong subjectivity in cable detection, and achieves efficient and accurate cable anomaly detection.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INSPUR QILU SOFTWARE IND
- Filing Date
- 2025-12-01
- Publication Date
- 2026-07-31
AI Technical Summary
Existing cable testing technologies suffer from low efficiency, high false negative rates, and strong subjectivity. Furthermore, unsupervised testing methods require updating after changes in processes or raw materials, resulting in poor practicality and insufficient accuracy in anomaly detection.
A cable surface anomaly detection method based on invariant features is adopted. Through image acquisition and preprocessing, multi-level invariant feature vectors are generated. The feature distribution is modeled using the RealNVP normalized flow model. Combined with a customized feature vector constraint network and anomaly score matrix generation, cable anomaly detection is achieved.
It improves the accuracy and efficiency of cable inspection, solves the problem of high-dimensional spatial distance failure, enhances the model's ability to generalize to changes in process/raw materials, and reduces the missed detection rate and subjectivity of manual inspection.
Smart Images

Figure CN121661461B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision and anomaly detection technology, specifically a method and system for detecting anomalies on cable surfaces based on invariant features. Background Technology
[0002] With the improvement of industrial automation, the demand for quality inspection of cables, as core components for power transmission and signal connection, is becoming increasingly urgent. Traditional cable inspection relies on manual visual inspection, which suffers from low efficiency, high missed detection rate, and strong subjectivity. Among the existing automated inspection technologies, supervised learning methods require a large number of labeled samples, but cable defect samples are scarce and diverse, resulting in high labeling costs.
[0003] In actual industrial production scenarios, adjustments to production processes or changes in raw materials can cause changes in image imaging effects, which in turn can lead to a shift in the distribution of image features after feature extraction, ultimately resulting in a decrease in detection accuracy.
[0004] While unsupervised anomaly detection methods can achieve detection without defective samples, they still have the following shortcomings:
[0005] 1. Feature drift problem: In the production environment, adjustments to process parameters or changes in raw materials can easily lead to differences in image imaging effects, causing the normal features extracted by the model to deviate from the preset feature library, thus leading to false detections or missed detections; moreover, after each process iteration or change of raw materials, the algorithm often needs to be updated again, which is not very practical.
[0006] 2. Insufficient accuracy in anomaly detection: Existing unsupervised anomaly detection algorithms usually rely on Euclidean distance or cosine distance to determine anomalies. However, in high-dimensional feature spaces, the accuracy of such distance metrics is limited, which can easily lead to anomaly detection failure.
[0007] To address the aforementioned technical challenges, there is an urgent need to propose a cable anomaly detection method that offers stable feature extraction capabilities and strong noise resistance. Summary of the Invention
[0008] To overcome the shortcomings of existing unsupervised cable anomaly detection technologies, this invention provides a method and system for detecting cable surface anomalies based on invariant features.
[0009] In a first aspect, the present invention provides a method for detecting cable surface anomalies based on invariant features, and the technical solution adopted to solve the above-mentioned technical problems is as follows:
[0010] A method for detecting surface anomalies in cables based on invariant features, comprising the following steps:
[0011] S1. Image Acquisition and Preprocessing: Industrial-grade image acquisition equipment is used to acquire full-surface images of the cable. After preprocessing, a normal sample dataset for cable inspection is constructed.
[0012] S2. Invariant Feature Vector Generation and Feature Constraint: A pre-trained model is used to extract multi-level feature vectors of normal samples in the dataset and store them hierarchically in a feature vector library. For any normal sample in the dataset, the multi-level feature vector stored in the feature vector library is searched for its nearest neighbor feature vector at the corresponding level, and multi-level invariant feature vectors are generated through difference operations. After L2 normalization of the multi-level invariant feature vectors, they are input into a customized feature vector constraint network to constrain the multi-level invariant feature vectors of normal samples to a unit hypersphere.
[0013] S3. Invariant Eigenvector Distribution Estimation: A training dataset is constructed using multi-level invariant eigenvectors of constrained normal samples. The probability density function of the multi-level invariant eigenvectors of normal samples is modeled using the RealNVP normalized flow model, and the model training is completed by minimizing the negative log-likelihood loss.
[0014] S4. Inference Detection: Based on the image acquisition and preprocessing logic of step S1, the image of the cable to be detected is acquired; based on the multi-level feature vector extraction, multi-level invariant feature vector generation, L2 normalization, and customized feature vector constraint network operation logic of step S2, the multi-level invariant feature vector constrained by the image is obtained, and then input into the trained RealNVP normalized flow model to obtain the anomaly score matrix of each level of invariant feature vector; upsampling and weighted fusion operations are performed on the anomaly score matrix corresponding to each level of invariant feature vector to generate the global anomaly score matrix of the cable image to be detected;
[0015] S5. Result Output: Based on the preset threshold, the global anomaly score matrix is segmented for anomaly. The cable is judged to be abnormal according to the proportion of abnormal pixels, and the anomaly segmentation map is output for anomaly location, thereby completing the anomaly detection.
[0016] Optionally, the industrial-grade acquisition equipment involved includes a 2-megapixel high-definition industrial camera, a 16mm fixed-focus industrial lens, and a custom ring light source.
[0017] Optionally, step S1 may be performed, including preprocessing operations such as data cleaning, noise filtering, and deduplication of redundant samples.
[0018] When executing step S4, the preprocessing operations performed when acquiring the image of the cable to be detected based on the image acquisition and preprocessing operation logic of step S1 include data cleaning and noise filtering.
[0019] Optionally, step S2 specifically includes:
[0020] S2.1. A ResNet50 model pre-trained on a large-scale dataset is used as the backbone network. For normal samples in the dataset, the intermediate feature vectors of layer 2 and layer 3 are extracted and denoted as L2 and L3 respectively. Then, they are stored in the feature vector library in layers.
[0021] S2.2 For any normal sample in the dataset, the two layers of feature vectors stored in the feature vector library are searched for the nearest neighbor feature vectors of each layer in the feature vector library, and the two layers of invariant feature vectors are generated by difference operation.
[0022] S2.3. Perform L2 normalization on the two layers of invariant feature vectors respectively; input the two layers of invariant feature vectors after L2 normalization into the customized feature vector constraint network according to the level; constrain the two layers of invariant feature vectors of normal samples to fall within the unit hypersphere through the loss function, so that the L2 norm of the two layers of invariant feature vectors of normal samples is less than 1 and they are clustered towards the center of the sphere.
[0023] Alternatively, the customized feature vector constraint network involved is composed of stacked ConvBNReLU modules, with each layer using a 3×3 convolution kernel and padding=1 to ensure that the input and output dimensions of layer 2 and layer 3 are consistent.
[0024] Loss function L total It consists of two parts: the eigenvector constraint loss L1 and the eigenvector center clustering loss L2.
[0025]
[0026] L total =α·L1+(1-α)·L2,
[0027] In the formula, N represents the number of samples with invariant feature vectors of normal samples; i represents the sample index; This represents the invariant feature vector of the i-th normal sample; Let represent the L2 norm of the i-th normal sample invariant eigenvector; let c represent the center vector of the normal sample invariant eigenvector. α is the weighting coefficient, 0 < α < 1.
[0028] Further optionally, step S3 specifically includes:
[0029] S3.1. A training dataset is constructed using two layers of invariant feature vectors from constrained normal samples. The RealNVP normalized flow model is used as the core modeling tool, and a standard Gaussian distribution is selected as the target distribution. The RealNVP normalized flow model consists of two stacked reversible transformation layers. Each layer contains two core operations: ① Masking operation: The input feature channels are randomly or fixedly divided into two parts to ensure that the subsequent transformation process satisfies the reversibility; ② Affine transformation: For the non-fixed feature channels after masking, the built-in neural network adaptively predicts the scale factor and offset, and performs a linear transformation on the channel to achieve flexible mapping of the feature space.
[0030] S3.2 The RealNVP normalized flow model uses iterative mapping of two layers of invertible transformation layers to gradually transform the two layers of invariant feature vectors of normal samples in the training dataset into latent variables that conform to the standard Gaussian distribution. Finally, the distribution law of the two layers of invariant feature vectors is quantified into a computable probability density function, thus completing the modeling of the distribution of invariant feature vectors of normal samples.
[0031] S3.3. Minimizing the negative log-likelihood loss is used as the training objective. The model parameters are iteratively adjusted through backpropagation, which continuously improves the modeling accuracy of the RealNVP normalized flow model for the distribution of invariant feature vectors of normal samples.
[0032] Preferably, the negative log-likelihood loss is minimized using the following formula:
[0033]
[0034] In the formula, The logp vector represents the invariant feature vector of normal samples in the training dataset; z represents the latent variable; logp z (z) represents the log probability density of the latent variable z under the standard Gaussian distribution; Represents a multi-level invertible mapping function; represents the logarithm of the Jacobian determinant of the invertible transformation; N represents the number of samples in the training dataset whose invariant eigenvectors are in the training dataset. This represents the invariant feature vector of the i-th normal sample in the training dataset. The log-likelihood; This represents the invariant feature vector of the i-th normal sample in the training dataset.
[0035] Optionally, step S4 is performed to upsample and weighted fusion operations on the anomaly score matrices corresponding to the two layers of invariant feature vectors to generate a global anomaly score matrix for the cable image to be detected. This process specifically includes the following operations:
[0036] S4.1. Upsampling: For the abnormal score matrices of different sizes output by the two-layer invariant feature vectors, with a target resolution of 224×224, an interpolation algorithm is used to enlarge the size of each abnormal score matrix; during the operation, according to the spatial distribution characteristics of the original abnormal scores in the matrix, the relative relationship of the abnormal degree at each position and the position information of the key abnormal regions are retained during the enlargement process. Finally, both of the two-layer abnormal score matrices are uniformly converted to a size of 224×224 pixels, ensuring the consistency of the spatial dimensions of different-level matrices and laying a foundation for subsequent fusion operations;
[0037] S4.2. Weighted fusion: First, assign corresponding weight coefficients to each 224×224-dimensional abnormal score matrix that has completed upsampling. The weights are set according to the importance of the two-layer invariant feature vectors for the abnormal detection of cable images; then, perform weighted summation calculations on the corresponding pixel positions of the two-layer abnormal score matrices to generate a 224×224-pixel global abnormal score matrix for the cable image to be detected. The formula involved in weighted summation is as follows:
[0038] M global M(i, j) = w1·M1(i, j) + w2·M2(i, j),
[0039] In the formula, M global represents the fused global abnormal score matrix, with a dimension of 224×224; M global (i, j) represents the fused abnormal score of the pixel in the i-th row and j-th column of the global matrix; M1 represents the first-layer abnormal score matrix, and M1(i, j) represents the abnormal score of the pixel in the i-th row and j-th column of the first-layer abnormal score matrix; M2 represents the second-layer abnormal score matrix, and M2(i, j) represents the abnormal score of the pixel in the i-th row and j-th column of the second-layer abnormal score matrix; w1 represents the weight coefficient of the first-layer abnormal score matrix, 0 < w1 < 1; w2 represents the weight coefficient of the second-layer abnormal score matrix, 0 < w2 < 1.
[0040] In the second aspect, a cable surface abnormal detection system based on invariant features according to the present invention adopts the following technical solution to solve the above technical problems:
[0041] A cable surface abnormal detection system based on invariant features, which is used to implement the method described in the first aspect, specifically includes:
[0042] An image acquisition and preprocessing module, which is used to obtain the full-surface image of the cable by using an industrial-grade image acquisition device, and construct a normal sample data set for cable detection after preprocessing;
[0043] A multi-level feature vector extraction module, which is used to extract the multi-level feature vectors of the normal samples in the data set by using a pre-trained model and store them in the feature vector library layer by layer;
[0044] The invariant feature vector generation module is used to find the nearest neighbor feature vector at the corresponding level in the feature vector library for any normal sample in the dataset, and generate multi-level invariant feature vectors through difference operation.
[0045] The invariant eigenvector constraint module is used to perform L2 normalization on multi-level invariant eigenvectors, which are then input into a customized eigenvector constraint network to constrain the multi-level invariant eigenvectors of normal samples to the unit hypersphere.
[0046] The dataset construction and model training module is used to construct a training dataset with multi-level invariant feature vectors of constrained normal samples, model the probability density function of multi-level invariant feature vectors of normal samples using the RealNVP normalized flow model, and complete the model training by minimizing the negative log-likelihood loss.
[0047] The inference detection execution module is used to call the image acquisition and preprocessing module to acquire and preprocess the cable image to be detected, call the multi-level feature vector extraction module to extract the multi-level feature vectors of the image, call the invariant feature vector generation module to generate the multi-level invariant feature vectors of the image, call the invariant feature vector constraint module to constrain the multi-level invariant feature vectors, and then input the trained RealNVP normalized flow model to obtain the anomaly score matrix of each level of invariant feature vectors. Finally, upsampling and weighted fusion operations are performed on the anomaly score matrix corresponding to each level of invariant feature vector to generate the global anomaly score matrix of the cable image to be detected.
[0048] The inference detection result output module is used to perform anomaly segmentation on the global anomaly score matrix based on a preset threshold, determine whether the cable is abnormal based on the proportion of abnormal pixels, and output an anomaly segmentation map for anomaly localization, thereby completing anomaly detection.
[0049] The cable surface anomaly detection method and system based on invariant features of the present invention have the following advantages compared with the prior art:
[0050] 1. This invention designs an invariant feature extraction mechanism, which obtains invariant normal features by subtracting the feature vectors of neighboring normal samples, highlighting the difference between the feature vectors of normal samples and the feature vectors of abnormal samples; it uses a customized feature vector constraint network to constrain the feature vectors, highlighting the boundary between the feature vectors of normal samples and the feature vectors of abnormal samples, thereby improving the accuracy and efficiency of cable detection anomaly judgment, solving the problems of low efficiency, high missed detection rate and strong subjectivity of manual detection, and overcoming the defects of existing unsupervised cable anomaly detection technology;
[0051] 2. This invention uses feature distribution estimation to replace distance-based anomaly detection, solving the problem of distance failure in high-dimensional space, while improving the computational efficiency of the RealNVP normalized flow model. Attached Figure Description
[0052] Appendix Figure 1 This is a block diagram illustrating the method implementation of Embodiment 1 of the present invention;
[0053] Appendix Figure 2 This is a system module connection block diagram of Embodiment 2 of the present invention. Detailed Implementation
[0054] To make the technical solution, the technical problem solved, and the technical effect of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with specific embodiments.
[0055] Example 1:
[0056] Combined with appendix Figure 1 This embodiment proposes a method for detecting cable surface anomalies based on invariant features, which includes the following steps:
[0057] S1. Image Acquisition and Preprocessing: Industrial-grade image acquisition equipment is used to acquire full-surface images of the cable. After preprocessing, a normal sample dataset for cable inspection is constructed.
[0058] The industrial-grade acquisition equipment includes a 2-megapixel high-definition industrial camera (50fps, output image resolution 1920×1080), a 16mm fixed-focus industrial lens (depth of field 20-40cm to adapt to large-diameter cables), and a custom ring light source (the light source angle is set to 45 degrees to enhance the shadow contrast of the defect area).
[0059] The preprocessing operations performed include data cleaning, noise filtering, and deduplication of redundant samples.
[0060] S2. Invariant Feature Vector Generation and Feature Constraint: A pre-trained model is used to extract multi-level feature vectors of normal samples in the dataset and store them hierarchically in a feature vector library. For any normal sample in the dataset, the multi-level feature vector stored in the feature vector library is searched for its nearest neighbor feature vector at the corresponding level, and multi-level invariant feature vectors are generated through difference operations. After L2 normalization of the multi-level invariant feature vectors, they are input into a customized feature vector constraint network to constrain the multi-level invariant feature vectors of normal samples to a unit hypersphere.
[0061] This step specifically includes:
[0062] S2.1. A ResNet50 model pre-trained on a large-scale dataset is used as the backbone network. For normal samples in the dataset, the intermediate feature vectors of layer 2 and layer 3 are extracted and denoted as L2 and L3 respectively. Then, they are stored in the feature vector library in layers.
[0063] Taking an input of 224×224 as an example, the shape of the output feature of layer 2 is N×512×28×28, and the shape of the output feature of layer 3 is N×1024×14×14, where N is the number of normal samples in the dataset. The outputs of the two layers of the ResNet50 model are stored separately and denoted as L2 and L3.
[0064] S2.2 For any normal sample in the dataset, the two layers of feature vectors stored in the feature vector library are searched for the nearest neighbor feature vectors of each layer in the feature vector library, and the two layers of invariant feature vectors are generated by difference operation.
[0065] S2.3. Perform L2 normalization on the two layers of invariant feature vectors respectively; input the two layers of invariant feature vectors after L2 normalization into the customized feature vector constraint network according to the level; constrain the two layers of invariant feature vectors of normal samples to fall within the unit hypersphere through the loss function, so that the L2 norm of the two layers of invariant feature vectors of normal samples is less than 1 and they are clustered towards the center of the sphere.
[0066] The customized feature vector constraint network is composed of stacked ConvBNReLU modules. Each layer uses a 3×3 convolution kernel and padding=1 to ensure that the input and output dimensions of layer 2 and layer 3 are consistent.
[0067] Loss function L total It consists of two parts: the eigenvector constraint loss L1 and the eigenvector center clustering loss L2.
[0068]
[0069] L total =α·L1+(1-α)·L2,
[0070] In the formula, N represents the number of samples with invariant feature vectors of normal samples; i represents the sample index; This represents the invariant feature vector of the i-th normal sample; Let represent the L2 norm of the i-th normal sample invariant eigenvector; let c represent the center vector of the normal sample invariant eigenvector. α is the weighting coefficient, 0 < α < 1.
[0071] S3. Invariant Eigenvector Distribution Estimation: A training dataset is constructed using multi-level invariant eigenvectors of constrained normal samples. The probability density function of the multi-level invariant eigenvectors of normal samples is modeled using the RealNVP normalized flow model, and the model training is completed by minimizing the negative log-likelihood loss.
[0072] This step specifically includes:
[0073] S3.1. A training dataset is constructed using two layers of invariant feature vectors from constrained normal samples. The RealNVP normalized flow model is used as the core modeling tool, and a standard Gaussian distribution is selected as the target distribution. The RealNVP normalized flow model consists of two stacked reversible transformation layers. Each layer contains two core operations: ① Masking operation: The input feature channels are randomly or fixedly divided into two parts to ensure that the subsequent transformation process satisfies the reversibility (providing a basis for the bidirectional mapping between features and latent variables); ② Affine transformation: For the non-fixed feature channels after masking, the built-in neural network adaptively predicts the scale factor and offset, and performs a linear transformation on the channel to achieve flexible mapping of the feature space.
[0074] S3.2 The RealNVP normalized flow model uses iterative mapping of two layers of invertible transformation layers to gradually transform the two layers of invariant feature vectors of normal samples in the training dataset into latent variables that conform to the standard Gaussian distribution. Finally, the distribution law of the two layers of invariant feature vectors is quantified into a computable probability density function, thus completing the modeling of the distribution of invariant feature vectors of normal samples.
[0075] S3.3. By minimizing the negative log-likelihood loss as the training objective, and by iteratively adjusting the model parameters (including the masking strategy and the scale / offset prediction network parameters of the affine transformation) through backpropagation, the modeling accuracy of the RealNVP normalized flow model for the distribution of invariant feature vectors of normal samples is continuously improved.
[0076] Specifically, the negative log-likelihood loss (Loss) is minimized using the following formula:
[0077]
[0078] In the formula, The logp vector represents the invariant feature vector of normal samples in the training dataset; z represents the latent variable; logp z (z) represents the log probability density of the latent variable z under the standard Gaussian distribution; Represents a multi-level invertible mapping function; represents the logarithm of the Jacobian determinant of the invertible transformation; N represents the number of samples in the training dataset whose invariant eigenvectors are in the training dataset. This represents the invariant feature vector of the i-th normal sample in the training dataset. The log-likelihood; This represents the invariant feature vector of the i-th normal sample in the training dataset.
[0079] After the RealNVP normalized flow model is trained, the anomaly detection logic is upgraded from the traditional "distance matching" to "out-of-distribution judgment". After the sample to be detected is preprocessed, feature extracted, invariant feature generated and feature constrained, it is input into the trained RealNVP normalized flow model. If the latent variable after mapping deviates from the standard Gaussian distribution (the probability density is lower than the set threshold), it is judged as a defect sample. In the end, the accurate detection of cable defects is achieved, while improving the model's generalization ability to process / raw material changes.
[0080] S4. Inference Detection: Based on the image acquisition and preprocessing operation logic of step S1, the image of the cable to be detected is obtained; based on the operation logic of multi-level feature vector extraction, multi-level invariant feature vector generation, L2 normalization and customized feature vector constraint network constraint of step S2, the multi-level invariant feature vector constrained by the image is obtained, and then input into the trained RealNVP normalized flow model to obtain the anomaly score matrix of each level of invariant feature vector; perform upsampling and weighted fusion operations on the anomaly score matrix corresponding to each level of invariant feature vector to generate the global anomaly score matrix of the cable image to be detected.
[0081] This step obtains the image of the cable to be inspected based on the image acquisition and preprocessing operation logic of step S1. The specific process is described as follows: The full surface image of the cable is acquired using an industrial-grade image acquisition device, and the image of the cable to be inspected is obtained after data cleaning and noise filtering preprocessing.
[0082] This step, based on the multi-level feature vector extraction, multi-level invariant feature vector generation, L2 normalization, and customized feature vector constraint network operation logic of step S2, obtains the constrained multi-level invariant feature vectors of the image. The specific process is described as follows: ① Use a pre-trained model to extract two layers of feature vectors from the cable image to be detected; ② Search for the nearest neighbor feature vectors of the two layers of feature vectors at the corresponding layers in the feature vector library, and generate two layers of invariant feature vectors through difference operation; ③ After L2 normalization of the two layers of invariant feature vectors, input them into the customized feature vector constraint network to constrain the two layers of invariant feature vectors of the image, and obtain the constrained two layers of invariant feature vectors.
[0083] Input the two - layer invariant feature vectors after constraint into the trained RealNVP normalizing flow model, and then input it into the trained RealNVP normalizing flow model to obtain the anomaly score matrix of the two - layer invariant feature vectors. Perform upsampling and weighted fusion operations on the anomaly score matrix corresponding to the two - layer invariant feature vectors to generate the global anomaly score matrix of the cable image to be detected. This process specifically includes the following operations:
[0084] S4.1 Upsampling: For the anomaly score matrices of different sizes output by the two - layer invariant feature vectors, with a target resolution of 224×224, use an interpolation algorithm (such as bilinear interpolation, transposed convolution, etc.) to magnify the size of each anomaly score matrix. During the operation, according to the spatial distribution characteristics of the original anomaly scores in the matrix, the relative relationship of the anomaly degree at each position and the position information of the key anomaly regions are retained during the magnification process. Finally, both of the two - layer anomaly score matrices are uniformly converted to a size of 224×224 pixels, ensuring that the spatial dimensions of different - level matrices are consistent, laying a foundation for subsequent fusion operations;
[0085] S4.2 Weighted fusion: First, assign corresponding weight coefficients to each 224×224 - dimensional anomaly score matrix that has completed upsampling. The weights are set according to the importance of the two - layer invariant feature vectors for cable image anomaly detection (for example, the matrix weight of the deep - layer feature vector is higher, focusing on the global anomaly trend; the matrix weight of the shallow - layer feature vector is adaptively adjusted, focusing on local cable defect details; relatively speaking, the feature vector related to the layer2 is the shallow - layer feature vector, and the feature vector related to the layer3 is the deep - layer feature vector). Subsequently, perform weighted summation calculations on the corresponding pixel positions of the two - layer anomaly score matrices to generate the 224×224 - pixel global anomaly score matrix of the cable image to be detected. The formula for weighted summation is as follows:
[0086] M global (i, j)=w1·M1(i, j)+w2·M2(i, j),
[0087] In the formula, M global represents the fused global anomaly score matrix, with a dimension of 224×224; M global (i, j) represents the fused anomaly score of the pixel in the i - th row and j - th column of the global matrix; M1 represents the first - layer anomaly score matrix, and M1(i, j) represents the anomaly score of the pixel in the i - th row and j - th column of the first - layer anomaly score matrix; M2 represents the second - layer anomaly score matrix, and M2(i, j) represents the anomaly score of the pixel in the i - th row and j - th column of the second - layer anomaly score matrix; w1 represents the weight coefficient of the first - layer anomaly score matrix, 0 < w1 < 1; w2 represents the weight coefficient of the second - layer anomaly score matrix, 0 < w2 < 1.
[0088] S5. Result Output: Based on the preset threshold, perform anomaly segmentation on the global anomaly score matrix, determine whether the cable is abnormal according to the proportion of abnormal pixels (e.g., set the proportion of abnormal pixels to be more than 5% to be an abnormal image), and output the anomaly segmentation map for anomaly location, thereby completing the anomaly detection.
[0089] Example 2:
[0090] Combined with appendix Figure 2 This embodiment proposes a cable surface anomaly detection system based on invariant features, which is used to implement the method described in Embodiment 1. Specifically, it includes: an image acquisition and preprocessing module, a multi-level feature vector extraction module, an invariant feature vector generation module, an invariant feature vector generation module, a dataset construction and model training module, an inference detection execution module, and an inference detection result output module.
[0091] The functions implemented by each module in this embodiment are described in detail below.
[0092] A. Image acquisition and preprocessing module: This module is used to acquire full-surface images of cables using industrial-grade image acquisition equipment, and then construct a normal sample dataset for cable inspection after preprocessing.
[0093] The industrial-grade acquisition equipment includes a 2-megapixel high-definition industrial camera (50fps, output image resolution 1920×1080), a 16mm fixed-focus industrial lens (depth of field 20-40cm to adapt to large-diameter cables), and a custom ring light source (the light source angle is set to 45 degrees to enhance the shadow contrast of the defect area).
[0094] The preprocessing operations performed include data cleaning, noise filtering, and deduplication of redundant samples.
[0095] B. Multi-level feature vector extraction module, used to extract multi-level feature vectors of normal samples in the dataset using a pre-trained model, and store them hierarchically in the feature vector library.
[0096] Specifically, a ResNet50 model pre-trained on a large-scale dataset is used as the backbone network. For normal samples in the dataset, the intermediate feature vectors of layer 2 and layer 3 are extracted and denoted as L2 and L3, respectively. Then, they are stored in the feature vector library in layers.
[0097] Taking an input of 224×224 as an example, the shape of the output feature of layer 2 is N×512×28×28, and the shape of the output feature of layer 3 is N×1024×14×14, where N is the number of normal samples in the dataset. The outputs of the two layers of the ResNet50 model are stored separately and denoted as L2 and L3.
[0098] C. The invariant feature vector generation module is used to find the nearest neighbor feature vector at the corresponding level in the feature vector library for any normal sample in the dataset, and generate multi-level invariant feature vectors through difference operation.
[0099] D. The invariant eigenvector constraint module is used to perform L2 normalization on multi-level invariant eigenvectors, which are then input into a customized eigenvector constraint network to constrain the multi-level invariant eigenvectors of normal samples to the unit hypersphere.
[0100] The customized feature vector constraint network is composed of stacked ConvBNReLU modules. Each layer uses a 3×3 convolution kernel and padding=1 to ensure that the input and output dimensions of layer 2 and layer 3 are consistent.
[0101] Loss function L total It consists of two parts: the eigenvector constraint loss L1 and the eigenvector center clustering loss L2.
[0102]
[0103] L total =α·L1+(1-α)·L2,
[0104] In the formula, N represents the number of samples with invariant feature vectors of normal samples; i represents the sample index; This represents the invariant feature vector of the i-th normal sample; Let represent the L2 norm of the i-th normal sample invariant eigenvector; let c represent the center vector of the normal sample invariant eigenvector. α is the weighting coefficient, 0 < α < 1.
[0105] E. The dataset construction and model training module is used to construct a training dataset using multi-level invariant feature vectors of constrained normal samples, model the probability density function of multi-level invariant feature vectors of normal samples using the RealNVP normalized flow model, and complete the model training by minimizing the negative log-likelihood loss.
[0106] The dataset construction and model training module specifically performs the following operations:
[0107] (1) A training dataset is constructed using two layers of invariant feature vectors of normal samples after constraints. The RealNVP normalized flow model is used as the core modeling tool, and the standard Gaussian distribution is selected as the target distribution. The RealNVP normalized flow model consists of two layers of reversible transformation stacked together. Each layer contains two core operations: ① Masking operation: The channels of the input features are randomly or fixedly divided into two parts to ensure that the subsequent transformation process satisfies the reversibility (providing a basis for the bidirectional mapping between features and latent variables); ② Affine transformation: For the non-fixed feature channels after masking, the built-in neural network adaptively predicts the scale factor and offset, and performs a linear transformation on the channel to achieve flexible mapping of the feature space.
[0108] (2) The RealNVP normalized flow model transforms the two layers of invariant feature vectors of normal samples in the training dataset into latent variables that conform to the standard Gaussian distribution through iterative mapping of two layers of invertible transformation layers. Finally, the distribution law of the two layers of invariant feature vectors is quantified into a computable probability density function, thus completing the modeling of the distribution of invariant feature vectors of normal samples.
[0109] (3) The model parameters (including masking strategy and scale / offset prediction network parameters of affine transformation) are adjusted iteratively through backpropagation by minimizing the negative log-likelihood loss as the training objective, so that the modeling accuracy of RealNVP normalized flow model for the distribution of invariant feature vectors of normal samples is continuously improved.
[0110] Specifically, the negative log-likelihood loss (Loss) is minimized using the following formula:
[0111]
[0112] In the formula, The logp vector represents the invariant feature vector of normal samples in the training dataset; z represents the latent variable; logp z (z) represents the log probability density of the latent variable z under the standard Gaussian distribution; Represents a multi-level invertible mapping function; represents the logarithm of the Jacobian determinant of the invertible transformation; N represents the number of samples in the training dataset whose invariant eigenvectors are in the training dataset. This represents the invariant feature vector of the i-th normal sample in the training dataset. The log-likelihood; This represents the invariant feature vector of the i-th normal sample in the training dataset.
[0113] After the RealNVP normalized flow model is trained, the anomaly detection logic is upgraded from the traditional "distance matching" to "out-of-distribution judgment". After the sample to be detected is preprocessed, feature extracted, invariant feature generated and feature constrained, it is input into the trained RealNVP normalized flow model. If the latent variable after mapping deviates from the standard Gaussian distribution (the probability density is lower than the set threshold), it is judged as a defect sample. In the end, the accurate detection of cable defects is achieved, while improving the model's generalization ability to process / raw material changes.
[0114] F. The inference and detection execution module is used to call the image acquisition and preprocessing module to acquire and preprocess the image of the cable to be detected, call the multi-level feature vector extraction module to extract the multi-level feature vectors of the image, call the invariant feature vector generation module to generate the multi-level invariant feature vectors of the image, call the invariant feature vector constraint module to constrain the multi-level invariant feature vectors, and then input the trained RealNVP normalized flow model to obtain the anomaly score matrix of each level of invariant feature vectors. Finally, upsampling and weighted fusion operations are performed on the anomaly score matrix corresponding to each level of invariant feature vector to generate the global anomaly score matrix of the cable image to be detected.
[0115] The inference detection execution module calls the image acquisition and preprocessing module to acquire and preprocess the image of the cable to be detected. The specific process is described as follows: The full surface image of the cable is acquired using industrial-grade image acquisition equipment, and the image of the cable to be detected is obtained after data cleaning and noise filtering preprocessing.
[0116] Reference Appendix Figure 2 The dashed box in the diagram indicates that the inference detection execution module sequentially calls the image acquisition and preprocessing module, the multi-level feature vector extraction module, the invariant feature vector generation module, the invariant feature vector constraint module, and the trained RealNVP normalized flow model, and receives the anomaly score matrix of the multi-level invariant feature vectors output by the RealNVP normalized flow model. The specific process is described as follows: ① Use the pre-trained model to extract two layers of feature vectors from the cable image to be detected; ② Find the nearest neighbor feature vectors of the two layers of feature vectors at the corresponding levels in the feature vector library, and generate two layers of invariant feature vectors through difference operation; ③ After L2 normalization of the two layers of invariant feature vectors, input them into the customized feature vector constraint network to constrain the two layers of invariant feature vectors of the image, and obtain the constrained two layers of invariant feature vectors; input the constrained two layers of invariant feature vectors into the trained RealNVP normalized flow model to obtain the anomaly score matrix of the two layers of invariant feature vectors.
[0117] Subsequently, the inference detection execution module performs upsampling and weighted fusion operations on the anomaly score matrix corresponding to the two layers of invariant feature vectors to generate a global anomaly score matrix for the cable image to be detected. This process specifically includes the following operations:
[0118] (1) Upsampling: For the abnormal score matrices of different sizes output by the two-layer invariant feature vectors, with a target resolution of 224×224, interpolation algorithms (such as bilinear interpolation, transposed convolution, etc.) are used to enlarge the size of each abnormal score matrix; during the operation, according to the spatial distribution characteristics of the original abnormal scores of the matrix, the relative relationship of the abnormal degree at each position and the position information of the key abnormal regions are retained during the enlargement process. Finally, both of the two-layer abnormal score matrices are uniformly converted to the size of 224×224 pixels, ensuring that the spatial dimensions of the matrices at different levels are consistent, laying a foundation for subsequent fusion operations;
[0119] (2) Weighted fusion: First, corresponding weight coefficients are assigned to each 224×224-dimensional abnormal score matrix that has completed upsampling. The weights are set according to the importance of the two-layer invariant feature vectors for the abnormal detection of cable images (for example, the matrix weight of the deep feature vector is higher, focusing on the global abnormal trend; the matrix weight of the shallow feature vector is adjusted adaptively, focusing on the local cable defect details); then, weighted summation calculations are performed on the corresponding pixel positions of the two-layer abnormal score matrices to generate a 224×224-pixel global abnormal score matrix for the cable image to be detected; the formula for weighted summation is as follows:
[0120] M global M(i, j) = w1·M1(i, j) + w2·M2(i, j),
[0121] In the formula, M global represents the fused global abnormal score matrix, with a dimension of 224×224; M global (i, j) represents the fused abnormal score of the pixel in the i-th row and j-th column of the global matrix; M1 represents the first-layer abnormal score matrix, and M1(i, j) represents the abnormal score of the pixel in the i-th row and j-th column of the first-layer abnormal score matrix; M2 represents the second-layer abnormal score matrix, and M2(i, j) represents the abnormal score of the pixel in the i-th row and j-th column of the second-layer abnormal score matrix; w1 represents the weight coefficient of the first-layer abnormal score matrix, 0 < w1 < 1; w2 represents the weight coefficient of the second-layer abnormal score matrix, 0 < w2 < 1.
[0122] G. Inference and detection result output module, which is used to perform abnormal segmentation on the global abnormal score matrix based on a preset threshold, judge whether the cable is abnormal according to the proportion of abnormal pixels (for example, if the proportion of the number of abnormal pixels exceeds 5%, the image is recorded as an abnormal image), and output an abnormal segmentation map for positioning the abnormality, thereby completing the abnormal detection.
[0123] In summary, the cable surface anomaly detection method and system based on invariant features of the present invention can improve the accuracy and efficiency of cable anomaly detection, solve the problems of low efficiency, high missed detection rate and strong subjectivity of manual detection, and overcome the defects of existing unsupervised cable anomaly detection technology.
[0124] The above specific examples illustrate the principles and implementation methods of the present invention in detail. These embodiments are merely for the purpose of helping to understand the core technical content of the present invention. Based on the above specific embodiments of the present invention, any improvements and modifications made to the present invention by those skilled in the art without departing from the principles of the present invention should fall within the patent protection scope of the present invention.
Claims
1. A method for detecting surface anomalies in cables based on invariant features, characterized in that, Includes the following steps: S1. Image Acquisition and Preprocessing: Industrial-grade image acquisition equipment is used to acquire full-surface images of the cable. After preprocessing, a normal sample dataset for cable inspection is constructed. S2. Invariant Feature Vector Generation and Feature Constraint: A pre-trained model is used to extract multi-level feature vectors of normal samples in the dataset and store them hierarchically in a feature vector library. For any normal sample in the dataset, the multi-level feature vector stored in the feature vector library is searched for its nearest neighbor feature vector at the corresponding level, and multi-level invariant feature vectors are generated through difference operations. After L2 normalization of the multi-level invariant feature vectors, they are input into a customized feature vector constraint network to constrain the multi-level invariant feature vectors of normal samples to a unit hypersphere. S3. Invariant Eigenvector Distribution Estimation: A training dataset is constructed using multi-level invariant eigenvectors of constrained normal samples. The probability density function of the multi-level invariant eigenvectors of normal samples is modeled using the RealNVP normalized flow model, and the model training is completed by minimizing the negative log-likelihood loss. S4. Inference Detection: Based on the image acquisition and preprocessing logic of step S1, the image of the cable to be detected is acquired; based on the multi-level feature vector extraction, multi-level invariant feature vector generation, L2 normalization, and customized feature vector constraint network operation logic of step S2, the multi-level invariant feature vector constrained by the image is obtained, and then input into the trained RealNVP normalized flow model to obtain the anomaly score matrix of each level of invariant feature vector; upsampling and weighted fusion operations are performed on the anomaly score matrix corresponding to each level of invariant feature vector to generate the global anomaly score matrix of the cable image to be detected; S5. Result Output: Based on the preset threshold, the global anomaly score matrix is segmented for anomaly. The cable is judged to be abnormal according to the proportion of abnormal pixels, and the anomaly segmentation map is output for anomaly location, thereby completing the anomaly detection.
2. The method for detecting cable surface anomalies based on invariant features according to claim 1, characterized in that, The industrial-grade data acquisition equipment includes a 2-megapixel high-definition industrial camera, a 16mm fixed-focus industrial lens, and a custom-designed ring light source.
3. The method for detecting cable surface anomalies based on invariant features according to claim 1, characterized in that, Step S1 involves preprocessing operations including data cleaning, noise filtering, and deduplication of redundant samples. When executing step S4, the preprocessing operations performed when acquiring the image of the cable to be detected based on the image acquisition and preprocessing operation logic of step S1 include data cleaning and noise filtering.
4. The method for detecting cable surface anomalies based on invariant features according to claim 1, characterized in that, Step S2 specifically includes: S2.
1. A ResNet50 model pre-trained on a large-scale dataset is used as the backbone network. For normal samples in the dataset, the intermediate feature vectors of layer 2 and layer 3 are extracted and denoted as L2 and L3 respectively. Then, they are stored in the feature vector library in layers. S2.2 For any normal sample in the dataset, the two layers of feature vectors stored in the feature vector library are searched for the nearest neighbor feature vectors of each layer in the feature vector library, and the two layers of invariant feature vectors are generated by difference operation. S2.
3. Perform L2 normalization on the two layers of invariant feature vectors respectively; input the two layers of invariant feature vectors after L2 normalization into the customized feature vector constraint network according to the level; constrain the two layers of invariant feature vectors of normal samples to fall within the unit hypersphere through the loss function, so that the L2 norm of the two layers of invariant feature vectors of normal samples is less than 1 and they are clustered towards the center of the sphere.
5. The cable surface anomaly detection method based on invariant features according to claim 4, characterized in that, The customized feature vector constraint network is composed of stacked ConvBNReLU modules. Each layer uses a 3×3 convolution kernel with padding=1 to ensure that the input and output dimensions of layer 2 and layer 3 are consistent. Loss function L total Loss L1 constrained by the feature vector and loss L2 of the feature vector center aggregation composition: L total = a - Li + (1 - a) - L2, In the formula, N represents the number of samples with invariant feature vectors of normal samples; i represents the sample index; This represents the invariant feature vector of the i-th normal sample; Let represent the L2 norm of the i-th normal sample invariant eigenvector; let c represent the center vector of the normal sample invariant eigenvector. α is the weighting coefficient, 0 < α < 1.
6. The cable surface anomaly detection method based on invariant features according to claim 4, characterized in that, Step S3 specifically includes: S3.
1. A training dataset is constructed using two layers of invariant feature vectors from constrained normal samples. The RealNVP normalized flow model is used as the core modeling tool, and a standard Gaussian distribution is selected as the target distribution. The RealNVP normalized flow model consists of two stacked reversible transformation layers. Each layer contains two core operations: ① Masking operation: The input feature channels are randomly or fixedly divided into two parts to ensure that the subsequent transformation process satisfies the reversibility; ② Affine transformation: For the non-fixed feature channels after masking, the built-in neural network adaptively predicts the scale factor and offset, and performs a linear transformation on the channel to achieve flexible mapping of the feature space. S3.2 The RealNVP normalized flow model uses iterative mapping of two layers of invertible transformation layers to gradually transform the two layers of invariant feature vectors of normal samples in the training dataset into latent variables that conform to the standard Gaussian distribution. Finally, the distribution law of the two layers of invariant feature vectors is quantified into a computable probability density function, thus completing the modeling of the distribution of invariant feature vectors of normal samples. S3.
3. Minimizing the negative log-likelihood loss is used as the training objective. The model parameters are iteratively adjusted through backpropagation, which continuously improves the modeling accuracy of the RealNVP normalized flow model for the distribution of invariant feature vectors of normal samples.
7. The method for detecting cable surface anomalies based on invariant features according to claim 6, characterized in that, Minimize the negative log-likelihood loss using the following formula: In the formula, The logp vector represents the invariant feature vector of normal samples in the training dataset; z represents the latent variable; logp z (z) represents the log probability density of the latent variable z under the standard Gaussian distribution; Represents a multi-level invertible mapping function; represents the logarithm of the Jacobian determinant of the invertible transformation; N represents the number of samples in the training dataset whose invariant eigenvectors are in the training dataset. This represents the invariant feature vector of the i-th normal sample in the training dataset. The log-likelihood; This represents the invariant feature vector of the i-th normal sample in the training dataset.
8. The method for detecting cable surface anomalies based on invariant features according to claim 7, characterized in that, Step S4 involves performing upsampling and weighted fusion operations on the anomaly score matrices corresponding to the two layers of invariant feature vectors to generate a global anomaly score matrix for the cable image to be detected. This process specifically includes the following operations: S4.1 Upsampling: For the different sizes of anomaly score matrices output by the two layers of invariant feature vectors, an interpolation algorithm is used to enlarge the size of each anomaly score matrix with a target resolution of 224×224. During the operation, based on the spatial distribution characteristics of the original anomaly scores in the matrix, the relative relationship of the degree of anomaly at each position and the location information of key anomaly areas are preserved during the enlargement process. Finally, both layers of anomaly score matrices are uniformly converted to a size of 224×224 pixels to ensure that the spatial dimension of the matrices at different levels is consistent, laying the foundation for subsequent fusion operations. S4.
2. Weighted fusion: First, assign corresponding weight coefficients to each upsampled 224×224 - dimensional anomaly score matrix. The weights are set according to the importance of the two - layer invariant feature vectors for the anomaly detection of cable images. Subsequently, perform weighted summation calculations on the corresponding pixel positions of the two - layer anomaly score matrices to generate a 224×224 - pixel global anomaly score matrix for the cable image to be detected. The formula for weighted summation is as follows: M global (i,j)=w1·M1(i,j)+w2·M2(i,j), In the formula, M global M represents the fused global anomaly score matrix, with dimensions 224×224; global (i, j) represents the fused abnormal score of the pixel in the i-th row and j-th column of the global matrix; M1 represents the first - layer anomaly score matrix, and M1(i, j) represents the anomaly score of the pixel in the i - th row and j - th column of the first - layer anomaly score matrix; M2 represents the second - layer anomaly score matrix, and M2(i, j) represents the anomaly score of the pixel in the i - th row and j - th column of the second - layer anomaly score matrix; w1 represents the weight coefficient of the first - layer anomaly score matrix, where 0 < w1 < 1; w2 represents the weight coefficient of the second - layer anomaly score matrix, where 0 < w2 < 1.
9. A cable surface anomaly detection system based on invariant features, characterized in that, It is used to implement the method described in any one of claims 1 - 8, specifically including: An image acquisition and pre - processing module, which is used to obtain the full - surface image of the cable using an industrial - grade image acquisition device, perform pre - processing, and construct a normal sample data set for cable detection; A multi - level feature vector extraction module, which is used to extract multi - level feature vectors of normal samples in the data set using a pre - trained model and store them in layers in a feature vector library; An invariant feature vector generation module, which is used to find the nearest - neighbor feature vector of the corresponding level in the feature vector library for any normal sample in the data set corresponding to the multi - level feature vectors in the feature vector library, and generate multi - level invariant feature vectors through difference operations; An invariant feature vector constraint module, which is used to perform L2 normalization on the multi - level invariant feature vectors, and then input them into a customized feature vector constraint network respectively to constrain the multi - level invariant feature vectors of normal samples within the unit hypersphere; A data set construction and model training module, which is used to construct a training data set with the multi - level invariant feature vectors of the constrained normal samples, model the probability density function of the multi - level invariant feature vectors of normal samples using a RealNVP normalizing flow model, and complete model training by minimizing the negative log - likelihood loss; An inference detection execution module, which is used to call the image acquisition and pre - processing module to collect and pre - process the cable image to be detected, call the multi - level feature vector extraction module to extract the multi - level feature vectors of this image, call the invariant feature vector generation module to generate the multi - level invariant feature vectors of this image, call the invariant feature vector constraint module to constrain the multi - level invariant feature vectors, then input them into the trained RealNVP normalizing flow model to obtain the anomaly score matrices of the invariant feature vectors at each level, and then perform upsampling and weighted fusion operations on the anomaly score matrices corresponding to the invariant feature vectors at each level to generate a global anomaly score matrix for the cable image to be detected; An inference detection result output module, which is used to perform anomaly segmentation on the global anomaly score matrix based on a preset threshold, judge whether the cable is abnormal according to the proportion of abnormal pixels, and output an anomaly segmentation map for anomaly localization, thereby completing anomaly detection.