In the production of aluminum alloys, the presence of non-metallic inclusions, primarily oxides and other slag particles, represents a critical challenge. These slag inclusions compromise the integrity, mechanical properties, and surface finish of final products, leading to significant scrap rates. It is estimated that a substantial portion of aluminum casting defects originate during the melting and holding stages. Therefore, accurate assessment of the melt cleanness, specifically the slag inclusion content, is paramount for quality control. My work focuses on overcoming the limitations of traditional manual evaluation methods by developing a robust, automated slag inclusion detection system based on advanced machine learning, significantly enhancing both the precision and efficiency of melt quality inspection.
The K-Mold Test and Its Manual Limitations
The K-mold test is a widely adopted industrial method for assessing aluminum melt quality due to its simplicity and low cost. The procedure involves pouring a sample of the refined melt into a pre-designed K-shaped mold. Upon solidification and cooling, the sample is fractured along predefined notches, producing several fracture surfaces. These surfaces are then examined, typically using a stereomicroscope, to identify and quantify the visible slag inclusions.

The slag inclusion rate (SIR), a key metric, is calculated by classifying the detected slag inclusions into size grades, each assigned a specific weighting factor. The standard classification is summarized in the table below.
| Inclusion Size (µm) | Grade | Weighting Factor (Xi) |
|---|---|---|
| (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 slag inclusion rate for a sample is computed using the following formula, where count(i) represents the number of slag inclusions belonging to grade i:
$$ \text{Slag Inclusion Rate (SIR)} = \frac{\sum_{i=1}^{5} \text{count}(i) \cdot X_i}{\text{Number of Fracture Surfaces}} $$
Based on the calculated SIR, the melt quality is assigned a level, as shown in the following standard.
| SIR Range (%) | Slag Inclusion 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 |
The conventional approach relies on human operators to visually inspect micrographs of the fracture surfaces, manually count the slag inclusions, and measure their sizes. This method is inherently subjective, time-consuming, and prone to significant errors due to fatigue, inconsistency in judgment, and the difficulty of detecting small or low-contrast slag inclusions. This creates a bottleneck for rapid, high-volume production quality control and can lead to incorrect acceptance or rejection of melt batches.
Principle of Automated Slag Inclusion Detection
To address these challenges, I turned to machine learning-based computer vision, specifically object detection. Object detection algorithms can automatically identify and localize objects of interest within digital images. For the task of slag inclusion detection, this involves not only classifying a region as containing a slag inclusion but also precisely drawing a bounding box around it and categorizing it into its correct size grade. This automation promises objectivity, repeatability, and speed unattainable by manual methods.
Among various object detection architectures, single-stage detectors like YOLO (You Only Look Once) are preferred for industrial applications due to their excellent balance between speed and accuracy. YOLO frames object detection as a single regression problem, directly predicting bounding boxes and class probabilities from the full image in one evaluation, making it exceptionally fast. After evaluating different versions, I selected YOLOv5 as the foundational model for this project. Its performance on standard datasets, as conceptually represented below, demonstrates superior speed and mean Average Precision (mAP) compared to other contemporary models like SSD, making it ideal for real-time or near-real-time quality inspection scenarios.
| Model | Inference Speed (FPS) | mAP (COCO) |
|---|---|---|
| SSD321 | ~16 | ~0.28 |
| YOLOv5s | >150 | >0.45 |
The core architecture of YOLOv5 consists of three main parts: the Backbone, the Neck, and the Head. The Backbone (CSPDarknet) extracts rich multi-scale features from the input image. The Neck (PANet) aggregates these features from different levels to combine both high-resolution spatial information and high-level semantic information, which is crucial for detecting small slag inclusions. Finally, the Head performs the actual detection, outputting the final bounding boxes, objectness scores, and class probabilities.
YOLOv5 introduces several key improvements that are highly beneficial for slag inclusion detection:
- Mosaic Data Augmentation: During training, four images are randomly combined into one. This dramatically increases the diversity of the training data, exposes the model to more varied backgrounds and contexts, and improves its robustness, especially for detecting smaller slag inclusions which are prevalent in our samples.
- Adaptive Anchor Box Calculation: Instead of using predefined anchor box sizes, YOLOv5 automatically calculates optimal anchor box dimensions based on the specific dataset. This ensures the initial bounding box priors are well-suited to the typical sizes and shapes of slag inclusions in our K-mold images.
- Focus and CSP Structures: These architectural choices improve gradient flow, enhance feature representation capability, and reduce computational complexity, leading to more efficient and effective learning.
Algorithm Optimization for Slag Inclusion Detection
Direct application of a standard YOLOv5 model to raw K-mold fracture images yielded suboptimal results. The unique challenges of slag inclusion detection necessitated a series of optimizations in data preparation, preprocessing, and model training.
Data Preparation and Preprocessing
A dataset of 500 high-resolution micrographs (2560×1920 pixels) of K-mold fracture surfaces was compiled. The images contained slag inclusions of varying sizes, shapes, and contrasts against the metallic background. To ensure a robust model, the dataset was split using stratified sampling into 80% for training and 20% for testing, guaranteeing a representative distribution of slag inclusion types in both sets.
Raw fracture images often suffer from uneven lighting, low contrast between slag and matrix, and visual noise from the metallic grain structure. To enhance the salient features of the slag inclusions, I implemented a preprocessing pipeline based on spatial domain techniques. The core operation is defined as:
$$ 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. Among various techniques tested (inversion, gamma correction, Sobel filtering), Contrast Limited Adaptive Histogram Equalization (CLAHE) proved most effective. CLAHE operates by dividing the image into small tiles, applying histogram equalization to each, and then clipping the histogram to limit amplification of noise before redistributing the excess pixels. This process, conceptually shown below, significantly improves local contrast, making slag inclusion edges sharper and more distinguishable from the background texture without introducing unnatural artifacts.
Model Architecture and Training Strategy
I experimented with two variants of YOLOv5: YOLOv5s (small, fast) and YOLOv5m (medium, more accurate). To distinguish the optimized versions developed in this work, I refer to them as YOLOv5so and YOLOv5mo, respectively. The overall algorithm workflow is as follows: Input Image → CLAHE Preprocessing → YOLOv5so/mo Model (Backbone+Neck+Head) → Bounding Box & Class Prediction → SIR Calculation.
The training leveraged Mosaic data augmentation extensively. Furthermore, the model’s loss functions were critical for learning. The total loss \(L_{total}\) is a combination of bounding box regression loss (\(L_{box}\)), objectness loss (\(L_{obj}\)), and classification loss (\(L_{cls}\)):
$$ L_{total} = \lambda_{box} L_{box} + \lambda_{obj} L_{obj} + \lambda_{cls} L_{cls} $$
Where the \(\lambda\) terms are weighting coefficients. For bounding box regression, I utilized the Complete IoU (CIoU) loss, which considers overlap area, central point distance, and aspect ratio consistency, leading to more accurate and stable box predictions for slag inclusions.
Model Evaluation Metrics
The performance of the trained models was rigorously evaluated using standard object detection metrics derived from the confusion matrix:
| Metric | Formula | Description |
|---|---|---|
| Precision (P) | $$ P = \frac{TP}{TP + FP} $$ | Proportion of correct slag inclusion detections among all positive predictions. |
| Recall (R) | $$ R = \frac{TP}{TP + FN} $$ | Proportion of actual slag inclusions that were correctly detected. |
| mAP@0.5 | Mean Average Precision at IoU=0.5 | Average precision across all classes when the predicted box overlaps with the ground truth box by at least 50%. |
| mAP@0.5:0.95 | mAP averaged over IoU thresholds from 0.5 to 0.95 in steps of 0.05. | A stricter metric that requires higher localization accuracy. |
The Precision-Recall (P-R) curve and the Average Precision (AP) calculated from it provide a comprehensive view of the model’s performance across different confidence thresholds.
Results and Discussion
The training process for the optimized YOLOv5so model showed excellent convergence. Key loss functions, including box loss and objectness loss, steadily decreased and plateaued near zero after approximately 100 epochs, indicating the model was learning effectively. More importantly, the precision and recall metrics for the training and validation sets converged to high values (approaching 1.0), demonstrating that the model was not overfitting and had learned generalizable features for slag inclusion detection.
The final performance comparison of the different model configurations on the test dataset is summarized below. The results clearly show the impact of our optimizations.
| 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 YOLOv5so model achieved a remarkable precision of 97%, a significant 14-point improvement over the baseline YOLOv5s. While YOLOv5mo had a slightly higher mAP@0.5:0.95, indicating potentially better localization for stricter IoU thresholds, the precision of YOLOv5so was superior. Since the primary goal in quality inspection is to minimize false positives (erroneously labeling clean areas as containing slag inclusion), the higher precision of YOLOv5so makes it the preferred choice for this application.
Qualitative results on sample images further confirmed the superiority of the optimized model. In comparative tests, the YOLOv5so model consistently identified slag inclusions with higher confidence and more accurate bounding boxes (IoU > 90%) compared to both the baseline and the YOLOv5mo model, which often produced lower-confidence detections or missed smaller slag inclusions.
The ultimate validation involved comparing the automated slag inclusion detection system against manual expert evaluation. Five sample sets were analyzed by both methods. The automated system consistently detected a higher number of slag inclusions, particularly smaller ones (Grade I and II), that were frequently missed during manual inspection due to human error or fatigue. This led to a critical difference in the final quality judgment.
| Sample Group | Manual SIR / Level | Auto SIR / Level (YOLOv5so) | Manual Judgment | Auto Judgment |
|---|---|---|---|---|
| 1 | 0.74% / Level 2 | 2.20% / Level 5 | Acceptable | Unacceptable |
| 2 | 1.20% / Level 3 | 2.72% / Level >5 | Acceptable | Unacceptable |
| 3 | 0.52% / Level 2 | 1.04% / Level 3 | Acceptable | Acceptable |
| 4 | 1.40% / Level 4 | 2.02% / Level 5 | Unacceptable | Unacceptable |
| 5 | 1.10% / Level 3 | 1.10% / Level 3 | Acceptable | Acceptable |
As the table demonstrates, for Sample Groups 1 and 2, the manual method deemed the melt acceptable, while the automated system, with its more sensitive and consistent detection of slag inclusion, correctly flagged them as unacceptable. This underscores a major risk of the manual method: potentially allowing low-quality melt to proceed in production, which could lead to downstream defects and scrap. The automated system provides a more reliable and conservative assessment, enhancing overall product quality.
Conclusion
This work successfully developed and validated an automated machine learning-based system for detecting and quantifying slag inclusion in aluminum melt using K-mold test samples. By integrating specialized image preprocessing (CLAHE) to enhance slag inclusion contrast and optimizing the YOLOv5 model architecture and training regimen, the system achieved a significant performance breakthrough. The optimized YOLOv5so model attained a precision of 97%, a substantial 14% increase over the non-optimized baseline. More importantly, comparative testing proved that this automated system is more accurate, consistent, and sensitive than traditional manual evaluation, often identifying critical slag inclusion that human inspectors miss. This technology enables fast, objective, and highly precise assessment of aluminum melt cleanness, providing a powerful tool for foundries to improve process control, reduce defect rates, and ensure the production of high-integrity aluminum components.
