In the modern automotive industry, turbochargers have become an essential component for enhancing engine performance and achieving fuel efficiency. The growing demand for turbochargers directly increases the need for high-quality casting production. During the casting process, surface defects are almost inevitable due to complex interactions among temperature, humidity, sand quality, and cooling rate. These defects significantly impair the mechanical strength, fatigue life, and safety of the final products. However, most manufacturers still rely on manual visual inspection to identify and mark defects. This practice suffers from low efficiency, high labor costs, and inconsistent judgments among inspectors. Therefore, developing a fast and accurate intelligent detection algorithm is of great theoretical and practical value for the turbocharger industry. In this paper, I propose a deep learning based method for casting defect detection that can simultaneously localize and classify four common defect types appearing on turbocharger castings.
Through a comprehensive analysis of existing object detection algorithms, I select YOLOv3 as the baseline framework due to its outstanding balance between speed and accuracy, as well as its capability for multi-scale feature fusion. I then adapt the network by introducing a multi-path aggregation structure to enhance the propagation of shallow features, which is critical for detecting small and irregular casting defects. I also investigate appropriate image preprocessing and data augmentation techniques to improve the robustness of the trained model. Extensive experiments on a real-world dataset collected from a casting workshop demonstrate that the proposed algorithm achieves a recall of 97.9% and a precision of 96.7%, satisfying the industrial requirements. Finally, I design defect-specific post-processing steps for subsequent data analysis and record generation.
1. Introduction
Casting is one of the oldest metal forming processes in human history, and it remains a cornerstone of modern manufacturing. In the automotive sector, approximately 17% of all components are produced by casting, and the turbocharger is among the most critical ones. According to industry reports, the number of vehicles equipped with turbochargers in China is expected to reach 15.84 million in 2020. Thus, casting quality directly influences both the performance and the safety of these vehicles. Defects such as blow holes, gas pores, inclusions, and binder residue not only degrade the appearance but also weaken the structural integrity, potentially leading to catastrophic failures. Consequently, reliable and efficient defect detection is imperative.
Traditional defect detection methods heavily depend on hand-crafted features and rule-based classifiers. These methods require careful tuning and often fail when the appearance of defects varies significantly. With the rapid advancement of deep learning, convolutional neural networks (CNNs) have shown remarkable performance in various computer vision tasks, including object detection and semantic segmentation. In the field of industrial defect detection, deep learning methods have been successfully applied to concrete cracks, steel surfaces, wood veneers, and photovoltaic cells. These successes motivate me to adopt a deep learning based approach for turbocharger casting defects.
In this work, I focus on four types of casting defects: blow (呛火), hole (气孔), inclusion (渣眼), and binder residue (掉胶). These defects appear frequently on the surface of turbocharger castings and have distinctive morphological characteristics. The main contributions of this paper are summarized as follows:
- I propose a systematic image preprocessing and data augmentation pipeline that reduces the influence of noise and effectively expands a small dataset using a label-aware random cropping strategy.
- I improve the YOLOv3 detection network by incorporating multi-path aggregation, which strengthens the fusion of features across different scales and reduces information loss during the propagation from shallow layers to deep layers.
- I adopt transfer learning with a two-stage training scheme and refine the position regression evaluation using CIoU as well as label smoothing for classification loss, resulting in optimized training convergence.
- I verify the proposed algorithm on a real-world turbocharger casting defect dataset, demonstrating that it meets the required technical indicators: recall above 95%, precision above 95%, and detection speed under 1 second per image.
- I design defect-specific post-processing methods based on the appearance characteristics of each defect type, which facilitate subsequent defect recording and data analytics.
2. Theoretical Foundations
2.1 Multilayer Perceptron and Backpropagation
The multilayer perceptron (MLP), also known as an artificial neural network, is the fundamental architecture of deep learning. It consists of an input layer, one or more hidden layers, and an output layer. Each neuron in a layer is connected to every neuron in the next layer via weighted connections. The output of a single neuron can be expressed as:
$$ O_{\omega,b}(\mathbf{x}) = f\left(\sum_{n=1}^{N} \omega_n x_n + b\right), $$
where $\mathbf{x}$ is the input vector, $\omega_n$ are the weights, $b$ is the bias, and $f(\cdot)$ is a nonlinear activation function. The backpropagation (BP) algorithm, introduced by Rumelhart et al., is the key learning algorithm used to train such networks. BP computes the gradient of the loss function with respect to every weight by the chain rule and updates the parameters to minimize the total error.
2.2 Convolutional Neural Networks
A convolutional neural network (CNN) is a specialized type of neural network designed for processing grid-structured data such as images. CNNs exploit the spatial locality and weight sharing to drastically reduce the number of parameters compared with fully connected networks. The main components of a CNN are described below.
Convolutional layers: A convolutional kernel (filter) slides over the input feature map, performing element-wise multiplication and summation to produce an output feature map. For a 5×5 input with a 3×3 kernel and stride 1, the output size becomes 3×3. The convolution operation enables the network to learn local patterns such as edges, textures, and shapes.
Nonlinear activation layers: Activation functions introduce nonlinearity into the network. The Rectified Linear Unit (ReLU) is widely used due to its simplicity and effectiveness:
$$ \text{ReLU}(x) = \max(0, x). $$
ReLU helps mitigate the vanishing gradient problem and accelerates convergence.
Pooling layers: Pooling performs down-sampling by aggregating local regions. The most common operations are max pooling and average pooling. For a 2×2 pooling window with stride 2, the output is half the spatial size of the input. Pooling increases the receptive field and provides a certain degree of translation invariance.
Fully connected layers: These layers act as classifiers at the end of a CNN. They transform the learned feature maps into a vector and map it to the desired output space, such as class probabilities.
Batch normalization: Batch normalization (BN) normalizes the activations of each mini-batch to have zero mean and unit variance, which stabilizes training and allows higher learning rates. The scaled and shifted output is given by:
$$ y^{(k)} = \gamma^{(k)} \hat{x}^{(k)} + \beta^{(k)}, $$
where $\gamma^{(k)}$ and $\beta^{(k)}$ are learnable parameters.
2.3 Two-Stage Object Detection Algorithms
Object detection involves both classification and localization. Traditional sliding window methods are computationally prohibitive. Two-stage detectors first generate region proposals and then classify them. The R-CNN family represents this paradigm.
R-CNN uses selective search to generate about 2,000 candidate regions, resizes them, and feeds each through a CNN followed by an SVM classifier. It outperformed classical methods but was slow due to redundant computations.
Fast R-CNN improved R-CNN by performing a single forward pass on the entire image and using an ROI pooling layer to extract fixed-length features for each proposal. Nevertheless, region proposal generation still relied on selective search, which was a bottleneck.
Faster R-CNN introduced a Region Proposal Network (RPN) that runs in parallel with the detection network. RPN uses anchor boxes to predict whether a region contains an object and refines its coordinates. This made the detector fully trainable in an end-to-end manner and significantly accelerated inference.
2.4 One-Stage Object Detection Algorithms
One-stage detectors skip the region proposal step and directly predict class probabilities and bounding box coordinates from the input image. They are generally faster and more suitable for real-time applications.
SSD (Single Shot MultiBox Detector) predicts objects from multiple feature maps of different resolutions. It applies a set of default anchors to each feature map cell, covering a wide range of scales and aspect ratios.
YOLO (You Only Look Once) treats detection as a regression problem. The original YOLO divides the image into an S by S grid and predicts bounding boxes and class probabilities for each grid cell. YOLOv2 introduced anchor boxes and batch normalization, achieving better accuracy and speed. YOLOv3 further improved the architecture by using a deeper backbone network (Darknet53) and introducing a feature pyramid network (FPN) for multi-scale predictions.
2.5 Comparison of Mainstream Detectors
To choose a suitable baseline for casting defect detection, I compare several mainstream object detectors in terms of backbone parameters, accuracy on COCO, and multi-scale handling strategy. Table 1 summarizes these aspects.
| Category | Algorithm | Backbone | Parameters (M) | COCO mAP50 | Multi-scale handling |
|---|---|---|---|---|---|
| Two-stage | Faster R-CNN | ResNet-101 | 44.7 | 55.7 | None |
| Faster R-CNN (FPN) | ResNet-101 | 44.7 | 59.1 | Multi-scale feature fusion | |
| One-stage | YOLOv2 | Darknet-19 | 20.8 | 44.0 | Fine-grained features |
| YOLOv3 | Darknet-53 | 40.6 | 55.3 | Multi-scale feature fusion | |
| SSD300 | VGG16 | 22.9 | 41.2 | Multi-layer detection | |
| SSD513 | ResNet-101 | 44.7 | 50.4 | Multi-layer detection | |
| DSSD | ResNet-101 | 44.7 | 53.3 | Deconvolution fusion |
From Table 1, YOLOv3 offers competitive accuracy, fewer parameters, and a good balance between speed and precision. Its FPN structure is especially beneficial for detecting objects with a wide range of sizes, which is typical for casting defects. Therefore I choose YOLOv3 as the baseline and improve its network according to the specific characteristics of turbocharger casting defects.
3. Image Preprocessing and Data Augmentation
3.1 Research Object and Defect Types
The turbocharger is a type of air compressor that increases the engine intake air density. It operates under high-speed rotation and harsh thermal conditions, making its casting quality extremely critical. The typical product is shown in Figure 1.

Based on field surveys in a casting workshop, four frequent and severe defect types are selected for this study:
- Blow: large, highly irregular voids caused by gas accumulation during solidification. These defects appear as rough holes and usually make the casting unusable.
- Hole: small spherical or nearly spherical pores resulting from entrapped gases. They often have smooth inner walls and appear as dark spots after shot blasting.
- Inclusion: irregular depressions or cavities left by slag or sand particles. They always lead to product rejection.
- Binder residue: shallow circular depressions caused by excess adhesive from sand cores. Their surfaces are smooth and match the surrounding material in color.
The detection requirements for turbocharger casting defects are as follows:
- The algorithm must detect all four defect types simultaneously.
- The recall rate should be above 95%.
- The precision rate should be above 95%.
- The processing time per image should be less than one second.
3.2 Image Denoising
Images captured in a casting workshop inevitably contain noise from dust, thermal fluctuations, and electromagnetic interference. To mitigate these effects, I evaluated five widely used denoising algorithms: median filtering, Gaussian filtering, mean filtering, bilateral filtering, and two-dimensional discrete cosine transform (DCT). Each algorithm has its own strengths and limitations. I compared their performance using peak signal-to-noise ratio (PSNR) and structural similarity index (SSIM). PSNR is defined as:
$$ \mathrm{PSNR} = 10 \log_{10} \left( \frac{\mathrm{MAX}^2}{\mathrm{MSE}} \right), $$
where MAX is the maximum pixel value and MSE is the mean squared error between the original and processed images. SSIM measures the luminance, contrast, and structural similarities. I randomly selected 20 images from the dataset and computed the average metrics. The processing time was also recorded. Table 2 lists the comparative results.
| Method | PSNR (dB) | SSIM | Average time (s) |
|---|---|---|---|
| Median filter | 34.499 | 0.812 | 0.870 |
| Gaussian filter | 35.715 | 0.925 | 0.150 |
| Mean filter | 34.057 | 0.801 | 0.165 |
| Bilateral filter | 38.572 | 0.963 | 0.346 |
| Discrete cosine transform | 37.917 | 0.959 | 2.046 |
The bilateral filter achieved the highest PSNR and SSIM values while maintaining a reasonable processing time. Unlike the DCT method, it does not require expensive spatial-frequency transformations. Therefore I chose bilateral filtering as the preprocessing step for all defect images.
3.3 Data Annotation and Enhancement
Deep learning models require a large number of labeled samples. However, collecting and labeling thousands of images from a real production line is time-consuming and expensive. I initially gathered 304 images containing various defects. To increase the diversity of the dataset, I employed both geometric and color-space transformations.
First, I annotated each image using the Labelimg tool, which generates XML files in the Pascal VOC format. The XML file records the image name, size, defect category, and bounding box coordinates.
For geometric augmentation, I performed horizontal/vertical flips, 90-degree rotations, and a novel random cropping strategy based on prior annotation information. The principle is illustrated as follows: given all ground-truth bounding boxes, I compute the bounding rectangle that covers all defects. Then I select a random crop window that fully contains this rectangle, ensuring that no defect is truncated or lost. This approach simultaneously achieved cropping and translation, effectively increasing the diversity of object positions and image sizes.
Mathematically, let the top-left and bottom-right corners of the bounding rectangle be $(x_{\min}, y_{\min})$ and $(x_{\max}, y_{\max})$. I choose random points $(x_1, y_1)$ within the left/top margin region and compute the side length $l$ of the square crop as follows:
$$ x_1 = \alpha \cdot x_{\min}, \quad 0 < \alpha < 1, $$
$$ y_1 = \beta \cdot y_{\min}, \quad 0 < \beta < 1, $$
$$ l_{\max} = \min(x_0 – x_1, y_0 – y_1), $$
$$ l_{\min} = \max(x_1 – x_{\max}, y_1 – y_{\max}), $$
where $(x_0, y_0)$ is the upper-left corner of the original image. This method guarantees that the cropped region contains all defect instances while providing random variations in scale and position.
For color-space augmentation, I adjusted brightness, contrast, hue, saturation, and value in both RGB and HSV spaces. The brightness and contrast operations are expressed as:
$$ g(x,y) = a \cdot f(x,y) + b, $$
where $a$ controls contrast and $b$ controls brightness. In HSV space, I applied random perturbations to hue (H), saturation (S), and value (V):
$$ H'(x,y) = H(x,y) + h, $$
$$ S'(x,y) = S(x,y) \cdot s, $$
$$ V'(x,y) = V(x,y) \cdot v. $$
Through these augmentations, I expanded the dataset to 2,192 training/validation images and 240 test images. Figure 2 shows examples of the color transformations.
4. Proposed Detection Algorithm and Training
4.1 Backbone Network
The backbone network, Darknet53, is retained from YOLOv3. It consists of 53 convolutional layers and uses residual connections to enable training of a deep network. The architecture is listed in Table 3.
| Type | Filters | Size/Stride | Output |
|---|---|---|---|
| Convolutional | 32 | 3×3 | 416×416 |
| Convolutional | 64 | 3×3/2 | 208×208 |
| Residual block ×1 | 32 | 1×1 | 208×208 |
| 64 | 3×3 | ||
| Convolutional | 128 | 3×3/2 | 104×104 |
| Residual block ×2 | 64 | 1×1 | 104×104 |
| 128 | 3×3 | ||
| Convolutional | 256 | 3×3/2 | 52×52 |
| Residual block ×8 | 128 | 1×1 | 52×52 |
| 256 | 3×3 | ||
| Convolutional | 512 | 3×3/2 | 26×26 |
| Residual block ×8 | 256 | 1×1 | 26×26 |
| 512 | 3×3 | ||
| Convolutional | 1024 | 3×3/2 | 13×13 |
| Residual block ×4 | 512 | 1×1 | 13×13 |
| 1024 | 3×3 |
4.2 Multi-Path Aggregation Detection Network
YOLOv3 uses a feature pyramid network (FPN) to combine three scales: 13×13, 26×26, and 52×52. However, the original FPN only transfers deep semantic information to shallow layers. For casting defects, edge and texture information from shallow layers is critical, especially for small or irregular defects. To improve the transmission of shallow features, I adopt a multi-path aggregation network inspired by PANet. The modified detection network is shown in Figure 3.
The multi-path aggregation structure adds a bottom-up path augmentation after the FPN. The features from the 52×52 scale are first processed and then aggregated into the 26×26 scale, and finally into the 13×13 scale. This creates a shorter path for shallow information to reach the deepest prediction layer, thereby reducing information loss. The number of convolutional layers between the topmost and bottommost feature maps is reduced to 20 in this design.
To control the increase in parameters, I employ depthwise separable convolutions for the down-sampling operations in the added paths. Depthwise separable convolutions factorize a standard convolution into a depthwise convolution and a pointwise convolution. The parameter count for a standard convolution is $H \times W \times C \times N$, whereas the depthwise separable version has $H \times W \times C + C \times N$ parameters, where $C$ is the number of input channels and $N$ is the number of output channels. This significantly reduces computational cost.
4.3 Loss Function and Position Regression
During training, the loss function measures the discrepancy between predictions and ground truths. YOLOv3 separates the loss into four components: bounding box coordinate loss, width/height loss, confidence loss, and classification loss. The box coordinate loss is:
$$ \mathcal{L}_{xy} = \sum_{i=0}^{M} \sum_{j=0}^{N} \mathbb{1}_{ij}^{obj} C_{wh}^{ij} \left[ \mathrm{CE}(x_i, \hat{x}_i) + \mathrm{CE}(y_i, \hat{y}_i) \right], $$
where $C_{wh}^{ij}$ is the scale factor based on box size, and $\mathrm{CE}$ denotes binary cross entropy. The width and height loss is:
$$ \mathcal{L}_{wh} = \sum_{i=0}^{M} \sum_{j=0}^{N} \mathbb{1}_{ij}^{obj} \frac{1}{2} \left[ (w_i – \hat{w}_i)^2 + (h_i – \hat{h}_i)^2 \right]. $$
The confidence and classification losses are also binary cross-entropy terms, with separate handling for objectness and no-objectness boxes.
To better evaluate the location accuracy, I replace the standard IoU with the Complete IoU (CIoU) when determining whether a predicted box matches a ground truth. CIoU considers three geometric factors: overlap area, center distance, and aspect ratio. It is defined as:
$$ \mathrm{CIoU} = \mathrm{IoU} – \frac{\rho^2}{c^2} – \alpha v, $$
where $\rho$ is the Euclidean distance between the centers of two boxes, $c$ is the diagonal length of the smallest enclosing box, and $v$ measures the consistency of aspect ratios:
$$ v = \frac{4}{\pi^2} \left( \arctan \frac{w_A}{h_A} – \arctan \frac{w_B}{h_B} \right)^2, $$
$$ \alpha = \frac{v}{(1 – \mathrm{IoU}) + v}. $$
Using CIoU provides a more accurate gradient for bounding box regression, especially when the predicted box has no overlap with the ground truth.
Additionally, I employ label smoothing for the classification loss to prevent the model from becoming overconfident. The smoothed label is:
$$ l_k = (1 – \epsilon) y_k + \frac{\epsilon}{K}, $$
where $y_k$ is the original one-hot label, $K$ is the number of classes, and $\epsilon$ is the smoothing parameter. This regularization improves generalization on small datasets.
4.4 Training Strategy
Since the dataset is relatively small, I adopt a transfer learning strategy. The entire training procedure consists of two stages:
- Stage 1: Load the pretrained Darknet53 weights, freeze the backbone layers, and only fine-tune the detection head for 5 epochs with a batch size of 24.
- Stage 2: Unfreeze the entire network and train all layers with a smaller batch size of 4. The learning rate is initially set to a higher value and is reduced by a factor of 10 whenever the validation loss does not improve for 3 consecutive epochs. An early-stopping mechanism stops training when the validation loss has not decreased for 15 epochs.
The learning rate schedule is illustrated in Figure 4. The training platform consisted of an Intel i7-8700 CPU, an NVIDIA GTX 1060 (6 GB) GPU, Python, and Keras.
4.5 Experimental Results
First, I investigated the influence of dataset size on the performance. I trained the proposed algorithm on datasets of 1,096, 1,644, and 2,192 images, with 11% of samples used for validation. The results are listed in Table 4.
| Number of images | Stopping epoch | mAP (IoU=0.5) |
|---|---|---|
| 1,096 | 47 | 89.94% |
| 1,644 | 58 | 95.25% |
| 2,192 | 64 | 97.66% |
As expected, a larger dataset leads to better mAP, although the improvement from 1,644 to 2,192 is less significant because data augmentation does not create completely new information.
For the final evaluation, I used 1,952 training images, 240 validation images, and 240 test images. The test set contained 140 binder residue defects, 112 holes, 111 blows, and 60 inclusions. I compared the proposed multi-path aggregation network with the original YOLOv3. Table 5 reports the recall and precision for each defect type at an IoU threshold of 0.5 and a confidence threshold of 0.3.
| Defect type | YOLOv3 recall | Proposed recall | YOLOv3 precision | Proposed precision |
|---|---|---|---|---|
| Binder residue | 98.6% | 97.9% | 93.9% | 97.9% |
| Hole | 90.2% | 97.3% | 89.4% | 92.4% |
| Blow | 95.5% | 98.2% | 93.0% | 100.0% |
| Inclusion | 95.0% | 98.3% | 91.9% | 96.7% |
| Total | 95.0% | 97.9% | 92.2% | 96.7% |
The proposed algorithm outperforms the baseline in both recall and precision, especially for the small and irregular defects (holes and blows). The mean Average Precision (mAP) comparison is shown in Figure 5. The proposed algorithm improves mAP by 3.66% over the original YOLOv3.
In terms of efficiency, Table 6 lists the parameter count and inference time. Although the proposed network has more parameters due to the additional paths, the use of depthwise separable convolutions limits the increase to 22.8%. The inference time is only 0.313 seconds per image, which is still well within the industrial requirement of 1 second.
| Model | Total parameters | Trainable parameters | Inference time (s) |
|---|---|---|---|
| YOLOv3 | 61,592,497 | 61,539,889 | 0.297 |
| Proposed | 75,630,769 | 75,565,105 | 0.313 |
A visualization of the detection result on a test image is shown in Figure 6, where each defect is enclosed by a colored bounding box with its category and confidence score. The algorithm successfully identifies all visible defects with high confidence.
5. Post-Processing of Defect Images
After obtaining the detection results, further processing is often required for defect repair, process analysis, and constructing defect databases. Because the four defect types differ significantly in shape and boundary characteristics, I designed tailored post-processing methods for each type.
5.1 Post-Processing for Binder Residue and Hole
Binder residue and hole defects typically appear as circular or nearly circular regions. Binder residue has a smooth but blurred boundary due to the similar color between the defect and the surrounding metal surface. Therefore, I use image morphology and a minimum enclosing circle to extract the defect region. The process is as follows:
- Crop the detected bounding box from the original image to isolate the defect area.
- Convert the cropped RGB image to grayscale.
- Apply Otsu’s thresholding to obtain a binary mask.
- Perform morphological erosion and dilation to refine the contour.
- Extract the largest contour and fit a minimum enclosing circle.
For hole defects, the boundary is usually sharp and dark. I use a Laplacian-based sharpening operator followed by Canny edge detection. Then a Hough transform is applied to fit the circular shape. The complete procedures are summarized in Table 7.
| Step | Binder residue | Hole | Blow | Inclusion |
|---|---|---|---|---|
| Grayscale conversion | ✓ | ✓ | ✓ | ✓ |
| Contrast enhancement | ✓ | ✓ | ✓ | |
| Edge sharpening | ✓ | |||
| Thresholding (Otsu) | ✓ | ✓ | ✓ | ✓ |
| Edge detection | ✓ | |||
| Morphological operations | ✓ | ✓ | ✓ | |
| Largest contour extraction | ✓ | ✓ | ✓ | |
| Minimum enclosing circle | ✓ | |||
| Hough transform | ✓ |
5.2 Post-Processing for Blow and Inclusion
Blow and inclusion defects tend to be large and irregular in shape, so circular fitting is not appropriate. For these defects, I enhance the contrast of the grayscale image, convert it to a binary image via Otsu thresholding, apply morphological operations to suppress noise, and then extract the largest contour. The extracted contour outlines the exact defect region. After coordinate transformation, the segmentation result can be overlaid on the original image. This process is illustrated in Figure 7.
These post-processing steps not only aid in quantitative defect analysis but also provide a basis for automatic labeling and data augmentation in future semantic segmentation tasks.
6. Conclusion
In this paper, I have presented a deep learning based algorithm for the detection of casting defects on turbocharger surfaces. The main contributions are summarized as follows:
- A comprehensive comparison of different image denoising methods demonstrated that the bilateral filter provides the best trade-off between noise reduction and processing speed. A label-aware random cropping method and color-space transformations were used to augment a small dataset, enabling effective training of a deep detection network.
- I improved the YOLOv3 detector by introducing a multi-path aggregation network that enhances the flow of shallow features to deeper prediction layers. This modification significantly improves the detection of small and irregular casting defects.
- I incorporated CIoU for location regression and label smoothing for classification loss, which stabilized the training process and improved generalization.
- The proposed algorithm achieves a total recall of 97.9% and a total precision of 96.7%, surpassing the original YOLOv3 by 2.9% and 4.5% respectively. The inference time of 0.313 seconds per image satisfies the real-time requirement.
- Defect-specific post-processing methods were designed based on the appearance characteristics of each defect type, facilitating subsequent defect recording and analysis.
In future work, I plan to explore generative models for further data augmentation to address class imbalance, and to extend the proposed method to other industrial inspection tasks such as machining defects and painting defects. Additionally, model compression and knowledge distillation could be investigated to reduce the computational burden and enable deployment on edge devices.
