Machine Learning-Based Automated Detection of Slag Inclusions in Aluminum Melts

The pursuit of lightweight, high-strength, and corrosion-resistant materials has positioned aluminum alloys as critical components in modern industries such as automotive, aerospace, and transportation. However, the very properties that make aluminum advantageous—its high affinity for oxygen and gases—render its melt highly susceptible to the formation of non-metallic inclusions during the melting and casting processes. The presence of these slag inclusions is a primary cause of defects in final products, significantly impacting both surface finish and internal structural integrity. It is estimated that approximately 70% of scrap in aluminum production originates from the melting and casting stage. Consequently, the accurate quantification of slag content has become an indispensable metric for assessing molten aluminum quality and ensuring downstream product performance.

Traditionally, methods for inclusion assessment have ranged from highly sophisticated laboratory techniques to simpler foundry-floor tests. Advanced methods like the Liquid Metal Cleanliness Analyzer (LiMCA) can quantitatively detect inclusions as small as 15 micrometers, while techniques such as Prefil-Footprinter and PoDFA involve filtering the melt and analyzing the captured particles via scanning electron microscopy. Although these methods offer high precision, their complexity, stringent operational requirements, and high cost make them impractical for routine, high-volume production monitoring. In contrast, the K-mold test has gained widespread adoption in foundries due to its simplicity, low cost, and suitability for on-the-spot analysis. The procedure involves pouring a sample of the treated molten aluminum into a specially designed multi-cavity mold. Once solidified, the specimen is broken along pre-defined notches to reveal five distinct fracture surfaces. These surfaces are then examined, typically under a stereomicroscope, to manually identify, count, and measure the visible slag inclusions.

The critical step in the K-mold test is the calculation of an “Inclusion Rating,” which classifies the melt quality. This is achieved by first categorizing each detected inclusion based on its size and assigning it a corresponding weighted value. The overall rating for the sample is then computed using the following formula:

$$ \text{Inclusion Rating} = \frac{\sum_{i=1}^{5} ( \text{Count}(i) \cdot W_i )}{\text{Number of Fractures}} $$

Where \( i \) represents the inclusion size grade (I to V), \( \text{Count}(i) \) is the number of inclusions belonging to grade \( i \), and \( W_i \) is the predetermined weight for that grade. The standard size-grade-weight correspondence is detailed in the table below.

Inclusion Size (µm) Grade Weight (Wi)
(50, 100] I 0.1
(100, 500] II 0.5
(500, 800] III 1.0
(800, 1200] IV 1.5
>1200 V 2.0

The final calculated Inclusion Rating is compared against a standard scale to determine the melt’s cleanliness level, ranging from Grade 1 (best) to Grade 6 (worst). Despite its practical advantages, the conventional K-mold test suffers from significant drawbacks rooted in its reliance on manual inspection. The process of visually identifying and measuring slag inclusions on fracture surfaces is inherently subjective, time-consuming, and prone to human error, especially when dealing with high sample throughput. Factors such as variable lighting conditions, subtle contrast between inclusions and the metal matrix, and inspector fatigue lead to inconsistent results, undermining the reliability of the quality assessment. This manual bottleneck presents a clear opportunity for automation through machine vision and machine learning.

The core challenge of automating the detection of slag inclusions lies in the complex nature of the captured images. The fracture surfaces are non-uniform, textured, and often contain scratches, oxide films, or other artifacts that act as noise, obscuring the true boundaries of the slag inclusions. Furthermore, the contrast between the dark, often irregularly shaped inclusions and the metallic background can be low, and edges can be fuzzy, making precise feature extraction difficult. Traditional computer vision algorithms based on simple thresholding or edge detection consistently fail under these variable conditions. This is where data-driven machine learning, particularly deep learning-based object detection, offers a robust solution. By learning the distinguishing features of slag inclusions from a large set of labeled examples, a model can learn to generalize and accurately locate and classify these defects despite the challenging image conditions.

Object detection architectures are broadly classified into two-stage and one-stage detectors. Two-stage detectors (e.g., R-CNN, Faster R-CNN) first generate region proposals and then classify and refine them. While generally accurate, they are computationally heavy and slower. For industrial applications requiring real-time or high-throughput analysis, one-stage detectors that perform localization and classification in a single pass are preferred. Among these, the YOLO (You Only Look Once) family has emerged as a leading framework due to its excellent balance between speed and accuracy. After evaluating various models, YOLOv5 was selected as the foundation for this project. Its architecture incorporates several advancements that make it highly effective: an input module using Mosaic data augmentation and adaptive image scaling; a backbone network combining Focus and Cross Stage Partial (CSP) structures for efficient feature extraction; and a neck and head designed for multi-scale prediction. A comparative analysis of models trained on the COCO dataset clearly shows YOLOv5’s superior performance, offering a significantly higher mean Average Precision (mAP) and faster processing speed than contemporaries like SSD, making it ideal for the rapid detection of slag inclusions.

The initial phase of developing a reliable detection system involved meticulous data collection and preprocessing. A dataset of 500 high-resolution (2560×1920 px) images of K-mold fracture surfaces was acquired using a stereomicroscope at 16x magnification. To train and evaluate the model effectively, this dataset was split into training (80%) and testing (20%) sets using stratified sampling. This method ensures that both sets contain a representative distribution of different inclusion sizes and types, preventing bias and improving the model’s generalization capability. The raw images presented several challenges: uneven illumination, low contrast around inclusion edges, and background texture noise. To enhance the features relevant to slag inclusions and suppress irrelevant information, a series of spatial domain image processing techniques were applied. These include point operations like histogram equalization and contrast-limited adaptive histogram equalization (CLAHE), as well as neighborhood operations for sharpening. The CLAHE algorithm proved particularly effective. It works by dividing the image into tiles, applying histogram equalization to each, and then clipping the histogram to limit amplification of noise before redistributing the clipped pixels. The transformation can be described as enhancing the local contrast. If \( f(x, y) \) is the original image pixel value, the CLAHE process generates an enhanced image \( g(x, y) \) where the local histogram in a region around \( (x, y) \) is manipulated to stretch contrast. The result was a significant improvement in image quality; the once subtle slag inclusions became more distinctly separated from the metal matrix, with sharper edges and better-defined boundaries, providing a much cleaner input for the neural network.

Following enhancement, the critical task of labeling was performed. Each slag inclusion in every training image was manually annotated by drawing bounding boxes around them and assigning the correct size grade label. These annotations were initially saved in a JSON format and then programmatically converted to the TXT format required by YOLOv5. The conversion involves normalizing the bounding box coordinates relative to the image dimensions. For a bounding box with top-left coordinates \( (x_1, y_1) \) and bottom-right coordinates \( (x_2, y_2) \) in an image of width \( W_{img} \) and height \( H_{img} \), the YOLO-formatted center coordinates \( (x_{center}, y_{center}) \) and normalized width \( w \) and height \( h \) are calculated as:

$$ x_{center} = \frac{(x_1 + x_2)}{2W_{img}}, \quad y_{center} = \frac{(y_1 + y_2)}{2H_{img}} $$
$$ w = \frac{(x_2 – x_1)}{W_{img}}, \quad h = \frac{(y_2 – y_1)}{H_{img}} $$

To combat the risk of overfitting—where a model performs well on training data but poorly on new, unseen data—and to improve the model’s robustness, aggressive data augmentation was employed. The Mosaic augmentation technique, a hallmark of YOLOv5’s training pipeline, was instrumental. This method randomly selects four training images, resizes them, and stitches them together into a single composite image. The corresponding bounding boxes are adjusted accordingly. This effectively increases the batch size and, more importantly, exposes the model to a wider variety of contexts and scales within a single forward pass. It is especially beneficial for detecting small slag inclusions, as the random scaling creates many more “small object” scenarios than present in the original dataset. The model thus learns to recognize inclusions under diverse conditions of scale and spatial arrangement.

Building upon the standard YOLOv5 framework, two model variants were explored and optimized: YOLOv5s (small) and YOLOv5m (medium). The ‘s’ variant is faster and has a smaller model size, while the ‘m’ variant has more network depth and parameters, potentially offering higher accuracy at the cost of speed. The optimized versions, termed YOLOv5so and YOLOv5mo, incorporated the specific preprocessing and augmentation strategies tailored for slag inclusion images. The training process was monitored using key performance metrics. Precision measures the accuracy of the positive predictions (what fraction of detected boxes are actually slag inclusions), while Recall measures the model’s completeness (what fraction of all actual slag inclusions are found). The harmonic mean of Precision and Recall is the F1-Score. The primary evaluation metric was mean Average Precision (mAP), specifically mAP@0.5 (the average precision when the Intersection over Union (IoU) threshold between a predicted box and a ground truth box is 0.5). The training loss, consisting of bounding box regression loss, objectness loss, and classification loss, was tracked to ensure the model was converging effectively.

The performance of the optimized models was rigorously evaluated. The training curves for both YOLOv5so and YOLOv5mo showed stable convergence, with all loss values trending towards zero and Precision/Recall values approaching 1, indicating effective learning. The quantitative results, however, revealed a notable finding. While YOLOv5mo exhibited slightly more stable training dynamics, the final detection accuracy of YOLOv5so surpassed it for this specific task. This is summarized in the table below, which compares the post-training metrics of the base YOLOv5s model with our two optimized versions.

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

The results clearly demonstrate the impact of the optimization pipeline. The YOLOv5so model achieved a remarkable precision of 97%, a substantial 14-percentage-point increase over the unoptimized baseline. This indicates that when the model predicts a bounding box, it is correct 97% of the time. The improved mAP@0.5 also confirms better overall detection performance. The superior performance of the ‘s’ variant suggests that for the specific task of detecting slag inclusions—which are often small to medium-sized objects on a relatively consistent background—the additional complexity of the ‘m’ model may not be necessary and could even lead to slight overfitting. The visual evidence was compelling. When processing the same fracture image, the YOLOv5so model produced bounding boxes with a much higher Intersection over Union (IoU) with the ground truth annotations compared to both the baseline and the YOLOv5mo model, demonstrating more precise localization of the slag inclusions.

To validate the system’s practical utility and superiority over manual inspection, a blind test was conducted on five new sample sets. Each set was evaluated both by an experienced human inspector and by the automated YOLOv5so detection system. The system not only matched human judgment but frequently identified additional, subtler slag inclusions that were missed during manual inspection. This is reflected in the comparative inclusion count data and the subsequent rating calculation. The automated system’s finer-grained detection typically led to a slightly higher, and arguably more accurate, Inclusion Rating. In one representative case, human inspection identified only one prominent inclusion, whereas the automated system successfully detected all five visible slag inclusions on the fracture surface, showcasing a significant reduction in oversight. The calculated Inclusion Ratings from both methods are compared below.

Sample Set Manual Rating Auto Rating (YOLOv5so) Manual Judgment Auto Judgment
Set 1 0.74 (Grade 2) 2.20 (Grade 5) Pass Fail
Set 2 1.20 (Grade 3) 2.72 (Grade >5) Pass Fail
Set 3 0.52 (Grade 2) 1.04 (Grade 3) Pass Pass
Set 4 1.40 (Grade 4) 2.02 (Grade 5) Fail Fail
Set 5 1.10 (Grade 3) 1.10 (Grade 3) Pass Pass

This discrepancy is critical. Cases where the automated system yields a higher, failing grade compared to a passing manual grade highlight the inherent subjectivity and potential for error in human-based assessment. The machine learning model, consistent and unbiased, provides a more reproducible and stringent standard for evaluating melt cleanliness based on the actual presence of slag inclusions.

In conclusion, this work successfully demonstrates the development and application of an optimized YOLOv5-based machine learning pipeline for the automated detection and rating of slag inclusions in aluminum melts via K-mold test images. By implementing a tailored image preprocessing stage featuring CLAHE enhancement, we effectively mitigated issues of low contrast and noise, providing clearer input data. The use of Mosaic data augmentation significantly improved the model’s robustness and ability to detect inclusions of various sizes. The optimized YOLOv5s (YOLOv5so) model achieved a precision of 97%, a substantial improvement over the baseline, proving that a carefully tuned, efficient architecture is highly effective for this industrial vision task. Most importantly, the system eliminates the subjectivity, inconsistency, and labor intensity of manual inspection, enabling faster, more accurate, and completely traceable quality assessment of molten aluminum. This technology provides a practical and reliable bridge between the simple K-mold test and the demand for digital, data-driven process control in modern foundries, ensuring higher product quality and reduced scrap rates.

Scroll to Top