Intelligent defect detection method for electronic ceramic components based on YOLO algorithm
Patent Information
- Application Number
- CN202611147137.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-07-30
- Publication Date
- 2026-10-27
AI Technical Summary
但在实际电子陶瓷元器件缺陷检测任务中,该类融合机制仍存在明显局限:其一,颈部网络的特征融合通常开始于较深的语义层(如P3层),对骨干网络中更浅层、保有丰富空间细节的高分辨率特征(如输出步长为4的特征图)利用不足或仅通过间接路径传递,大量精准的轮廓、纹理信息在多层传递中被稀释,不利于捕捉语义模糊的小尺寸缺陷;其二,现有损失函数多基于标准的IoU及其变体(如CIoU、DIoU)进行边界框回归,并采用常规二值交叉熵计算置信度及类别损失,缺乏对缺陷尺度和难分样本的自适应聚焦能力——对小目标的定位偏差惩罚不足,对模糊边界处的难分样本也难以施以足够的学习强度,致使模型在面对语义模糊缺陷时,判别边界极易崩溃
本发明的有益效果:本发明的方法首先构建改进YOLO缺陷检测模型,再输入训练数据,使用改进的小尺度特征融合和模糊语义损失函数进行训练。训练完成后采集测试数据输入模型进行模型测试,完成样本缺陷检测。本发明的方法通过本方法通过引入小目标特征尺度融合及模糊语义补偿,提升了检测精度与鲁棒性,可以使模型学习真正的缺陷模式,以满足复杂工业场景下的高精度、低误报检测需求。
Smart Images

Figure CN122989606A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of appearance inspection technology for electronic ceramic components, specifically to an intelligent defect detection method for electronic ceramic components based on the YOLO algorithm, with the aim of alleviating the problem of appearance defect detection for electronic ceramic components in semantically ambiguous scenarios. Background Technology
[0002] Electronic ceramic components mainly include wafer ceramic capacitors, varistors, and thermistors. During the production process of electronic ceramic components, surface defects (such as dents, shrinkage cavities, cracks, surface damage, and surface adhesion) directly affect the insulation performance, withstand voltage rating, and long-term reliability of the products. Therefore, visual inspection of appearance defects in electronic ceramic components has become a core aspect of quality control. In recent years, single-stage detectors based on convolutional neural networks (such as the YOLO series) have been widely used in industrial defect detection due to their excellent real-time performance and accuracy. Among them, the YOLOv11 algorithm further improves the detection performance of general targets through an improved C3k2 module, C2PSA attention mechanism, and efficient feature pyramid structure. However, when directly transferring YOLOv11 to the surface defect detection of electronic ceramic components, a prominent problem of "defect semantic ambiguity" will be encountered, as shown in the appendix to the manual. Figure 1 As shown, some defects (such as tiny scratches) are highly similar in shape and texture to normal areas (such as dirt, which does not affect the performance of electronic ceramic components). They may even have blurred boundaries with the background or normal texture in the feature space, making it difficult for the model to extract discriminative features, resulting in high false negative and false positive rates.
[0003] Existing YOLO-based defect detection methods generally employ a combination of Feature Pyramid Network (FPN) and Path Aggregation Network (PAN) to fuse multi-scale features through top-down and bottom-up paths. However, in actual electronic ceramic component defect detection tasks, this type of fusion mechanism still has obvious limitations: First, feature fusion in the neck network usually starts in a deeper semantic layer (such as the P3 layer), which does not make full use of the shallower, high-resolution features in the backbone network that retain rich spatial details (such as feature maps with a stride of 4) or only passes them through indirect paths. A large amount of accurate contour and texture information is diluted in the multi-layer transmission, which is not conducive to capturing small-sized defects with ambiguous semantics. Second, existing loss functions are mostly based on standard IoU and its variants (such as CIoU, DIoU) for bounding box regression, and use conventional binary cross-entropy to calculate confidence and class loss. They lack the ability to adaptively focus on defect scale and difficult-to-distinguish samples—the penalty for localization deviation of small targets is insufficient, and it is also difficult to apply sufficient learning intensity to difficult-to-distinguish samples at ambiguous boundaries, which makes the discrimination boundary of the model very easy to collapse when facing semantically ambiguous defects.
[0004] Related studies have shown that relying solely on the feature reuse of existing neck structures and standard training loss, when the model detects semantically ambiguous defects such as minor breaks and shallow scratches on the surface of electronic ceramic components, the attention distribution often deviates from the real defect area, and the feature expression exhibits problems of excessive granularity and weak discriminability. In summary, the existing technology has the following main shortcomings in the detection of appearance defects of electronic ceramic components: (1) The granularity of multi-scale feature fusion is not fine, and the shallow high-resolution features are not directly and adaptively utilized, causing the spatial details of small defects to be submerged in deep features; (2) The loss function lacks scale awareness and hard example focusing mechanism, and cannot highlight the localization and classification constraints of semantically ambiguous defects during training, resulting in insufficient learning of such defects by the model; (3) There is a lack of multi-source information collaborative enhancement strategy for ambiguous defects, and the model fails to effectively integrate the underlying detail clues and the high-level semantic context to eliminate ambiguity.
[0005] Therefore, there is an urgent need for an improved YOLO method for detecting appearance defects in electronic ceramic components. By designing a new multi-scale feature fusion module and a targeted loss function, the model's ability to express features of semantically ambiguous defects and its training strength can be enhanced, thereby significantly improving the detection accuracy and robustness of small, low-contrast defects while maintaining real-time performance. Summary of the Invention
[0006] To address the aforementioned technical problems, this invention provides an intelligent defect detection method for electronic ceramic components based on the YOLO algorithm. By constructing a multi-level feature extraction and adaptive difficulty mining mechanism, the detection sensitivity and robustness in fuzzy semantic scenarios are significantly improved.
[0007] The technical solution adopted in this invention is: an intelligent defect detection method for electronic ceramic components based on the YOLO algorithm, the specific steps of which are as follows: S1. Construct an intelligent defect detection model for electronic ceramic components based on the YOLO algorithm; This step constructs an intelligent defect detection model for electronic ceramic components based on the YOLO algorithm. The model includes a backbone network, a neck network, and a detection head. A newly designed small-scale enhancement module is introduced into the neck network to enhance the feature representation ability of small-sized defects. The model takes a single or batch defect image as input and outputs the category and location information of the defects in the image.
[0008] S11. Construct a backbone network to extract features from the input image. The backbone network includes five CBS modules, four C3k2 modules, one SPPF module, and one C2PSA module. One CBS module forms the head of the backbone network. The remaining four CBS modules and four C3k2 modules are stacked alternately to form the middle section of the backbone network. Finally, the SPPF and C2PSA modules form the tail section of the backbone network. Each C3k2 module contains n repeatedly stacked C3k2 sub-modules, and each C2PSA module contains n repeatedly stacked C2PSA sub-modules. The value of n is determined by a reference... The value is determined by the product of the network depth parameter (depth); the input image undergoes feature extraction through the backbone network, with commands P0-P10 assigned according to the module positions. The backbone network generates five feature maps P2, P4, P6, P8, and P10 at different scales; the resolutions of P2, P4, P6, and P8 are 1 / 4, 1 / 8, 1 / 16, and 1 / 32 of the input image resolution, respectively, while the resolution of P10 is the same as P8. The number of channels in the feature map is determined by the baseline number of channels, the network width coefficient (width), and the upper limit of the number of channels (max_channel), specifically: The P2 feature map is output from the shallow layer of the network, with a resolution of 1 / 4 of the input image resolution and a channel number of min(256*width, max_channel), preserving rich details and location information; The P4 feature map is obtained by subsequent downsampling and the C3k2 module, with a resolution of 1 / 8 of the input image resolution and a channel number of min(512*width, max_channel). The P6 feature map is obtained through further downsampling and the C3k2 module, with a resolution of 1 / 16 of the input image resolution and a channel number of min(512*width, max_channel). The P8 feature map is downsampled in the final stage and then processed by the SPPF and C2PSA modules before being output. The resolution is 1 / 32 of the input image resolution, and the number of channels is min(1024*width, max_channel). It contains high-level semantic information. The P10 feature map is obtained by fusing features from P8 using SPPF and C2PSA, and has the same resolution as P8. S12. Construct a neck network for multi-scale feature fusion. The neck network consists of stacked Upsample, Concat, C3k2, and CBS modules. Within each C3k2 module, n C3k2 sub-modules are repeatedly stacked, where n is determined by the product of the baseline value and the network depth parameter. The feature map generated in S11 is processed by the neck network to output detection feature maps at different scales: in the top-down path, P10 is upsampled and concatenated with P6 to obtain feature map P13; P13 is upsampled and concatenated with P4 to obtain feature map P14. P16; The backbone network output P2 is downsampled to the same resolution as P16, and the downsampled P2 and P16 are adaptively fused to obtain a small-scale enhanced feature map P16′; In the bottom-up path, P16′ is downsampled and concatenated with P13 to obtain a medium-scale feature map P19, and P19 is downsampled and concatenated with P10 to obtain a large-scale feature map P22; The neck network finally outputs three detection feature maps with resolutions of 1 / 8, 1 / 16, and 1 / 32 of the input image resolution: P16′, P19, and P22. To improve the model's ability to detect minute defects, a small-scale enhancement module (FeatureFusion) is designed and inserted into the neck network to adaptively fuse the shallow high-resolution features P2 of the backbone network with the deep semantic features P16 of the neck network. The structure of this multi-scale feature fusion module is as follows: First, average pooling is applied to P2 for downsampling, making its spatial resolution consistent with P16. Then, the downsampled P2 and P16 are simultaneously input into an adaptive attention fusion unit. In the adaptive attention fusion unit, channels of the downsampled P2 and P16 are concatenated, and the two description vectors are input into a shared 1x1 convolutional layer and ReLU activation function, respectively. The number of channels in the fused feature is adjusted to 256, resulting in an enhanced shallow feature map, denoted as P16′. This fusion method allows the network to dynamically focus on the importance of different feature sources, fully combining low-level spatial details and high-level semantic information. The specific process is summarized as follows:
[0009] in: `interpolate` is used for image interpolation. It interpolates P2 directly, rather than convolving it, to 1 / 8 the size of the output image. This preserves more subtle details. Because the area mode is used, and P2 and P16 are multiples of each other, this is equivalent to average pooling.
[0010] `concat` performs image convolution, using a convolution of size (Input_channal + Output_channal, Output_channal), which doesn't add many new parameters overall. Therefore, the training and inference speeds are similar to the original YOLO.
[0011] BatchNorm2d: performs standardization at the channel scale. The specific operation is as follows: , , ,
[0012] ReLU: is the activation function, and its specific expression is: .
[0013] After obtaining P16′, the neck network continues to construct a bottom-up enhancement path: starting from the original P13, it is downsampled through a convolution with a stride of 2 and then concatenated with P4, resulting in an enhanced mid-scale feature map P16 via the C3k2 module; P16 is downsampled through a convolution with a stride of 2 and then concatenated with P13, resulting in an enhanced large-scale feature map P19 via the C3k2 module. P19 is downsampled through a convolution with a stride of 2 and then concatenated with P10. After passing through the C3k2 module, an ultra-large-scale feature map P22 is obtained. At this point, the neck network outputs three feature maps for final detection: a small-scale feature map P16′, a mid-scale feature map P19, and a large-scale feature map P22, corresponding to resolutions of 1 / 8, 1 / 16, and 1 / 32 of the input image, respectively. Among them, P16′ incorporates high-resolution detail information from the backbone network C2, which not only preserves the location information of small targets but also has strong semantic discrimination ability, making it particularly suitable for identifying minute defects in defect detection scenarios.
[0014] S13. Construct a detection head, which consists of three layers of feature pyramid modules. Each layer of feature pyramid modules is composed of two DSC modules plus a Covn2d module and two CBS modules plus a Conv2d module. Input feature maps P16′, P19 and P22 into the three-layer detection head. Perform target classification and bounding box regression on the three detection feature maps through parallel convolution branches. Output the detection results including defect category probability, bounding box coordinate offset and target confidence. Specifically, the detection head receives feature maps P16′, P19, and P22 at three scales from the neck network, performing target classification and bounding box regression on each scale feature map. The detection head consists of parallel convolutional branches that predict the defect class probability, bounding box coordinate offset, and target confidence at each location. Through dense prediction on multi-scale feature maps, the model can cover defect targets of different sizes and output the final defect detection result.
[0015] This completes the construction of the improved YOLO defect detection model. This model, through the newly added small-scale enhancement module, effectively fuses shallow high-resolution features with deep semantic features, enhancing the feature representation of small defect targets and providing a structural foundation for subsequent model training and high-precision detection.
[0016] S2, The detection model built in training step S1: After constructing the improved model, the improved YOLO defect detection model constructed in step S1 is trained using training samples with defect categories and bounding box annotations. During the training process, an improved loss function is used to calculate the prediction error, and the model parameters are updated through backpropagation to obtain a high-precision model for the defect detection task.
[0017] S21. Training Image Data Preparation: Collect images of electronic ceramic components containing defective targets, label the defective targets in the images with categories and bounding boxes, and divide the labeled images into training set and validation set; perform data augmentation on the images in the training set, and uniformly adjust them to the preset input size and perform normalization to generate input image data for model training, thus obtaining training image data; the corresponding images in the validation set are the validation image data. The collected image data includes images of various defects. For each defect target in an image, its category label and ground truth bounding box coordinates are annotated. The annotated image dataset is divided into training and validation sets. During training, the input images undergo image augmentation processing, including random rotation, translation, scaling, erasing, cropping, perspective adjustment, flipping, color jittering, Mosaic enhancement, and Mixup enhancement, to improve the model's generalization ability. The augmented images are then uniformly scaled to a fixed size and their pixel values are normalized to obtain the input tensors for the training batch.
[0018] S22. Forward Propagation and Prediction Output: The images in the training set are input into the detection model constructed in step S1 in batches. Multi-scale feature extraction and fusion are performed through the backbone network and the neck network to output feature maps at multiple scales. Based on the feature maps, target classification and bounding box regression are performed through the detection head to obtain the class probability, bounding box coordinates and target confidence prediction results at each scale. Specifically, the training batch of images is input into the defect detection model constructed in step S1. The images are processed by the backbone network to extract feature maps P2, P4, P6, and P10. The neck network performs multi-scale feature fusion through top-down and bottom-up paths, and uses a multi-scale feature fusion module to adaptively fuse P2 and P16 to obtain an enhanced small-scale feature map P16′. Finally, feature maps P16′, P19, and P22 at three scales are output. At each grid position of each scale feature map, the detection head predicts the defect category probability, bounding box coordinate offset, and target confidence of a predetermined number of anchor boxes, forming a dense prediction set.
[0019] S23. Loss Function Construction and Optimization: Construct the overall loss function for model training. The overall loss function is composed of a weighted average of the bounding box regression loss, confidence loss, and classification loss, and its expression is: λ represents the weights of the three losses; the bounding box regression loss A CIoU-based loss function is used to constrain the positional and shape differences between the predicted bounding boxes and the ground truth bounding boxes; the classification loss... An improved Focal mechanism is introduced based on the binary cross-entropy loss. By setting differentiated modulation coefficients for different categories, the focus on semantically confusing categories and difficult-to-classify samples is enhanced, thereby improving the ability to identify fuzzy semantic defects. The distributed focus loss is used to optimize the learning of the discrete coordinate distribution. To improve the model's detection accuracy for defects, especially those with ambiguous semantics, an improved category classification loss function was designed. This improved loss function was incorporated into the overall loss to guide the model's learning. The overall loss function consists of a weighted average of the bounding box regression loss, confidence loss, and classification loss. λ represents the weights of the three loss functions. The specific expressions for the three loss functions are as follows: (1) Bounding box regression loss function
[0020] in: : The bounding box predicted by the model; : Real frame; CIoU: CIoU loss function. It is a loss function that comprehensively considers IoU, the distance between the center points of the two bounding boxes, and the consistency of their aspect ratios. The expression is: Where IoU is the common intersection-union ratio, expressed as: , This represents the center point b of the predicted bounding box and the center point of the ground truth bounding box. The Euclidean distance between them. This represents the square of the diagonal length of the smallest bounding rectangle corresponding to the predicted bounding box and the ground truth bounding box. v is an indicator used to calculate the consistency of the aspect ratios of the two boxes, expressed as: α is a weighting coefficient used to balance aspect ratio loss, expressed as: This shows that when the IoU is small, α approaches 0, meaning the aspect ratio is ignored. When the IoU is large, α approaches 1, meaning the aspect ratio is fully considered.
[0021] (2) Classification loss function The original algorithm uses a binary cross-entropy loss with logits, i.e.
[0022] This algorithm has been optimized here, with the addition of class-differentiated hard example mining and learning guidance to enhance semantic ambiguity, referencing Focal loss. Details are as follows: The original YOLOv11 uses a logic-based cross-entropy loss function. Specifically:
[0023] in: and .
[0024] This loss function treats all categories equally, failing to consider the varying learning difficulties across different categories. Inspired by the focal loss function, this method designs a differentiated learning loss function based on category difficulty, aiming to alleviate the learning problem in scenarios with ambiguous category semantics. For categories with ambiguous semantics, we modify their loss weights.
[0025]
[0026] in: α is the preset decay weight.
[0027] The weighted calculation reduces the loss from incorrect judgments, and the more confident the model is in a misjudgment scenario, the more severe the weight decay. This approach can mitigate the impact of misjudgments caused by ambiguous semantics on the model parameters to some extent.
[0028] Furthermore, in ambiguous semantic scenarios, because the two categories are semantically similar, the model's confidence in some correct regions will be low. Therefore, additional learning is needed for these regions. Specifically:
[0029] This achieves gradient modulation for category differentiation. Categories without fuzzy semantics are assigned a positive weight of 1. In semantically ambiguous scenarios, the impact of fuzzy semantics on the model can be reduced by decreasing the number of negative examples and enhancing the learning of positive examples.
[0030] (3) Distribution focus loss The distributed focus loss is suitable for optimizing bounding box coordinate prediction. The specific expression is as follows:
[0031] Where y represents the actual normalized coordinates. The left boundary of the interval corresponding to y. The right boundary of the interval containing y. This represents the probability that the model predicts the coordinates to fall within the intervals i and i+1.
[0032] S24. Model parameter update: Based on the overall loss function, the gradient of the model parameters is calculated using the backpropagation algorithm, and the model parameters are iteratively updated using the optimizer; during the training process, the learning rate is dynamically adjusted according to the preset learning rate strategy until the model converges on the validation set, and the trained defect detection model is obtained. Specifically, based on the calculated total loss, the backpropagation algorithm is used to calculate the gradient of the loss relative to all learnable parameters of the model, and the optimizer is used to update the parameters. During training, the initial learning rate is set to a preset value, and a cosine annealing learning rate decay strategy is used to gradually reduce the learning rate as the training rounds increase, in order to achieve stable convergence. Training is performed in multiple iterations until the total loss no longer decreases significantly on the validation set, resulting in a well-trained defect detection model.
[0033] S3. Input the image of the electronic ceramic component to be detected into the defect detection model trained in step S2, and output the category, bounding box location, and confidence information of the defect in the image of the electronic ceramic component to be detected: The intelligent defect detection model for electronic ceramic components based on the YOLO algorithm, trained in step S2, is used to detect defects in the product images of the electronic ceramic components to be detected, and outputs the defect category, bounding box location, and confidence information.
[0034] S31. Image preprocessing: Acquire the image of the electronic ceramic component to be detected, perform the same preprocessing operation as in the training phase, and obtain a tensor that meets the requirements of the model input. S32. Input the preprocessed tensor into the model trained in step S2, and then extract features through the backbone network and perform multi-scale feature fusion through the neck network to output feature maps P16′, P19 and P22. Specifically, the preprocessed tensor is input into the trained defect detection model for forward inference. The backbone network extracts features layer by layer from the input image, generating a shallow high-resolution feature map P2 and deep feature maps P16, P19, and P22 for the neck network. In the top-down path, the neck network upsamples P10 and concatenates it with P6 to obtain P13, then upsamples P13 and concatenates it with P4 to obtain P16. Subsequently, a multi-scale feature fusion module adaptively fuses P2 and P16 with attention, enhancing the complementary spatial details of the shallow layer and the semantic information of the deep layer, generating a small-scale feature map P16′ with rich details and strong discriminative power. The neck network continues in the bottom-up path, fusing P4, P13, and P10 to output enhanced multi-scale feature maps P16′, P19, and P22, corresponding to 1 / 8, 1 / 16, and 1 / 32 resolution of the input image, respectively. Among them, P16′ incorporates high-resolution information from P2, thus enhancing its ability to characterize small-sized defects.
[0035] S33. Target Prediction and Decoding: The detection head receives the feature maps P16′, P19, and P22, predicts the bounding box offset through the regression branch, and predicts the category score and target confidence through the classification branch; it performs coordinate transformation on the bounding box offset in combination with a preset benchmark to obtain the predicted box coordinates in the image space of the electronic ceramic component to be detected; it multiplies the category score and the target confidence to calculate the comprehensive classification confidence of each predicted box; S34. Filter and remove duplicates from the prediction results, and output the location, category and confidence level of the defect bounding box on the image of the electronic ceramic component to be detected. The process involves filtering and deduplicating the large number of predicted bounding boxes obtained from decoding: First, a confidence threshold is set, and predicted boxes with an overall confidence level below the threshold are filtered out. Then, for each defect category, non-maximum suppression is performed, and redundant overlapping boxes are removed based on the intersection-union ratio (IUU) between the predicted boxes, retaining the detection results with the highest confidence. The coordinates of the finally retained detection boxes are then mapped back to the original image size using the scaling and padding parameters from the preprocessing stage, yielding the defect bounding box coordinates, category labels, and confidence scores on the original image. The detection results can be plotted on the original image as visual bounding boxes and labels, or output as structured data for subsequent quality assessment or production line rejection processes. The beneficial effects of this invention are as follows: The method of this invention first constructs an improved YOLO defect detection model, then inputs training data, and trains it using an improved small-scale feature fusion and fuzzy semantic loss function. After training, test data is collected and input into the model for testing, completing the sample defect detection. This invention improves detection accuracy and robustness by introducing small-target feature scale fusion and fuzzy semantic compensation, enabling the model to learn true defect patterns and meet the high-precision, low-false-detection requirements of complex industrial scenarios. Attached Figure Description
[0036] Figure 1 An example diagram illustrating semantic ambiguity; Figure 2 This is a schematic diagram of the overall structure of the intelligent defect detection model in this embodiment of the invention; Figure 3 This is a schematic diagram of the skeleton network structure of the intelligent defect detection model in an embodiment of the present invention; Figure 4 This is a schematic diagram of the neck network structure of the defect intelligent detection model in an embodiment of the present invention; Figure 5 This is a newly added feature fusion module in the embodiments of the present invention; Figure 6 This is the training process in an embodiment of the present invention. Detailed Implementation
[0037] The method of the present invention will be further described below with reference to the accompanying drawings and embodiments.
[0038] S1. Construct an intelligent defect detection model for electronic ceramic components based on the YOLO algorithm; This step constructs an intelligent defect detection model for electronic ceramic components based on the YOLO algorithm, such as... Figure 2 As shown, the model includes a backbone network, a neck network, and a detection head. A newly designed multi-scale feature fusion module is introduced into the neck network to enhance the feature representation ability of small-sized defects. The model takes a single defect image as input and outputs the category and location information of the defect in the image. This case is tested based on a major version of YOLOv11S. The specific model size is: depth=0.50, width=0.50, max_channel=1024. The specific steps are as follows: S11. Construct a backbone network to extract features from the input image, as shown in the instruction manual. Figure 3As shown, the backbone network includes five CBS modules, four C3k2 modules, one SPPF module, and one C2PSA module. One CBS module forms the head of the backbone network. The remaining four CBS modules and four C3k2 modules are stacked alternately to form the middle section of the backbone network. Finally, the SPPF and C2PSA modules form the tail section of the backbone network. Each C3k2 module contains n repeatedly stacked C3k2 sub-modules, and each C2PSA module contains n repeatedly stacked C2PSA sub-modules. The value of n is determined by a base value and a network depth parameter. The product of the depth values determines the input image's feature extraction. The input image is processed by the backbone network to generate five feature maps P2, P4, P6, P8, and P10 at different scales. The resolutions of P2, P4, P6, and P8 are 1 / 4, 1 / 8, 1 / 16, and 1 / 32 of the input image resolution, respectively, while the resolution of P10 is the same as P8. The number of channels in each feature map is determined by the baseline number of channels, the network width coefficient (width), and the upper limit of the number of channels (max_channel). Specifically, the number of channels for P2 is min(256×width, max_channel), for P4 and P6 it is min(512×width, max_channel), and for P8 and P10 it is min(1024×width, max_channel). S12. Construct a neck network for multi-scale feature fusion, such as... Figure 4 As shown, the neck network is composed of stacked Upsample, Concat, C3k2, and CBS modules. Within each C3k2 module, n C3k2 sub-modules are repeatedly stacked, with the value of n determined by the product of the baseline value and the network depth parameter. The feature map generated by S11 is processed by the neck network to output detection feature maps at different scales: in the top-down path, P10 is upsampled and concatenated with P6 to obtain feature map P13; P13 is upsampled and concatenated with P4 to obtain feature map P16. The backbone network... The output P2 of the network is downsampled to the same resolution as P16, and the downsampled P2 and P16 are adaptively fused to obtain a small-scale enhanced feature map P16′. In the bottom-up path, P16′ is downsampled and concatenated with P13 to obtain a medium-scale feature map P19, and P19 is downsampled and concatenated with P10 to obtain a large-scale feature map P22. The final output of the neck network consists of three detection feature maps with resolutions of 1 / 8, 1 / 16, and 1 / 32 of the input image resolution: P16′, P19, and P22. S13. Construct a detection head, which consists of three layers of feature pyramid modules. Each layer of feature pyramid modules is composed of two DSC modules plus a Covn2d module and two CBS modules plus a Conv2d module. Input feature maps P16′, P19 and P22 into the detection head. Perform target classification and bounding box regression on the three detection feature maps through parallel convolution branches. Output the detection results, which include defect category probability, bounding box coordinate offset and target confidence. S2, Training the detection model constructed in step S1; The defect detection model constructed in step S1 is trained using training samples labeled with defect categories and bounding boxes. During training, an improved loss function is used to calculate the prediction error, and the model parameters are updated through backpropagation to obtain a high-precision model for the defect detection task. Figure 6 As shown, the training process is as follows: S21. Training Image Data Preparation: Collect images of electronic ceramic components containing defective targets, label the defective targets in the images with categories and bounding boxes, and divide the labeled images into training set and validation set; perform data augmentation on the images in the training set, and uniformly adjust them to the preset input size and perform normalization to generate input image data for model training, thus obtaining training image data; the corresponding images in the validation set are the validation image data. The collected images included various defects in electronic ceramic components. For each image, the defect target was labeled with its category label and the ground truth coordinates of its bounding box. The labeled image dataset was divided into training and validation sets. During training, data augmentation was performed on the training set images, including random rotation, translation, scaling, erasing, cropping, perspective adjustment, flipping, color jittering, Mosaic enhancement, and Mixup enhancement, to improve the model's generalization ability. The augmented images were then uniformly scaled to a fixed size and their pixel values were normalized to obtain the input tensors for the training batch.
[0039] The data augmentation methods used in this case study include: enlarging the input image to 1280×1280; mosaic=1; mixup=0.2; setting the hue, saturation, and luminance dithering to: hsv_h=0.015, hsv_s=0.7, hsv_v=0.4; setting random rotation to ±10°; random translation to 0.1; random scaling to 0.5; random cropping to 2; perspective transformation to 0.0005; vertical and horizontal flips to 0.5 each; random erasure to 0.4; and enabling label softening.
[0040] S22. Forward Propagation and Prediction Output: The images in the training set are input into the detection model constructed in step S1 in batches. Multi-scale feature extraction and fusion are performed through the backbone network and the neck network to output feature maps at multiple scales. Based on the feature maps, target classification and bounding box regression are performed through the detection head to obtain the class probability, bounding box coordinates and target confidence prediction results at each scale. Specifically, the training batch of images is input into the improved YOLO defect detection model constructed in step S1. The images are processed by the backbone network to extract feature maps P2, P4, P6, and P10. The neck network performs multi-scale feature fusion through top-down and bottom-up paths, and the multi-scale feature fusion module adaptively fuses P2 and P16 to obtain an enhanced small-scale feature map P16′. Finally, three scale feature maps P16′, P19, and P22 are output. At each grid position of each scale feature map, the detection head predicts the defect category probability, bounding box coordinate offset, and target confidence for a preset number of anchor boxes (or no anchor boxes), forming a dense prediction set. In this case, the initial parameters of the feature fusion module are set to 256 output channels. The multi-scale feature fusion module is as follows... Figure 5 As shown.
[0041] S23. Loss Function Construction and Optimization: Construct the overall loss function for model training. The overall loss function is composed of a weighted average of the bounding box regression loss, confidence loss, and classification loss, and its expression is: λ represents the weights of the three losses; the bounding box regression loss A CIoU-based loss function is used to constrain the positional and shape differences between the predicted bounding boxes and the ground truth bounding boxes; the classification loss... An improved Focal mechanism is introduced based on the binary cross-entropy loss. By setting differentiated modulation coefficients for different categories, the focus on semantically confusing categories and difficult-to-classify samples is enhanced, thereby improving the ability to identify fuzzy semantic defects. The distributed focus loss is used to optimize the learning loss function design of the discretized coordinate distribution. To improve the model's detection accuracy for defects, especially those with ambiguous semantics, an improved category classification loss function was designed. This improved loss function was incorporated into the overall loss to guide the model's learning. The overall loss function consists of a weighted average of the bounding box regression loss, confidence loss, and classification loss. λ represents the weights of the three loss functions.
[0042] This case uses the aforementioned two-way improvement method. The loss function parameters are: α=0.5, λ=2, θ=0.4.
[0043] S24. Model parameter update: Based on the overall loss function, the gradient of the model parameters is calculated using the backpropagation algorithm, and the model parameters are iteratively updated using the optimizer; during the training process, the learning rate is dynamically adjusted according to the preset learning rate strategy until the model converges on the validation set, and the trained defect detection model is obtained. Specifically, based on the calculated total loss, the backpropagation algorithm is used to calculate the gradient of the loss relative to all learnable parameters of the model, and the parameters are updated using an optimizer; in this case, the Adam optimizer is used. During training, the initial learning rate is set to a preset value; in this case, the initial learning rate is 0.0005, and a cosine annealing learning rate decay strategy is used, gradually reducing the learning rate as the training epochs increase. In this case, the final learning rate is 0.00001 to achieve stable convergence. Training is performed in multiple iterations until the total loss no longer decreases significantly on the validation set, resulting in a well-trained defect detection model.
[0044] S3. Input the image of the electronic ceramic component to be detected into the defect detection model trained in step S2, and output the category, bounding box location, and confidence information of the defect in the image of the electronic ceramic component to be detected: The intelligent defect detection model for electronic ceramic components based on the YOLO algorithm, trained in step S2, is used to detect defects in the product images of the electronic ceramic components to be detected, and outputs the defect category, bounding box location, and confidence information.
[0045] S31. Image preprocessing: Acquire the image of the electronic ceramic component to be detected, perform the same preprocessing operation as in the training phase, and obtain a tensor that meets the requirements of the model input. Acquire images of the electronic ceramic components to be detected and use them as input images. Perform the same preprocessing on the input images as in the training phase to form tensors that can be input into the model.
[0046] S32. Input the preprocessed tensor into the model trained in step S2, and then extract features through the backbone network and perform multi-scale feature fusion through the neck network to output feature maps P16′, P19 and P22. Specifically, the preprocessed tensor is input into the trained defect detection model for forward inference. The backbone network extracts features layer by layer from the input image, generating a shallow high-resolution feature map P2 and deep feature maps P16, P19, and P22 for the neck network. In the top-down path, the neck network upsamples P10 and concatenates it with P6 to obtain P13, then upsamples P13 and concatenates it with P4 to obtain P16. Subsequently, a multi-scale feature fusion module adaptively fuses P2 and P16 with attention, enhancing the complementary spatial details of the shallow layer and the semantic information of the deep layer, generating a small-scale feature map P16′ with rich details and strong discriminative power. The neck network continues in the bottom-up path, fusing P4, P13, and P10 to output enhanced multi-scale feature maps P16′, P19, and P22, corresponding to 1 / 8, 1 / 16, and 1 / 32 resolution of the input image, respectively. Among them, P16′ incorporates high-resolution information from P2, thus enhancing its ability to characterize small-sized defects.
[0047] S33. Target Prediction and Decoding: The detection head receives the feature maps P16′, P19, and P22, predicts the bounding box offset through the regression branch, and predicts the category score and target confidence through the classification branch; it performs coordinate transformation on the bounding box offset in combination with a preset benchmark to obtain the predicted box coordinates in the image space of the electronic ceramic component to be detected; it multiplies the category score and the target confidence to calculate the comprehensive classification confidence of each predicted box; S34. Filter and remove duplicates from the prediction results, and output the location, category and confidence level of the defect bounding box on the image of the electronic ceramic component to be detected. The process involves filtering and deduplicating the large number of predicted bounding boxes obtained from decoding: First, a confidence threshold is set, and predicted boxes with an overall confidence level below the threshold are filtered out. Then, for each defect category, non-maximum suppression is performed, and redundant overlapping boxes are removed based on the intersection-union ratio (IUU) between the predicted boxes, retaining the detection results with the highest confidence. The coordinates of the finally retained detection boxes are then mapped back to the original image size using the scaling and padding parameters from the preprocessing stage, yielding the defect bounding box coordinates, category labels, and confidence scores on the original image. The detection results can be plotted on the original image as visual bounding boxes and labels, or output as structured data for subsequent quality assessment or production line rejection processes.
[0048] The evaluation metrics include: average accuracy P, R, AP, mAP50, and mAP50-95.
[0049] (1) P (Precision), i.e., accuracy. The formula is: It means: among all results where the model predicts a positive sample (the target exists), the proportion that is truly correct. TP (True Positive): Detection results where the IoU between the predicted bounding box and the ground truth bounding box is ≥ the threshold and the class is correct. FP (False Positive): Samples where the predicted bounding box is judged as a false detection (IoU < threshold, misclassification, or duplicate detection).
[0050] (2) R (Recall), i.e., recall rate. The formula is: The value is the proportion of all real targets that are successfully detected by the model. FN (False Negative): Samples where real targets were not detected (missed detections).
[0051] (3) AP (Average Precision), which is the area under the PR (Precision-Recall) curve. It is a curve plotted with precision P on the Y-axis and recall on the X-axis. This curve represents the relationship between precision and recall at different confidence thresholds. The higher the AP value, the better the model prediction.
[0052] (4) mAP50: The average AP of all types when the IoU threshold is set to 0.5. The higher the mAP50, the better the prediction accuracy of the model.
[0053] (5) mAP50-95, which is a more stringent evaluation criterion than mAP50, is calculated by averaging the AP values at 10 thresholds (0.5, 0.55, ..., 0.95) with IoU thresholds ranging from 0.5 to 0.95 (step size 0.05). A higher mAP50 value indicates better predictive accuracy.
[0054] This embodiment also compares and validates the method of the present invention with the existing method (YOLOv11s) on a test dataset. The comparison results of the method of the present invention and the existing method on the validation dataset are shown in Table 1.
[0055]
[0056] In Table 1, column 3, mAP50 / AP50, means that for all categories in the first row, this column represents the mAP metric. For a specific defect, this column represents the AP metric. We primarily examine the AP and mAP metrics because they comprehensively consider precision and recall, i.e., the overall situation of false positives and false negatives.
[0057] Table 1 shows that the improved method achieved improvements in AP for all three defect categories and the average category. Specifically, the improvements for lateral concavity, surface damage, and surface adhesion performance were 0.5%, 1.4%, and 1.3%, respectively. The overall performance improvement across the three categories was 1%. This indicates that the improved model, to some extent, enhances the learning performance under semantically ambiguous conditions.
[0058] In summary, the method of this invention constructs an improved defect detection architecture through small-scale feature extraction and adaptive fusion mechanism, as well as fuzzy semantic error learning suppression and correct reward. This improves the detection sensitivity and robustness in semantically ambiguous scenarios, and can better learn defect patterns of fuzzy semantic categories to meet the high-precision, low-false-report detection requirements in complex industrial scenarios.
[0059] Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the principles of the invention, and should be understood that the scope of protection of the invention is not limited to such specific statements and embodiments. Various modifications and variations can be made to the invention by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the invention should be included within the scope of the claims of the invention.
Claims
1. A method for intelligent defect detection of electronic ceramic components based on the YOLO algorithm, characterized in that, The specific steps are as follows: S1. Construct an intelligent defect detection model for electronic ceramic components based on the YOLO algorithm; S11. Construct a backbone network to extract features from the input image. The backbone network includes five CBS modules, four C3k2 modules, one SPPF module, and one C2PSA module. One CBS module forms the head of the backbone network. The remaining four CBS modules and four C3k2 modules are stacked alternately to form the middle section of the backbone network. Finally, the SPPF and C2PSA modules form the tail section of the backbone network. Each C3k2 module contains n repeatedly stacked C3k2 sub-modules, and each C2PSA module contains n repeatedly stacked C2PSA sub-modules. The value of n is... The number of channels is determined by the product of the baseline value and the network depth parameter. The input image is processed by the backbone network to extract features, generating five feature maps P2, P4, P6, P8, and P10 at different scales. The resolutions of P2, P4, P6, and P8 are 1 / 4, 1 / 8, 1 / 16, and 1 / 32 of the input image resolution, respectively, while the resolution of P10 is the same as that of P8. The number of channels in the feature maps is determined by the baseline number of channels, the network width coefficient (width), and the upper limit of the number of channels (max_channel). Specifically, the number of channels for P2 is min(256×width, max_channel), the number of channels for P4 and P6 is min(512×width, max_channel), and the number of channels for P8 and P10 is min(1024×width, max_channel). S12. Construct a neck network for multi-scale feature fusion. The neck network consists of stacked Upsample, Concat, C3k2, and CBS modules. Within each C3k2 module, n C3k2 sub-modules are repeatedly stacked, where n is determined by the product of the baseline value and the network depth parameter. The feature map generated in S11 is processed by the neck network to output detection feature maps at different scales: in the top-down path, P10 is upsampled and concatenated with P6 to obtain feature map P13; P13 is upsampled and concatenated with P4 to obtain feature map P14. P16; The backbone network output P2 is downsampled to the same resolution as P16, and the downsampled P2 and P16 are adaptively fused to obtain a small-scale enhanced feature map P16′; In the bottom-up path, P16′ is downsampled and concatenated with P13 to obtain a medium-scale feature map P19, and P19 is downsampled and concatenated with P10 to obtain a large-scale feature map P22; The neck network finally outputs three detection feature maps with resolutions of 1 / 8, 1 / 16, and 1 / 32 of the input image resolution: P16′, P19, and P22. S13. Construct a detection head, which consists of three layers of feature pyramid modules. Each layer of feature pyramid modules is composed of two DSC modules plus a Covn2d module and two CBS modules plus a Conv2d module. Input feature maps P16′, P19 and P22 into the detection head. Perform target classification and bounding box regression on the three detection feature maps through parallel convolution branches. Output the detection results, which include defect category probability, bounding box coordinate offset and target confidence. S2, The detection model built in training step S1: S21. Training Image Data Preparation: Collect images of electronic ceramic components containing defective targets, label the defective targets in the images with categories and bounding boxes, and divide the labeled images into training set and validation set; perform data augmentation on the images in the training set, and uniformly adjust them to the preset input size and perform normalization to generate input image data for model training, thus obtaining training image data; the corresponding images in the validation set are the validation image data. S22. Forward Propagation and Prediction Output: The images in the training set are input into the detection model constructed in step S1 in batches. Multi-scale feature extraction and fusion are performed through the backbone network and the neck network to output feature maps at multiple scales. Based on the feature maps, target classification and bounding box regression are performed through the detection head to obtain the class probability, bounding box coordinates and target confidence prediction results at each scale. S23. Loss Function Construction and Optimization: Construct the overall loss function for model training. The overall loss function is composed of a weighted average of the bounding box regression loss, confidence loss, and classification loss, and its expression is: λ represents the weights of the three losses; the bounding box regression loss A CIoU-based loss function is used to constrain the positional and shape differences between the predicted bounding boxes and the ground truth bounding boxes; the classification loss... An improved Focal mechanism is introduced based on the binary cross-entropy loss. By setting differentiated modulation coefficients for different categories, the focus on semantically confusing categories and difficult-to-classify samples is enhanced, thereby improving the ability to identify fuzzy semantic defects. The distributed focus loss is used to optimize the learning of the discrete coordinate distribution. S24. Model parameter update: Based on the overall loss function, the gradient of the model parameters is calculated using the backpropagation algorithm, and the model parameters are iteratively updated using the optimizer; during the training process, the learning rate is dynamically adjusted according to the preset learning rate strategy until the model converges on the validation set, and the trained defect detection model is obtained. S3. Input the image of the electronic ceramic component to be detected into the defect detection model trained in step S2, and output the category, bounding box location, and confidence information of the defect in the image of the electronic ceramic component to be detected: S31. Image preprocessing: Acquire the image of the electronic ceramic component to be detected, perform the same preprocessing operation as in the training phase, and obtain a tensor that meets the requirements of the model input. S32. Input the preprocessed tensor into the model trained in step S2, and then extract features through the backbone network and perform multi-scale feature fusion through the neck network to output feature maps P16′, P19 and P22. S33. Target Prediction and Decoding: The detection head receives the feature maps P16′, P19, and P22, predicts the bounding box offset through the regression branch, and predicts the category score and target confidence through the classification branch; it performs coordinate transformation on the bounding box offset in combination with a preset benchmark to obtain the predicted box coordinates in the image space of the electronic ceramic component to be detected; it multiplies the category score and the target confidence to calculate the comprehensive classification confidence of each predicted box; S34. Filter and remove duplicates from the prediction results, and output the location, category, and confidence level of the defect bounding box on the image of the electronic ceramic component to be detected.
2. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 1, characterized in that, In S12, the steps for generating the small-scale enhanced feature map P16' are as follows: P2 is downsampled through interpolation to make its resolution consistent with P16, resulting in the downsampled feature map P2'. The calculation formula is as follows: ; The downsampled feature maps P2' and P16 are concatenated along the channel dimension to obtain the concatenated feature map, as shown below. ,Will The enhanced small-scale feature map P16' is obtained by sequentially processing through convolutional layers, batch normalization layers, and ReLU activation functions, and the calculation formula is as follows: ; Where interpolate() represents the area interpolation function, Concat() represents the channel concatenation function, Conv() represents the convolution operation, BatchNorm() represents the batch normalization operation, and ReLu() represents the linear rectified activation function.
3. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 2, characterized in that, P2 is a shallow feature map in the backbone network with a resolution of 1 / 4 of the input image resolution, and P16 is a fused feature map in the neck network with a resolution of 1 / 8 of the input image resolution.
4. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 1, characterized in that, The loss function in step S23 is as follows: Calculate the cross-entropy loss function with logic. The calculation formula is: ; in: ; ; against The missed detection categories of fuzzy semantics in its loss weights are weighted as follows: ; Where: α is the preset decay weight; against The false detection categories of fuzzy semantics in its loss weights are weighted as follows: ; Where: λ is the category fuzzy weight, that is, the weight set for fuzzy semantic categories. For categories without fuzzy semantics, a positive weight of 1 is used.
5. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 4, characterized in that, The loss function employs a differentiated weight adjustment mechanism to differentiate the penalties for missed and false detection samples. The specific logic includes: determining the sample's tendency to miss or falsely detect based on the relationship between the sample's true class label and the model's predicted probability; introducing decay weights and fuzzy class weights when calculating the classification loss; wherein the decay weights are applied to samples with a tendency to miss, decreasing or increasing their weights according to the model's confidence level—decreasing weights for high-confidence samples and increasing weights for low-confidence samples—allowing the model to adaptively adjust the difficulty based on its prediction confidence; the fuzzy class weights are applied to samples with a tendency to falsely detect, enhancing their contribution to the loss; the decay weights and fuzzy class weights are unequal adjustment parameters, resulting in asymmetric gradient backpropagation for missed and false detections.
6. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 1, characterized in that, Data acquisition in S21 uses industrial cameras to capture images of defects in electronic ceramic components, including lateral dents, surface damage, and surface adhesion.
7. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 1, characterized in that, The data annotation in S21 involves professionals using annotation tools to accurately annotate defects in electronic ceramic components, ensuring that each type of defect is correctly identified and classified.
8. The intelligent defect detection method for electronic ceramic components based on the YOLO algorithm according to claim 7, characterized in that, The defects are classified into four types: lateral concavity, surface damage, surface adhesion, and no defects. The image data for each type is labeled and categorized.