Automatic Detection of Slag Inclusion Defects in Aluminum Melt Using Machine Learning

In aluminum alloy production, the presence of slag inclusion defects severely compromises the quality and performance of final products. These defects, arising from oxidation, gas absorption, and impurity entrapment during melting and casting, lead to increased scrap rates and reduced mechanical properties. Traditional methods for assessing slag inclusion levels, such as the K-mold test, rely on manual inspection of fracture surfaces, which is time-consuming, labor-intensive, and prone to human error. To address these challenges, I propose an automated detection system based on machine learning, specifically leveraging the YOLOv5 model, to accurately identify and quantify slag inclusion defects in aluminum melt samples. This approach not only enhances detection precision but also enables real-time quality control in industrial settings.

The core of this research revolves around optimizing target detection algorithms to handle the inherent uncertainties in slag inclusion imaging, such as variations in lighting, angle, and sample morphology. By integrating advanced image preprocessing, data augmentation techniques, and deep learning architectures, I have developed a robust framework that achieves high accuracy in slag inclusion detection. The system automatically calculates the slag inclusion rate, providing a reliable metric for melt quality assessment. In this article, I will detail the methodology, experimental setup, and results, emphasizing the improvements made to the YOLOv5 model and its application in reducing the negative feedback from environmental factors. The goal is to offer a scalable solution that can be deployed in foundries to streamline quality inspection processes.

Aluminum alloys are widely used in automotive, aerospace, and transportation industries due to their light weight, high strength, and corrosion resistance. However, the melt’s susceptibility to oxidation and inclusion formation poses significant challenges during casting. Slag inclusion defects, often consisting of oxides and non-metallic particles, can initiate cracks and reduce fatigue life, leading to product failures. Currently, methods like LiMCA, PoDFA, and Prefil-Footprinter offer quantitative analysis but are expensive and complex, limiting their use in high-volume production. The K-mold test remains popular for its simplicity and low cost, but its reliance on manual evaluation introduces inconsistencies. Therefore, automating this process with machine learning presents a promising avenue for improving efficiency and accuracy.

My work focuses on enhancing the YOLOv5 model to tackle specific issues in slag inclusion image analysis, such as noise interference and unclear defect boundaries. Through iterative optimization, I have achieved a significant boost in detection precision, paving the way for more reliable melt quality monitoring. The following sections will explore the K-mold detection technique, the principles of machine learning for target detection, the YOLOv5 model’s adaptations, and the experimental validation of the proposed system. By incorporating tables and formulas, I aim to provide a comprehensive overview of the technical details and performance metrics.

K-Mold Detection Technique and Its Limitations

The K-mold test is a standardized method for evaluating slag inclusion levels in aluminum melt. It involves pouring the melt into a K-shaped mold, allowing it to solidify, and then breaking the sample to produce five fracture surfaces. These surfaces are examined under a stereomicroscope to count and measure slag inclusion defects. The slag inclusion rate is calculated based on the size and quantity of defects, with weighted values assigned to different size categories. The formula for calculating the slag inclusion rate is:

$$ \text{Slag Inclusion Rate} = \frac{\sum_{i=1}^{5} \text{count}(i) \cdot X_i}{\text{Number of Fracture Surfaces}} $$

Here, \( i \) represents the slag inclusion size grade, \( \text{count}(i) \) is the number of inclusions in grade \( i \), and \( X_i \) is the weighting factor for that grade. The size grades and their corresponding weightings are summarized in the table below:

Slag Inclusion Size (μm) Grade Weighting Factor (\(X_i\))
(50, 100] I 0.1
(100, 500] II 0.5
(500, 800] III 1.0
(800, 1200] IV 1.5
(1200, ∞) V 2.0

Based on the calculated slag inclusion rate, the melt quality is classified into levels, as shown in the following table:

Slag Inclusion Rate (%) Quality Level
[0, 0.4] 1
(0.4, 0.8] 2
(0.8, 1.2] 3
(1.2, 1.8] 4
(1.8, 2.5] 5
(2.5, ∞) 6

Manual inspection of fracture images is subjective and inefficient, often resulting in missed defects or inaccurate measurements due to factors like poor lighting, oblique angles, and sample variability. This underscores the need for an automated system that can consistently detect slag inclusion defects across diverse conditions. In my approach, I leverage machine learning to overcome these limitations, aiming to achieve higher precision and faster processing times.

Machine Learning Foundations for Slag Inclusion Defect Detection

Machine learning, particularly deep learning, has revolutionized computer vision tasks, including object detection. For slag inclusion defect detection, the primary challenge lies in accurately locating and classifying defects within images that contain noise, uneven backgrounds, and ambiguous edges. Two-stage detectors like R-CNN offer high accuracy but are computationally intensive, while one-stage detectors like YOLO (You Only Look Once) provide a good balance between speed and precision, making them suitable for real-time industrial applications.

YOLOv5, an evolution of the YOLO series, incorporates several advancements such as Mosaic data augmentation, adaptive anchor box computation, and adaptive image scaling. Its architecture includes a Focus module for efficient downsampling and CSP (Cross Stage Partial) structures for enhanced feature extraction. These features make YOLOv5 robust for detecting small objects like slag inclusion defects, which often appear as dark regions against a metallic background. The model’s loss function combines bounding box regression and confidence loss, optimized through iterative training. The overall framework can be described as:

$$ \text{Output} = \text{Head}(\text{Backbone}(\text{Input})) $$

Where the Backbone extracts features, and the Head predicts bounding boxes and class probabilities. For slag inclusion defect detection, I selected YOLOv5s and YOLOv5m variants due to their trade-offs between speed and accuracy. However, direct application to slag inclusion images yielded suboptimal results due to the unique characteristics of these defects, necessitating custom optimizations.

The key issues in slag inclusion image analysis include: (1) noise from uneven fracture surfaces and lighting variations, and (2)模糊的缺陷边缘 that blend with the background. To address these, I implemented a preprocessing pipeline that enhances image quality before feeding them into the YOLOv5 model. This involves contrast adjustment, noise reduction, and edge sharpening techniques, which are detailed in the following section. By improving the input data, the model’s ability to distinguish slag inclusion defects from artifacts is significantly enhanced.

Optimized YOLOv5 Model for Slag Inclusion Defect Recognition

My optimized algorithm, referred to as YOLOv5so (for YOLOv5s optimized), builds upon the base YOLOv5s model with enhancements in image preprocessing and data augmentation. The process begins with collecting a dataset of K-mold fracture images. I used 100 samples, each producing five fracture surfaces, imaged at 16× magnification with a resolution of 2560×1920 pixels. From these, 500 images containing slag inclusion defects were selected for training and testing. The dataset was split into 80% for training and 20% for testing, using stratified sampling to ensure representative distribution of defect types.

Image preprocessing is critical for highlighting slag inclusion defects. I applied several spatial domain techniques to enhance contrast and reduce noise. The general transformation is given by:

$$ g(x, y) = f(x, y) \cdot h(x, y) $$

Where \( g(x, y) \) is the processed image, \( f(x, y) \) is the original image, and \( h(x, y) \) is a transformation function. For edge enhancement, I used gradient-based methods:

$$ G(i, j) = \sqrt{[f(i+1, j) – f(i, j)]^2 + [f(i, j+1) – f(i, j)]^2} $$

Among various algorithms, CLAHE (Contrast Limited Adaptive Histogram Equalization) proved most effective for slag inclusion images. CLAHE operates by dividing the image into tiles, applying histogram equalization to each, and then clipping and redistributing pixel intensities to avoid over-amplification. This process accentuates the dark slag inclusion defects against the brighter metal background, making them more distinguishable. After preprocessing, the images were annotated using LabelMe, with bounding boxes around each slag inclusion defect. The annotations were converted to YOLO format, where coordinates are normalized relative to image dimensions. The conversion formulas are:

$$ dw = \frac{1}{w_{\text{img}}}, \quad dh = \frac{1}{h_{\text{img}}} $$
$$ x = \frac{(x_2 + x_1)}{2} – 1, \quad y = \frac{(y_2 + y_1)}{2} – 1 $$
$$ w = x_2 – x_1, \quad h = y_2 – y_1 $$
$$ x_{\text{new}} = dw \cdot x, \quad y_{\text{new}} = dh \cdot y $$
$$ w_{\text{new}} = dw \cdot w, \quad h_{\text{new}} = dh \cdot h $$

Here, \( (x_1, y_1) \) and \( (x_2, y_2) \) are the top-left and bottom-right coordinates of the bounding box, and \( w_{\text{img}} \) and \( h_{\text{img}} \) are the image width and height. This normalization ensures consistency across different image sizes.

Data augmentation was employed to increase dataset diversity and prevent overfitting. Mosaic augmentation combines four images into one through random scaling, cropping, and拼接, introducing variations in scale and context. This technique is particularly beneficial for detecting small slag inclusion defects, as it creates more examples of such objects in varied backgrounds. The augmented images are then fed into the YOLOv5 model for training. The loss function used during training includes bounding box loss and confidence loss, which are minimized through backpropagation. The bounding box loss uses IoU (Intersection over Union) metrics, while confidence loss measures the accuracy of defect predictions.

To evaluate the model, I used standard metrics such as precision, recall, and mean Average Precision (mAP). Precision (\(P\)) is the ratio of true positives to all predicted positives, while recall (\(R\)) is the ratio of true positives to all actual positives. The F1 score balances both:

$$ P = \frac{TP}{TP + FP}, \quad R = \frac{TP}{TP + FN}, \quad F1 = \frac{2PR}{P + R} $$

Where \(TP\) is true positives, \(FP\) is false positives, and \(FN\) is false negatives. The mAP is computed at different IoU thresholds, typically 0.5 and 0.5:0.95, to assess overall detection performance. For slag inclusion defect detection, high precision is crucial to avoid false alarms, while high recall ensures that most defects are captured.

Experimental Setup and Training Results

The training was conducted on a dataset of 500 preprocessed and annotated images. I compared the base YOLOv5s model, the optimized YOLOv5so model, and the YOLOv5m model to evaluate improvements. Training parameters included a batch size of 16, 300 epochs, and an initial learning rate of 0.01, decayed using cosine annealing. The models were implemented in PyTorch and trained on an NVIDIA GTX 1080 Ti GPU. The performance metrics after training are summarized in the table below:

Model Precision Recall mAP@0.5 mAP@0.5:0.95
YOLOv5s 0.83 0.64 0.73 0.41
YOLOv5so (optimized) 0.97 0.76 0.81 0.42
YOLOv5m 0.92 0.75 0.77 0.43

The results show that YOLOv5so achieves the highest precision (97%), a significant improvement over the base model. This indicates that the optimizations in preprocessing and augmentation effectively reduce false positives. Recall also improved, meaning more slag inclusion defects are correctly identified. The mAP values reflect better overall detection accuracy, especially at higher IoU thresholds. The training curves for loss, precision, and recall over epochs demonstrate stable convergence, with YOLOv5so showing smoother trends compared to other models.

To further validate the model, I tested it on images captured under different lighting conditions to assess泛化能力. The model maintained high performance, detecting slag inclusion defects even in suboptimal environments. This robustness is essential for industrial deployment where conditions may vary. A comparison between manual and automated detection on five sample groups revealed that the automated system identified more defects, as manual inspection often missed small or faint slag inclusion defects. The table below presents a comparison of defect counts for one sample group:

Detection Method Grade I Grade II Grade III Grade IV Grade V Total Defects
Manual 2 7 0 0 0 9
Automated (YOLOv5so) 0 22 0 0 0 22

This discrepancy highlights the superiority of automated detection in capturing subtle slag inclusion defects. Moreover, the automated system provided more accurate measurements of defect sizes, leading to more reliable slag inclusion rate calculations. For instance, in one image, manual measurement reported a defect length of 456.57 μm, while YOLOv5so measured it as 479.96 μm, closer to the actual size. The slag inclusion rates computed by the automated system were consistently higher than manual calculations, as shown in the table below for five sample groups:

Sample Group Manual Slag Inclusion Rate (%) Automated Slag Inclusion Rate (%) Manual Quality Level Automated Quality Level
1 0.74 2.20 2 5
2 1.20 2.72 3 >5
3 0.52 1.04 2 3
4 1.40 2.02 4 5
5 1.10 1.10 3 3

These findings indicate that manual inspection tends to underestimate slag inclusion levels, potentially allowing defective melts to pass quality checks. The automated system, by contrast, provides a more accurate assessment, enabling better decision-making in production.

Discussion of Algorithm Enhancements and Performance

The success of YOLOv5so in slag inclusion defect detection can be attributed to several key optimizations. First, the CLAHE-based preprocessing enhances contrast and reduces noise, making defects more prominent. This addresses the issue of unclear edges that often plagues manual inspection. Second, Mosaic data augmentation increases the diversity of training samples, improving the model’s ability to generalize to new images. Third, the use of adaptive anchor boxes allows the model to better fit the varying sizes of slag inclusion defects, from small Grade I inclusions to large Grade V ones. These modifications collectively boost precision and recall.

Another important aspect is the model’s efficiency. YOLOv5so maintains fast inference times, processing images in milliseconds, which is crucial for real-time applications in foundries. Compared to two-stage detectors, it offers a better speed-accuracy trade-off. The integration of Focus and CSP structures reduces computational overhead while preserving feature richness, enabling effective detection of small slag inclusion defects. The loss function optimization also plays a role; by focusing on both bounding box accuracy and confidence, the model learns to localize defects precisely while minimizing false positives.

However, challenges remain. For example, extremely small slag inclusion defects (below 50 μm) may still be missed, as they fall outside the defined size grades. Future work could involve training on higher-resolution images or using multi-scale detection approaches to capture these fine defects. Additionally, the model’s performance on highly reflective or textured surfaces needs further testing. Despite these limitations, the current system represents a significant advancement over manual methods, offering a reliable tool for automated slag inclusion defect detection.

The implications for industry are substantial. By automating the K-mold test, foundries can reduce labor costs, increase throughput, and improve consistency in quality control. The system can be integrated into production lines, providing real-time feedback on melt quality and enabling timely adjustments to melting and refining processes. This not only enhances product quality but also reduces waste and energy consumption, contributing to more sustainable manufacturing.

Conclusion and Future Directions

In this study, I have developed an automated detection system for slag inclusion defects in aluminum melt using an optimized YOLOv5 model. The system addresses the limitations of manual inspection by leveraging machine learning to achieve high precision and robustness. Key contributions include: (1) an image preprocessing pipeline that enhances slag inclusion defect visibility through CLAHE and other techniques; (2) a data augmentation strategy using Mosaic to improve model generalization; and (3) optimizations to the YOLOv5 architecture that boost detection accuracy for small and模糊 defects. Experimental results demonstrate that YOLOv5so achieves 97% precision, a marked improvement over the base model’s 83%, and outperforms manual methods in defect identification and slag inclusion rate calculation.

The system’s ability to handle variable imaging conditions makes it suitable for industrial deployment. By automating the detection process, it reduces human error and provides objective, repeatable assessments of melt quality. Future research will focus on expanding the dataset to include more defect types and environmental variations, as well as exploring lightweight model versions for edge computing applications. Additionally, integrating this system with other sensing technologies could enable comprehensive melt quality monitoring, further advancing the foundry industry toward smart manufacturing.

In summary, this work underscores the potential of machine learning in transforming traditional quality control methods. By tackling the specific challenges of slag inclusion defect detection, I have shown that automated systems can deliver superior performance, paving the way for wider adoption in aluminum production and beyond. The techniques developed here may also be applicable to other material inspection tasks, highlighting the versatility of deep learning in industrial applications.

Scroll to Top