Pipeline surface defect detection method for improving capsule network

By integrating dynamic snake convolution, pixel attention-oriented fusion module and variational Bayesian routing algorithm in traditional capsule networks, the recognition of pipeline surface defects is optimized, and the recognition accuracy and generalization performance of traditional capsule networks is solved. Inadequate, high accuracy recognition of pipeline surface defects is achieved.

CN119027376APending Publication Date: 2024-11-26HUAIYIN INSTITUTE OF TECHNOLOGY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411031875.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-30
Publication Date
2024-11-26

AI Technical Summary

Technical Problem

Traditional capsule networks are difficult to effectively identify the size, shape, position and direction of pipeline surface defects, and are affected by complex background noise, resulting in low recognition accuracy.

Method used

Fusion of dynamic serpentine convolution, pixel attention-oriented fusion module, channel self-attention module and variable Bayes-based routing algorithms in the traditional capsule network architecture to optimize the network structure to improve recognition accuracy.

Benefits of technology

By dynamically adjusting the shape and size of the convolution kernel, effectively integrating multi-scale features and automatically adjusting capsule routing, the accuracy and generalization performance of pipeline surface defects are improved, and the precise identification of defects of different sizes and shapes is achieved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119027376A_ABST
    Figure CN119027376A_ABST
Patent Text Reader

Abstract

The invention relates to the field of chemical engineering fault detection, and discloses a pipeline surface defect detection method for improving a capsule network, and the method specifically comprises the steps: firstly, obtaining a pipeline surface defect data set; secondly, randomly dividing a training set, a verification set and a test set; then, the capsule network is improved, and dynamic snakelike convolution, a pixel attention guiding fusion module, a channel self-attention module and a variational Bayesian-based routing algorithm are fused in the architecture of the traditional capsule network; then, training the model and optimizing model parameters by using the training set data and the verification set data respectively, and storing the optimal model; and finally, testing the performance of the trained model by using a test set to obtain an identification result. According to the invention, the capsule network architecture is optimized and expanded, and the accuracy of identifying the pipeline surface defects by the capsule network is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the field of chemical fault detection, and in particular to a pipeline surface defect detection method using an improved capsule network. Background Art

[0002] With the rapid development of industry, pipelines, as important transmission tools, are widely used in the transportation of various fluid media, such as water, oil, gas, etc. However, due to the long-term influence of factors such as fluid media, external environment and internal pressure on pipelines, various defects such as cracks, corrosion, wear, etc. may appear on their surfaces. These defects will not only affect the normal use of pipelines, but may also lead to safety accidents such as leakage and explosion in serious cases. Therefore, timely and accurate identification of pipeline surface defects is of great significance to ensure industrial production and public safety.

[0003] Traditional pipeline surface defect identification methods, such as visual inspection, ultrasonic testing, and X-ray testing, can detect defects on the pipeline surface to a certain extent, but they have many limitations. For example, visual inspection relies on manual experience and judgment, and has problems of subjectivity and low efficiency; although ultrasonic testing and X-ray testing have high accuracy, the equipment is expensive, the operation is complicated, and there are certain requirements for the testing environment, making it difficult to apply them to the inspection of all pipelines on a large scale.

[0004] In recent years, with the rapid development of artificial intelligence and deep learning technology, pipeline defect recognition methods based on computer vision and deep learning have gradually attracted attention. Among them, Capsule Network (CapsNet), as a new type of deep learning model, can better capture the spatial hierarchy and local features in the image by simulating the hierarchical information processing method in the human visual system, providing a new idea for the recognition of pipeline surface defects. However, pipeline surface defects usually include scratches, cracks, inclusions, bubbles and other types. The size, shape, position and direction of these defects are not fixed, and are often accompanied by complex background noise. Traditional CapsNet is difficult to fully extract these features due to its fixed routing protocol and capsule layer design, which affects its recognition accuracy. Therefore, it is necessary to improve CapsNet and optimize its network structure in order to better identify pipeline surface defects. Summary of the invention

[0005] Purpose of the invention: In view of the problems pointed out in the background technology, the present invention provides a pipeline surface defect detection method based on an improved capsule network, which integrates dynamic snake convolution (DSConv) and pixel-attention-oriented fusion module (Pixel-attention-

[0006] guided,Pag), channel self-attention module CloAttention and variational Bayes routing algorithm (VB Routing) are designed to optimize and expand the CapsNet architecture and improve the accuracy of CapsNet in identifying pipeline surface defects.

[0007] Technical solution: The present invention provides a pipeline surface defect detection method based on an improved capsule network, which specifically includes the following steps:

[0008] Step 1: Obtain the pipeline surface defect dataset and preprocess it. After preprocessing, randomly divide the dataset into training set, validation set and test set.

[0009] Step 2: Improve the capsule network and use the dynamic snake convolution (DSConv) to replace the single convolution structure of the classic capsule network. The defect information output by DSConv is fused through the pixel-attention-guided fusion module (Pag) and the channel self-attention module CloAttention, and multi-scale defect features are output. The multi-scale features are encoded into a multi-dimensional capsule structure in the primary capsule layer; the feature transfer between the primary capsule layer and the dynamic capsule layer is realized with the help of the variational Bayes routing algorithm (VB Routing);

[0010] Step 3: Use the training set and validation set to train the model and optimize the model parameters, and save the best model;

[0011] Step 4: Use the test set to test the performance of the trained model and obtain the recognition results.

[0012] Furthermore, the step 1 specifically includes:

[0013] A high-definition camera and a portable ultrasonic scanner are used to obtain a pipeline surface defect image dataset, and the collected image dataset is preprocessed; the preprocessing includes labeling the image category, image denoising and normalization.

[0014] Furthermore, when randomly dividing the training set, validation set, and test set, a random number generator is used to ensure the randomness of the division, and the ratio of the training set, validation set, and test set is set to 6:2:2. The divided training set, validation set, and test set are saved in different files respectively.

[0015] Furthermore, the capsule network structure in step 2 includes: a convolutional layer, a primary capsule layer, a digital capsule layer and a dynamic routing;

[0016] The convolution layer extracts features, the primary capsule layer expands the output of the convolution into a vector form, and the digital capsule layer is responsible for building a vector representation for each class in the dataset. Dynamic routing is only performed between the primary capsule layer and the digital capsule layer, and the weights of other layers are only adjusted in the mini-batch back-propagation method and remain unchanged in the forward pass of the entire network.

[0017] Furthermore, the DSConv dynamically adjusts the shape and size of the convolution kernel, and its specific working principle is as follows:

[0018] The convolution kernel is deformed in the x-axis and y-axis directions, and the deformation offset is used as the calculation indicator. Based on the key characteristics of the boundary, shape, and size of the pipeline surface defects, DSConv calculates the corresponding ones, thereby applying convolution kernels of different sizes to defects at different locations and scales.

[0019] Furthermore, the DSConv uses an iterative strategy to ensure that the convolution kernel does not deviate too much from the defect area.

[0020] Furthermore, when learning the features of pipeline surface defects, the Pag performs effective feature fusion. The pixel attention-guided fusion module Pag calculates the product of the pixel feature vectors corresponding to the two branches, the two branches are branch A and branch B, and uses the Sigmoid function to calculate a possibility value σ, which indicates the degree to which the two pixels may belong to the same object; if σ is higher, it is considered that the features provided by the I branch are more valuable for reference, and vice versa; the final output result of the pixel attention-guided fusion module Pag is obtained by dynamically fusing the pixel features of the I branch and the P branch based on a specific weight coefficient, and is expressed as follows:

[0021]

[0022] in, represents the vector of the corresponding pixel in the feature map of branch A, Represents the vector of the corresponding pixel in the feature map of branch B, Out Pag It is the final output result of the pixel attention-guided fusion module Pag.

[0023] Furthermore, CloAttention combines the vanilla attention mechanism and convolution AttnConv. Each channel self-attention module CloAttention consists of a global branch and a local branch. The local branch uses AttnConv to aggregate high-frequency local information. AttnConv uses shared weights and context-aware weights to capture high-frequency information; the global branch uses vanilla attention to pay attention to low-frequency global information.

[0024] Furthermore, the VB Routing approximately calculates the routing probability between capsules and automatically updates the distribution of the capsule's posture parameters, and finds the optimal capsule connection by automatically adjusting the number of iterations and parameters of capsule routing, so as to better transfer and interpret feature information between the primary capsule layer and the digital capsule layer.

[0025] Furthermore, in step 3, when training the model, the total loss function used is a linear combination of the negative log-likelihood loss NLLLoss and the optional variational autoencoder VAE loss:

[0026] NLL Loss is based on the likelihood principle in probability theory, as follows:

[0027]

[0028] Among them, K is the category of pipeline surface defects, j is the number of training samples, and y jK is the k-th defect label corresponding to the sample, Represents the predicted probability value of classifying the training sample into the kth class;

[0029] VAE consists of reconstruction loss and KL divergence loss, as follows:

[0030]

[0031] Among them, d represents the number of capsules, F represents the number of filters in the convolutional layer, and the mean μ jd And the log variance are calculated by the encoder, K is the type of pipeline surface defect, ||x K -f(x K )|| is the modulus of the capsule vector, representing the probability of identifying the Kth type of defect;

[0032] The expression of the total loss function is:

[0033] L=L NLL +αL VAE Formula (4)

[0034] Among them, α is a hyperparameter used to balance the weight between classification loss and VAE loss. By adjusting this parameter during the training process, the trade-off between the classification performance and reconstruction ability of the model is controlled.

[0035] Beneficial effects:

[0036] (1) The present invention uses capsule vectors to capture and represent the spatial relationship of features, thereby retaining the local feature information of pipeline surface defects, improving the traditional capsule network, and expanding its network architecture. It can better identify pipeline surface defects of different sizes and shapes, with high recognition accuracy and good generalization performance. Through intelligent recognition, it can reduce the cost of manual recognition and improve the efficiency of pipeline surface defect recognition.

[0037] (2) The present invention replaces the single convolution structure of the classic capsule network with DSConv. The convolution kernel size of DSConv can be dynamically changed according to the characteristics of the pipeline surface defects to achieve preliminary feature extraction. In order to speed up the model convergence and overcome the problem of gradient disappearance, DSConv uses BatchNorm and ReLU function activation.

[0038] (3) The present invention combines CloAttention and Pag, fuses the defect information output by DSConv, and outputs multi-scale defect features, which can perform effective feature fusion when learning the features of pipeline surface defects.

[0039] (4) The present invention encodes multi-scale features into a multi-dimensional capsule structure in the primary capsule layer. In order to ensure that the feature information is not interfered, the present invention uses the VB Routing algorithm to realize the feature transfer between the primary capsule layer and the dynamic capsule layer. By automatically adjusting the number of iterations and parameters of the capsule routing, the optimal capsule connection is found to better transfer and interpret the feature information between the primary capsule layer and the digital capsule layer, thereby improving the feature learning ability of the capsule network.

[0040] (5) The dynamic capsule layer maps these features into the probability distribution of defect categories and selects the category with the highest probability as the output. The decoder is used to decode the classification capsule. Through the processing of the decoder, the model can output the defect category and probability of each pixel, thereby achieving accurate identification and classification of pipeline surface defects.

[0041] (6) When training the model, the total loss function used by the present invention is a linear combination of negative log-likelihood loss (NLL Loss) and optional variational autoencoder (VAE) loss. A hyperparameter is used to balance the weight between classification loss and VAE loss. By adjusting the parameter during the training process, the trade-off between classification performance and reconstruction ability of the model can be controlled. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] Figure 1 It is a schematic block diagram of the process of the present invention;

[0043] Figure 2It is a capsule network structure diagram of the present invention;

[0044] Figure 3 This is the improved capsule network model diagram of the present invention;

[0045] Figure 4 This is the result of the ablation experiment. DETAILED DESCRIPTION

[0046] The present invention is described in detail below in conjunction with the embodiments shown in the accompanying drawings:

[0047] The present invention provides a pipeline surface defect detection method based on an improved capsule network, which specifically comprises the following steps:

[0048] Step 1: Obtain the pipeline surface defect dataset and perform preprocessing.

[0049] Use high-definition cameras, portable ultrasonic scanners and other equipment to obtain pipeline surface defect image datasets. And perform defect category annotation, image denoising and normalization on the collected image datasets.

[0050] Step 2: In the preprocessed dataset, use a random number generator to randomly divide the dataset into training set, validation set, and test set in a ratio of 6:2:2.

[0051] Step 3: Improve the capsule network by integrating the dynamic snake convolution (DSConv), pixel-attention-guided fusion (Pag), channel self-attention module CloAttention and variational Bayes routing algorithm (VBRouting).

[0052] The structure of the capsule network includes: convolution layer, primary capsule layer, digital capsule layer and dynamic routing. The convolution layer is responsible for extracting features; the primary capsule layer expands the output of the convolution into a vector form; the digital capsule layer is responsible for building a vector representation for each class in the dataset; dynamic routing is only performed between the primary capsule layer and the digital capsule layer. The weights of other layers are only adjusted in the mini-batch backpropagation method and remain unchanged in the forward pass of the entire network.

[0053] The specific improvement plan is:

[0054] First, DSConv replaces the single convolution structure of the classic capsule network. The convolution kernel size of DSConv can be dynamically changed according to the characteristics of the pipeline surface defects to achieve preliminary feature extraction. In order to speed up the model convergence and overcome the problem of gradient disappearance, DSConv uses BatchNorm and ReLU function activation.

[0055] DSConv can dynamically adjust the shape and size of the convolution kernel, adapt to the tubular structure, and better learn defect information. Its specific working principle is: deform the convolution kernel in the x-axis and y-axis directions, and use the deformation offset as the calculation indicator. Based on the key characteristics of the boundary, shape, size, etc. of the pipeline surface defect, DSConv calculates the corresponding, thereby applying convolution kernels of different sizes to defects at different locations and scales to improve feature learning capabilities. At the same time, DSConv uses an iterative strategy to ensure that the convolution kernel does not deviate too much from the defect area.

[0056] Then, through CloAttention and Pag, the defect information output by DSConv is fused and multi-scale defect features are output. Then, the multi-scale features are encoded into a multi-dimensional capsule structure in the primary capsule layer.

[0057] Pag can perform effective feature fusion when learning the features of pipeline surface defects. The Pag module calculates the product of the pixel feature vectors corresponding to the two branches (branch A and branch B) and uses the Sigmoid function to calculate a probability value σ, which indicates the degree to which the two pixels may belong to the same object. If σ is higher, the features provided by the I branch are considered to be more valuable for reference, and vice versa. The final output result of Pag is obtained by dynamically fusing the pixel features of the I branch and the P branch based on a specific weight coefficient, and the expression is shown in formula (1).

[0058]

[0059] In formula (1), represents the vector of the corresponding pixel in the feature map of branch A, A vector representing the corresponding pixel in the B branch feature map.

[0060] CloAttention combines the vanilla attention mechanism and the convolution AttnConv. Each Clo block consists of a global branch and a local branch. The local branch uses AttnConv to aggregate high-frequency local information, while the global branch uses vanilla attention to focus on low-frequency global information. Compared with traditional convolution operations, AttnConv uses shared weights and context-aware weights to capture high-frequency information, which can better handle the relationship between different positions in the image.

[0061] Furthermore, in order to ensure that the feature information is not disturbed, the model uses the VB Routing algorithm to realize the feature transfer between the primary capsule layer and the dynamic capsule layer. The dynamic capsule layer maps these features into the probability distribution of defect categories and selects the category with the highest probability as the output. VB Routing approximates the routing probability between capsules and automatically updates the distribution of the capsule's posture parameters. By automatically adjusting the number of iterations and parameters of capsule routing, the optimal capsule connection is found to better transfer and interpret feature information between the primary capsule layer and the digital capsule layer, thereby improving the feature learning ability of the capsule network.

[0062] Finally, the decoder is used to decode the classification capsule. Through the processing of the decoder, the model can output the defect category and probability of each pixel, thereby realizing accurate identification and classification of pipeline surface defects.

[0063] Step 4: Use the training set and validation set to train the model and optimize the model parameters;

[0064] When training the model, the total loss function used is a linear combination of the Negative Log Likelihood Loss (NLL Loss) and the optional Variational Autoencoder (VAE) loss.

[0065] NLL Loss is based on the likelihood principle in probability theory, and its expression is shown in formula (2):

[0066]

[0067] In formula (2), K is the category of pipeline surface defects, j is the number of training samples, and y jK is the k-th defect label corresponding to the sample, Represents the predicted probability value of classifying the training sample into the kth class.

[0068] VAE is mainly composed of reconstruction loss and KL divergence loss, and the expression is shown in formula (3):

[0069]

[0070] In formula (3), d represents the number of capsules, F represents the number of filters in the convolutional layer, and the mean μ jd And the log variance are calculated by the encoder, K is the type of pipeline surface defect, ||x K -f(x K )|| is the modulus of the capsule vector, representing the probability of identifying the Kth type of defect.

[0071] In summary, the expression of the total loss function is shown in formula (4):

[0072] L=L NLL +αL VAE Formula (4)

[0073] In formula (4), α is a hyperparameter used to balance the weight between classification loss and VAE loss. By adjusting this parameter during the training process, the trade-off between the model's classification performance and reconstruction ability can be controlled.

[0074] In addition, to avoid overfitting of the model, the early stopping method is used during the training process. The accuracy rate is used as a dynamic indicator to determine when to stop training by monitoring the performance of the model on the validation set. If the accuracy rate of the validation set keeps decreasing within a certain round, the training is stopped and the current model is saved as the best model.

[0075] Step 5: Use the test set to test the performance of the trained model and obtain the recognition result.

[0076] The performance of the model is evaluated by calculating indicators. The indicators are as follows:

[0077] (1) Confusion matrix: By comparing the relationship between the classifier prediction results and the true labels, the indicators of each category are obtained. See Table 1.

[0078] Table 1 Confusion matrix

[0079]

[0080] In Table 1, true positive (TP) means that the positive sample is correctly identified as positive; true negative (TN) means that the negative sample is correctly identified as negative; false positive (FP) means that the negative sample is incorrectly identified as positive; false negative (FN) means that the positive sample is incorrectly identified as negative.

[0081] (2) Precision refers to the proportion of samples predicted to be positive that are actually positive. The larger the value, the better. The expression is shown in formula (5):

[0082]

[0083] (3) Accuracy refers to the proportion of correctly classified samples to the total samples, as shown in formula (6):

[0084]

[0085] In formula (6), TP+TN is the sum of all correctly predicted negative and positive classes. In general, the higher the accuracy, the better the classifier.

[0086] (4) Recall rate refers to the proportion of correctly identified positive samples among all positive samples. The expression of recall rate is shown in formula (7):

[0087]

[0088] (5)F 1-score It is the harmonic mean of Precision and Recall, indicating the balance between the accuracy and recall of the model. The expression is shown in formula (8):

[0089]

[0090] Figure 4 This is the ablation experiment result, which is mainly used to compare the changes of the model's Loss and Accuracy with the number of epochs on the training set (Train) and the validation set (Val):

[0091] On the one hand, based on the Val Accuracy values ​​of each model in the figure, CapsNet has a maximum of 0.9099, while the model SPV-CapsNet in this paper can reach 0.9963 in the 30th round, which is nearly 9% higher than CapsNet, indicating that the model in this paper has successfully improved the recognition accuracy of CapsNet for pipeline surface defects. At the same time, VB-CapsNet, DSC-CapsNet, Pag-CapsNet and Clo-CapsNet also perform better than CapsNet. The recognition rates of these four models can be as high as 0.95, which can show that the modules introduced in this paper can play a positive role in the task of identifying pipeline surface defects and improve the recognition performance of traditional CapsNet. On the other hand, from the trend of Loss and Accuracy, VB-CapsNet, DSC-CapsNet, Pag-CapsNet and Clo-CapsNet all perform better on the training set than on the validation set, which can indicate that these models have overfitting. However, SPV-CapsNet does not have this phenomenon, which means that the improvement scheme in this paper is reasonable and SPV-CapsNet is more suitable for detecting pipeline surface defects.

[0092] Table 2 Comparative experiment

[0093]

[0094] From the above comparative experiments, it can be seen that the SPV-CapsNet model of the present invention has fewer parameters, improved accuracy and smaller memory usage compared to other models.

[0095] The above embodiments are only for illustrating the technical concept and features of the present invention, and their purpose is to enable people familiar with the technology to understand the content of the present invention and implement it accordingly, and they cannot be used to limit the protection scope of the present invention. Any equivalent transformation or modification made according to the spirit of the present invention should be included in the protection scope of the present invention.

Claims

1. A pipeline surface defect detection method based on an improved capsule network, characterized in that: The specific steps include: Step 1: Obtain the pipeline surface defect dataset and preprocess it. After preprocessing, randomly divide the dataset into training set, validation set and test set. Step 2: Improve the capsule network and use the dynamic snake convolution (DSConv) to replace the single convolution structure of the traditional capsule network. The defect information output by DSConv is fused through the pixel-attention-guided fusion module (Pag) and the channel self-attention module CloAttention, and multi-scale defect features are output. The multi-scale features are encoded into a multi-dimensional capsule structure in the primary capsule layer. The feature transfer between the primary capsule layer and the dynamic capsule layer is realized by using the Variational Bayes Routing (VB Routing) algorithm; Step 3: Use the training set and validation set to train the model and optimize the model parameters, and save the best model; Step 4: Use the test set to test the performance of the trained model and obtain the recognition results.

2. According to the improved capsule network pipeline surface defect detection method of claim 1, it is characterized in that: The step 1 specifically includes: A high-definition camera and a portable ultrasonic scanner are used to obtain a pipeline surface defect image dataset, and the collected image dataset is preprocessed; the preprocessing includes labeling the image category, image denoising and normalization.

3. According to the improved capsule network pipeline surface defect detection method of claim 1, it is characterized in that: When randomly dividing the training set, validation set, and test set, a random number generator is used to ensure the randomness of the division. The ratio of the training set, validation set, and test set is set to 6:2:2, and the divided training set, validation set, and test set are saved in different files respectively.

4. The pipeline surface defect detection method based on improved capsule network according to claim 1, characterized in that: The capsule network structure of step 2 includes: a convolutional layer, a primary capsule layer, a digital capsule layer and a dynamic routing; The convolution layer extracts features, the primary capsule layer expands the output of the convolution into a vector form, and the digital capsule layer is responsible for building a vector representation for each class in the dataset. Dynamic routing is only performed between the primary capsule layer and the digital capsule layer, and the weights of other layers are only adjusted in the mini-batch back-propagation method and remain unchanged in the forward pass of the entire network.

5. The pipeline surface defect detection method based on improved capsule network according to claim 1 or 4, characterized in that: The DSConv dynamically adjusts the shape and size of the convolution kernel. Its specific working principle is: The convolution kernel is deformed in the x-axis and y-axis directions, and the deformation offset is used as the calculation indicator. Based on the key characteristics of the boundary, shape, and size of the pipeline surface defects, DSConv calculates the corresponding ones, thereby applying convolution kernels of different sizes to defects at different locations and scales.

6. The pipeline surface defect detection method based on improved capsule network according to claim 5, characterized in that: The DSConv uses an iterative strategy to ensure that the convolution kernel does not deviate too much from the defect area.

7. The pipeline surface defect detection method based on improved capsule network according to claim 1 or 4, characterized in that: When learning the features of pipeline surface defects, Pag performs effective feature fusion. The pixel attention-guided fusion module Pag calculates the product of the pixel feature vectors corresponding to the two branches, the two branches are A branch and B branch, and uses the Sigmoid function to calculate a possibility value σ, which indicates the degree to which the two pixels may belong to the same object; if σ is higher, it is considered that the features provided by the I branch are more valuable for reference, and vice versa; the final output result of the pixel attention-guided fusion module Pag is obtained by dynamically fusing the pixel features of the I branch and the P branch based on a specific weight coefficient, and is expressed as follows: in, represents the vector of the corresponding pixel in the feature map of branch A, Represents the vector of the corresponding pixel in the feature map of branch B, Out Pag It is the final output result of the pixel attention-guided fusion module Pag.

8. The pipeline surface defect detection method based on improved capsule network according to claim 1 or 4, characterized in that: The CloAttention combines the vanilla attention mechanism and the convolution AttnConv. The module consists of a global branch and a local branch. The local branch uses AttnConv to aggregate high-frequency local information. AttnConv uses shared weights and context-aware weights to capture high-frequency information. The global branch uses vanilla attention to focus on low-frequency global information.

9. The pipeline surface defect detection method based on improved capsule network according to claim 1 or 4, characterized in that: The VB Routing approximates the routing probability between capsules and automatically updates the distribution of capsule posture parameters. It finds the optimal capsule connection by automatically adjusting the number of iterations and parameters of capsule routing so as to better transfer and interpret feature information between the primary capsule layer and the digital capsule layer.

10. The pipeline surface defect recognition method based on improved capsule network according to claim 1, characterized in that: When training the model in step 3, the total loss function used is a linear combination of the negative log-likelihood loss NLL Loss and the optional variational autoencoder VAE loss: NLL Loss is based on the likelihood principle in probability theory, as follows: Among them, K is the category of pipeline surface defects, j is the number of training samples, and y jK is the k-th defect label corresponding to the sample, Represents the predicted probability value of classifying the training sample into the kth class; VAE consists of reconstruction loss and KL divergence loss, as follows: Among them, d represents the number of capsules, F represents the number of filters in the convolutional layer, and the mean μ jd And the log variance are calculated by the encoder, K is the type of pipeline surface defect, ||x K -f(x K )|| is the modulus of the capsule vector, representing the probability of identifying the Kth type of defect; The expression of the total loss function is: L=L NLL +αL VAE Among them, α is a hyperparameter used to balance the weight between classification loss and VAE loss. By adjusting this parameter during the training process, the trade-off between the classification performance and reconstruction ability of the model is controlled.