Endoscope spring tube defect detection method based on improved YOLOv8n

By improving the YOLOv8n network and combining spatial domain filtering algorithms with multi-module collaborative design, the problems of low detection efficiency and insufficient accuracy in the production of medical endoscope spring tubes were solved, achieving efficient and accurate defect detection.

CN120997198BActive Publication Date: 2026-01-20ZHEJIANG SCI-TECH UNIV
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202511486409.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-10-17
Publication Date
2026-01-20
Estimated Expiration
2045-10-17

AI Technical Summary

Technical Problem

In the production of medical endoscope spring tubes, existing technologies suffer from low efficiency and high false detection rate in manual visual inspection, while machine vision inspection methods are slow and inaccurate in complex backgrounds, making it difficult to achieve efficient and accurate defect detection.

Method used

An improved YOLOv8n network is adopted, and the feature extraction and detection output are optimized through the collaborative design of spatial domain filtering algorithm preprocessing, DEMA-PMSFA module, CGRFPN network and LSBECD module, so as to achieve lightweight deployment.

Benefits of technology

It enables high-precision, real-time detection of surface defects in medical endoscope spring tubes, improving detection speed and accuracy to meet the needs of industrial production.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120997198B_ABST
    Figure CN120997198B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of spring tube production detection, and discloses an endoscope spring tube defect detection method based on an improved YOLOv8n. After collecting spring tube surface pictures, performing space domain filtering algorithm preprocessing, and then scaling the size, a detection picture with a defect prediction frame and confidence is obtained through a DCL-YOLOv8 network. The DCL-YOLOv8 network is based on a YOLOv8n network, adopts a DEMA-PMSFA module to replace a C2f module in an original backbone network, adopts a CGRFPN network to replace a feature pyramid in an original neck network, and adopts an LSBECD module to replace three detection heads in an original head network. The application realizes whole-process synergistic effect from input optimization to feature optimization to detection output, so that the model has high-precision recognition capability and meets the lightweight deployment requirement, can be stably applied to a mobile device of a medical endoscope spring tube production line, and can efficiently complete a real-time detection task.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of medical endoscope spring tube production and detection, in particular to an endoscope spring tube defect detection method based on improved YOLOv8n. BACKGROUND

[0002] Medical device quality and safety are the core guarantee of clinical diagnosis and treatment, and medical endoscope spring tube, as a key component of endoscope system, must meet stringent industry standards in terms of quality and safety because it directly contacts the mucosa of the digestive tract. In the current endoscope spring tube manufacturing process, the production speed has been increased to 12-20 m / min, but due to the limitations of the process level, small defects such as black spots, color spots and breakage inevitably appear on the surface of the product. Due to the fuzzy and small size of these defect features, detection is difficult. The existing detection scheme still mainly relies on manual visual inspection, with a detection speed of only 0.2-0.5 m / min, low efficiency and high labor cost. At the same time, long-term visual inspection can easily cause visual fatigue, greatly reducing the attention of workers, increasing the misdiagnosis rate and missed diagnosis rate, and thus causing economic losses, thereby seriously restricting the industrialization process of spring tube mass production.

[0003] In recent years, with the rapid development of machine vision, a variety of methods combining image processing and machine learning algorithms for defect detection have emerged, but these methods have limited ability to describe defect features and are difficult to cope with defect imaging scenarios in complex backgrounds or high-noise environments. Another method is a target detection method based on deep learning, which labels the spring tube surface defect dataset and then uses a neural network to train a detection model. Although this detection method has achieved excellent results in many fields, it still has limitations in practical applications: for example, the improved Faster RCNN algorithm has high precision in small target detection, but the model is too large to be deployed in actual production sites; YOLOv8n, as a lightweight model in the YOLOv8 series, has good detection efficiency, but when applied to medical endoscope spring tube surface defect detection, it still has problems such as insufficient detection speed, low detection accuracy, and high missed detection rate. SUMMARY

[0004] The technical problem to be solved by the present application is to provide an endoscope spring tube defect detection method based on improved YOLOv8n, which can be deployed in a lightweight manner, from input optimization to feature extraction optimization and detection output, to effectively and efficiently detect medical endoscope spring tube surface defects in real time.

[0005] In order to solve the above technical problems, the application provides an endoscope spring tube defect detection method based on improved YOLOv8n, which comprises the following steps: collecting pictures of the surface of the spring tube, performing spatial domain filtering algorithm pretreatment, then scaling to a uniform size, and inputting into the offline trained DCL-YOLOv8 network, and outputting a detection picture with a spring tube surface defect prediction frame and confidence.

[0006] The DCL-YOLOv8 network is based on the YOLOv8n network, adopts the DEMA-PMSFA module to replace the C2f module in the original backbone network, adopts the CGRFPN network to replace the feature pyramid in the original neck network, and adopts the LSBECD module based on parameter sharing to replace the three detection heads in the original head network.

[0007] As an improvement of the endoscope spring tube defect detection method based on improved YOLOv8n of the application, the DEMA-PMSFA module comprises a convolution module and an EMA attention mechanism.

[0008] The input features are sequentially subjected to convolution with three different convolution kernel sizes to extract defect local texture detail features, mesoscale semantic information and deep semantic information, the defect local texture detail features, the mesoscale semantic information and the deep semantic information are spliced by channels, then subjected to convolution and the EMA attention mechanism to generate dynamic attention weights, and then the dynamic attention weights are added to the input features element by element.

[0009] As a further improvement of the endoscope spring tube defect detection method based on improved YOLOv8n of the application, the CGRFPN network comprises a pyramid context extraction module.

[0010] The features P3, P4 and P5 output by the backbone network are output as features , and respectively after passing through the pyramid context extraction module, the feature P5 passes through a rectangular self-calibration module and is output together with the feature to a multi-scale feature fusion module to output a feature , the feature P4 passes through a rectangular self-calibration module and is output together with the feature to a dynamic interpolation fusion module, and then together with the feature to the multi-scale feature fusion module to output a feature , and the output of the feature P3 after passing through a rectangular self-calibration module is output together with the feature to a dynamic interpolation fusion module, and then together with the feature to the multi-scale feature fusion module to output a feature .

[0011] As a further improvement of the improved YOLOv8n-based endoscope spring tube defect detection method of the application:

[0012] The operation of the pyramid context extraction module is:

[0013]

[0014] Among them, represents different levels of input features, represents a pooling operation, represents cross-channel feature integration, represents continuous passing through 3 times of rectangular self-calibration modules, represents the dimension adjustment and integration of the output channel.

[0015] As a further improvement of the improved YOLOv8n-based endoscope spring tube defect detection method of the application:

[0016] The spatial domain filtering algorithm preprocessing includes first correcting the spring tube in the input image to a horizontal state through a dithering displacement correction, and then removing the spring tube background area through a mask operation to reserve the complete target detection area.

[0017] As a further improvement of the improved YOLOv8n-based endoscope spring tube defect detection method of the application:

[0018] The offline training process of the DCL-YOLOv8 network is:

[0019] Collect and select spring tube pictures with surface defects, perform spatial domain filtering algorithm preprocessing, then scale to a uniform size, and classify as black spots, color spots and damage, and then randomly divide into a training set and a test set. The labeled pictures in the training set are input into the DCL-YOLOv8 network for training, and the loss function is continuously optimized to obtain a weight closer to the label; the labeled test set pictures are input into the trained model for evaluation index verification.

[0020] The beneficial effects of the application mainly include:

[0021] 1、The spatial domain filtering algorithm of the application is used for preprocessing the input image, the imaging offset problem of the real-time shooting image in the production process is corrected through the dithering displacement correction algorithm, and the complex background noise is effectively removed in combination with the background mask generation algorithm, so as to provide high-quality input data for the subsequent neural network model and lay a foundation for improving the defect target recognition accuracy.

[0022] 2、The application innovatively designs a DEMA-PMSFA module to replace the C2f module of the original YOLOv8n network, the module fuses the partial convolution (PConv) idea, innovatively introduces a three-stage progressive feature extraction mechanism in the module bottleneck unit, realizes step-by-step deepening extraction of features, and at the same time, through integration of the EMA attention mechanism and the path aggregation mechanism, strengthens the dynamic update of the key feature weight, avoids the loss of interaction information between different channels. Compared with the ordinary C2f module, the DEMA-PMSFA module significantly enhances the feature extraction capability while improving the computing efficiency, so as to more accurately capture the local details and global correlation features of defects, and realize deep extraction of feature information based on the high-quality input after preprocessing.

[0023] 3、The application adopts a CGRFPN network to replace the FPN network in the original YOLOv8n network, wherein the rectangular candidate region construction (RCM) module can realize accurate frame selection and feature focusing of the rectangular region of interest for potential defect regions in the image. The architecture cooperates with the DEMA-PMSFA module to further strengthen the capture ability of the model for small defects, fuzzy defects and other detail features based on the multi-dimensional features extracted by the previous module, and greatly improves the recognition accuracy of the model for low contrast and small scale defects.

[0024] 4、The application replaces the three Detect modules in the Head part of the original YOLOv8n network with an LSBECD module, the module embeds a detail enhancement convolution (DEConv) in the shared convolution layer, strengthens the capture ability of the model for small defect shapes and texture features, and innovatively adds a separate batch normalization strategy in the module to ensure the accuracy of the model. Based on the refined features output by the previous network, the improvement reduces the model parameters and the amount of calculation through parameter sharing and optimization of the calculation process, improves the detection accuracy, greatly reduces the model parameters and the amount of calculation, provides core support for lightweight deployment, and realizes the balance between accuracy and efficiency.

[0025] 5、The medical endoscope spring tube surface defect detection method proposed in the application has high confidence in the spring tube surface defect recognition task through multi-module collaborative design. The whole process of each module from input optimization to feature optimization to detection output is synergistic, so that the model not only has high-precision recognition ability, but also meets the lightweight deployment demand, and can be stably applied to mobile devices of medical endoscope spring tube production lines to efficiently complete real-time detection tasks. BRIEF DESCRIPTION OF DRAWINGS

[0026] The specific embodiments of the application will be further described in detail below with reference to the accompanying drawings.

[0027] Figure 1 It is a structural schematic diagram of the basic YOLOv8n network;

[0028] Figure 2 Fig. 1 is a structural schematic diagram of the DCL-YOLOv8 network of the present application;

[0029] Figure 3 Fig. 2 is a structural schematic diagram of the DEMA-PMSFA module of the present application;

[0030] Figure 4 Fig. 3 is a structural schematic diagram of the CGRFPN network of the present application;

[0031] Figure 5 Fig. 4 is a structural schematic diagram of the PCE module of the present application;

[0032] Figure 6 Fig. 5 is a structural schematic diagram of the RCM module of the present application;

[0033] Figure 7 Fig. 6 is a structural schematic diagram of the FBM module and the DIF module of the present application,

[0034] Figure 7 Fig. 7 is a structural schematic diagram of (a) the FBM module and (b) the DIF module of the present application;

[0035] Figure 8 Fig. 8 is a structural schematic diagram of the DEConv module;

[0036] Figure 9 Fig. 9 is a structural schematic diagram of the LSBECD module of the present application;

[0037] Figure 10 Fig. 10 is a schematic diagram of the effect after processing by the spatial domain filtering algorithm of the present application;

[0038] Figure 11 Fig. 11 is an example diagram of the collected medical endoscope spring tube surface defect picture;

[0039] Figure 12 Fig. 12 is a process schematic diagram of the DCL-YOLOv8 network of the present application for online detection;

[0040] Figure 13 Fig. 13 is an example diagram of the detection effect of the DCL-YOLOv8 network of the present application on spring tube surface breakage and color spot defects;

[0041] Figure 14 Fig. 14 is an example diagram of the detection effect of the DCL-YOLOv8 network of the present application on spring tube surface black spot and color spot defects. DETAILED DESCRIPTION

[0042] The present application will be further described below in conjunction with specific embodiments, but the protection scope of the present application is not limited to this:

[0043] Embodiment 1, an endoscope spring tube defect detection method based on improved YOLOv8n, the specific process is as follows:

[0044] 1. Improved YOLOv8n network

[0045] The application is based on YOLOv8n network and makes targeted improvements. First, a spatial domain filtering algorithm is introduced for pre-processing in the image input stage, which removes image background noise while rotating and correcting the inclined spring tube, providing high-quality input data for subsequent feature extraction; secondly, the feature extraction module of the YOLOv8n network is innovatively designed, a three-stage progressive feature extraction mechanism that integrates the PConv (Partial Convolution) idea is introduced in the bottleneck part of the original C2f, and EMA (Efficient Multi-Scale Attention Mechanism) and path aggregation mechanism are used to build DEMA-PMSFA (Path Aggregation and EMA Attention Fusion Partial Multi-Scale Feature Aggregation) module to replace the C2f module in the backbone network, realizing efficient and deep extraction of spring tube defect features; thirdly, the network feature fusion architecture is optimized, the original FPN network (Feature Pyramid Network) in the network is replaced by CGRFPN network (Context Guided Spatial Feature Reconstruction Feature Pyramid Network), which further amplifies the micro-defect features through regional focusing based on the multi-dimensional features extracted by the previous module, significantly improving the model's recognition sensitivity to low-contrast and small-scale defects; finally, the LSBECD (Lightweight Shared Detail Enhanced Batch Normalization Separable Convolution Head) module with parameter sharing design is introduced to reconstruct the network detection head, which realizes the improvement of detection accuracy while greatly reducing the model parameters through parameter optimization, detail enhancement and calculation simplification, so that the model meets the detection accuracy requirement while improving the detection speed of endoscope spring tube production, the improved DCL-YOLOv8 network structure of the application is as shown in Figure 2 DCL-YOLOv8, Defect-oriented Context Enhancement and Lightweight YOLOv8, represents defect-oriented context enhancement and lightweight YOLOv8.

[0046] 1.1. Constructing the basic YOLOv8n network

[0047] The YOLOv8n network mainly consists of Backbone (main network), Neck (neck network) and Head (head network), and its structure is as shown in Figure 1As shown. The Backbone part mainly includes the CBS module, the C2f module and the SPPF (Fast Spatial Pyramid Pooling) module. Among them, the C2f module optimizes the gradient propagation path through the cross-layer feature aggregation mechanism, ensuring that YOLOv8 obtains more rich gradient flow information on the basis of lightweight design. The Neck part is inspired by the design idea of FPN and PAN (Path Aggregation Network), which transmits deep and shallow feature map information, realizes the comprehensive fusion of information flow in the network, and improves the detection ability of the model. The Head part uses a decoupled head structure to extract the position information and category information of the target respectively, and learns through different network branches, thereby improving the accuracy of the model.

[0048] 1.2 DEMA-PMSFA module based on partial convolution idea

[0049] The C2f module used in the YOLOv8n network is an improved structure based on CSPNet (Cross Stage Partial Network), which realizes a basic balance between feature extraction and computational efficiency through two convolutions, feature segmentation and jump connection. However, for the fine detection needs of small-scale and low-contrast defects on the surface of medical endoscope spring tubes, its feature capturing ability still needs to be improved. Therefore, the present application proposes an improved three-stage progressive feature extraction mechanism to replace the traditional Bottleneck part in the C2f module.

[0050] For input features, grouping division is achieved by tensor segmentation of feature channels: first, select some channels for 3x3 convolution to extract local texture detail features, then perform 5x5 convolution on the selected key channels to capture mid-scale semantic information, and finally perform 7x7 convolution to obtain deep semantic information. At the end of feature processing, multi-scale integration of the three branch outputs and the original input features is achieved through adaptive weighted fusion, realizing preliminary aggregation of features of different scales.

[0051] Considering that multi-channel parallel processing may cause loss of key feature information transmission, the present application introduces a path aggregation mechanism and an EMA attention mechanism in the branch structure to construct a new DEMA-PMSFA module to replace the C2f module in the backbone network, as shown in Figure 3 . Among them, the path aggregation mechanism effectively fuses information expression under different scales by orderly combining the intermediate features of each convolution branch, channel splicing and 1x1 convolution reconstruction, significantly improving the feature integrity; the EMA attention mechanism extracts spatial dimension information through horizontal and vertical pooling operations respectively, generates dynamic attention weights to weight and enhance the original features, and strengthens the feature information of key defect areas.

[0052] After the preprocessed image passes through the backbone network of the DCL-YOLOv8 network of the present application, multi-scale defect features (i.e., feature P3, feature P4 and feature P5) are output. The feature extraction mechanism designed by the present application has significant advantages over the original Bottleneck in the C2f module. On the one hand, the convolution operation adopts a multi-core parallel design and is performed only in part of the channels, effectively controlling the amount of calculation while ensuring the depth of feature extraction, and ensuring the detection efficiency in a high-speed production environment. On the other hand, the path aggregation and EMA attention mechanism work together to achieve cross-scale feature information integration while significantly enhancing the key target area, making the module more effectively capture the fine-grained information of small-scale and low-contrast defects on the surface of the spring tube, and improve the detection accuracy in the production process.

[0053] 1.3, FPN network reconstruction

[0054] To further enhance the recognition ability of the YOLOv8n network for micro-defects and low-contrast defects, the present application designs a CGRFPN network to replace the FPN network in the original Neck, based on the feature focusing concept of CGRSeg (Context Guided Spatial Feature Reconstruction Network). This architecture cooperates with the previous DEMA-PMSFA to enhance the precision fusion of multi-scale features and the defect area focusing ability based on the multi-scale defect features extracted by the previous module, thereby improving the effectiveness of feature information transmission. The CGRFPN network is shown in Figure 4 P3', P4', P5' are generated, then the context is strengthened through the RCM module, followed by multi-scale fusion, and finally the new features P3'', P4'', P5'' are output through the dynamic interpolation fusion module. Specifically, the multi-scale defect features output by the backbone network (i.e., feature P3, feature P4 and feature P5 output by the 4th, 6th and 9th layers of the backbone network, respectively) are output as features P3', P4' and P5' after passing through the PCE module. Then, the output of the feature P5 after passing through the RCM module is output together with the feature P5' through the FBM module to output the feature P5''. The output of the feature P4 after passing through the RCM module is output together with the feature P5'' through the DIF module, and then together with the feature P4' through the FBM module to output the feature P4''. The output of the feature P3 after passing through the RCM module is output together with the feature P4'' through the DIF module, and then together with the feature P3' through the FBM module to output the feature P3''.

[0055] (1) The structure of the pyramid context extraction module is shown in Figure 5 Fig. 1, which adopts a cascade design. For the multi-channel features output by the backbone network (i.e., features P3, features P4, and features P5), the pyramid context extraction module realizes step-by-step improvement of feature expression capability and completes integration of multi-channel features through continuous connection of three RCM (Rectangular Self-Calibration Module) modules, and finally outputs multi-scale feature representation rich in context information. The mathematical expression formula is as follows:

[0056] (1)

[0057] wherein represents input features at different levels, represents a pooling operation, represents cross-channel feature integration, represents continuous passing through 3 RCM modules, represents dimension adjustment and integration of output channels, represents output features of the pyramid context extraction module.

[0058] The RCM module, as the core unit of the pyramid context extraction module, realizes precise calibration and enhancement of input features through the synergistic effect of rectangular self-calibration attention, shape self-calibration function, and feature fusion function. The structure of the RCM module is shown in Figure 6 Fig. 2.

[0059] The rectangular self-calibration attention adopts a double-path pooling strategy. Based on the axial features extracted by the DEMA-PMSFA module, the rectangular self-calibration attention further captures the feature distribution law in the spatial domain through horizontal pooling and vertical pooling, thereby effectively constructing a rectangular region of interest and realizing precise focusing on the defect area.

[0060] The shape self-calibration function realizes fine calibration of feature geometry through bidirectional strip convolution. Based on the feature contour extracted by the DEMA-PMSFA module, first, a horizontal strip convolution kernel (k x 1) is used to calibrate the input feature map in the horizontal direction. By adaptively adjusting the weight of each row element, the horizontal contour of the feature map is made to better fit the target geometric shape. After the introduction of nonlinearity through the BN layer normalization and ReLU activation, a vertical strip convolution kernel (1 x k) is used to complete the vertical calibration, realizing bidirectional alignment of the spatial dimension. The mathematical expression formula of the shape self-calibration function is as follows:

[0061] (2)

[0062] wherein represents a large-kernel strip convolution operation, represents the length of strip convolution, BN+ReLU combination operation, sigmoid function to generate attention weights, input feature map.

[0063] The feature fusion function first further extracts local details from the input feature by 3x3 deep convolution, and then uses the calibrated attention feature as a spatial weight to adaptively weight and enhance the local detail feature by Hadamard product, so as to realize selective amplification of defect features. The mathematical expression formula of the feature fusion function is as follows:

[0064] (3)

[0065] wherein, denotes a deep convolution with a kernel of 3x3, and x denotes an input original feature map, denotes the attention feature calculated by formula (2), denotes Hadamard product operation.

[0066] Finally, the overall operation framework of RCM can be represented as:

[0067] (4)

[0068] wherein, denotes broadcast addition, and denotes horizontal and vertical pooling, denotes BN and MLP, denotes an input original feature map.

[0069] (2) Multi-scale feature fusion (FBM) is aimed at the scale difference of different levels of features. First, the two input features are respectively subjected to convolution dimension reduction. One of the features is subjected to activation function to generate dynamic weight, and then the spatial size is aligned by interpolation operation. Finally, the feature weighting fusion is completed by element-by-element multiplication, so as to strengthen the correlation of cross-scale features. Dynamic interpolation fusion (DIF) is aimed at different resolution features. The input feature size is matched by interpolation operation, then the interpolation result is subjected to convolution optimization, and finally the other part of the input feature is fused by element-by-element addition. The structure of multi-scale feature fusion and dynamic interpolation fusion is shown in Figure 7 , and the mathematical expressions are shown in formulas (5) and (6) respectively:

[0070] (5)

[0071] (6)

[0072] wherein, and denotes different input features, denotes an interpolation operation, denotes a convolution operation with a convolution kernel parameter denotes a sigmoid function, denotes a Hadamard product operation.

[0073] 1.4, detection head module LSBECD combined with shared parameters and separated batch normalization

[0074] In the YOLOv8n network, the Head part contains 3 independent Detect modules, which are respectively used for detecting targets of different scales to improve the adaptability of the overall model to different data sets. Each Detect module is divided into two branches: the Reg branch is responsible for bounding box regression, and the Cls branch is used to determine the class information, and each branch is composed of 2 CBS modules containing 3x3 convolution and a 1x1 Conv module. Although this design can effectively improve the performance and recognition accuracy of the model on data sets with many target categories, it also leads to a significant increase in the parameter quantity and computational complexity of the detection head part. Therefore, the optimization of the YOLOv8n detection head is of key significance to reduce the overall parameter size of the model and realize industrial scene deployment.

[0075] In view of the fact that the defect data set handled by the present application has fewer categories, the marginal effect of too many modules on performance improvement is limited, so the detection head does not need to retain redundant Conv modules. Therefore, the present application uses a detection head LSBECD module based on the parameter sharing idea to replace the three detection heads of the original YOLOv8 network: except for the independent setting of the front-end 3 1x1 Conv modules, the remaining convolution layers all use a parameter sharing mechanism, which greatly reduces the parameter quantity of the model by reusing weights.

[0076] To enhance the ability to capture defect details and make up for the precision loss that may be caused by parameter sharing, the present application integrates a detail enhancement convolution (DEConv) into the shared convolution layer through a separated batch normalization strategy (SBN). As shown in Figure 8 DEConv is composed of a normal convolution layer and 4 parallel differential convolution layers: the normal convolution layer is responsible for capturing intensity level information of features, and the differential convolution layers focus on gradient level information enhancement. Among them, the central differential convolution (CDC) and the angular differential convolution (ADC) reduce the computational cost through kernel weight reordering, and the vertical differential convolution (VDC) and the horizontal differential convolution (HDC) embed traditional edge operators into convolution layers to learn effective gradient information by encoding gradient prior knowledge, thereby improving convolution efficiency and feature extraction performance. The feature output formula of DEConv is as follows:

[0077] (7) ​

[0078] wherein, represents 5 convolution kernels, represents a convolution operation, represents a converted convolution kernel obtained by combining parallel convolutions, represents an input feature.

[0079] DEConv can efficiently extract the texture, shape and other detailed features of the spring tube surface defects, thereby meeting the accuracy requirements of the detection task. By integrating DEConv into the shared convolution layer through the split batch normalization strategy, the detection accuracy can be maintained to the greatest extent while significantly reducing the number of parameters, thereby meeting the performance requirements of real-time detection. The specific structure of LSBECD is shown in Figure 9 : After the shared convolution layer, an independently calculated BN layer is set to normalize the feature distribution of different branches; a learnable Scale layer is set at the end of the network to dynamically scale the features, so that the detection head can adapt to the feature differences of targets of different scales.

[0080] In combination with steps 1.1-1.5, the improved YOLOv8n network (DCL-YOLOv8 network) is used as the detection network for medical endoscope spring tube surface defects, as shown in Figure 2 : In the YOLOv8n network, the C2f modules in the Backbone part are all replaced with DEMA-PMSFA modules to improve the feature extraction capability of the model; the traditional FPN architecture (feature pyramid) is replaced with the CGRFPN network which is more sensitive to micro-defect features; finally, the shared convolution idea is introduced to reconstruct the three Detect modules in the detection head part, and the LSBECD detection head module is designed, which greatly reduces the number of model parameters.

[0081] 2、Model training

[0082] 2.1、Data preprocessing

[0083] To solve the imaging position offset of the spring tube caused by shaking during production, and to eliminate the interference problem caused by the background in the defect image with background entering the neural network, the present application proposes an OpenCV-based spatial domain filtering algorithm preprocessing method, mainly including shaking displacement correction and mask generation technology, and the processing effect is as shown in Figure 10 , and the specific implementation steps are as follows:

[0084] (1) Shaking displacement correction

[0085] Firstly, the spring tube contour in each image is recognized by using the FindingContour algorithm of the contour extraction function in OpenCV; then the contour perimeter is calculated by using the arcLength function, and the four vertex coordinates of the actual spring tube circumscribed contour are determined according to the optimal proportion of the contour perimeter; then the spring tube tilt angle is calculated through the vertex coordinates; finally, the tilted spring tube is presented in a horizontal state by using rotation correction.

[0086] (2) Mask generation technology

[0087] For the spring tube image after displacement correction, firstly, the pixel intensity mean and standard deviation are calculated through a sliding window, and pixel-level difference analysis is performed on the input image; then the image is smoothed and filtered by using a Gaussian filter algorithm, the light conditions are balanced, and the detail information in the dark area of the image is enhanced; finally, the target spring tube image mask is generated by using the pixel difference between the background and the spring tube itself, the background area of the spring tube is accurately removed through the mask operation, and the complete target detection area is reserved.

[0088] 2.2, Establishment of data set

[0089] The data set is collected from a medical technology company in Hangzhou, Zhejiang Province, and the data set images are all shot by using a 50 million pixel MV-CSO50-10GM industrial area camera combined with an MVL-KF2524M-25MP industrial lens. The picture acquisition pixel size is adjusted to 640x640, and then preprocessed by a spatial domain filtering algorithm. In the computer, the spring tube surface defect pictures are selected from the preprocessed pictures and labeled by Roboflow, in which the black spots are labeled as 'black', the color spots are labeled as 'color', and the damaged spots are labeled as 'damaged'. The total number of images is 3359, of which the number of training set is 2351 and the number of test set is 1008. The spring tube surface defect image is shown in Figure 11 .

[0090] 2.3 Training and testing process

[0091] The labeled pictures in the training set are input into the DCL-YOLOv8 network for training. Firstly, the feature extraction is performed by the main network mainly composed of the CBS module, the DEMA-PMSFA module and the SPPF module, then the multi-scale feature fusion is performed by the Neck network containing the new CGRFPN network, and finally the defect type candidate prediction box is generated by the LSBECD detection head module. According to the loss function, the candidate prediction box is continuously optimized to train the model to obtain weights closer to the label. The loss function of the present application is consistent with the loss function of the basic YOLOv8n network, mainly including positioning loss and classification loss The positioning loss part mainly adopts the CIoU strategy. After the center distance and the aspect ratio of the bounding box are constrained, the overlap area and the intersection over union between the predicted box and the real box are measured, and the corresponding matching degree is obtained. The formula is as follows:

[0092] (8)

[0093] (9)

[0094] Wherein:

[0095] : the Euclidean distance between the center points of the predicted box and the real box;

[0096] : the diagonal length of the minimum circumscribed rectangle enclosing the predicted box and the real box;

[0097] : the consistency of the aspect ratio;

[0098] : the intersection area of the predicted box and the real box;

[0099] : the union area of the predicted box and the real box.

[0100] The classification loss is used to measure the accuracy of target classification. The project mainly uses the binary cross entropy (BCE) algorithm to evaluate the difference between the predicted class and the real class. For each detection box, the model will predict the probability that the box belongs to a certain class. The classification loss function optimizes the model classification part by calculating the error between the predicted class probability and the real class. The formula is as follows:

[0101] (10)

[0102] Wherein:

[0103] : the total number of target classes;

[0104] : the label of the real class (1 indicates the target class, 0 indicates the non-target class);

[0105] : the probability of the model predicting this class.

[0106] The preset learning rate of the trained parameters is 0.01, the num_work is set to 8, the batch size is set to 16, and the epoch is set to 300. During the training process, the loss function value is calculated to continuously perform back propagation to the model parameters for iterative optimization, and the training is ended when the 300th epoch is completed.

[0107] The test process is to put the labeled test set pictures into the trained model to generate candidate prediction boxes, calculate the intersection over union of the candidate prediction boxes and the labeled boxes, and determine positive samples when the intersection over union is greater than 0.5 and negative samples when the intersection over union is less than 0.5. The mean Average Precision (mAP) is used as the evaluation index, and the mAP0.5=85.4 is obtained, thereby obtaining the online available DCL-YOLOv8 network.

[0108] 3. Online use of the trained DCL-YOLOv8 network

[0109] The MV-CSO50-10GM industrial area camera is used to collect spring tube production pictures, which are preprocessed by spatial domain filtering algorithm and scaled up to 640x640 pixels in proportion. Then the pictures are input into the online available DCL-YOLOv8 network obtained in step 2, and the model weight file is loaded for inference to generate spring tube surface defect prediction candidate boxes. By setting a confidence threshold, low-confidence candidate boxes are removed, and non-maximum suppression (NMS) is used for screening to output spring tube surface defect detection pictures with defect features. The overall process is shown in Figure 12 .

[0110] 4. Experiment

[0111] 4.1. The data set of example 1 is used in the experiment

[0112] 4.2. Evaluation index

[0113] The experimental evaluation index includes parameter quantity, precision, recall, average precision (AP), and mean Average Precision (mAP). The formulas are shown in equations (11) to (14):

[0114] (11)

[0115] (12)

[0116] (13)

[0117] (14)

[0118] wherein, 、 、 respectively represent the number of correctly identified real samples, the number of incorrectly identified samples, and the number of missing correct samples. The numbers under mAP indicate the average precision of the model when the IOU is this value.

[0119] 4.3, Comparative experiment

[0120] To verify the detection performance of the DCL-YOLOv8 network proposed in the present application, experiments were conducted under the same test set and compared with other six mainstream target detection algorithms, and the results are shown in Table 1. Through analysis of Table 1, it can be seen that in terms of model detection accuracy, the mAP0.5 value and the mAP0.5:0.95 value of the DCL-YOLOv8 network proposed in the present application are better than all the comparison algorithms; in terms of model lightweight, the parameter amount of DCL-YOLOv8 is only 2.58M, which is basically the same as YOLOv5n(2.54M) and YOLOv11n(2.59M) with the lowest parameter amount, and is much lower than Faster R-CNN and SSD, realizing the goal of maintaining lightweight model characteristics while ensuring high detection accuracy. It is proved that the present application reduces the parameter amount of the model while ensuring the detection accuracy, and significantly improves the average precision of the model.

[0121] Table 1 Performance comparison of target detection algorithms

[0122]

[0123] 4.4, Ablation experiment

[0124] To further verify the effectiveness of the DCL-YOLOv8 model proposed, the present application carried out a series of ablation experiments based on YOLOv8n to evaluate the influence of different modules on the detection performance and lightweight characteristics of the network, and the experimental results are shown in Table 2.

[0125] Table 2 Ablation experiment results of DCL-YOLOv8

[0126]

[0127] Experiment 1: based on YOLOv8n network, the dataset is not processed.

[0128] Experiment 2: based on YOLOv8n network, the dataset is preprocessed according to step 2.1 of embodiment 1.

[0129] Experiment 3: Based on the YOLOv8n network, the data set is preprocessed according to the step 2.1 of embodiment 1, and in the Backbone, all C2f modules are replaced with DEMA-PMSFA modules.

[0130] Experiment 4: Based on the YOLOv8n network, the data set is preprocessed according to the step 2.1 of embodiment 1, and the FPN network in the Neck part is replaced with the CGRFPN network.

[0131] Experiment 5: Based on the YOLOv8n network, the data set is preprocessed according to the step 2.1 of embodiment 1, and in the Head, three Detect modules are replaced with one LSBECD module.

[0132] Experiment 6: Based on the YOLOv8n network, the data set is preprocessed according to the step 2.1 of embodiment 1, and in the Backbone, all C2f modules are replaced with DEMA-PMSFA modules, and in the Neck, the FPN network is replaced with the CGRFPN network.

[0133] Experiment 7: Based on the YOLOv8n network, the data set is preprocessed according to the step 2.1 of embodiment 1, and in the Backbone, all C2f modules are replaced with DEMA-PMSFA modules, and in the Head, three Detect modules are replaced with one LSBECD module.

[0134] Experiment 8: Based on the YOLOv8n network, the data set is preprocessed according to the step 2.1 of embodiment 1, and in the Neck, the FPN network is replaced with the CGRFPN network; and in the Head, three Detect modules are replaced with one LSBECD module.

[0135] Experiment 9: DCL-YOLOv8 network of the application.

[0136] As shown in Table 2, in the data preprocessing link, the comparison results of experiment 1 and experiment 2 show that by introducing the spatial domain filtering algorithm, the precision and recall of the model can be significantly improved, and finally the mAP0.5 value of the model is improved by 6.7% compared with the initial state without processing, which fully verifies the basic supporting role of data preprocessing for defect detection task.

[0137] In the algorithm improvement part, the independent role and synergistic effect of each module are fully verified:

[0138] The DEMA-PMSFA module realizes the accurate capture of low-contrast defects such as fine scratches and depressions on the surface of the spring tube through the synergistic effect of three-stage progressive feature extraction and EMA attention mechanism. The results of Experiment 3 show that the introduction of this module reduces the model's parameter amount by 6.6% while increasing the mAP0.5 value by 3.1%, reflecting its dual advantages in feature extraction efficiency and accuracy.

[0139] The CGRFPN network strengthens the cross-scale feature correlation by pyramid context extraction and dynamic interpolation fusion to address the feature transmission attenuation problem of traditional FPN networks. In Experiment 4, the introduction of this architecture alone increases the model's mAP0.5 value by 4.7%. When the DEMA-PMSFA module and the CGRFPN network work together (Experiment 6), the high-quality defect features output by the DEMA-PMSFA module provide better input for the CGRFPN network, enabling more accurate capture of defect context correlation through pyramid context extraction and enhancing cross-scale complementarity through dynamic interpolation fusion due to the improved input feature quality. Therefore, the model's mAP0.5 value is further increased by 5.7% compared to the initial model.

[0140] The LSBECD detection head shows significant suppression of parameter expansion caused by multi-scale feature fusion: The results of Experiment 7 and Experiment 8 show that after the introduction of this module, the model's parameter amount is reduced by 28.2% and 7.3%, respectively. In addition, the multi-scale features optimized by the pre-sequence network have improved semantic consistency, reducing the difficulty of feature recognition in the parameter sharing scenario for the LSBECD module, making it easier for the DEConv to enhance details. The results of Experiment 9 show that under the synergistic effect of the three improvements, the model's parameter amount is reduced by 14.2% while the mAP0.5 value is increased by 6.2% compared to the initial model.

[0141] Compared with the unimproved YOLOv8n basic model, the integrated improved DCL-YOLOv8 model achieves the highest precision improvement, with an mAP0.5 value of 85.4%. Therefore, the improved algorithm realizes the comprehensive optimization goal of fewer parameters and higher detection accuracy through data preprocessing and module synergy, verifying the effectiveness of the scheme.

[0142] Figures 13-14For the detection effect example diagram of the medical endoscope spring tube surface defect in the production process using the DCL-YOLOv8 network of the present application, it can be seen directly that the improved algorithm proposed in the present application has a very high confidence score in the spring tube surface defect recognition task, can accurately frame and recognize black spots, color spots and damage, and realize the accurate detection task of the spring tube surface defect. At the same time, it is verified by experiment that the DCL-YOLOv8 model of the present application can still maintain a detection speed of 217.4 FPS under the premise of ensuring high-precision detection performance, fully meeting the rate requirements of real-time detection of the production line, and therefore is suitable for deployment on the real-time production line of the medical endoscope spring tube.

[0143] Finally, it should also be noted that the above enumeration is only a few specific embodiments of the present application. Obviously, the present application is not limited to the above embodiments, but can also have many variations. All variations that can be directly derived or inferred from the content disclosed in the present application by those of ordinary skill in the art should be considered as falling within the scope of protection of the present application.

Claims

1. An endoscope spring tube defect detection method based on improved YOLOv8n, characterized in that: The method comprises the following steps: collecting a picture of a spring tube surface, performing a spatial domain filtering algorithm preprocessing, then scaling to a unified size, inputting into a DCL-YOLOv8 network trained offline, and outputting a detection picture with a spring tube surface defect prediction frame and confidence; The DCL-YOLOv8 network is based on a YOLOv8n network, adopts a DEMA-PMSFA module to replace a C2f module in the original backbone network, adopts a CGRFPN network to replace a feature pyramid in the original neck network, and adopts a LSBECD module based on parameter sharing to replace three detection heads in the original head network; DCL-YOLOv8, namely Defect-oriented Context Enhancement and Lightweight YOLOv8, represents a defect-oriented context enhancement and a lightweight YOLOv8; DEMA-PMSFA, namely a partial multi-scale feature aggregation combined with an EMA attention mechanism, introduces a three-stage progressive feature extraction mechanism combined with a partial convolution PConv thought into a bottleneck part in the original C2f, and cooperates with an efficient multi-scale attention mechanism EMA and a path aggregation mechanism; The CGRFPN network, namely a context-guided spatial feature reconstruction feature pyramid network, comprises a pyramid context extraction PCE module, a multi-scale feature fusion FBM module and a dynamic interpolation fusion DIF module; The LSBECD, namely a lightweight shared detail enhancement type batch normalization separated convolution head, adopts a parameter sharing mechanism for all convolution layers except the front-end three 1×1 Conv modules; a BN layer is independently calculated after the shared convolution layer, and different branch feature distributions are normalized; A learnable Scale layer is arranged at the end of the network to dynamically scale the features, so that the detection head can adapt to the feature differences of different scale targets.

2. The endoscope spring tube defect detection method based on the improved YOLOv8n according to claim 1, wherein the DEMA-PMSFA module comprises a convolution module and an EMA attention mechanism; input features are sequentially subjected to convolution with three different convolution kernel sizes to extract defect local texture detail features, medium-scale semantic information and deep semantic information; the defect local texture detail features, the medium-scale semantic information and the deep semantic information are spliced by channels, subjected to convolution and the EMA attention mechanism to generate dynamic attention weights, and then the dynamic attention weights are added to the input features element by element.

3. The endoscope spring tube defect detection method based on the improved YOLOv8n according to claim 2, wherein the CGRFPN network comprises a pyramid context extraction module, a multi-scale feature fusion module and a dynamic interpolation fusion module.

4. The endoscope spring tube defect detection method based on the improved YOLOv8n according to claim 3, wherein the pyramid context extraction module is configured to perform the following operations: In the CGRFPN network, the features P3, P4 and P5 output by the backbone network are output as features , and respectively after passing through the pyramid context extraction module; the feature P5 is output as feature after passing through the rectangular self-calibration module together with the feature and passing through the multi-scale feature fusion module; the feature P4 is output as feature after passing through the rectangular self-calibration module together with the feature , passing through the dynamic interpolation fusion module, and then passing through the multi-scale feature fusion module together with the feature ; and the output of the feature P3 after passing through the rectangular self-calibration module is output as feature after passing through the dynamic interpolation fusion module together with the feature , and then passing through the multi-scale feature fusion module together with the feature .

5. The endoscope spring tube defect detection method based on the improved YOLOv8n according to claim 4, wherein the multi-scale feature fusion module is configured to perform the following operations: ​ wherein, represents different level input features, represents a pooling operation, represents cross-channel feature integration, represents continuous passing through 3 times of rectangular self-calibration modules, represents dimension adjustment and integration of output channels. ​ The spatial domain filtering algorithm preprocessing includes first correcting the spring tube in the input image to a horizontal state by dithering displacement correction, and then removing the background area of the spring tube by mask operation to reserve the complete target detection area.

6. The endoscope spring tube defect detection method based on improved YOLOv8n according to claim 5, characterized in that: The offline training process of the DCL-YOLOv8 network is: Collect and select spring tube pictures with surface defects, perform spatial domain filtering algorithm preprocessing, then scale to a uniform size, and classify as black spots, color spots and damage, then randomly divide into a training set and a test set, input the labeled pictures in the training set into the DCL-YOLOv8 network for training, and continuously optimize the training model according to the loss function to obtain weights closer to the labels; input the labeled test set pictures into the trained model for evaluation index verification.

Citation Information

Patent Citations

  • Lightweight yarn defect detection method based on improved YOLOv8n network

    CN119672027A

  • Traffic sign target detection method based on improved CPBM-YOLO

    CN120298997A