Next Article in Journal
Effect of the Internal Architecture of Titanium Interbody Cages on Signal Loss Artifacts at 3.0 T Magnetic Resonance Imaging
Previous Article in Journal
Prediction-Regularized Spatio-Temporal Transformer Framework for Offline Multi-Intersection Traffic Signal Control
 
 
Font Type:
Arial Georgia Verdana
Font Size:
Aa Aa Aa
Line Spacing:
Column Width:
Background:
Article

Surface Defect Detection of Copper Tube Based on YOLOX with Convolutional Block Attention and Adaptive Spatial Feature Fusion

School of Automation, Central South University, Changsha 410083, China
*
Author to whom correspondence should be addressed.
Appl. Sci. 2026, 16(10), 5155; https://doi.org/10.3390/app16105155
Submission received: 17 March 2026 / Revised: 12 May 2026 / Accepted: 12 May 2026 / Published: 21 May 2026

Abstract

Surface defect detection technology is important to improve product quality and save production costs. In order to realize automatic detection of copper tube surface defects, an improved YOLOX algorithm is proposed based on convolutional block attention (CBA) and adaptive spatial feature fusion (ASFF), named as CBA-ASFF-YOLOX. The improved YOLOX backbone feature extraction network is replaced with CSPDarknet-53. Then, we construct a convolutional block attention module and an adaptively spatial feature fusion module in the feature fusion part to enhance the spatial position correlation between features by learning the connections between different feature maps. To solve the unbalanced differences in real label samples, we utilize Focal Loss function to replace the cross-entropy loss function. In addition, the bounding box regression loss in this study is based on the SIoU formulation, and a simplified variant is adopted to improve regression quality and facilitate more stable convergence. Finally, the algorithm is applied to copper tube surface defect detection task. Experimental results show that the accuracy of CBA-ASFF-YOLOX algorithm is higher than those of other series of YOLO algorithm.

1. Introduction

Copper tube is an important raw material of refrigeration devices, and it is mainly used to make heat exchangers and connecting pipe fittings. Copper tubes in air conditioner radiators are known in the industry as the “blood vessels” of air conditioners. The surface quality and welding quality of these “blood vessels” directly determine the sealing performance and heat exchange efficiency of the refrigeration system. With the development of the air conditioning industry towards high efficiency, energy saving, environmental protection and material saving, we need high-cleanliness, high-surface-quality, high-performance, ultra-fine, ultra-thin copper tube. This undoubtedly put forward strict requirements for the processing and manufacturing process of copper tube. Copper tube processing technology is divided into many steps, the main flow is cylindrical long copper tube feeding, according to the requirements of different sizes after cutting, drilling, expanding, shrinking, bending, and welding and other different operations. After a series of processes, the surface of copper tube will inevitably cause some defects, such as surface burr, cracking, scratches, pits and welding tumors and other types. According to the actual needs of the factory, the inspection is mainly carried out for defects generated in the welding process. The common typical defect images are shown in Figure 1. It can be seen that the target size of black spot defects is small and the proportion of pixels is relatively small. The features are not obvious and difficult to detect. For defects of faulty welding, there are various forms of characterization, as shown in Figure 1b,c.
Surface defect inspection of metal tubes is generally related to nondestructive evaluation (NDE) [1], which aims to identify defects without damaging the inspected component. For copper tube inspection, commonly used NDE methods mainly include ultrasonic testing (UT) and eddy current testing (ET) [2,3]. UT is suitable for detecting internal discontinuities or thickness-related defects by analyzing the propagation and reflection of ultrasonic waves, while ET is widely used for conductive materials and is sensitive to surface or near-surface defects. Compared with these two methods, radiographic testing (RT) [4], infrared thermography, and penetrant testing (PT) are less frequently used for copper tube surface defect detection in high-speed industrial production [5]. RT usually involves higher equipment cost and radiation safety requirements; infrared thermography is sensitive to thermal excitation conditions and environmental interference; and PT often requires surface pretreatment and post-cleaning, making it less suitable for continuous online inspection. Therefore, although traditional NDE methods are effective in specific scenarios, they may face limitations in detecting complex visual surface defects on copper tube welds under real-time industrial conditions. In addition, some defect images exhibit issues such as texture similarity and coupled appearance features across different data types, which considerably increases the difficulty of defect identification and localization. Currently, the identification of metal surface flaws in the industry is mostly dependent on human eye detection. However, owing to the high workload and rising fault kinds, eye detection struggles to satisfy the objectives of organization growth and transformation [6,7]. Compared to manual inspection, image-based surface defect detection using machine vision instead of human eyes provides higher accuracy and efficiency [8,9,10,11,12].
In recent years, the research on appearance detection of metal products is increasing gradually. There are machine learning and deep learning methods to realize image recognition of copper tube and other metal surfaces. The classic image processing approach is mostly used by machine-learning-based methods to extract the form and texture properties of the metal surface. Following this, the machine learning algorithm is utilized to create the matching classifier to finish the classification and recognition of the picture [13,14,15]. The advantages of those methods are strong pertinence and strong interpretability of features, while the disadvantages are poor detection robustness. The shooting angle, illumination and other external interference factors of target image acquisition is highly required [16,17,18]. The deep-learning-based methods automatically extract the deep abstract features of the image through the convolutional neural network to achieve end-to-end image detection, with high detection accuracy, fast detection speed and good generalization ability of the algorithm. But there are high requirements for data set samples and poor interpretability [19,20].
Defect detection approaches that are based on computer vision have steadily been employed in industry as a result of the development of machine vision and deep learning. An end-to-end convolutional neural network was suggested by Fu et al. [21] in order to perform high-precision classification of strip surface defects. A generative adversarial network is used in [22,23] in order to produce a substantial amount of unlabeled data and then categorize faults. This approach finds a solution to the issues of inadequate defect samples and challenging training. Nevertheless, the above detection model only solves the classification problem of strip surface defects and lacks the identification of defect location. For achieving the end-to-end detection of strip surface defects, a defect detection network (DDN) [24] was developed, and it was able to reach an accuracy of 70% to 80%. Unfortunately, despite the fact that the approach has a high detection accuracy, it is not quick enough to differentiate between the confusing faults. An upgraded version of the YOLOv3 algorithm was used by Li et al. [25] to identify flaws on the surfaces of strip steel, and the detection accuracy reached 80%. Liu et al. [26] proposed a novel network structure based on YOLOv5s, combined with CoTNet transformer module, global attention mechanism and adaptive spatial feature fusion algorithm. In [27], to address the presence of numerous small defects, information augmentation and multiscale feature fusion with YOLO (IAMF-YOLO) based on YOLOv8 is proposed, and it surpasses YOLOv8 in terms of detection accuracy and precision. The detecting speed was sufficient to satisfy the continuous requirements of industrial production. However, because of its regression box loss function, the actual object box that has extreme dimensions in terms of height, length, and breadth will be screened and filtered out owing to its big aspect ratio. This is something that is often extremely significant in real detection tasks and detection issues that need to be handled. Existing YOLO-based methods typically achieve detection accuracies (mAP) in the range of 70–80% on industrial defect datasets [24,25,26,27], indicating that there is still room for improvement in more challenging scenarios. To sum up, although extensive studies have been conducted on general metal surface defect detection, research specifically tailored to copper tube defects remains limited. In particular, the unique characteristics of copper tube defects, such as small defect size, high texture similarity, and complex welding-induced patterns, are not sufficiently addressed in existing methods. Therefore, a dedicated detection framework is required, and a copper tube surface defect detection method based on YOLOX is developed in this study.
From a methodological perspective, the baseline YOLOX model still exhibits several limitations when applied to copper tube defect detection. First, it has difficulty in detecting small-scale defects due to insufficient multi-scale feature fusion. Second, feature inconsistency across different pyramid levels affects the robustness of detection under complex backgrounds. Third, the model is sensitive to class imbalance in defect datasets. Finally, its bounding box regression mechanism is not sufficiently robust for defects with irregular shapes and varying aspect ratios. To address the above limitations, this study proposes a unified improvement framework by integrating multiple complementary components into YOLOX. Specifically, the CBA module enhances feature representation under complex backgrounds, ASFF improves multi-scale feature fusion for small defect detection, Focal Loss alleviates class imbalance, and a SIoU-based regression loss improves localization accuracy. Unlike existing YOLO-based improvements that typically focus on a single aspect, the proposed method jointly addresses multiple challenges in a coordinated manner, leading to more robust performance in copper tube defect detection. Specifically, the CBA module is introduced to enhance feature representation under complex backgrounds, ASFF is adopted to improve multi-scale feature fusion, Focal Loss is used to alleviate class imbalance, and an SIoU-based regression loss is employed to improve localization accuracy and convergence stability. These components are designed to work collaboratively, with each module targeting a specific limitation identified in existing approaches.
The main contributions of this paper are summarized as follows:
(1) A modified YOLOX-based detection framework is developed by incorporating CBA and ASFF modules, which improves feature extraction and multi-scale representation for complex copper tube surface defects.
(2) A training optimization strategy is designed by integrating Focal Loss and a simplified SIoU-based regression loss, effectively addressing class imbalance and enhancing localization accuracy.
(3) Extensive experiments on a copper tube defect dataset demonstrate that the proposed CBA-ASFF-YOLOX framework achieves superior detection performance compared with existing YOLO-based methods, validating the effectiveness of the integrated design.

2. CBA-ASFF-YOLOX

The YOLO series algorithms [28,29,30] have steadily garnered an increasing amount of interest as a result of the development of its target detecting capabilities. YOLOX [31], which is an update of the algorithms in the YOLO series, is a detector that has a greater detection accuracy and a quicker detection speed than other single-stage detection algorithms that are currently in use. The network structure of YOLOX is shown in Figure 2.

2.1. YOLOX

a. Network structure
YOLOX is a one-stage anchor-free object detector consisting of a backbone, a neck, and a decoupled detection head. Given an input image I R 640 × 640 × 3 , feature extraction is first performed by the backbone network to obtain multi-scale feature maps. These features are then processed by a PAN-based neck to enhance feature aggregation across different scales. Finally, a decoupled head is employed to separately predict classification scores and bounding box regression parameters. The overall detection pipeline can be summarized as:
I B a c k b o n e N e c k ( P A N ) D e c o u p l e d   H e a d Y
where Y denotes the predicted bounding boxes and corresponding class probabilities after non-maximum suppression.
b. Detection process
YOLOX adopts an anchor-free mechanism, where predictions are generated based on feature points rather than predefined anchor boxes. Positive samples are determined according to their spatial relationship with the ground-truth boxes, including center proximity and geometric constraints. The overall loss function consists of three components:
L = L c l s + L o b j + L r e g
where L c l s , L o b j , and L r e g represent the classification loss, objectness loss, and bounding box regression loss, respectively. The classification and objectness losses are typically computed using cross-entropy-based formulations, while the regression loss is based on IoU-related metrics.

2.2. CBA-ASFF-YOLOX Network Structure

The YOLOX method utilizes Darknet53 as its backbone feature extraction network, generating three feature layers of differing dimensions that may extract defect characteristics of varied sizes and kinds to a limited degree. Nonetheless, the black dots on the copper tube surface resemble the traits of partial welding defects, rendering direct use of the original YOLOX method suboptimal for detection outcomes. This section optimizes and adjusts the network topology to address the issue of insufficient feature differentiation among fault kinds. Firstly, the backbone part is replaced by Darknet53 of CSPDarknet53 of YOLOv5 [30], as shown in Figure 3. By introducing a cross-stage-partial (CSP) module, the network architecture can realize richer gradient combination and reduce.
The amount of computation. The cross-stage partial module is shown in Figure 4, the input is split into two distinct branches. A convolution layer is the first thing that the first branch travels through. After that, it goes through many residual structures and has a convolution operation performed on it. The output also concatenates both branches. Because of the additional residual structure, the gradient value of the back-propagation between layers is strengthened, and the issue of gradient disappearance, which is caused by the network being too deep, is avoided. As a result, fine-grained features may be retrieved without the network degrading.
At the conclusion of the backbone network, we provide the convolutional block attention module [32]. This is the second addition to the network. There are two distinct channel attention modules (CAM) and spatial attention modules (SAM) included inside the CBA module, which is a lightweight plug-and-play pass-through module. Figure 5 depicts the channel attention module in its entirety. It is the feature map F that serves as the input for the channel attention module. The height of the feature map is H, and its width is W. The channel number of the feature graph is C. The first step is to acquire the AvgPool and MaxPool based on the height and width of F by using the average pooling operation and the maximum pooling operation, respectively. Following this, the AvgPool and MaxPool are then fed into the fully connected layer with shared parameters of two layers. The quotient of the number of channels in the feature map and ratio (the ratio = 8 was used for this work) is the number of output units that are produced by the first completely linked layer. The feature graph has a total of channels that corresponds to the number of output units that are produced by the second complete connection layer. Once this is done, the channel attention map is created by adding the average pooling output, denoted by AvgPool, and the maximum pooling output, denoted by MaxPool, which were both acquired after the entire connection layer.
The Sigmoid activation function is then used to obtain the channel attention map M c . Specifically, the channel attention can be formulated as:
M c F = σ MLP AvgPool F + MLP MaxPool F
The spatial attention module is shown in Figure 6. The input of the spatial attention module is the product of F and M c , namely channel-refined feature map F . Then, the average pooling result and the maximum pooling result were concatenate. The obtained result is convolved with a 7 × 7 convolution kernel with a number of 1, and sigmoid activation function was used to obtain the spatial attention map M s , which can be expressed as:
M s F = σ f 7 × 7 AvgPool F ; MaxPool F
Finally, the output of the CBA module is given by:
F = F M s F
The channel attention mechanism and the spatial attention mechanism are both included in the CBA module. CBA can enhance discriminative feature representation for visually similar textures in industrial defect detection. It integrates channel attention and spatial attention mechanisms to adaptively recalibrate feature weights. The channel attention module suppresses redundant and irrelevant feature channels while highlighting key feature channels that carry subtle texture differences among similar defects. The spatial attention further focuses on critical local regions of defect textures, weakening background interference and trivial texture noise. Figure 7 shows the whole module. The attention maps are inferred along two independent dimensions (channel and spatial) and then multiplied with the input feature map to perform adaptive feature refinement.
Additionally, to resolve the issue of internal inconsistency in the feature pyramid of one-stage detectors, the adaptively spatial feature fusion (ASFF) module is introduced into the neck of the network [26]. ASFF adaptively aligns and fuses multi-scale feature maps from different network layers. It resolves spatial offset and semantic inconsistency among hierarchical features by adjusting spatial weights dynamically. Low-level features retain fine-grained details for tiny defects, while high-level features provide global semantic context. It eliminates scale conflict and feature misalignment in conventional pyramid fusion, enabling consistent cross-scale feature representation and greatly improving the localization accuracy of small defects. The feature maps of different levels are first resized to the same resolution. Then, adaptive weighted fusion is performed as follows:
F ASFF = α 1 F 1 + α 2 F 2 + α 3 F 3
α i 0 , i = 1 3 α i = 1
where α i are learnable weights. This mechanism enables the network to adaptively fuse multi-scale features while suppressing spatial inconsistency and enhancing discriminative information. The structure of the ASFF module is shown in Figure 8.

2.3. Focal Loss Function

For the purpose of determining the loss value of confidence and classification, the YOLOX method makes use of the cross-entropy loss function. However, it is important to note that the cross-entropy loss function is mostly relevant to situations when the data distribution is uniform. The purpose of this research is to investigate the fact that there exist imbalanced disparities in actual label samples, beginning with the data labels. In order to find a solution to this issue, the Focal Loss [33] function was used as a replacement for the cross-entropy loss function, which was responsible for calculating confidence loss and classification loss. In order to cope with uneven sample categorization, a loss function known as Focal Loss is used. It focuses on adding weight to the matching loss of samples in accordance with the difficulty of sample resolution, which means adding a smaller weight to the samples that are readily identifiable and providing a bigger weight to the samples that are difficult to separate:
C E ( P t ) = log ( p t )
Focal L o s s ( P t ) = α ( 1 p t ) γ log ( p t )
Formula (1) is the cross-entropy loss function and formula (2) is the Focal Loss function. It can be seen from the formula that the Focal Loss function introduces two hyperparameters to adjust the data imbalance. Where α is the weight factor, γ is the regulating factor. By changing the value of the weight factor, different weights are added to different categories so as to balance the importance of positive and negative samples. At the same time, changing the value of the regulating factor can make a better distinction between difficult and simple cases, reduce the loss value in the sample interval of easy classification, and make the loss function more focused on the distinction between difficult cases, thus improving the overall performance of the model.

2.4. Optimized IoU Loss Function

A significant portion of the YOLOX algorithm’s loss function is comprised of three distinct categories: confidence loss, classification loss, and prediction box regression loss. The cross-entropy loss function is used for both the confidence loss and the classification loss, while the CIoU loss function is utilized for the prediction box regression loss [34]. The Intersection-over-Union (IoU) between the ground truth and the predicted box is used by the CIoU loss function in order to accurately represent the degree of overlap that exists between the two boxes. In addition to this, it takes into consideration the overlap between the two boxes, the distance between the center point and the length and width ratio, which helps to alleviate the divergence issue that occurs during the processing of the training. In order to compute the formula, the convergence of the model is brought into consideration as follows:
L C I o U = 1 I o U + ρ 2 b , b g t c 2 + α v
α = v ( 1 I o U ) + v
v = 4 π 2 arctan w g t h g t arctan w h 2
where b and bgt are the centroid coordinates of the predicted and actual bounding boxes, respectively, and represent the equilibrium coefficient, v quantifies the similarity of the aspect ratio, whereas w and wgt denote the widths of the predicted and actual boxes, respectively, and h and hgt represent the heights of the predicted and actual boxes, respectively.
This study enhances the convergence of the bounding box regression by optimizing the regression loss function and redefining its penalty term. Based on the SIoU loss [35], a simplified variant is adopted in this work.
L s i o u = 1 ( A r e a _ i A r e a _ b e t w e e n _ c e n t e r ) A r e a _ c
where Area_i is the intersection area between the predicted bounding box and the ground-truth bounding box. Area_between_center is the area of the rectangle formed by the center points of the predicted box and the ground-truth box. Area_c is the area of the minimum enclosing rectangle that covers both the predicted box and the ground-truth box.
SIoU is particularly beneficial for small or irregular defect shapes because it introduces angle, distance and shape constraint losses beyond merely overlapping area. Unlike traditional IoU variants that only focus on intersection ratios, SIoU aligns direction and geometric morphology between bounding boxes. For tiny defects with limited pixels and irregular defects with complex contours, it reduces positioning deviation, eliminates angular mismatch and better fits distorted defect outlines, greatly improving localization accuracy. The SIoU loss function first evaluates the ratio of the overlapping area of two boxes to the minimal enclosing area. In contrast to IoU, this component more accurately represents the genuine overlap between the ground truth and the prediction box, hence enhancing the overlap between the prediction box and the ground truth for small-scale defect targets. Secondly, to normalize the centroid coordinates of the two boxes and expedite the convergence of the target prediction frame in both horizontal and vertical directions, SIoU incorporated the area of the rectangle formed by the centers of the actual and predicted boxes as an additional penalty term.
Figure 9 illustrates the variation in loss values within the same model using both the original and enhanced loss functions on the copper tube surface defect dataset. The blue color denotes the variation in loss value using the original IoU function. Orange curves represent the change in loss value using CIoU function and green curves represent the change in loss value using SIoU function; the horizontal coordinate is the training times (Epoch); the ordinate represents the total loss value (Loss). It can be found that the initial loss value of SIoU loss function is significantly lower than that of other loss functions. The model using SIoU function basically converges when the epoch reaches about 100, while the other functions converge when the epoch reaches 150, and the final loss values of IoU, CIoU and SIoU are 3.23, 2.11 and 1.69, respectively. Therefore, when the model adopts SIoU loss function, the model converges faster and its total loss value is smaller.

3. Experimental Results and Analysis

This study develops a deep learning network architecture using YOLOX inside a Linux environment. The hardware setup used in this experiment is as follows: The operating system is Ubuntu 18.04 and the central processing unit is an Intel (R) Core (TM) i9-9900K CPU working at 3.60 GHz. We use two NVIDIA GeForce RTX 2080Ti graphics cards. The software environment is CUDA 12.0 and PyTorch 1.7 is used for programing.
The hyperparameters of CBA-ASFF-YOLOX include learning rate, batch size, number of epochs, α and γ . The model uses the AdamW optimizer with a weight decay coefficient of 0.001 and its batch size is 8. The initial learning rate is set to 0.001, and number of epochs is 100. α and γ are 0.25 and 0.5, respectively, which are chosen by grid search method.

3.1. Data Set

The data set used in this paper is a standard VOC format data set. The source of image data is obtained by us based on defective copper pipes provided by a refrigeration equipment company. It contains four kinds of pictures of black spots (BS), flow welding (FlW), faulty welding (FaW) and uneven edge (UE). The ratio of these four defects is 1.07:1:1.19:1.29. Part of the data set samples is shown in Figure 10. Black spots are generally shown as black points or spots attached to the welding interface, which are relatively small in size. Flow welding are irregular massive objects at the welding interface, and their size is relatively large. Faulty welding is generally the obvious loss of welding interface or welding is not compact; the uneven edge is characterized by discontinuous or irregular edge. Labeling was used to annotate the data set, and XML files of adhesion between the welding interface and surface of copper tube containing defect categories, sizes and locations were generated, which were then converted into TXT text containing center point coordinates, width, and height for model training. There were 3033 images in the dataset, which were randomly divided into training set, validation set and test set in a ratio of 8:1:1.

3.2. Evaluation Indexes

In the field of target detection, the quality of a target detection model is usually evaluated by detection accuracy. Detection accuracy also includes classification accuracy and positioning accuracy. When evaluating the performance of network models, both precision and recall should be taken into account. In target detection, Mean Average Precision (mAP) is generally used to evaluate the performance of network models.
p r e c i s i o n = T P T P + F P
r e c a l l = T P T P + F N
The formula above is the calculation formula of accuracy and recall rate, wherein TP is the positive example successfully predicted, FP is the negative example incorrectly predicted by the model, and FN is the positive example incorrectly predicted by the model.
Average Precision (AP) is defined as the mean accuracy across various recall rates, often used to assess a certain category of detection accuracy. The mAP is the average detection accuracy across all target categories and is often used to assess the overall performance of the network model. The formula for calculation is as follows:
m A P = i = 0 n A P ( i ) n
The computation of mean Average Precision (mAP) involves using the Intersection-over-Union (IoU) to assess the accuracy of the anticipated target’s location relative to the actual target. It is widely accepted that a projected target with an IoU greater than 0.5 is considered correctly predicted; thus mAP is synonymous with mAP0.5. mAP0.5:0.95 indicates that the Intersection-over-Union (IoU) threshold is varied from a constant 0.5 to compute the Average Precision (AP) value at intervals of 0.05 within the range of 0.5 to 0.95, with the mean of all outcomes being used as the final result. This index enhances the IoU threshold value and evaluates the model’s accuracy against a more rigorous criterion. This article uses mAP0.5 and mAP0.5:0.95 to collectively assess the model’s accuracy.

3.3. Ablation Experiments

In this part of the experiment, YOLOX default parameters were used as the benchmark, and only one research variable was changed in each training, including baseline, classification loss function, IoU loss training function, IoU threshold selection strategy and the minimum number of feature points for k values.
(a) Comparison of baseline performance
We changed the baseline network to CSPdarknet53 and added the adaptive spatial feature fusion module to make a performance comparison with YOLOX algorithm. The results are shown in Table 1. It can be found that each module provides an improvement in accuracy, with CSPDarknet, CBA module and ASFF increasing map values by 0.5%, 0.8% and 4.4%, respectively. Although the number of model parameters has increased, the detection accuracy has been greatly raised from 70.5% to 75.6%. Whereas, map0.5:0.95 at the high threshold is only weakly increased, and the effect of only adjusting the trunk network is limited.
(b) Comparison between different classification loss functions
We compared the experimental results of different classification loss functions in both YOLOX and CBA-ASFF-YOLOX algorithms, as shown in Table 2. In general, Focal Loss can effectively improve the accuracy compared with cross-entropy. It increased the map value by 4.3% on YOLOX. And this trick is the most obvious improvement point, compared with each network module added in the previous section. Moreover, it can still play a good effect on the CBA-ASFF-YOLOX, which adds CBA and ASFF modules on the basis of the network model, and the mAP value increases by 1.5%.
(c) Comparison between different IoU loss functions
We also compared the experimental results of different bounding box regression loss functions in both YOLOX and CBA-ASFF-YOLOX, as shown in Table 3. Compared with other intersection ratio algorithms, YOLOX algorithm and CBA-ASFF-YOLOX algorithm with SIoU have achieved the best experimental results. For YOLOX algorithm, SIoU improves mAP0.5 value by 0.7% and mAP0.5:0.95 value by 0.3%, showing a weak improvement effect. For CBA-ASFF-YOLOX algorithm, mAP0.5 value is raised by 1.1% and mAP0.5:0.95 value is also increased by 1.6%. Through the analysis of the annotation data set, it is found that the targets of black spot defects at the welding interface of copper tube are mostly small in size, accounting for a small number of pixels in the whole image. Therefore, the setting of IoU threshold should be considered to minimize the missed detection of small targets.
(d) IoU threshold selection policy analysis
To detect and identify black spot defect targets in copper tube surface defect images and ensure the confidence of detection frame as much as possible, the IoU threshold was reduced from 0.65 to 0.35 per 0.1 in the ablation experiment for a comparison experiment, and comparison results are shown in Table 4. We found that, when the IoU threshold was set to 0.45, the recognition accuracy of small and medium objects in the image was increased. If the confidence is too low, the target will be ignored in the non-maximum suppression process. After the detection range of IoU is expanded, the model can recognize more targets, which is suitable for the detection and recognition of small targets such as black spots in copper tube defects.
(e) The minimum number of feature points for k values
The experiment also analyzed and compared the minimum feature points of k value obtained in the dynamic top-k algorithm of label allocation. Since the k value was set as 10 in YOLOX algorithm, the values of 7, 12, 15 and 18 were sampled near 10 for comparison experiment in this section. The experimental results are shown in Table 5. As can be seen from the table, when the number of feature points decreases from 10, the accuracy decreases significantly, while, when the number of feature points increases from 10, the accuracy increases gradually. When the value is 15, the detection accuracy reaches the highest but, when the number of feature points continues to increase, the accuracy presents a downward trend. The possible reasons for this change are analyzed as follows, since the calculation of k value is obtained by adding the IoU values of the least number of feature points before. When the minimum number of feature points is reduced, the corresponding IoU value of the lost feature points is usually high, which has a great influence on k value. This reduces the number of positive samples and results in a serious decrease in accuracy. However, when the number of feature points increases gradually, the IoU value corresponding to the added feature points has little influence. When the number increases to a certain threshold, k value will be affected. This leads to an increase in the number of the positive samples, which may lead to an increase in the accuracy.

3.4. Analysis of Experimental Results

By combining several ablation experiments in the previous section, we obtained a comprehensive performance comparison between the YOLOX algorithm and other algorithms. The results are shown in Table 6 and Figure 11. In this paper, the proposed CBA-ASFF-YOLOX model is compared with the existing state-of-the-art object detection models, Faster RCNN [36], SSD [37], YOLOv5 [30], YOLOX [31], RT-DETRv4 [38], LW-DETR [39], and MobileNetV4-based defect detection method [40] on the copper tube surface defect data set, and the efficiency of CBA-ASFF-YOLOX is verified by the AP index of various types in the data set and the average detection accuracy mAP. The mAP of t CBA-ASFF-YOLOX model reached 79.0%, which was 17.2%, 34.6%, 11.9%, and 8.5% higher than Faster RCNN, SSD, YOLOV5, and YOLOX, respectively. We can find that the overall effect has been greatly enhanced, and the accuracy of BS, FlW and UE categories has increased by more than 10%, reflecting the superiority of our algorithm. At the same time, by observing the actual detection effect in Figure 11, CBA-ASFF-YOLOX algorithm can make up for the missed detection problem of YOLOX in the copper tube surface defect detection task, and the detection accuracy is better than that of YOLOX algorithm. In addition, the detection speed has been increased from 21 fps to 26 fps. The detection effect is based on meeting the actual detection task.

4. Conclusions

Surface flaw detection of copper tubes is an important task in industrial quality inspection, because exposed defects may affect tube appearance quality, welding reliability, and subsequent service performance. This study investigates copper tube surface defect detection and develops a task-oriented enhancement of the YOLOX framework by integrating feature representation and loss optimization strategies. Specifically, CSPDarknet53, CBA, and ASFF are incorporated to improve multi-scale feature extraction and fusion, while Focal Loss and a simplified SIoU-based regression loss are adopted to address class imbalance and localization accuracy. In addition, the IoU threshold selection strategy is adjusted according to the characteristics of the dataset. Experimental results show that the proposed method achieves an mAP of 79.0%, improving performance by approximately 8% compared with the baseline YOLOX.
Despite these improvements, several limitations remain. First, the dataset size is relatively limited, and the samples are collected under constrained conditions, which may restrict the robustness of the model. Second, the generalization ability of the proposed method to other industrial environments, imaging conditions, or defect types has not been fully validated. Third, although the SIoU-based regression loss contributes to performance improvement, its gain is relatively moderate and may be dependent on specific data characteristics. In addition, the detection performance for the defective welding category remains lower than that of other classes, indicating that class imbalance and inter-class similarity are still challenging issues.
Future work will focus on addressing these limitations. Specifically, larger and more diverse datasets will be constructed to improve generalization capability. Real-time deployment and validation in practical industrial environments will be conducted to evaluate robustness under varying conditions. Transfer learning strategies will be explored to extend the model to different materials and defect types. Furthermore, multimodal inspection strategies that combine the proposed vision-based detection method with conventional NDE/NDT techniques, especially ultrasonic testing and eddy current testing, will be investigated to further enhance detection reliability and accuracy.

Author Contributions

J.H.: wrote the main manuscript text, software, simulation, review and editing. J.W.: review and editing, supervision, project administration. All authors have read and agreed to the published version of the manuscript.

Funding

This work was supported by the National Natural Science Foundation of China under Grant No. 62373377.

Data Availability Statement

The data presented in this study are available on request from the corresponding author. The data are not publicly available due to privacy and industrial confidentiality restrictions.

Conflicts of Interest

The authors declare no competing interests.

References

  1. Jodhani, J.; Handa, A.; Gauta, A. Ultrasonic non-destructive evaluation of composites: A review. Mater. Today Proc. 2023, 78, 627–632. [Google Scholar] [CrossRef] [Scilit]
  2. Darmon, M. Special Issue on Ultrasonic Modeling for Non-Destructive Testing. Appl. Sci. 2024, 14, 2008. [Google Scholar] [CrossRef] [Scilit]
  3. Saddoud, R.; Sergeeva, N.; Darmon, M. Eddy Current Sensors Optimization for Defect Detection in Parts Fabricated by Laser Powder Bed Fusion. Sensors 2023, 23, 4336. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  4. Palma, D.; Ross, B.; Font, P. Deep convolutional neural network for weld defect classification in radiographic images. Heliyon 2024, 10, e30590. [Google Scholar] [CrossRef] [Scilit]
  5. Ou, Y.; Xu, T.; Fan, J. Vision-based quality evaluation method towards automated penetrant testing. NDT E Int. 2025, 153, 103334. [Google Scholar] [CrossRef] [Scilit]
  6. Zuo, X.; Zhao, N.; Wang, K.; Hu, J. MDEB-YOLO: A Lightweight Multi-Scale Attention Network for Micro-Defect Detection on Printed Circuit Boards. Micromachines 2026, 17, 192. [Google Scholar]
  7. Hu, Y.; Chen, N.; Zhang, H.; Hou, Y.; Liu, P. RoadDiffBox: Automatic Road Distress Diagnosis through Controlled Image Generation and Semi-Supervised Learning. Research 2025, 8, 0833. [Google Scholar] [CrossRef] [Scilit]
  8. Zhang, Y.; Fan, R.; Chen, J.; Shi, Y.; Cai, G. RA-RCNN: A Physical-Feature-Aware Adaptive Detection Network for Multi-Scale Rail Surface Defects. Appl. Sci. 2026, 16, 4970. [Google Scholar] [CrossRef] [Scilit]
  9. Zhang, H.; Pan, D.; Liu, J.; Jiang, Z. A novel MAS-GAN-based data synthesis method for object surface defect detection. Neurocomputing 2022, 499, 106–114. [Google Scholar]
  10. Versini, E.; Snidaro, L.; Liani, A. SCL—Segmentation–classification combined loss for surface defect detection. Expert Syst. Appl. 2022, 198, 116710. [Google Scholar]
  11. Lian, J.; Jia, W.; Zareapoor, M.; Zheng, Y.; Luo, R.; Jain, D.K.; Kumar, N. Deep-learning-based small surface defect detection via an exaggerated local variation-based generative adversarial network. IEEE Trans. Ind. Inform. 2019, 16, 1343–1351. [Google Scholar] [CrossRef] [Scilit]
  12. Li, J.; Yang, Y.; Geng, R.; Chang, Y.; Jiang, Y.; Wu, K.; Lu, J. YOLOv11-LLR: An Enhanced Framework for Steel Surface Defect Detection in Industrial Settings. Appl. Sci. 2026, 16, 4609. [Google Scholar] [CrossRef] [Scilit]
  13. Zhang, H.; Zhang, Z.; Chen, Y.; Wu, T.; Zhong, H.; Wang, Y. Application advance and prospect of nondestructive testing technology for industrial casting defects. Acta Autom. Sin. 2022, 48, 935–956. [Google Scholar]
  14. Božič, J.; Tabernik, D.; Skočaj, D. Mixed supervision for surface-defect detection: From weakly to fully supervised learning. Comput. Ind. 2021, 129, 103459. [Google Scholar] [CrossRef] [Scilit]
  15. Li, Y.; Wang, S.; Jing, Z.; Zheng, J.; Han, X.; Zheng, X.; Sun, F. DSRF: Few-shot PCB surface defect detection via dynamic selective regulation fusion. J. Supercomput. 2025, 81, 529. [Google Scholar] [CrossRef] [Scilit]
  16. Mao, H.; Ren, J.; Tang, Y.; Chen, Y.; Yi, X.; Huang, Z.; Li, X. Detection of weld defects using ultrasonic-guided waves based on matching pursuit and density peak clustering. Trans. Inst. Meas. Control. 2023, 45, 1470–1483. [Google Scholar] [CrossRef] [Scilit]
  17. Wang, H.; Zhang, J.; Tian, Y.; Chen, H.; Sun, H.; Liu, K. A simple guidance template-based defect detection method for strip steel surfaces. IEEE Trans. Ind. Inform. 2019, 15, 2798–2809. [Google Scholar] [CrossRef] [Scilit]
  18. Yoshimura, H.H.Y. Specular surface detection with deep static specular flow and highlight. Mach. Vis. Appl. 2024, 35, 126. [Google Scholar] [CrossRef] [Scilit]
  19. Zhang, J.; Su, H.; Zou, W.; Gong, X.; Zhang, Z.; Shen, F. CADN: A weakly supervised learning-based category-aware object detection network for surface defect detection. Pattern Recognit. 2021, 109, 107571. [Google Scholar] [CrossRef] [Scilit]
  20. Xie, S.; Xie, Y.; Ying, H.; Jiang, Z.; Gui, W. Neurofuzzy-based plant-wide hierarchical coordinating optimization and control: An application to zinc hydrometallurgy plant. IEEE Trans. Ind. Electron. 2020, 67, 2207–2219. [Google Scholar] [CrossRef] [Scilit]
  21. Fu, G.; Peize, S.; Zhu, W.; Yang, J.; Cao, Y.; Yang, M.; Cao, Y. A deep-learning-based approach for fast and robust steel surface defects classification. Opt. Lasers Eng. 2019, 121, 397–405. [Google Scholar] [CrossRef] [Scilit]
  22. Zhang, H.; Lu, Z.; Chen, X.; Lu, S.; Yao, L. Masked contrastive generative adversarial network for defect detection of yarn-dyed fabric. J. Supercomput. 2025, 81, 239. [Google Scholar] [CrossRef] [Scilit]
  23. Xu, D.; Cao, B. Adaptive Multiobjective Evolutionary Generative Adversarial Network for Metaverse Network Intrusion Detection. Research 2025, 8, 0665. [Google Scholar] [CrossRef] [Scilit]
  24. He, Y.; Song, K.; Meng, Q.; Yan, Y. An end-to-end steel surface defect detection approach via fusing multiple hierarchical features. IEEE Trans. Instrum. Meas. 2020, 69, 1493–1504. [Google Scholar] [CrossRef] [Scilit]
  25. Li, W.; Ye, X.; Zhao, Y.; Wang, W. Strip steel surface defect detection based on improved YOLOv3 Algorithm. Acta Electron. Sin. 2020, 48, 1284–1292. [Google Scholar]
  26. Liu, L.; Feng, X.; Li, F.; Xian, Q.; Chen, Z.; Jia, Z. Surface defect detection of industrial components based on improved YOLOV5s. IEEE Sens. J. 2024, 24, 23940–23950. [Google Scholar] [CrossRef] [Scilit]
  27. Chao, C.; Mu, X.; Guo, Z.; Sun, Y.; Tian, X.; Yong, F. IAMF-YOLO: Metal surface defect detection based on improved YOLOv8. IEEE Trans. Instrum. Meas. 2025, 74, 5016817. [Google Scholar] [CrossRef] [Scilit]
  28. Redmon, J.; Divvala, S.; Girshick, R.B.; Farhadi, A. You Only Look Once: Unified, real-time object detection. In Proceedings of the 2016 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Las Vegas, NV, USA, 27–30 June 2016; pp. 779–788. [Google Scholar]
  29. Redmon, J.; Farhadi, A. YOLO9000: Better, Faster, Stronger. In Proceedings of the 2017 IEEE Conference on Computer Vision and Pattern Recognition (CVPR), Honolulu, HI, USA, 21–26 July 2017; pp. 6517–6525. [Google Scholar]
  30. Xie, Y.; Hu, W.; Xie, S.; He, L. Surface defect detection algorithm based on feature-enhanced YOLO. Cogn. Comput. 2023, 15, 565–579. [Google Scholar] [CrossRef] [Scilit]
  31. Ge, Z.; Liu, S.; Wang, F.; Li, Z.; Sun, J. YOLOX: Exceeding YOLO Series in 2021. arXiv 2021, arXiv:2107.08430. [Google Scholar] [CrossRef] [Scilit]
  32. Woo, S.; Park, J.; Lee, J.-Y.; Kweon, I.-S. CBAM: Convolutional block attention module. In European Conference on Computer Vision (ECCV), Munich, Germany, 8–14 September 2018; Springer International Publishing: Cham, Switzerland, 2018. [Google Scholar]
  33. Lin, T.-Y.; Goyal, P.; Girshick, R.B.; He, K.; Dollár, P. Focal loss for dense object detection. IEEE Trans. Pattern Anal. Mach. Intell. 2020, 42, 318–327. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  34. Zheng, Z.; Wang, P.; Liu, W.; Li, J.; Ye, R.; Ren, D. Distance-IoU Loss: Faster and better learning for bounding box regression. arXiv 2020, arXiv:1911.08287. [Google Scholar] [CrossRef] [Scilit]
  35. Gevorgyan, Z. SIoU Loss: More Powerful Learning for Bounding Box Regression. arXiv 2022, arXiv:2205.12740. [Google Scholar] [CrossRef] [Scilit]
  36. Ren, S.; He, K.; Girshick, R.B.; Sun, J. Faster R-CNN: Towards real-time object detection with region proposal networks. IEEE Trans. Pattern Anal. Mach. Intell. 2015, 39, 1137–1149. [Google Scholar] [CrossRef] [Scilit] [PubMed]
  37. Liu, W.; Anguelov, D.; Erhan, D.; Szegedy, C.; Reed, S.E.; Fu, C.-Y.; Berg, A. SSD: Single shot multibox detector. In European Conference on Computer Vision (ECCV), Amsterdam, The Netherlands, 11–14 October 2016; Springer International Publishing: Cham, Switzerland, 2016. [Google Scholar]
  38. Liao, Z.; Zhao, Y.; Shan, X.; Yan, Y.; Liu, C.; Lu, L.; Ji, X.; Chen, J. RT-DETRv4: Painlessly Furthering Real-Time Object Detection with Vision Foundation Models. arXiv 2025, arXiv:2510.25257. [Google Scholar]
  39. Song, B.; Zhao, S.; Wang, Z.; Chen, J.; Liu, W.; Liu, X. LW-DETR: A lightweight transformer-based object detection algorithm for efficient railway crossing surveillance. Complex Intell. Syst. 2025, 11, 480. [Google Scholar] [CrossRef] [Scilit]
  40. Qin, D.; Leichner, C.; Delakis, M.; Fornoni, M.; Luo, S.; Yang, F.; Wang, W.; Banbury, C.; Ye, C.; Akin, B.; et al. MobileNetV4: Universal models for the mobile ecosystem. In European Conference on Computer Vision, Milan, Italy, 29 September–4 October 2024; Springer Nature: Cham, Switzerland, 2024; pp. 78–96. [Google Scholar]
Figure 1. Different typical defect images. (a) Black spots. A black speckled or spotted object attached to a weld junction. (b,c) Faulty welding. Apparent absence of weld junction or poor welding compactness. (d) Flowing welding. An irregular mass at the weld junction. (e) Uneven edge. Discontinuous or irregular edges are adhered to the surface of the welding interface and copper tube fittings.
Figure 1. Different typical defect images. (a) Black spots. A black speckled or spotted object attached to a weld junction. (b,c) Faulty welding. Apparent absence of weld junction or poor welding compactness. (d) Flowing welding. An irregular mass at the weld junction. (e) Uneven edge. Discontinuous or irregular edges are adhered to the surface of the welding interface and copper tube fittings.
Applsci 16 05155 g001
Figure 2. YOLOX network structure.
Figure 2. YOLOX network structure.
Applsci 16 05155 g002
Figure 3. CBA-ASFF-YOLOX. In a straightforward approach, we extract each stage’s properties from the backbone network and combine them into multi-scale features using a PAFPN network. Multi-scale features are sent into the adaptively spatial feature fusion module, allowing feature fusion to improve features at various sizes. Target categorization and regression prediction are achieved using three detection heads.
Figure 3. CBA-ASFF-YOLOX. In a straightforward approach, we extract each stage’s properties from the backbone network and combine them into multi-scale features using a PAFPN network. Multi-scale features are sent into the adaptively spatial feature fusion module, allowing feature fusion to improve features at various sizes. Target categorization and regression prediction are achieved using three detection heads.
Applsci 16 05155 g003
Figure 4. Cross-stage partial module.
Figure 4. Cross-stage partial module.
Applsci 16 05155 g004
Figure 5. Channel attention module.
Figure 5. Channel attention module.
Applsci 16 05155 g005
Figure 6. Spatial attention module.
Figure 6. Spatial attention module.
Applsci 16 05155 g006
Figure 7. CBA module.
Figure 7. CBA module.
Applsci 16 05155 g007
Figure 8. Adaptive spatial feature fusion (ASFF) module.
Figure 8. Adaptive spatial feature fusion (ASFF) module.
Applsci 16 05155 g008
Figure 9. Training curves of different IoU loss functions.
Figure 9. Training curves of different IoU loss functions.
Applsci 16 05155 g009
Figure 10. Sample of different defects.
Figure 10. Sample of different defects.
Applsci 16 05155 g010
Figure 11. Comparison diagram of detection effects of different algorithms on copper tube defect samples.
Figure 11. Comparison diagram of detection effects of different algorithms on copper tube defect samples.
Applsci 16 05155 g011
Table 1. Comparison of accuracy under different baseline networks.
Table 1. Comparison of accuracy under different baseline networks.
ModelParams (M)FLOPs (G)mAP0.5 (%)mAP0.5:0.95 (%)
YOLOX (Darknet53)8.7312.470.536.3
YOLOX
+CSPDarknet539.0512.771.036.6
+CBA module9.1512.871.836.7
+ASFF11.3416.175.637.2
+FocalLoss11.3416.177.138.3
+SIoU11.3416.177.838.6
Table 2. Comparison of Focal Loss under different baseline networks.
Table 2. Comparison of Focal Loss under different baseline networks.
ModelIoUmAP0.5mAP0.5:0.95
YOLOXCE70.536.3
Focal Loss74.836.8
CBA-ASFF-YOLOXCE75.637.2
Focal Loss77.138.3
Table 3. Comparison of IoU loss under different baseline networks.
Table 3. Comparison of IoU loss under different baseline networks.
ModelIoUmAP0.5mAP0.5:0.95
YOLOXIoU70.536.3
CIoU70.936.5
SIoU71.236.6
CBA-ASFF-YOLOXIoU75.637.2
CIoU75.937.4
SIoU78.038.6
Table 4. Detection precision under different IoU thresholds.
Table 4. Detection precision under different IoU thresholds.
ModelIoU ThresholdmAP0.5
CBA-ASFF-YOLOX0.3578.01
0.4578.24
0.5577.80
0.6576.92
Table 5. Detection precision under different minimum number of feature points for k values.
Table 5. Detection precision under different minimum number of feature points for k values.
ModelMinimum Number of Feature PointsmAP0.5
CBA-ASFF-YOLOX772.67
1078.24
1278.94
1579.03
1876.50
Table 6. Performance comparison of YOLOX and CBA-ASFF-YOLOX.
Table 6. Performance comparison of YOLOX and CBA-ASFF-YOLOX.
ModelBSFaWFlWUEmAP0.5mAP0.5:0.95FPS
Faster RCNN [36]59.849.978.658.961.830.77
SSD [37]40.131.487.818.544.421.010
YOLOv5 [30]65.657.787.956.967.133.218
YOLOX [31]65.956.094.565.770.536.321
RT-DETRv4 [38]69.766.293.572.974.736.722
LW-DETR [39]71.565.195.274.878.237.520
MobileNetV4-based defect detection method [40]70.862.392.370.875.437.132
CBA-ASFF-YOLOX75.169.292.376.579.038.626
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content.

Share and Cite

MDPI and ACS Style

He, J.; Wang, J. Surface Defect Detection of Copper Tube Based on YOLOX with Convolutional Block Attention and Adaptive Spatial Feature Fusion. Appl. Sci. 2026, 16, 5155. https://doi.org/10.3390/app16105155

AMA Style

He J, Wang J. Surface Defect Detection of Copper Tube Based on YOLOX with Convolutional Block Attention and Adaptive Spatial Feature Fusion. Applied Sciences. 2026; 16(10):5155. https://doi.org/10.3390/app16105155

Chicago/Turabian Style

He, Jianjun, and Ji Wang. 2026. "Surface Defect Detection of Copper Tube Based on YOLOX with Convolutional Block Attention and Adaptive Spatial Feature Fusion" Applied Sciences 16, no. 10: 5155. https://doi.org/10.3390/app16105155

APA Style

He, J., & Wang, J. (2026). Surface Defect Detection of Copper Tube Based on YOLOX with Convolutional Block Attention and Adaptive Spatial Feature Fusion. Applied Sciences, 16(10), 5155. https://doi.org/10.3390/app16105155

Note that from the first issue of 2016, this journal uses article numbers instead of page numbers. See further details here.

Article Metrics

Back to TopTop