4.2. Comparison Experiment of Dataset Threshold Results
The similarity threshold used in source-domain sample screening directly affects the transfer learning performance. If the threshold is too low, many semantically irrelevant samples may be retained, which can introduce negative transfer. In contrast, if the threshold is too high, the number of source-domain samples available for pre-training will be sharply reduced, weakening the benefit of source-domain knowledge for small-sample tasks. Therefore, an appropriate threshold is required to balance sample relevance and sample quantity.
To determine the optimal threshold, this study analyzed the cosine similarity distribution between matched source-domain and target-domain samples. The results show that samples with similar defect textures, such as bubbles and scratches, generally have higher similarity scores, whereas unrelated samples are mainly concentrated in a lower similarity range. When the threshold is set below 0.70, the retained set still contains many background-texture or non-defect samples. However, when the threshold exceeds 0.85, the number of source-domain samples for pre-training is significantly reduced, which adversely affects model convergence.
Under the settings shown in
Table 2, the improved RT-DETR model was trained with identical parameters, and Precision, Recall, and mAP@0.5 on the target-domain test set were recorded. As the similarity threshold increases from 0.60 to 0.80, Precision improves from 0.88 to 0.92, Recall increases from 0.87 to 0.89, and mAP@0.5 rises from 0.88 to 0.90. This indicates that filtering out low-related source-domain samples can effectively improve transfer learning quality. However, when the threshold is further increased to 0.85, although Precision remains at 0.92, Recall drops to 0.87, and the retained source-domain sample proportion decreases to 44%. This suggests that excessive screening weakens the pre-training effect and reduces the model’s ability to learn sufficient defect representations.
Considering both detection performance and retained source-domain sample quantity, the model achieves the best overall balance when the similarity threshold is set to 0.80. Therefore, this study selects 0.80 as the final threshold for source-domain sample screening.
4.3. Result Analysis
4.3.1. Ablation Experiment
To systematically evaluate the effectiveness of the Dynamic Inception Convolution Module (DICM) and the Hierarchical Attention Fusion Block (HAFB), ablation experiments were conducted based on the benchmark RT-DETR model, and the results are listed in
Table 3.
The baseline model, without any enhancement modules, achieved Precision, Recall, and mAP@0.5 values of 0.78, 0.80, and 0.83, respectively, with an FPS of 75.29 and a model size of 80.7 MB, which serves as the reference for subsequent comparison.
When only DICM was introduced, Recall increased from 0.80 to 0.81 and mAP@0.5 improved to 0.84, indicating that DICM enhances defect representation and helps reduce missed detections. However, Precision slightly decreased to 0.77 and FPS dropped to 72.67, suggesting that the strengthened feature modeling also introduced a certain computational burden and false-positive risk. Notably, the model size was reduced to 51.6 MB, a decrease of 36.1% compared with the baseline, demonstrating the advantage of DICM in lightweight design.
When only HAFB was introduced, the model achieved more balanced improvements, with Precision, Recall, and mAP@0.5 reaching 0.81, 0.83, and 0.87, respectively, while FPS increased to 78.96 and the model size slightly decreased to 77.5 MB. These results indicate that HAFB can effectively improve both feature fusion quality and detection efficiency by integrating local details with global semantic information.
When DICM and HAFB were integrated simultaneously, the model achieved the best overall performance. Precision, Recall, and mAP@0.5 reached 0.86, 0.89, and 0.88, respectively, representing improvements of 10.3%, 11.3%, and 6.0% over the baseline model. Meanwhile, FPS increased to 82.77, about 9.9% higher than the baseline, while the model size remained at 78.4 MB, which is close to that of the original model. Compared with the single-module settings, the combined model showed superior performance across all metrics, indicating that DICM and HAFB play complementary roles in feature extraction and feature fusion.
As shown in
Figure 9, DICM exhibits clear advantages in lightweight design and feature enhancement, whereas HAFB is more effective in improving accuracy and efficiency. Their combination enables a better balance among detection accuracy, inference speed, and model size.
4.3.2. Comparison of Transfer Learning Experiments
To further verify the effectiveness of transfer learning combined with detection head optimization, comparative experiments were conducted on the target-domain dataset. Model A denotes the configuration without transfer learning, while Model B denotes the configuration with transfer learning and an optimized detection head. The comparison results are listed in
Table 4.
As shown in
Table 4, the overall detection performance is significantly improved after introducing transfer learning and detection head optimization. Compared with Model A, Model B increases Precision from 0.86 to 0.87, Recall from 0.89 to 0.94, and mAP@0.5 from 0.88 to 0.94. Among these metrics, the improvement in Recall is particularly notable, indicating that the improved model is more capable of detecting real defect targets and reducing missed detections, especially for small or weak-texture defects. This result suggests that the optimized model provides better adaptability to complex defect distributions under small-sample conditions.
In terms of comprehensive detection performance, the increase in mAP@0.5 from 0.88 to 0.94 shows that the combination of transfer learning and detection head optimization improves both localization and classification capability. On the one hand, the optimized detection head enhances the flexibility of target prediction; on the other hand, transfer learning enables the model to inherit useful feature representations from the source domain, thereby improving feature extraction efficiency on the target task. The joint effect of these two strategies leads to a clear improvement in overall detection accuracy.
In terms of inference efficiency, Model B achieves 87.62 FPS, which is higher than the 82.77 FPS of Model A, indicating that the improved model still maintains good real-time performance. In addition, the model size only increases slightly from 78.43 MB to 80.12 MB. Although the parameters grow modestly, the gain in detection accuracy and recall is more significant. Therefore, the improved model achieves a better balance among accuracy, recall, real-time performance, and model size.
To further validate the transferability claim and isolate the specific contributions of the transfer learning step across different morphological categories, an additional class-wise ablation experiment was conducted. We compared the model trained from scratch (without pre-trained weights) against the model initialized with source-domain transfer learning across point, line, and planar defect subsets. The results are summarized in
Table 5.
As the results clearly indicate, the transfer learning strategy yields consistent improvements across all defect subsets. Notably, point defects exhibited the most significant gain in AP@0.5 (from 0.84 to 0.95, an 11.0% improvement). This confirms that the pre-trained weights effectively mitigate the risk of overfitting, providing robust feature initialization for small, discrete targets under small-sample conditions. Furthermore, the performance boosts on linear (+7.0%) and planar defects (+6.0%) demonstrate that the general edge, contour, and complex texture representations learned from the source domain are highly transferable to geometrically complex targets in our target domain. This experiment strongly validates the effectiveness and generalizability of the proposed transfer learning strategy.
Figure 10 shows the detection results of Model A on the test images. The model can identify some linear defects, but it still has clear limitations in detecting point defects and surface defects. In several fine-textured or complex-background regions, missed detections occur, and some predicted bounding boxes are not well aligned with the actual defect regions. These results indicate that the baseline model still lacks sufficient representation ability for small defects and complex backgrounds.
Figure 11 shows the detection results of the improved Model B on the same test images. Compared with Model A, Model B exhibits more stable detection across different defect categories, especially for point defects and surface defects. The predicted boxes are more accurately aligned with the target boundaries, and missed detections are significantly reduced even under complex textured backgrounds. These observations further confirm the effectiveness of transfer learning and detection head optimization in improving small-defect detection performance.
4.3.3. Heatmap Analysis
To further compare the feature response differences between the original RT-DETR model and the improved model, heat map visualization analysis was conducted. Five representative samples with obvious response differences were selected, as shown in
Figure 12.
Overall, the improved model exhibits more concentrated and higher-intensity responses in defect regions, and its activation areas better coincide with the actual defect locations. In contrast, the original RT-DETR model shows more dispersed responses and stronger background interference, and some samples present response offsets or incomplete coverage.
For fine-grained defects such as microscopic scratches and point-like defects, the difference between the two models is more evident. The original model shows weak or blurred responses and fails to effectively highlight defect regions, whereas the improved model produces clearer high-response clusters in micro-defect areas. This indicates that the proposed improvements enhance the model’s ability to capture local details and improve small-defect perception.
For strip-shaped crack defects, the heat maps of the improved model present a more continuous and stable response distribution along the defect direction, which is closer to the actual defect contour. In addition, under complex backgrounds or irregular defect patterns, the improved model focuses more on defect regions while suppressing interference from background textures and illumination variations. These results demonstrate that the improved model achieves better feature selection, stronger anti-interference ability, and higher discriminative power than the original RT-DETR model.
4.3.4. Confusion Matrix Analysis
To further evaluate the classification performance and inter-class discrimination ability of the improved model for different defect categories, a confusion matrix was constructed based on the test set results, as shown in
Figure 13. In the matrix, the horizontal axis represents the true labels, the vertical axis represents the predicted labels, the diagonal elements denote correct classification proportions, and the off-diagonal elements indicate misclassification relationships.
Overall, most samples are concentrated along the diagonal, indicating that the improved model achieves high classification accuracy and strong category discrimination across the three defect types. Compared with the original model, the improved RT-DETR exhibits more accurate predictions for all categories, which further demonstrates the effectiveness of the optimization strategy.
For planar defects, the classification accuracy reaches 0.95. Since these defects usually exhibit relatively large spatial distribution and obvious texture characteristics, the model can effectively capture their regional features. Only a small proportion of planar defects are misclassified as linear defects or point defects, which is mainly caused by local linear boundary structures in some planar defects.
For linear defects, the classification accuracy reaches 0.97, which is one of the best among the three categories. This is mainly because linear defects have strong directional continuity and prominent geometric characteristics, making them easier to learn during feature extraction. A few samples are misclassified as planar defects, mostly because some wide crack-like defects show local planar expansion patterns and thus increase classification difficulty.
For point defects, the model also achieves a classification accuracy of 0.97, indicating strong fine-grained feature extraction capability. The confusion with other categories is minimal, which shows that the improved model performs well in representing small and discrete defect patterns. This result also verifies the effectiveness of the proposed optimization strategy in improving small-defect perception.
From the off-diagonal regions, a small number of defect samples are still misclassified as background. For example, a minor proportion of linear defects are predicted as background, mainly because some defect features are weak and show limited grayscale or texture differences from the surrounding area. In addition, illumination variation and reflection interference in industrial environments may further affect feature extraction. Nevertheless, the proportion of such errors remains low and has limited influence on overall model performance.
In summary, the confusion matrix shows that the improved RT-DETR model maintains high consistency and stability across different defect categories. The main confusion occurs between linear defects and planar defects, whereas point defects show very limited overlap with other categories. These results further confirm that the proposed method improves category discrimination and anti-interference ability in solar vacuum glass collector tube defect detection. To intuitively illustrate the specific geometric ambiguities contributing to these misclassifications within the confusion matrix,
Figure 14 presents typical cases where linear and planar defects are confused.
Geometrically, the proposed model occasionally struggles with these two classes due to the inherent cylindrical curvature of the vacuum tubes and the resulting perspective projections. As shown in
Figure 14a, a series of discrete point-like defects may align in a way that, when viewed from certain angles or compressed by the tube’s curvature, resembles a continuous linear feature. This topological similarity can mislead the model into classifying a cluster of small defects (planar-like) as a single linear defect.
Conversely, as depicted in
Figure 14b, extremely faint and blurred linear scratches often lack distinct edge features. Under low-contrast conditions, the blurred texture of these scratches can lose its directional information, causing the model to perceive the defect as a vague, two-dimensional region rather than a clear line. These geometric and optical factors explain the higher off-diagonal values between the linear and planar categories observed in the confusion matrix.
4.3.5. Comparison with Mainstream Algorithm Models
To evaluate the comprehensive performance of the proposed model for solar vacuum glass collector tube defect detection, comparative experiments were conducted on the self-built dataset using multiple mainstream object detection algorithms. The compared models included Faster R-CNN, YOLOX-S, PP-YOLOE-S, EfficientDet-D1, YOLOv8, DINO-DETR, and RT-DETR, together with two reference methods from the literature. All models were trained and tested under the same hardware environment and dataset settings to ensure fair comparison. The corresponding results are listed in
Table 6.
As shown in
Table 6, the proposed model achieves Precision, Recall, and mAP@0.5 of 0.96, 0.95, and 0.95, respectively, which are markedly higher than those of most comparison models. Compared with the original RT-DETR, whose mAP@0.5 is 0.83, the improved model shows clear gains in all major accuracy metrics, indicating that the proposed improvements effectively enhance feature representation and defect discrimination capability.
Among the compared methods, Faster R-CNN shows relatively stable accuracy, but its inference speed is limited to 45.25 FPS, which is insufficient for real-time industrial deployment. Lightweight detectors such as YOLOX-S and PP-YOLOE-S achieve FPS values above 90, but their mAP@0.5 values are only 0.78 and 0.71, respectively, indicating limited performance in small-sample and complex defect scenarios. For Transformer-based methods, DINO-DETR achieves an mAP@0.5 of 0.71, while the original RT-DETR reaches 0.83, showing better overall suitability for this task. The proposed model further improves upon RT-DETR and achieves a better balance between accuracy and real-time performance.
To further demonstrate the superiority of the proposed method, we incorporated MobileViT and YOLOv10-S as additional benchmarks in
Table 6. While MobileViT offers extreme model compactness, its pure Transformer-based architecture struggles to extract fine-grained local features from small-sample glass defects, resulting in a lower mAP@0.5 of 0.81. On the other hand, although YOLOv10-S achieves the highest inference speed (98.20 FPS), its general-purpose feature extraction backbone lacks specific mechanisms to suppress complex background noise and reflections inherent in solar vacuum tubes. In contrast, our improved RT-DETR leverages the DICM and HAFB modules to achieve a more robust balance, reaching an mAP@0.5 of 0.95 while maintaining real-time performance (83.21 FPS).
In terms of efficiency, the proposed model reaches 83.21 FPS with a model size of 82.36 MB. Although its speed is slightly lower than that of some lightweight YOLO models, it remains competitive among high-accuracy detectors. As shown in
Figure 15, the proposed model is positioned in the upper-right region of the mAP-FPS scatter plot, indicating that it maintains both high detection accuracy and favorable real-time performance. These results demonstrate that the proposed method achieves a strong trade-off between precision and computational efficiency.
It is worth noting that the proposed model achieves a substantial improvement in mAP@0.5 (from 0.83 to 0.95) compared to the baseline RT-DETR. This significant gain is a cumulative result of multi-stage optimization rather than data leakage or overfitting. As shown in the ablation study (
Table 3), structural optimizations (DICM and HAFB) alone improved the mAP to 0.88. The subsequent jump to 0.95 is strictly attributed to the high-quality transfer learning strategy guided by cosine similarity, which selectively filtered the most semantically relevant source-domain samples (threshold 0.80) to maximize pre-training efficiency while reducing negative transfer. To ensure experimental integrity, strict physical isolation was maintained between the training, validation, and testing sets, and shallow feature layers were frozen during fine-tuning to act as a regularizer against overfitting in small-sample scenarios.
4.4. Demonstration of Actual Results
After completing system construction and model deployment, a practical experimental platform was established to evaluate the real-world applicability of the proposed method, as shown in
Figure 16. The system mainly consists of an image acquisition module, a motion control module, and a host computer processing module. The camera is fixed above the platform to capture real-time images of solar vacuum glass collector tubes, and a stable light source is used to ensure imaging consistency. During operation, the collector tube is placed on a roller support, and the right-side motor drives continuous rotation to achieve full-surface scanning and avoid detection blind spots. The captured images are transmitted to the host computer, where preprocessing and defect detection are performed by the optimized RT-DETR model, and the final results are displayed visually on the interface.
To further validate the detection performance in practical industrial scenarios, multiple online detection experiments were conducted on real solar vacuum glass collector tubes, and statistical analysis was performed for different defect categories. The results show that the system achieves high recognition accuracy for all three representative defect types. Specifically, among 300 point defects, 295 were correctly detected, corresponding to a detection rate of 98.33%. Among 200 linear defects, 199 were detected, yielding a detection rate of 99.50%. For 100 planar defects, 98 were correctly identified, corresponding to a detection rate of 98.00%, as listed in
Table 7.
Overall, the system achieves detection rates above 98% for all three defect categories, indicating good accuracy and stability in practical deployment. Linear defects show the highest detection rate, suggesting that the model has strong capability in extracting slender structural features. Point defects also achieve satisfactory performance, confirming the effectiveness of the proposed method for small-scale defect perception. In comparison, the detection rate of planar defects is slightly lower, mainly because their irregular morphology makes them more susceptible to illumination variation and background texture interference.
Further analysis of the undetected samples shows that missed detections mainly occur in the following situations: defects with very small dimensions or low grayscale contrast provide insufficient feature representation; strong reflections or uneven local illumination reduce the contrast between the defect region and the background; and some linear defects have blurred edges, which causes slight localization deviations.
To evaluate real-time performance in industrial scenarios, inference speed tests were further conducted using FPS as the evaluation metric. Under GPU-accelerated continuous detection, the system achieves an average speed of 70.79 FPS, which satisfies the real-time requirements of industrial online inspection. Even in scenarios with multiple coexisting defects, the system maintains stable inference performance without significant degradation.