A Method and System for Cable Surface Anomaly Detection Based on Self-Supervised Comparative Learning

An anomaly detection model built using a self-supervised contrastive learning method, employing image masking and data augmentation techniques, addresses the problem of insufficient data in industrial quality inspection, thereby improving the model's robustness and detection accuracy.

CN117197060BActive Publication Date: 2025-11-14INSPUR QILU SOFTWARE IND
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202311093644.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-08-29
Publication Date
2025-11-14
Estimated Expiration
2043-08-29

AI Technical Summary

Technical Problem

In industrial quality inspection, existing technologies require a large amount of abnormal data and are sensitive to abnormal data, resulting in poor model robustness and difficulty in effective anomaly detection when data is insufficient.

Method used

A self-supervised contrastive learning method is adopted to construct an anomaly detection model through image masking and data augmentation techniques. The model is trained using loss functions of prediction and contrast branches to avoid interference from abnormal data and extract surface features of the cable.

Benefits of technology

It enables industrial quality inspection in the absence of abnormal data, improves the robustness and detection accuracy of the model, and reduces data acquisition costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117197060B_ABST
    Figure CN117197060B_ABST
Patent Text Reader

Abstract

This invention discloses a method and system for detecting cable surface anomalies based on self-supervised contrastive learning, belonging to the field of computer vision technology. The technical problem it addresses is how to conduct industrial quality inspection without requiring and avoiding interference from abnormal data. The method includes four steps: image processing, model building, model training, and anomaly detection. Using contrastive learning for training allows for better extraction of cable surface features, and the model can utilize a dataset with only positive samples during training, avoiding data labeling and reducing data acquisition costs. During model training, for images input to the prediction branch, the background is randomly masked using a mask image before data augmentation; for images input to the contrast branch, data augmentation is performed, increasing sample diversity and enhancing model robustness.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer vision technology, specifically to a method and system for detecting cable surface anomalies based on self-supervised contrastive learning. Background Technology

[0002] The biggest challenge in applying artificial intelligence algorithms in industrial quality inspection is the lack of data, especially the scarcity of abnormal data. While normal data is readily available in industrial production, abnormal data requires manual simulation. However, it is difficult to simulate defects with complex causes, leading to missed or false detections in practical applications.

[0003] Mainstream methods for industrial quality inspection are primarily based on image classification and object detection methods. These methods require a large amount of outlier data and have high data annotation costs. There are also various improved methods based on machine learning. These methods do not require outlier data, but they are very sensitive to outliers in the data and are easily affected by outlier data, resulting in poor model robustness.

[0004] How to conduct industrial quality inspection without requiring abnormal data and avoiding interference from abnormal data is a technical problem that needs to be solved. Summary of the Invention

[0005] The technical objective of this invention is to address the above-mentioned shortcomings by providing a method and system for detecting surface anomalies in cables based on self-supervised comparative learning, thereby solving the technical problem of how to conduct industrial quality inspection without requiring abnormal data and avoiding interference from abnormal data.

[0006] In a first aspect, the present invention provides a method for detecting surface anomalies in cables based on self-supervised contrastive learning, comprising the following steps:

[0007] Image processing: Images with cables and backgrounds are acquired as sample images. For each sample image, two operations are performed: one is to randomly mask the background in the sample image using an image mask, and then perform data augmentation on the sample image to obtain the mask-enhanced image; the other is to perform data augmentation on the sample image to obtain the data-enhanced image.

[0008] Model Construction: An anomaly detection model is constructed, comprising two branches: a prediction branch and a contrast branch. The prediction branch includes an encoder, a linear layer, and a multilayer perceptron structure. The linear layer and the multilayer perceptron structure serve as the two branches at the encoder output. The encoder takes an image as input and predicts a multidimensional feature vector as output. The linear layer takes the multidimensional feature vector output by the encoder as input and predicts the probability that the image is a positive sample. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The contrast branch includes an encoder and a multilayer perceptron structure. The encoder takes an image as input and predicts a multidimensional feature vector as output. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The encoder and the multilayer perceptron structure in both the prediction and contrast branches have the same model structure and the same initialization parameters.

[0009] Model training: The masked image is input into the prediction branch, and the data-enhanced image is input into the comparison branch. A loss function is constructed based on the output of the prediction branch and the output of the comparison branch. The model is trained by minimizing the loss function to obtain the weight parameters of the anomaly detection model and obtain the trained prediction branch. The encoder and linear layer in the trained prediction branch are used as the final anomaly detection model.

[0010] Anomaly detection: The image to be detected is input into the final anomaly detection model, which predicts the probability that the output image is a positive sample.

[0011] Preferably, in the sample image, the wire core is located at the center of the image, and the background is located on both sides of the wire core;

[0012] When randomly masking the background in a sample image using an image mask, the following operation is performed:

[0013] Set the range s of the occlusion area relative to the total area of ​​the sample image. l and s h Set the aspect ratio of the occlusion to r1 to r2, and set the occlusion background range to h1 and h2;

[0014] Calculate the area S of the mask image based on its height H and width W, and the occlusion area So. e The calculation formula is:

[0015] S e =Rand(s l ,s h )*S

[0016] Randomly obtain the aspect ratio r of the occlusion e =Rand(r1,r2), calculates the height H of the occluded portion. e and width We The calculation formula is as follows:

[0017]

[0018] Calculate the starting coordinates (x) of the occlusion based on the occlusion range. e ,y e The calculation formula is as follows:

[0019] x e =Rand(0,WW) e ), y e =Rand(a)

[0020] Where a∈(0,h1-H) e )∪(h2,HH e ).

[0021] Preferably, the sample image is data augmented, including horizontal and vertical image flipping, image scaling, and / or Gaussian blurring.

[0022] As a preferred option, the loss function expression is as follows:

[0023]

[0024] Where N is the preset batch size during model training, y i It is the feature vector generated by the prediction branch of the i-th sample image. p is the feature vector generated from the i-th sample image through the comparison branch. i It is the probability that the i-th sample image output by the linear prediction layer in the prediction branch is a positive sample;

[0025] λ is a hyperparameter used to balance the contrastive loss and the regression loss, and its value ranges from (0,1). The contrastive loss is the mean squared error of the feature vectors obtained from the two branches. Regression loss is It is the first

[0026] During model training, the learning rate, batch size, and number of training iterations are set, and the loss function is optimized based on the cosine learning rate decay strategy and the stochastic gradient descent method.

[0027] Preferably, during model training, the weight parameters corresponding to the prediction branch are updated according to the training iteration rounds, and the weight parameters of the comparison branch are updated based on the weight parameters of the prediction branch using the exponential moving average method.

[0028] In a second aspect, the present invention provides a cable surface anomaly detection system based on self-supervised contrastive learning, used to detect anomalies on the cable surface using a cable surface anomaly detection method based on self-supervised contrastive learning as described in any one of the first aspects, the system comprising:

[0029] The image processing module is used to acquire images with a core and a background as sample images. For each sample image, two operations are performed: one is to randomly mask the background in the sample image using an image mask, and then perform data augmentation processing on the sample image to obtain a mask-enhanced image; the other is to perform data augmentation processing on the sample image to obtain a data-enhanced image.

[0030] The model building module is used to construct an anomaly detection model. The anomaly detection model includes two branches: a prediction branch and a contrast branch. The prediction branch includes an encoder, a linear layer, and a multilayer perceptron structure. The linear layer and the multilayer perceptron structure serve as the two branches at the encoder output. The encoder takes an image as input and predicts a multidimensional feature vector. The linear layer takes the multidimensional feature vector output by the encoder as input and predicts the probability that the image is a positive sample. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The contrast branch includes an encoder and a multilayer perceptron structure. The encoder takes an image as input and predicts a multidimensional feature vector. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The encoder and the multilayer perceptron structure in the prediction and contrast branches have the same model structure and the same initialization parameters.

[0031] The model training module is used to input the mask-enhanced image into the prediction branch and the data-enhanced image into the comparison branch. A loss function is constructed based on the output of the prediction branch and the output of the comparison branch. The model is trained by minimizing the loss function to obtain the weight parameters of the anomaly detection model and obtain the trained prediction branch. The encoder and linear layer in the trained prediction branch are used as the final anomaly detection model.

[0032] The anomaly detection module, wherein the prediction detection module is used to input the image to be detected into the final anomaly detection model, and predict the probability that the output image is a positive sample through the final anomaly detection model.

[0033] Preferably, in the sample image, the wire core is located at the center of the image, and the background is located on both sides of the wire core;

[0034] When randomly masking the background in a sample image using an image mask, the image processing module performs the following operations:

[0035] Set the range s of the occlusion area relative to the total area of ​​the sample image. l and s h Set the aspect ratio of the occlusion to r1 to r2, and set the occlusion background range to h1 and h2;

[0036] Calculate the area S of the mask image based on its height H and width W, and the occlusion area So. e The calculation formula is:

[0037] S e =Rand(s l ,s h )*S

[0038] Randomly obtain the aspect ratio r of the occlusion e =Rand(r1,r2), calculates the height H of the occluded portion. e and width W e The calculation formula is as follows:

[0039]

[0040] Calculate the starting coordinates (x) of the occlusion based on the occlusion range. e ,y e The calculation formula is as follows:

[0041] x e =Rand(0,WW) e ), y e =Rand(a)

[0042] Where a∈(0,h1-H) e )∪(h2,HH e ).

[0043] Preferably, the sample image is augmented by data processing, wherein the image processing module is used to perform horizontal and vertical image flipping, image scaling and / or Gaussian blurring on the sample image.

[0044] As a preferred option, the loss function expression is as follows:

[0045]

[0046] Where N is the preset batch size during model training, y i It is the feature vector generated by the prediction branch of the i-th sample image. p is the feature vector generated from the i-th sample image through the comparison branch. i It is the probability that the i-th sample image output by the linear prediction layer in the prediction branch is a positive sample;

[0047] λ is a hyperparameter used to balance the contrastive loss and the regression loss, and its value ranges from (0,1). The contrastive loss is the mean squared error of the feature vectors obtained from the two branches. Regression loss is It is the first

[0048] During model training, the model training module is used to set the learning rate, batch size, and number of training iterations, and optimizes the loss function based on the cosine learning rate decay strategy and the stochastic gradient descent method.

[0049] Preferably, during model training, the model training module is used to update the weight parameters corresponding to the prediction branch according to the training iteration rounds, and update the weight parameters of the comparison branch based on the weight parameters of the prediction branch using the exponential moving average method.

[0050] The cable surface anomaly detection method and system based on self-supervised contrastive learning of the present invention have the following advantages:

[0051] 1. Using contrastive learning for training can better extract cable surface features, and the training of the model can use a dataset with only positive samples, avoiding data labeling and reducing data acquisition costs.

[0052] 2. During model training, for the image input to the prediction branch, the background is randomly masked by a mask image before data augmentation is performed on the image. For the image input to the contrast branch, data augmentation is performed on the image, which improves the diversity of samples and enhances the robustness of the model.

[0053] 3. The loss function combines regression loss and cross-entropy loss, enabling end-to-end training of the model. Attached Figure Description

[0054] To more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0055] The invention will be further described below with reference to the accompanying drawings.

[0056] Figure 1 This is a structural block diagram of the anomaly detection model in a cable surface anomaly detection method based on self-supervised contrastive learning, as shown in Example 1. Detailed Implementation

[0057] The present invention will be further described below with reference to the accompanying drawings and specific embodiments, so that those skilled in the art can better understand and implement the present invention. However, the embodiments are not intended to limit the present invention. In the absence of conflict, the embodiments of the present invention and the technical features in the embodiments can be combined with each other.

[0058] This invention provides a method and system for detecting surface anomalies in cables based on self-supervised comparative learning, which addresses the technical problem of how to conduct industrial quality inspection without requiring abnormal data and avoiding interference from abnormal data.

[0059] Example 1:

[0060] This invention discloses a method for detecting surface anomalies in cables based on self-supervised contrastive learning, comprising four steps: image processing, model building, model training, and anomaly detection.

[0061] Step S100 Image Processing: Acquire images with cables and background as sample images. Perform two operations on each sample image. One operation is to randomly mask the background in the sample image using an image mask and then perform data augmentation on the sample image to obtain the mask-enhanced image. The other operation is to perform data augmentation on the sample image to obtain the data-enhanced image.

[0062] In this embodiment, the sample image is located at the center of the image, with the background on both sides of the wire core. Changes in the background do not alter the abnormal defects on the wire core surface, and using random pixels to create a high-proportion mask on the background should not affect the model's judgment.

[0063] When randomly masking the background in a sample image using an image mask, the following operation is performed:

[0064] Set the range s of the occlusion area relative to the total area of ​​the sample image. l and s h Set the aspect ratio of the occlusion to r1 to r2, and set the occlusion background range to h1 and h2. Calculate the area S of the mask image based on its height H and width W. e The calculation formula is:

[0065] S e =Rand(s l ,s h )*S

[0066] Randomly obtain the aspect ratio r of the occlusion e =Rand(r1,r2), calculates the height H of the occluded portion. e and width W e The calculation formula is as follows:

[0067]

[0068] Then, calculate the starting coordinates (x) of the occlusion based on the occlusion range. e ,y e The calculation formula is as follows:

[0069] x e =Rand(0,WW) e ), y e =Rand(a)

[0070] Where a∈(0,h1-H) e )∪(h2,HH e ).

[0071] In this embodiment, data augmentation methods include horizontal and vertical image flipping, image scaling and / or Gaussian blurring, and color alteration processing of the sample image.

[0072] In this embodiment, for the same sample image, the operation is divided into two paths: one path performs image masking and data augmentation, and then inputs the data into the prediction branch; the other path only performs data augmentation, and then inputs the data into the comparison branch.

[0073] Step S200 Model Construction: Construct an anomaly detection model, which includes two branches: a prediction branch and a contrast branch. The prediction branch includes an encoder, a linear layer, and a multilayer perceptron structure. The linear layer and the multilayer perceptron structure serve as the two branches at the encoder output. The encoder is used to predict and output a multidimensional feature vector with the image as input. The linear layer is used to predict and output the probability that the image is a positive sample with the multidimensional feature vector output by the encoder as input. The multilayer perceptron structure is used to reduce the dimensionality of the multidimensional feature vector output by the encoder as input and output a feature vector. The contrast branch includes an encoder and a multilayer perceptron structure. The encoder is used to predict and output a multidimensional feature vector with the image as input. The multilayer perceptron structure is used to reduce the dimensionality of the multidimensional feature vector output by the encoder as input and output a feature vector. The encoder and the multilayer perceptron structure in the prediction and contrast branches have the same model structure and the same initialization parameters.

[0074] In this embodiment, the encoder and multilayer perceptron structure of the prediction branch and the comparison branch have the same structure. The encoders all adopt the ResNet50 backbone network and share the initialization parameters. The multilayer perceptron structure consists of two multilayer perceptrons.

[0075] For the prediction branch, after the masked and enhanced image is input, the image is encoded by the encoder to obtain a 2048-dimensional feature vector. After encoding, it is divided into two branches. One branch is a linear prediction layer, which directly predicts the probability that the image is a positive sample. The other branch consists of two multilayer perceptrons, which reduce the 2048-dimensional vector to a 128-dimensional feature vector for comparison with the feature vector obtained from the comparison branch.

[0076] For the contrast branch, the augmented image is input into the contrast branch, encoded by the encoder to obtain a 2048-dimensional feature vector, and then reduced to a 128-dimensional feature vector by a multilayer perceptron.

[0077] During the model training process, the 128-dimensional feature vector output by the prediction branch is compared with the 128-dimensional feature vector obtained by the comparison branch.

[0078] Step S300 Model Training: Input the masked image into the prediction branch and the data-enhanced image into the contrast branch. Construct a loss function based on the output of the prediction branch and the output of the contrast branch. Train the model by minimizing the loss function to obtain the weight parameters of the anomaly detection model and obtain the trained prediction branch. Use the encoder and linear layer in the trained prediction branch as the final anomaly detection model.

[0079] In step S300, the constructed loss function considers both contrastive loss and regression loss. Contrastive loss enables the model to effectively extract cable features, while regression loss describes feature similarity. The loss function expression is as follows:

[0080]

[0081] Where N is the preset batch size during model training, y i It is the feature vector generated by the prediction branch of the i-th sample image. p is the feature vector generated from the i-th sample image through the comparison branch. i It is the probability that the i-th sample image output by the linear prediction layer in the prediction branch is a positive sample;

[0082] λ is a hyperparameter used to balance the contrastive loss and the regression loss, and its value ranges from (0,1). The contrastive loss is the mean squared error of the feature vectors obtained from the two branches. Regression loss is It is the first

[0083] When the feature vectors calculated by the prediction branch and the comparison branch are similar, p i The closer the value is to 1, the smaller the overall loss, which allows the output of the linear prediction layer in the prediction branch to describe the similarity between two feature vectors, thus enabling the model to make end-to-end predictions.

[0084] In this embodiment, during model training, the stochastic gradient descent algorithm is used to optimize the loss function, the learning rate is set to 0.001, the cosine learning rate decay strategy is used, the batch size is set to 128, the training iterations are 150 rounds, and the model weight parameters are saved.

[0085] Step S400 Anomaly Detection: Input the image to be detected into the final anomaly detection model, and predict the probability that the output image is a positive sample through the final anomaly detection model.

[0086] In this embodiment, the trained model is deployed to an industrial control computer equipped with an AI accelerator card. Subsequently, only the weight parameters of the encoder and linear layer in the prediction branch are loaded as the final anomaly detection model. Cable images are captured by a camera and transmitted to the industrial control computer. The model predicts whether the cable in the image is an anomaly. If an anomaly is detected, the industrial control computer issues an alarm signal.

[0087] Example 2:

[0088] The present invention discloses a cable surface anomaly detection system based on self-supervised contrastive learning, comprising an image processing module, a model building module, a model training module, and an anomaly detection module. The system can perform anomaly detection on cables by executing the method disclosed in Embodiment 1.

[0089] The image processing module is used to acquire images with a core and a background as sample images. For each sample image, two operations are performed: one is to randomly mask the background in the sample image using an image mask, and then perform data augmentation processing on the sample image to obtain the mask-enhanced image; the other is to perform data augmentation processing on the sample image to obtain the data-enhanced image.

[0090] In the sample image acquired by the image processing module in this embodiment, the wire core is located at the center of the image, and the background is located on both sides of the wire core. Changes in the background do not alter the abnormal defects on the surface of the wire core, and using random pixels to perform a high-proportion masking on the background should not affect the model's judgment.

[0091] When randomly masking the background in a sample image using an image mask, the image processing module performs the following operations:

[0092] (1) Set the range s of the occlusion area relative to the total area of ​​the sample image. l and s h Set the aspect ratio of the occlusion to r1 to r2, and set the occlusion background range to h1 and h2. Calculate the area S of the mask image based on its height H and width W. e The calculation formula is:

[0093] S e =Rand(s l,s h )*S

[0094] (2) Randomly obtain the aspect ratio r of the occlusion. e =Rand(r1,r2), calculates the height H of the occluded portion. e and width W e The calculation formula is as follows:

[0095]

[0096] (3) Then calculate the starting coordinates (x, y) of the occlusion based on the occlusion range. e ,y e The calculation formula is as follows:

[0097] x e =Rand(0,WW) e ), y e =Rand(a)

[0098] Where a∈(0,h1-H) e )∪(h2,HH e ).

[0099] In this embodiment, data augmentation methods include horizontal and vertical image flipping, image scaling and / or Gaussian blurring, and color alteration processing of the sample image.

[0100] In this embodiment, for the same sample image, the operation is divided into two paths: one path performs image masking and data augmentation, and then inputs the data into the prediction branch; the other path only performs data augmentation, and then inputs the data into the comparison branch.

[0101] The model building module is used to construct an anomaly detection model, which includes two branches: a prediction branch and a contrast branch. The prediction branch includes an encoder, a linear layer, and a multilayer perceptron structure. The linear layer and the multilayer perceptron structure serve as the two branches at the encoder output. The encoder takes an image as input and predicts a multidimensional feature vector as output. The linear layer takes the multidimensional feature vector output by the encoder as input and predicts the probability that the image is a positive sample. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The contrast branch includes an encoder and a multilayer perceptron structure. The encoder takes an image as input and predicts a multidimensional feature vector as output. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The encoder and the multilayer perceptron structure in the prediction and contrast branches have the same model structure and the same initialization parameters.

[0102] In this embodiment, the encoder and multilayer perceptron structure of the prediction branch and the comparison branch have the same structure. The encoders all adopt the ResNet50 backbone network and share the initialization parameters. The multilayer perceptron structure consists of two multilayer perceptrons.

[0103] For the prediction branch, after the masked and enhanced image is input, the image is encoded by the encoder to obtain a 2048-dimensional feature vector. After encoding, it is divided into two branches. One branch is a linear prediction layer, which directly predicts the probability that the image is a positive sample. The other branch consists of two multilayer perceptrons, which reduce the 2048-dimensional vector to a 128-dimensional feature vector for comparison with the feature vector obtained from the comparison branch.

[0104] For the contrast branch, the augmented image is input into the contrast branch, encoded by the encoder to obtain a 2048-dimensional feature vector, and then reduced to a 128-dimensional feature vector by a multilayer perceptron.

[0105] During the model training process, the 128-dimensional feature vector output by the prediction branch is compared with the 128-dimensional feature vector obtained by the comparison branch.

[0106] The model training module is used to input the masked image into the prediction branch and the data-enhanced image into the contrast branch. A loss function is constructed based on the output of the prediction branch and the output of the contrast branch. The model is trained by minimizing the loss function to obtain the weight parameters of the anomaly detection model and obtain the trained prediction branch. The encoder and linear layer in the trained prediction branch are used as the final anomaly detection model.

[0107] In this embodiment, the loss function constructed by the model training module considers both contrastive loss and regression loss. Contrastive loss is used to enable the model to effectively extract cable features, while regression loss is used to describe feature similarity. The loss function expression is as follows:

[0108]

[0109] Where N is the preset batch size during model training, y i It is the feature vector generated by the prediction branch of the i-th sample image. p is the feature vector generated from the i-th sample image through the comparison branch. i It is the probability that the i-th sample image output by the linear prediction layer in the prediction branch is a positive sample;

[0110] λ is a hyperparameter used to balance the contrastive loss and the regression loss, and its value ranges from (0,1). The contrastive loss is the mean squared error of the feature vectors obtained from the two branches. Regression loss is It is the first

[0111] When the feature vectors calculated by the prediction branch and the comparison branch are similar, p i The closer the value is to 1, the smaller the overall loss, which allows the output of the linear prediction layer in the prediction branch to describe the similarity between two feature vectors, thus enabling the model to make end-to-end predictions.

[0112] In this embodiment, during model training, the model training module is used to optimize the loss function based on the stochastic gradient descent optimization algorithm, setting the learning rate to 0.001, using the cosine learning rate decay strategy, setting the batch size to 128, training for 150 rounds, and saving the model weight parameters.

[0113] The prediction detection module is used to input the image to be detected into the final anomaly detection model, and the final anomaly detection model predicts the probability that the output image is a positive sample.

[0114] In this embodiment, the trained model is deployed to an industrial control computer equipped with an AI accelerator card. Subsequently, only the weight parameters of the encoder and linear layer in the prediction branch are loaded as the final anomaly detection model. Cable images are captured by a camera and transmitted to the industrial control computer. The model predicts whether the cable in the image is an anomaly. If an anomaly is detected, the industrial control computer issues an alarm signal.

[0115] The present invention has been shown and described in detail above with reference to the accompanying drawings and preferred embodiments. However, the present invention is not limited to these disclosed embodiments. Based on the above embodiments, those skilled in the art will know that more embodiments of the present invention can be obtained by combining the means in the different embodiments described above, and these embodiments are also within the protection scope of the present invention.

Claims

1. A method for detecting surface anomalies in cables based on self-supervised contrastive learning, characterized in that, Includes the following steps: Image processing: Images with cables and backgrounds are acquired as sample images. For each sample image, two operations are performed: one is to randomly mask the background in the sample image using an image mask, and then perform data augmentation on the sample image to obtain the mask-enhanced image; the other is to perform data augmentation on the sample image to obtain the data-enhanced image. Model Construction: An anomaly detection model is constructed, comprising two branches: a prediction branch and a contrast branch. The prediction branch includes an encoder, a linear layer, and a multilayer perceptron structure. The linear layer and the multilayer perceptron structure serve as the two branches at the encoder output. The encoder takes an image as input and predicts a multidimensional feature vector as output. The linear layer takes the multidimensional feature vector output by the encoder as input and predicts the probability that the image is a positive sample. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The contrast branch includes an encoder and a multilayer perceptron structure. The encoder takes an image as input and predicts a multidimensional feature vector as output. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The encoder and the multilayer perceptron structure in both the prediction and contrast branches have the same model structure and the same initialization parameters. Model training: The masked image is input into the prediction branch, and the data-enhanced image is input into the comparison branch. A loss function is constructed based on the output of the prediction branch and the output of the comparison branch. The model is trained by minimizing the loss function to obtain the weight parameters of the anomaly detection model and obtain the trained prediction branch. The encoder and linear layer in the trained prediction branch are used as the final anomaly detection model. Anomaly detection: The image to be detected is input into the final anomaly detection model, which predicts the probability that the output image is a positive sample. In the sample image, the core of the line is located in the center of the image, and the background is located on both sides of the core of the line. When randomly masking the background in a sample image using an image mask, the following operation is performed: Set the range s of the occlusion area relative to the total area of ​​the sample image. l and s h Set the aspect ratio of the occlusion to r1 to r2, and set the occlusion background range to h1 and h2; Calculate the area S of the mask image based on its height H and width W, and the occlusion area So. e The calculation formula is: S e =Rand(s l ,s h )*S Randomly obtain the aspect ratio r of the occlusion e =Rand(r1,r2), calculates the height H of the occluded portion. e and width W e The calculation formula is as follows: Calculate the starting coordinates (x) of the occlusion based on the occlusion range. e ,y e The calculation formula is as follows: x e =Rand(0,W-W e ),y e =Rand(a) Where a∈(0,h1-H) e )∪(h2,HH e ); Among them, data augmentation of sample images includes horizontal and vertical image flipping, image scaling and / or Gaussian blurring of sample images. The loss function is expressed as follows: Where N is the preset batch size during model training, and y is... i It is the feature vector generated by the prediction branch of the i-th sample image. p is the feature vector generated by the comparison branch of the i-th sample image. i It is the probability that the i-th sample image output by the linear prediction layer in the prediction branch is a positive sample; λ is a hyperparameter used to balance the contrastive loss and the regression loss, and its value ranges from (0,1). The contrastive loss is the mean squared error of the feature vectors obtained from the two branches. Regression loss is During model training, the learning rate, batch size, and number of training iterations are set, and the loss function is optimized based on the cosine learning rate decay strategy and the stochastic gradient descent method. During model training, the weight parameters of the prediction branch are updated according to the training iteration rounds, and the weight parameters of the comparison branch are updated based on the weight parameters of the prediction branch using the exponential moving average method.

2. A cable surface anomaly detection system based on self-supervised contrastive learning, characterized in that, The system is used to detect anomalies on the cable surface using a self-supervised contrastive learning-based cable surface anomaly detection method as described in claim 1, the system comprising: The image processing module is used to acquire images with a core and a background as sample images. For each sample image, two operations are performed: one is to randomly mask the background in the sample image using an image mask, and then perform data augmentation processing on the sample image to obtain a mask-enhanced image; the other is to perform data augmentation processing on the sample image to obtain a data-enhanced image. The model building module is used to construct an anomaly detection model. The anomaly detection model includes two branches: a prediction branch and a contrast branch. The prediction branch includes an encoder, a linear layer, and a multilayer perceptron structure. The linear layer and the multilayer perceptron structure serve as the two branches at the encoder output. The encoder takes an image as input and predicts a multidimensional feature vector. The linear layer takes the multidimensional feature vector output by the encoder as input and predicts the probability that the image is a positive sample. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The contrast branch includes an encoder and a multilayer perceptron structure. The encoder takes an image as input and predicts a multidimensional feature vector. The multilayer perceptron structure takes the multidimensional feature vector output by the encoder as input and reduces the dimensionality of the output feature vector. The encoder and the multilayer perceptron structure in the prediction and contrast branches have the same model structure and the same initialization parameters. The model training module is used to input the mask-enhanced image into the prediction branch and the data-enhanced image into the comparison branch. A loss function is constructed based on the output of the prediction branch and the output of the comparison branch. The model is trained by minimizing the loss function to obtain the weight parameters of the anomaly detection model and obtain the trained prediction branch. The encoder and linear layer in the trained prediction branch are used as the final anomaly detection model. An anomaly detection module, wherein the prediction detection module is used to input the image to be detected into the final anomaly detection model, and predict the probability that the output image is a positive sample through the final anomaly detection model; In the sample image, the core of the line is located in the center of the image, and the background is located on both sides of the core of the line. When randomly masking the background in a sample image using an image mask, the image processing module performs the following operations: Set the range s of the occlusion area relative to the total area of ​​the sample image. l and s h Set the aspect ratio of the occlusion to r1 to r2, and set the occlusion background range to h1 and h2; Calculate the area S of the mask image based on its height H and width W, and the occlusion area So. e The calculation formula is: S e =Rand(s l ,s h )*S Randomly obtain the aspect ratio r of the occlusion e =Rand(r1,r2), calculates the height H of the occluded portion. e and width W e The calculation formula is as follows: Calculate the starting coordinates (x) of the occlusion based on the occlusion range. e ,y e The calculation formula is as follows: x e =Rand(0,W-W e ),y e =Rand(a) Where a∈(0,h1-H) e )∪(h2,HH e ); Among them, data augmentation is performed on the sample image, and the image processing module is used to perform horizontal and vertical image flipping, image scaling and / or image Gaussian blur processing on the sample image; The expression for the loss of function is as follows: Where N is the preset batch size during model training, y i It is the feature vector generated by the prediction branch of the i-th sample image. p is the feature vector generated from the i-th sample image through the comparison branch. i It is the probability that the i-th sample image output by the linear prediction layer in the prediction branch is a positive sample; λ is a hyperparameter used to balance the contrastive loss and the regression loss, and its value ranges from (0,1). The contrastive loss is the mean squared error of the feature vectors obtained from the two branches. Regression loss is During model training, the model training module is used to set the learning rate, batch size, and number of training iterations, and optimizes the loss function based on the cosine learning rate decay strategy and the stochastic gradient descent method. During model training, the model training module updates the weight parameters corresponding to the prediction branch according to the training iteration rounds, and updates the weight parameters of the comparison branch based on the weight parameters of the prediction branch using the exponential moving average method.

Citation Information

Patent Citations

  • Cervical OCT image classification method and system based on mask self-supervised learning

    CN116188901A