In modern manufacturing, the integrity of casting parts is paramount, as defects such as pores, cracks, and shrinkage can compromise the safety and performance of mechanical systems. These casting parts are often integral components in critical applications like automotive, aerospace, and railway industries, where failure under load can lead to severe consequences. Traditional inspection methods for casting parts rely on manual visual checks or basic imaging techniques, which are labor-intensive, subjective, and prone to error. With the advent of digital radiography (DR) imaging, non-destructive testing has become more accessible, providing high-resolution images of casting parts without damaging them. However, automating the detection of defects in casting parts remains challenging due to the variability in defect size, shape, and contrast within DR images. To address this, I propose a comprehensive deep learning-based approach that enhances detection accuracy and minimizes missed defects in casting parts. This method integrates advanced image preprocessing, network architecture improvements, and model fusion to achieve robust performance. In this paper, I detail the methodology, experimental validation, and results, emphasizing the use of formulas and tables to summarize key aspects. The goal is to provide a scalable solution for quality control in casting parts manufacturing.

The image above exemplifies a typical casting part inspected via DR technology, highlighting the need for precise defect detection. My approach begins with preprocessing casting parts DR images using guided filtering to enhance quality. Then, I modify the YOLOv3 network by incorporating a Spatial Pyramid Pooling (SPP) structure, extending multi-scale detection, and redesigning the loss function. Finally, I fuse this improved YOLOv3 with Faster RCNN and Cascade RCNN networks to create a hybrid model that excels in identifying multiple defect targets in casting parts. Experiments on a dataset of casting parts demonstrate that this fusion model achieves an average detection accuracy exceeding 97.5%, significantly reducing missed defects. Throughout this work, I focus on the unique challenges posed by casting parts, ensuring the method is tailored to their specific defect profiles.
Background and Motivation for Casting Parts Defect Detection
Casting parts are ubiquitous in engineering, formed through processes like sand casting or investment casting, where molten metal is poured into molds. Defects in casting parts can arise from various factors, including gas entrapment, solidification issues, or mold imperfections. These defects, if undetected, can propagate under stress, leading to catastrophic failures. For instance, in railway bolster casting parts, defects like cracks or pores can weaken the structure, risking derailments. Therefore, rigorous inspection of casting parts is essential. DR imaging offers a non-destructive way to visualize internal defects in casting parts by using X-rays to capture differential absorption patterns. However, DR images of casting parts often contain noise, low contrast, and artifacts that obscure defects. Manual inspection of these images is tedious and inconsistent, prompting the need for automated systems. Deep learning, particularly convolutional neural networks (CNNs), has revolutionized object detection by learning hierarchical features from data. Yet, standard models struggle with the multi-scale nature of defects in casting parts, where small pores and large shrinkage cavities coexist. My work aims to bridge this gap by refining deep learning algorithms specifically for casting parts defect detection, leveraging advances in network architecture and fusion strategies.
Image Preprocessing for Casting Parts DR Images
To improve the quality of casting parts DR images, I apply guided filtering, an edge-preserving smoothing technique. Let \( I \) denote the guidance image (often the original casting part DR image), and \( z \) represent the input image to be filtered. The filtered output \( \delta \) is computed as a locally linear model based on \( I \). For each pixel \( i \), the filter is expressed as:
$$ \delta_i = \sum_{j \in w_i} W_{ij}(I) z_j $$
where \( w_i \) is a local window centered at pixel \( i \), and \( W_{ij}(I) \) are weights derived from \( I \). These weights ensure that smoothing occurs while preserving edges, crucial for maintaining defect boundaries in casting parts. When \( z = I \), the filter reduces to an edge-preserving smoother. The weights are calculated using the mean and variance of \( I \) in \( w_i \):
$$ W_{ij}(I) = \frac{1}{|w|^2} \sum_{k \in w_i} \left(1 + \frac{(I_i – \mu_k)(I_j – \mu_k)}{\sigma_k^2 + \epsilon}\right) $$
Here, \( \mu_k \) and \( \sigma_k^2 \) are the mean and variance of \( I \) in window \( w_k \), and \( \epsilon \) is a regularization parameter. After smoothing, I enhance the casting parts image by extracting details via subtraction and amplification. The enhanced image \( I_e \) is given by:
$$ I_e = \alpha (I – \delta) + \delta $$
where \( \alpha \) is an amplification factor, typically set between 1.2 and 1.5 for casting parts images. This preprocessing boosts contrast and sharpens edges, making defects more discernible. To quantify the improvement, I measure metrics like peak signal-to-noise ratio (PSNR) and structural similarity index (SSIM) on casting parts datasets. Table 1 summarizes the effect of guided filtering on sample casting parts DR images.
| Image Set | Original PSNR (dB) | Processed PSNR (dB) | Original SSIM | Processed SSIM |
|---|---|---|---|---|
| Casting Parts Set 1 | 28.5 | 32.1 | 0.85 | 0.92 |
| Casting Parts Set 2 | 29.2 | 33.4 | 0.87 | 0.94 |
| Casting Parts Set 3 | 27.8 | 31.9 | 0.83 | 0.91 |
As shown, guided filtering significantly enhances casting parts images, providing a solid foundation for defect detection.
Improved YOLOv3 Network Architecture for Casting Parts
YOLOv3 is a real-time detection network that frames object detection as a regression problem. It divides the input image into an \( S \times S \) grid, with each grid cell predicting \( B \) bounding boxes and confidence scores. For casting parts defect detection, I enhance YOLOv3 in three ways: integrating SPP, extending multi-scale detection, and redesigning the loss function. These modifications address the multi-scale and subtle nature of defects in casting parts.
Spatial Pyramid Pooling (SPP) Integration
I insert an SPP structure between the fifth and sixth convolutional layers of YOLOv3. The SPP module includes parallel max-pooling layers with kernel sizes \( 5 \times 5 \), \( 9 \times 9 \), and \( 13 \times 13 \), along with a skip connection. This allows the network to pool features at multiple scales, generating a fixed-length representation regardless of input size. For casting parts images, this helps capture both local defect details and global context. The output of the SPP layer is concatenated and passed to subsequent layers. Mathematically, if \( F \) is the input feature map, the SPP output \( O_{\text{SPP}} \) is:
$$ O_{\text{SPP}} = \text{Concat}\left( \text{MaxPool}_{5 \times 5}(F), \text{MaxPool}_{9 \times 9}(F), \text{MaxPool}_{13 \times 13}(F), F \right) $$
This enriches feature representation for casting parts defects, improving detection robustness.
Multi-Scale Detection Network Enhancement
Standard YOLOv3 uses three detection scales at strides of 32, 16, and 8, corresponding to feature maps of size \( 13 \times 13 \), \( 26 \times 26 \), and \( 52 \times 52 \). To better detect tiny defects in casting parts, I add a fourth scale at stride 4, producing a \( 104 \times 104 \) feature map. This is achieved by upsampling the \( 52 \times 52 \) map and fusing it with earlier layer features. The multi-scale process is summarized in Table 2, highlighting the correspondence to defect sizes in casting parts.
| Scale ID | Feature Map Size | Stride | Target Defect Size in Casting Parts |
|---|---|---|---|
| Scale 1 | 13×13 | 32 | Large (e.g., shrinkage cavities >50px) |
| Scale 2 | 26×26 | 16 | Medium (e.g., cracks 20-50px) |
| Scale 3 | 52×52 | 8 | Small (e.g., pores 10-20px) |
| Scale 4 | 104×104 | 4 | Tiny (e.g., micro-pores <10px) |
Each scale predicts bounding boxes, confidence scores, and class probabilities for casting parts defects. The network architecture is detailed in Table 3, showing layer configurations tailored for casting parts images.
| Layer Type | Filters | Size/Stride | Output Dimension | Purpose for Casting Parts |
|---|---|---|---|---|
| Convolutional | 32 | 3×3/1 | 416x416x32 | Initial feature extraction |
| Convolutional + SPP | 64 | 3×3/2 | 208x208x64 | Multi-scale pooling |
| Upsample + Concat | – | – | 104x104x128 | Fuse for tiny defects |
| Detection Layer 1 | 255 | 1×1/1 | 13x13x255 | Large defect prediction |
| Detection Layer 2 | 255 | 1×1/1 | 26x26x255 | Medium defect prediction |
| Detection Layer 3 | 255 | 1×1/1 | 52x52x255 | Small defect prediction |
| Detection Layer 4 | 255 | 1×1/1 | 104x104x255 | Tiny defect prediction |
This enhanced network adapts to the diverse defect profiles in casting parts.
Loss Function Redesign for Casting Parts
The loss function guides network training by penalizing prediction errors. For casting parts defect detection, I modify the YOLOv3 loss to better handle coordinate regression and scale sensitivity. The overall loss \( L \) is:
$$ L = \lambda_{\text{coord}} L_{\text{coord}} + \lambda_{\text{obj}} L_{\text{obj}} + \lambda_{\text{noobj}} L_{\text{noobj}} + \lambda_{\text{class}} L_{\text{class}} $$
where \( \lambda \) terms are weighting factors. The coordinate loss \( L_{\text{coord}} \) computes errors in bounding box position and size. Let \( (x, y, w, h) \) denote the true box center and dimensions, and \( (\hat{x}, \hat{y}, \hat{w}, \hat{h}) \) the predictions. Using sigmoid for center offsets and exponential for dimensions, the predicted coordinates are:
$$ b_x = \sigma(\hat{x}) + c_x, \quad b_y = \sigma(\hat{y}) + c_y, \quad b_w = p_w e^{\hat{w}}, \quad b_h = p_h e^{\hat{h}} $$
Here, \( (c_x, c_y) \) is the grid offset, and \( (p_w, p_h) \) are prior dimensions. To reduce gradient instability from size variations in casting parts defects, I reformulate \( L_{\text{coord}} \) using a tangent-based term:
$$ L_{\text{coord}} = \sum_{i=0}^{S^2} \sum_{j=0}^{B} \mathbb{1}_{ij}^{\text{obj}} \left[ \left( \sigma(x_i) – \sigma(\hat{x}_i) \right)^2 + \left( \sigma(y_i) – \sigma(\hat{y}_i) \right)^2 \right] + \sum_{i=0}^{S^2} \sum_{j=0}^{B} \mathbb{1}_{ij}^{\text{obj}} \left[ \frac{ \left( \tan(\sqrt{w_i}) – \tan(\sqrt{\hat{w}_i}) \right)^2 }{ \tan(1) } + \frac{ \left( \tan(\sqrt{h_i}) – \tan(\sqrt{\hat{h}_i}) \right)^2 }{ \tan(1) } \right] $$
The objectness loss \( L_{\text{obj}} \) and no-object loss \( L_{\text{noobj}} \) use binary cross-entropy for confidence scores \( C \):
$$ L_{\text{obj}} = \sum_{i=0}^{S^2} \sum_{j=0}^{B} \mathbb{1}_{ij}^{\text{obj}} \left[ C_i \log(\hat{C}_i) + (1 – C_i) \log(1 – \hat{C}_i) \right] $$
$$ L_{\text{noobj}} = \sum_{i=0}^{S^2} \sum_{j=0}^{B} \mathbb{1}_{ij}^{\text{noobj}} \left[ C_i \log(\hat{C}_i) + (1 – C_i) \log(1 – \hat{C}_i) \right] $$
The classification loss \( L_{\text{class}} \) employs softmax cross-entropy over defect classes (e.g., pores, cracks, shrinkage) in casting parts:
$$ L_{\text{class}} = \sum_{i=0}^{S^2} \mathbb{1}_{i}^{\text{obj}} \sum_{c \in \text{classes}} p_i(c) \log(\hat{p}_i(c)) $$
This redesigned loss function stabilizes training and improves accuracy for casting parts defects.
Fusion Model for Casting Parts Defect Detection
To further enhance recall and precision, I fuse the improved YOLOv3 with Faster RCNN and Cascade RCNN networks. This fusion leverages the speed of YOLOv3 and the region-based accuracy of RCNN variants. The process involves training each network independently on preprocessed casting parts DR images, then combining their predictions during inference. Let \( M_1 \), \( M_2 \), and \( M_3 \) denote improved YOLOv3, Faster RCNN, and Cascade RCNN, respectively. For a test image of casting parts, each model outputs a set of detections \( D_k = \{ (b_i, s_i, c_i) \} \), where \( b_i \) is a bounding box, \( s_i \) the confidence score, and \( c_i \) the class. The fusion algorithm proceeds as follows:
- Compute pairwise Intersection over Union (IOU) between bounding boxes from different models. For boxes \( b_a \) and \( b_b \), IOU is defined as:
$$ \text{IOU}(b_a, b_b) = \frac{\text{Area}(b_a \cap b_b)}{\text{Area}(b_a \cup b_b)} $$ - If \( \text{IOU}(b_a, b_b) > \tau \) (threshold, e.g., 0.5), the boxes are considered the same defect in casting parts. The confidence scores are adjusted based on model weights \( w_k \), reflecting each model’s accuracy on casting parts data. The fused score \( s_f \) is:
$$ s_f = \sum_{k=1}^{3} w_k s_{i,k}, \quad \text{with} \quad \sum_{k} w_k = 1 $$ - The box with the highest fused score is retained, and its coordinates are averaged if needed.
- If IOU is below \( \tau \), all boxes are kept as separate detections, ensuring no defect in casting parts is missed.
The weights \( w_k \) are determined via cross-validation on casting parts validation sets. Table 4 shows typical values.
| Model | Weight \( w_k \) | Rationale for Casting Parts |
|---|---|---|
| Improved YOLOv3 | 0.4 | High recall for multi-scale defects |
| Faster RCNN | 0.3 | Precise localization for medium defects |
| Cascade RCNN | 0.3 | Robust classification for complex defects |
This fusion model capitalizes on the strengths of each network, providing comprehensive coverage for casting parts defects.
Experimental Setup and Dataset for Casting Parts
I evaluate the proposed method on a custom dataset of casting parts DR images, focusing on railway bolster casting parts. The dataset comprises 1200 images, each containing at least one defect type: pores, cracks, or shrinkage. Images are captured using a digital radiography system with parameters like 100 kVp tube voltage and 5 mA current, ensuring clarity for casting parts. The dataset is split into 960 images for training and 240 for testing, with annotations including bounding boxes and class labels. Data augmentation techniques—rotation, flipping, and contrast adjustment—are applied to increase diversity for casting parts training. Experiments are conducted on a system with an NVIDIA RTX 3080 GPU, using PyTorch 1.9.0. Training parameters include a learning rate of \( 10^{-3} \), weight decay of \( 5 \times 10^{-4} \), batch size of 16, and 6000 iterations. Performance metrics are average precision (AP), mean average precision (mAP) at IoU threshold 0.5, recall, and F1-score, all computed per defect class for casting parts. Baseline models include standard YOLOv3, Faster RCNN, and Cascade RCNN for comparison.
Results and Analysis on Casting Parts Defect Detection
The preprocessing step significantly enhances casting parts DR images, as quantified by PSNR and SSIM improvements (Table 1). This directly benefits defect detection. Training curves for the improved YOLOv3 network show rapid convergence, with loss stabilizing around 0.11 after 4000 iterations and average IoU reaching 0.85. These indicate effective learning for casting parts defects. Detection performance is summarized in Table 5, comparing various models on the casting parts test set.
| Model | AP Pores (%) | AP Cracks (%) | AP Shrinkage (%) | mAP (%) | Recall (%) | F1-Score |
|---|---|---|---|---|---|---|
| Standard YOLOv3 | 92.5 | 91.8 | 93.1 | 92.5 | 90.2 | 0.913 |
| Faster RCNN | 94.3 | 93.7 | 95.0 | 94.3 | 92.5 | 0.934 |
| Cascade RCNN | 95.1 | 94.5 | 95.8 | 95.1 | 93.8 | 0.944 |
| Improved YOLOv3 | 96.2 | 95.8 | 96.5 | 96.2 | 94.5 | 0.953 |
| Fusion Model | 97.8 | 97.5 | 97.9 | 97.7 | 96.8 | 0.972 |
The fusion model achieves the highest mAP of 97.7% and recall of 96.8%, demonstrating its superiority for casting parts defect detection. Notably, it excels in identifying tiny defects, reducing missed instances by over 15% compared to improved YOLOv3 alone. To delve deeper, I analyze performance by defect size in casting parts, as shown in Table 6.
| Defect Size in Casting Parts | Improved YOLOv3 Recall (%) | Fusion Model Recall (%) | Improvement |
|---|---|---|---|
| Large (>50px) | 98.2 | 98.5 | +0.3% |
| Medium (20-50px) | 96.8 | 97.9 | +1.1% |
| Small (10-20px) | 93.5 | 96.2 | +2.7% |
| Tiny (<10px) | 89.4 | 94.7 | +5.3% |
The fusion model shows substantial gains for small and tiny defects in casting parts, validating the multi-scale enhancements and fusion strategy. Qualitative results on sample casting parts images reveal that the fusion model accurately localizes and classifies multiple defects, whereas baselines may miss subtle ones. Additionally, I evaluate computational efficiency: the fusion model processes casting parts images at 22 frames per second (FPS) on the GPU, suitable for real-time inspection in production lines. The improved YOLOv3 alone runs at 35 FPS, but the fusion’s accuracy justifies the slight speed trade-off for casting parts quality control.
Discussion and Implications for Casting Parts Inspection
The proposed method addresses key challenges in casting parts defect detection: multi-scale variability, low contrast, and high precision requirements. The guided filtering preprocessing effectively enhances casting parts images without blurring defects, a common issue with Gaussian filters. The SPP integration and multi-scale extensions in YOLOv3 enable robust feature extraction across defect sizes, crucial for casting parts where defects range from microscopic pores to large cavities. The loss function redesign mitigates gradient issues from bounding box scale variations, stabilizing training for casting parts datasets. The fusion model synergizes YOLOv3’s recall with RCNNs’ precision, offering a balanced solution for casting parts inspection. However, limitations exist. The method depends on DR imaging, which may not be available for all casting parts manufacturers. Training requires annotated data, which can be scarce for rare defect types in casting parts. Future work could explore semi-supervised learning or generative adversarial networks to synthesize casting parts defect data. Moreover, extending the approach to 3D computed tomography (CT) images of casting parts could provide volumetric defect analysis. From an industrial perspective, this method can be integrated into automated inspection systems for casting parts, reducing reliance on human operators and improving throughput. It also aligns with Industry 4.0 trends, enabling data-driven quality assurance for casting parts production.
Conclusion
In this paper, I have presented an automated defect detection method for casting parts based on improved deep learning algorithms. The method combines guided filtering preprocessing, an enhanced YOLOv3 network with SPP and multi-scale detection, and a fusion model incorporating Faster RCNN and Cascade RCNN. Extensive experiments on casting parts DR images demonstrate that the fusion model achieves an average detection accuracy of over 97.5% with high recall, effectively identifying multiple defect targets while minimizing misses. The modifications to YOLOv3, particularly the loss function and scale additions, are tailored to the unique characteristics of casting parts defects. This work contributes to the field of non-destructive testing for casting parts, offering a scalable and accurate solution for industrial quality control. By leveraging advanced deep learning techniques, it paves the way for smarter manufacturing processes where casting parts are inspected with unprecedented precision and efficiency. Future directions include adapting the method to other materials and defect types, as well as optimizing for edge deployment in casting parts factories.
