1. Introduction
With the continuous development of science and technology and the improvement of quality of life, people pay more and more attention to environmental protection [
1]. Compared with the greenhouse gas produced by oil vehicles, the importance of clean and environmental protection of new energy vehicles is increasing day by day. As the core component of new energy vehicles, the stator of a flat wire motor is popular in the new energy vehicle industry because of its advantages, including an about 30% higher slot filling rate [
2] than the traditional round-wire winding with bare-welding parts. To ensure the safe, efficient, and long-term use of the motor, it is necessary to coat the flat wire of the flat wire motor stator with high-reliability insulation [
3]. In the flat wire motor stator manufacturing process, the solder joint area should be coated with epoxy resin after laser welding. There are three main defects in the stator of the flat wire motor with unqualified coating quality: copper leakage defect, adhesion defect, and impurity defect, as shown in
Figure 1. It is necessary to find and deal with the defects of the stator of the flat wire motor in the manufacturing process in time to avoid potential safety hazards. Therefore, it is necessary to accurately detect the coating quality of the stator of the flat wire motor to ensure its safety, stability, and reliability during operation so as to prevent failure.
The automatic production line of flat wire motors has high production capacity and efficiency requirements, generally reaching 60 s/pcs to 150 s/pcs. Therefore, the detection speed is also crucial. The traditional manual detection method has the disadvantages of poor real-time performance, low detection accuracy, and poor environmental adaptability, which makes it difficult to meet the requirements of real-time and accurate detection of industrial surface defects. If one wants to achieve the purpose of timely error correction’ one must analyze the image in real time and provide the test results so as to minimize the number of defective products, reduce waste, and overall production costs [
4]. In recent years, surface defect detection technology based on machine vision has gradually replaced manual detection [
5]. This has the advantages of high precision, high efficiency, and non-contact measurement and is widely used in the detection of various workpiece surfaces [
6], such as flat steel [
7], textiles [
8], mobile phone screens [
9], fruits/vegetables [
10], rails [
11], leather [
12], battery materials [
13], and other fields. Visual detection methods are usually divided into traditional image processing and deep learning. Both methods should consider three indicators: accuracy, robustness, and speed. Traditional image processing detection methods can be divided into statistical methods, spectral methods, network-based methods, and learning-based methods [
14]. They usually need to be designed according to the specific operation of the image and first converted into digital images to highlight the relevant features, followed by feature extraction of ROI (Region of Interest); finally, the automatic classifier is used to explain the content of the image. These tedious operations not only require experienced visual engineers to complete them manually but also need to be fine-tuned for specific problems. In different environments, they do not have adaptability. To a certain extent, this reflects the shortcomings of traditional image processing methods, such as poor generalization ability and harsh application conditions. In recent years, deep learning has shown superior performance in industrial defect detection. Still, there are also some shortcomings, for example, the dataset of workpiece surface defects is usually tiny and difficult to collect or mark, and the training time is extended. Nevertheless, deep learning can autonomously learn advanced features from training data compared to traditional image processing methods and has a more robust generalization performance. For example, Luo et al. [
15] proposed an enhanced Mask R-CNN algorithm, which improves the speed and accuracy of insulator defect detection by incorporating the fusion factor into FPN. Wang et al. [
16] proposed a method combining improved ResNet50 and Faster R-CNN to reduce the average running time and improve the accuracy of automatic detection and classification of steel surface defects.
Although the convolutional neural network based on Faster R-CNN and Mask R-CNN can be used for accurate detection of surface defects of metal workpieces, its applicability in practical applications is limited due to the long time, slow speed, and low efficiency of the two-stage target detection method. The YOLO network proposed by Redmon et al. [
17] is a typical one-stage target detection network that can directly output target candidate boxes and coordinates. With the successive launch of YOLOv2-YOLOv8, more and more researchers use the YOLO series network to complete target recognition and defect detection-related tasks and improve the YOLO network to meet various challenges in detection. For example, Zhang et al. [
18] realized the collection and identification of surface cracks on metal pipes by combining annular light and coaxial light and introducing dual attention and boundary refinement modules. Wang et al. [
19] adopted the de-weighted BiFPN structure, combined the ECA attention mechanism in the main part, and used the SIoU loss function instead of the original bounding box loss function to achieve efficient detection of strip surface defects. In summary, the existing methods have some shortcomings in real-time accuracy when identifying and locating the solder joint area of the stator of the flat wire motor and detecting defects in the solder joint area. In this scenario, the recognition rate and detection accuracy of some methods cannot meet the requirements, and the reliability of the detection results cannot be ensured. Although other methods have better detection ability, their network complexity is too high, resulting in slow detection speed and enabling guaranteeing real-time performance.
In view of the actual industrial application scenarios, this article designs a DSFI-HEAD detection head and a LEFG lightweight structure. The main contributions are as follows:
DSFI-HEAD Module: Traditional detection heads often suffer from feature loss or inaccurate localization when dealing with complex backgrounds and small targets. To address this challenge, the DSFI-HEAD module is proposed. This module enhances feature fusion and improves the detection head’s representational capability, thus significantly improving detection accuracy, especially for small targets and in complex scenarios;
LFEG Module: Conventional algorithms may face issues with increased network complexity and parameter count when handling complex task learning, which can affect the model’s real-time performance and efficiency. To tackle this, the LFEG module is introduced, which reduces network parameters and complexity, optimizing the network structure and enhancing detection speed and efficiency. The core is to use feature extractors to extract and fuse task-related features from multi-layer convolutional networks to generate joint feature maps with richer information. By aligning tasks, the synergy between tasks is improved, thereby improving the accuracy and efficiency of the network.
Based on YOLOv8s, DSFI-HEAD and LEFG are added to jointly construct the YOLOv8s-DFJA network, which realizes the requirements of network’s lightweightness and real-time accurate detection while ensuring accuracy.
2. Related Work
In industrial applications, accurate detection of large objects in images has been achieved, but the accurate detection of small objects is still a challenge [
20]. This article focuses on the small defects in the solder joint area of the stator of the flat wire motor. The pixel size of these defects is small, so the image quality requirements are high. Low-quality images make it difficult to distinguish various defect features, the background is complex, and the context clues are limited, which further increases the difficulty of defect detection.
Small-scale changes and huge similarities in complex backgrounds make it difficult to distinguish defects. Some studies have tried to make the network focus on a feature in the image and strengthen the learning of the feature. For example, Zhang et al. [
21] reorganized the link between CA attention and SA attention and combined the multi-branch ConvNet structure to improve the detection performance of YOLOv5s for small targets. Zhu et al. [
22] replaced the original prediction head of YOLOv5 with a Transformer pre-diction head constructed using the Transformer encoder block and incorporated a self-attention mechanism. This modification enhanced the network’s feature representation capabilities and improved detection accuracy. Kim et al. [
23] used an efficient channel attention module to modify the backbone of YOLO and proposed a channel attention pyramid method to improve the ability to detect small targets. Zhang et al. [
24] integrated the Contextual Transformer block and attention mechanism into the Darknet-53 backbone, significantly enhancing context information extraction, visual representation of small objects, and the network’s overall expressive ability. Analyzing all of the above research, it was found that while integrating the attention mechanism into the network can enhance its important feature learning ability in the spatial and channel dimensions, this approach typically captures only local information and fails to explore the data’s comprehensiveness fully.
There are also some studies that try to make the network pay attention to more scale information. For example, Jiang et al. [
25] proposed a joint multi-scale defect detection method that constructed a wider and more effective focusing feature to detect small targets accurately. Su et al. [
26] enhanced the ability of the YOLO network to detect small defects by multi-scale fusion method of region extraction and 16X down-sampling features and realized the accurate detection of metal gear end-face defects. Wang et al. [
27] proposed a method combining multi-scale channel information (MCI) and global local attention (GLA) to enhance the learning ability of the YOLOv7 network and achieve accurate detection of insulator defects. However, the network is too complex, and the parameter amount reaches 40.6 Mb, which cannot meet the real-time detection requirements. The above research shows that some researchers are committed to optimizing the sub-modules of the YOLO network to realize multi-scale feature fusion and enhance its detection ability. However, there are limitations in integrating more extensive context information, especially in small target detection. If the semantic features on a large scale (high level) are too emphasized, it will lead to insufficient capture of detailed information of small targets and vice versa.
The above studies not only did not consider strengthening the connection between localization and classification tasks but also lacked in all aspects of network light-weighting, which improves the detection performance to a certain extent but is often accompanied by an increase in network complexity and time cost. Therefore, in view of the above problems and combined with the industrial application scenarios of this article, to fully capture the feature information of small targets, this article proposes a YOLOv8s-DFJA network, which can not only detect stator defects with a high recognition rate and high precision but also meet the requirements of real-time detection.
3. Proposed YOLOv8s-DFJA
The YOLOv8s-DFJA network proposed in this article includes the DSFI-HEAD and LEFG modules. The DSFI-HEAD module enhances the network’s positioning and classification performance, and the LEFG module greatly reduces the number of parameters to lighten the entire network.
The YOLO network series has extremely high similarity [
28] regarding network structure. The network mainly has three components: the backbone, neck, and head. The backbone is responsible for extracting features from the input image, which is the basis of target detection in the subsequent network layer. In the YOLOv8 network, the backbone network adopts a structure similar to CSPDarknet, but unlike CSP, YOLOv8 uses a more gradient C2f module. The head network is the decision-making part of the object detection network, responsible for generating the final detection result. In the head part, YOLOv8s replaces the coupling head with the current mainstream decoupling head structure and replaces Anchor-Based with Anchor-Free. The neck network is located between the backbone and head networks for feature fusion and enhancement. YOLOv8s also uses the C2f structure in this part. Based on YOLOv8s, YOLOv8s-DFJA uses the DSFI-HEAD detection head to replace the DETECT detection head in the Head network and the LEFG module to replace the C2f module of the backbone structure. The network structure is shown in
Figure 2. Next, this article introduces the structure and function of DSFI-HEAD and LEFG and the effect after fusion.
3.1. DSFI-HEAD
The ROI of this article is the solder joint area of the flat wire motor stator. Although the number of solder joints is large, each solder joint occupies very few pixels. Although the traditional YOLOv8 network improves the detection performance of small targets compared with YOLOv5, it still cannot meet this article’s detection requirements. To improve the detection accuracy of small targets, this article designs a DSFI-HEAD module. The structure of the module is shown in
Figure 3.
To solve the problem of insufficient interaction between classification and localization tasks in traditional object detection networks, this article develops a Dynamic Selection of Feature Interactions Detection Head (DSFI-HEAD) based on the idea of TOOD [
29]. The number of output channels of P3, P4, and P5 layers is all adjusted to 512; the feature information of P3, P4, and P5 is input into two information-sharing GNConv. Then, the feature information of the first GNConv module and the feature information after two convolutions are spliced on the channel dimension to form a joint feature. The TAP structure, which is in TOOD, is used in the localization and classification branches after task classification, and the joint features are used in the localization branch to generate mask and offset for DCNv2 [
30], which enhances the interaction between tasks. In the classification branch, joint features are used for dynamic feature selection to improve the detection head positioning and classification performance.
Figure 3.
DSFI-HEAD module structure diagram. GNConv has the function of GroupNorm [
31] module, which can improve the performance of detection head positioning and classification.
Figure 3.
DSFI-HEAD module structure diagram. GNConv has the function of GroupNorm [
31] module, which can improve the performance of detection head positioning and classification.
Assuming that the feature size of the input to this detector is (B, C, W, H), it is first input to two information-sharing GNConvs. The first GNConv adjusts the number of channels, and the size becomes (B, C//2, W, H). After the second GNConv, the feature size does not change and is still (B, C//2, W, H). The feature information is processed twice by GNConv is spliced on the channel dimension to obtain Concat_features, whose feature size is (B, C, W, H).
Figure 3 shows that Concat_features are processed many times, and we introduce them individually:
- (1)
Concat_features generate offset_and_mask with the size of (B, 3 × 3 × 3, W, H) through the spatial offset convolution layer. Using offset _ dim with the shape of (B, 2 × 3 × 3), the first 18 channels are extracted as offset. The remaining nine channels are used as masks. The extracted mask processed by Sigmod is used to normalize the extracted mask so that offset_and_mask is divided into two parts: offset and mask, that is, classification and regression task decomposition module;
- (2)
After an adaptive average pooling, the size of Concat_features is changed to (B, C, 1, 1). In the classification and regression task decomposition modules, the feature size is changed to (B, 16, 1, 1) by convolution operation. After ReLU activation processing and convolution again, the size is adjusted to (B, 2, 1, 1), and weight (B, 2) is generated. The weight reshape is (B, 1, 2, 1), which is multiplied by the convolution weight and reshaped as (B, C/2, C). The input feature size is reshaped as (B, C, W * H). After torch.bmm operation, the size becomes (B, C//2, W * H) and is then reshaped as (B, C//2, W, H). After the regression task, the feature information, offset, and mask are input to the DCNv2 layer. The DCNv2 layer is subjected to convolution, normalization, and other operations, and the final output regression feature shape size is (B, C//2, W, H);
- (3)
Concat_features after Conv, ReLU, and Conv operations of Concat_features are processed by Sigmod to obtain the classification probability. The output features of the classification task and the classification probability are multiplied pixel by pixel to obtain the weighted classification features. Then, through a 1 × 1 convolution layer, the weighted classification features are transformed into the final classification prediction output, and the regression features are transformed into the required output dimension. Because of the shared weight, the detection head cannot detect targets of different sizes. Therefore, after the REG convolution, the feature information is transmitted to the scale layer for feature scaling to realize the function of detecting targets of different sizes. The regression prediction output and the classification prediction output are spliced in the channel dimension to form the final output result.
3.2. LEFG
When the mainstream CNN calculates the intermediate feature mapping, there is a lot of parameter redundancy. To solve this problem, this article designs the Lightweight Structure for Enhanced Feature-Extraction and Gradient-Looping (LEFG) module. Using the convolution module with 1 × 1 convolution kernel size to generate partially redundant features instead of the overall redundant features and abandoning the BottleNeck structure used in the traditional YOLO series, the number of parameters is greatly reduced to achieve the purpose of simplifying the computation process and reducing the training cost. To make up for the performance loss caused by discarding the residual structure, the RepCov module is used on the branch of the gradient flow, and feature fusion is performed during reasoning to enhance the ability of feature extraction and gradient flow. The scaling factor can also be adjusted to control the size of the LEFG, improving the speed of YOLOv8s target detection while considering both large and small networks. The structure of the LEFG module is shown in
Figure 4.
In this module, n is the number of intermediate convolutional layers, and hidden _ channels are calculated by the factor combination Formula (1) used to determine the number of hidden channels.
This module uses the scaling factor
to scale the number of intermediate channels.
The size change of the feature map is shown in
Figure 5:
It is assumed that the feature size input to this module is
. Firstly, some features are generated by 1 × 1 convolution, and the number of channels is adjusted to 2
. Then, the split module is used to perform chunk operation on the channel dimension, and the feature size is divided into two
. The second
is operated by RepConv, and the feature size becomes
. The middle layer contains n-1 convolution layers; each convolution layer is 3 × 3 convolution, and the number of input and output channels are both
. Therefore, after passing through the middle layer, the feature size is still
, and then, the Conv operation with k of 1 × 1 and stride of 1 is performed to obtain the feature size of
. At this time, the
features without any processing, the features obtained by RepConv processing, and the feature information obtained by 1 × 1 Conv operation are spliced on the channel dimension to obtain the feature size
.
Finally, the number of channels is adjusted to by 1 × 1 convolution operation.