In response to the safety hazards posed by the dynamic propagation of surface defects on casting parts under complex service conditions, this paper proposes an improved ACSN-YOLO detection method. By replacing the original convolutional layers with the ADown module, the model’s ability to extract and process features is enhanced. The Coordinate Attention (CA) mechanism and SEAMHead are employed to improve the model’s perception of defect features. Furthermore, the loss function is replaced with the Normalized Wasserstein Distance (NWD) to enhance the detection robustness for small target defects. Experimental results show that the improved model achieves 70.4% mAP@0.5, 71.9% precision, and 70.6% recall on a self-built dataset, representing improvements of 4.7, 5.0, and 7.3 percentage points, respectively, over the original YOLOv11 model. The parameter count is reduced by 21.7%, and the detection speed reaches 175 FPS, meeting the requirements for industrial online inspection.
The surface integrity of casting parts is paramount for the safe operation of critical industrial equipment. During long-term service, these components are subjected to complex working conditions such as cyclic loading, high-temperature oxidation, and corrosion media erosion. These factors can initiate and propagate surface defects—including fatigue cracks, corrosion pits, and micro-damage in stress concentration zones—posing significant safety risks. Research has shown that in key equipment like aero-engine turbine disks and chemical reactors, the propagation of surface defects to a critical size can lead to catastrophic failures. Therefore, the development of dynamic detection technologies for surface flaws on in-service casting parts is urgently needed to ensure operational safety and extend the service life of components.
Traditional non-destructive testing (NDT) methods used for in-service inspection, such as manual visual checks and periodic offline flaw detection, exhibit notable limitations. Manual inspection is highly subjective, constrained by environmental lighting and inspector experience, leading to low recognition rates for micrometer-scale defects. Methods like magnetic particle inspection require shutdowns and surface cleaning and cannot quantify defect depth. Conventional machine vision systems often suffer from poor algorithmic generalization, resulting in high false-positive rates when confronted with complex service environments featuring oil stains, rust, and varying surface oxidation layers on casting parts.
Deep learning-based object detection methods, particularly single-stage detectors like the YOLO series, offer promising solutions due to their end-to-end architecture and high inference speeds. However, deploying these models for in-service inspection of casting parts presents specific challenges: (1) The dynamic evolution of defect morphology (e.g., corrosion growth) demands high model generalization. (2) Complex background interference from casting textures, scratches, and stains coexisting with small target defects reduces detection precision. (3) There is an inherent conflict between the limited computational resources available on industrial sites and the requirement for real-time processing.
This work introduces ACSN-YOLO, an enhanced algorithm built upon the YOLOv11 framework, specifically designed to address these challenges in casting parts surface defect detection.

Methodology
1.1 The ACSN-YOLO Model Architecture
The proposed ACSN-YOLO model is an improved version of YOLOv11, tailored for detecting defects on casting parts. The model consists of three primary components: a backbone for feature extraction from input images, a neck for multi-scale feature fusion, and a head for predicting target class and bounding box locations. Standard convolutional downsampling in YOLOv11 can lead to feature map blurring or loss of fine details due to strided operations. To mitigate this, we replace the original Conv layers with the ADown module, which better preserves detailed information during downsampling. Furthermore, the detection head is augmented with a Coordinate Attention (CA) mechanism, enabling the model to focus on critical defect features. The head structure is also refined with an improved SEAMHead, and the loss function is substituted with the Normalized Wasserstein Distance (NWD). The overall structure of ACSN-YOLO integrates these components to optimize performance for casting parts inspection.
1.2 The ADown Module
Detecting defects on casting parts requires a balance of high real-time performance and accuracy, complicated by industrial environmental noise. Metallic surfaces cause complex reflections that may be mistaken for defects. Contaminants like oil and dust can obscure surface features, hindering the identification of fine cracks and pores. Additionally, the varying microstructures of different casting materials challenge traditional feature extraction. To address these issues, we substitute the convolutional downsampling layers in YOLOv11 with the ADown module. This module enhances detection capability while reducing parameter count and computational load through its pooling and convolution operations.
The core components of the ADown module include a 2D Average Pooling layer (AvgPool2d), a 2D Max Pooling layer (MaxPool2d), and Convolutional layers (Conv). AvgPool2d performs feature smoothing by computing the mean over input regions, suppressing local noise while capturing basic structural information. The input feature map is split equally along the channel dimension into two groups for differentiated downsampling. The first group undergoes MaxPool2d to extract local maximum features, reducing spatial dimensions by half and mitigating background noise, followed by a 1×1 convolution for deep feature fusion. The second group is downsampled via a 3×3 convolutional layer with a stride of 2. Finally, the processed feature maps from both groups are concatenated to restore the original channel count.
The parameter count and computational complexity of the ADown module are primarily determined by the 3×3 and 1×1 convolutional layers. Since channel splitting occurs before downsampling, the reduction in parameters and computations is significant. Let the original feature map dimensions be $h \times w \times c$ (height, width, channels). After ADown processing, the dimensions become $(h/2) \times (w/2) \times c$. The parameter count $P_a$ and computational complexity $F_a$ of the ADown module, compared to a standard 3×3 convolutional downsampling module with stride 2 (with parameters $P_c$ and complexity $F_c$), are given by:
$$
P_a = \frac{5}{2}c^2, \quad F_a = \frac{5}{8}c^2 \times h \times w
$$
$$
P_c = 9c^2, \quad F_c = \frac{9}{4}c^2 \times h \times w
$$
The equations show that ACSN-YOLO achieves a notable reduction in both parameters and computational cost compared to YOLOv11 for the downsampling operation. The ADown module offers clear advantages in efficiency, maintaining model performance while significantly lowering resource requirements—a critical factor for deploying models on edge devices for inspecting casting parts.
1.3 Coordinate Attention (CA) Mechanism
The uneven distribution of defects and complex backgrounds on in-service casting parts means defect feature extraction is easily disturbed. Attention mechanisms address this by dynamically weighting features, allowing the model to focus on critical defect regions while suppressing interference from reflections, oil stains, and other redundant features. This adaptability also enhances model robustness across different casting materials and conditions. We compared several attention mechanisms: Squeeze-and-Excitation (SE), which focuses on channel information but ignores spatial location; SimAM, which generates a hard attention mask based on self-information entropy; and Coordinate Attention (CA). CA captures both channel information and precise positional information through pooling operations along the height and width axes, finally concatenating and fusing them into a weight vector. Therefore, we integrated the CA mechanism before the three detection heads in YOLOv11. CA aids in accurately locating key information without a significant computational overhead, making the model suitable for inspecting casting parts.
The CA mechanism achieves precise location awareness through feature aggregation along two spatial dimensions. For an input feature map $\mathbf{X}$, average pooling kernels of size $(H,1)$ and $(1,W)$ are used to encode each channel along the horizontal and vertical directions, respectively:
$$
z_c^h(h) = \frac{1}{W} \sum_{0 \leq i < W} x_c(h, i), \quad z_c^w(w) = \frac{1}{H} \sum_{0 \leq j < H} x_c(j, w)
$$
where $c$ is the channel index. These aggregated features are then concatenated and transformed via a shared 1×1 convolution and a non-linear activation $\delta$:
$$
\mathbf{f} = \delta\left(F_1\left([\mathbf{z}^h, \mathbf{z}^w]\right)\right)
$$
where $[\cdot, \cdot]$ denotes concatenation. The intermediate feature map $\mathbf{f}$ is then split into $\mathbf{f}^h$ and $\mathbf{f}^w$ along the spatial dimension. After another 1×1 convolution and a sigmoid activation $\sigma$, the attention weights $\mathbf{g}^h$ and $\mathbf{g}^w$ are generated:
$$
\mathbf{g}^h = \sigma(F_h(\mathbf{f}^h)), \quad \mathbf{g}^w = \sigma(F_w(\mathbf{f}^w))
$$
The final output $\mathbf{Y}$ of the CA block is obtained by applying the attention weights to the input:
$$
y_c(i, j) = x_c(i, j) \times g_c^h(i) \times g_c^w(j)
$$
This process allows CA to model long-range dependencies with precise positional information, which is crucial for distinguishing small defects from complex backgrounds on casting parts.
1.4 SEAMHead
Occlusion, often from dirt, grease, or overlapping parts, can cause target misalignment, local feature confusion, and the loss of key defect characteristics. To tackle this challenge in casting parts inspection, we incorporate the SEAM attention module and its associated exclusion loss into the detection head. SEAM builds a feature pyramid to integrate multi-scale contextual information, emphasizing specific image regions to facilitate detection across scales and minimize background distraction. To maintain computational efficiency, SEAM employs depthwise separable convolutions and introduces pointwise convolutions for information fusion, compensating for the lack of inter-channel relationship modeling in depthwise operations. A two-layer fully connected network integrates channel information, strengthening inter-channel correlations. By leveraging prior knowledge about occluded versus non-occluded surfaces, the loss during inefficient occlusion stages is reduced. The connected layer’s output undergoes an exponential mapping, transforming the range from [0,1] to [1,e]. This monotonic mapping increases tolerance to positional errors. Ultimately, the SEAM module’s output serves as an attention weight to enhance the original features, strengthening the detection head’s capability and improving robustness against occlusion for casting parts.
1.5 NWD Loss Function
The choice of loss function significantly influences model performance. The original YOLOv11 uses CIoU as its bounding box regression loss. CIoU considers the overlap area, center-point distance, and aspect ratio between the predicted box $B$ and the ground truth box $A$:
$$
\mathcal{L}_{CIoU} = 1 – IoU + \frac{\rho^2(\mathbf{b}, \mathbf{b}^{gt})}{c^2} + \alpha v
$$
$$
v = \frac{4}{\pi^2} \left( \arctan\frac{w^{gt}}{h^{gt}} – \arctan\frac{w}{h} \right)^2, \quad \alpha = \frac{v}{(1 – IoU) + v}
$$
where $\rho^2(\cdot)$ is the squared Euclidean distance between box centers, $c$ is the diagonal length of the smallest enclosing box covering both $A$ and $B$, and $v$ measures the aspect ratio consistency. While CIoU performs well generally, it suffers from gradient insensitivity when dealing with very small targets—a common scenario for incipient defects on casting parts.
To address this, we combine CIoU with the Normalized Wasserstein Distance (NWD) to compute the localization loss. NWD measures the similarity between two bounding boxes by modeling them as 2D Gaussian distributions and calculating the normalized Wasserstein distance between them. This approach is more sensitive to minor deviations for small objects. First, a bounding box $R=(x_c, y_c, w, h)$ is modeled as a 2D Gaussian distribution $\mathcal{N}(\boldsymbol{\mu}, \boldsymbol{\Sigma})$, where $\boldsymbol{\mu} = [x_c, y_c]^T$ and $\boldsymbol{\Sigma} = \text{diag}\left(\frac{w^2}{4}, \frac{h^2}{4}\right)$. For two Gaussian distributions $\mathcal{N}_A$ and $\mathcal{N}_B$, the Wasserstein distance $W_2^2$ has a closed form:
$$
W_2^2(\mathcal{N}_A, \mathcal{N}_B) = \left\| \left([x_c^A, y_c^A, \frac{w_A}{2}, \frac{h_A}{2}]^T, [x_c^B, y_c^B, \frac{w_B}{2}, \frac{h_B}{2}]^T \right) \right\|_2^2
$$
This distance is then normalized to derive a similarity measure that is scale-insensitive:
$$
\text{NWD}(\mathcal{N}_A, \mathcal{N}_B) = \exp\left(-\frac{\sqrt{W_2^2(\mathcal{N}_A, \mathcal{N}_B)}}{C}\right)
$$
where $C$ is a constant closely related to the dataset. The final localization loss is a weighted combination:
$$
\mathcal{L}_{LOC} = (1 – \beta)[1 – \text{NWD}(\mathcal{N}_A, \mathcal{N}_B)] + \beta (1 – \text{CIoU})
$$
where $\beta$ is a balancing coefficient. By incorporating NWD, the loss function can effectively measure similarity even for non-overlapping or very small boxes, addressing the gradient issue of IoU-based losses and improving convergence precision for tiny defects on casting parts.
Experiments and Results
2.1 Experimental Setup
Dataset: Publicly available datasets for surface defects on casting parts are limited in both quantity and quality. To this end, we collected 1,444 images of defective casting surfaces, categorized into 7 different defect types. The proportion of each type varied between 10% and 25%. Data augmentation techniques, including image flipping, brightness adjustment, and noise injection, were applied to generate more training samples and improve dataset robustness. The dataset encompasses various shooting scenarios to ensure diversity. The dataset was split into training and validation sets with an 8:2 ratio.
Experimental Environment and Parameters: The experiments were conducted on a workstation with a Quadro RTX 4000 GPU, 16GB of RAM, running Windows 11. The framework was built with Python 3.8.20 and PyTorch 2.2.1. The input image size was set to 640×640. The model was trained for 300 epochs with a batch size of 8, using the SGD optimizer. A patience parameter of 100 was used for early stopping considerations.
Evaluation Metrics: The performance was evaluated using Precision (P), Recall (R), Average Precision (AP), mean Average Precision (mAP), and the F1 score. Precision measures the proportion of correct positive predictions, while Recall measures the proportion of actual positives correctly identified. AP summarizes the precision-recall curve for a single class, and mAP@0.5 is the mean AP over all classes at an Intersection over Union (IoU) threshold of 0.5. The F1 score is the harmonic mean of Precision and Recall. The formulas are as follows:
$$
\text{Precision} = \frac{TP}{TP + FP}, \quad \text{Recall} = \frac{TP}{TP + FN}
$$
$$
AP = \int_0^1 P(R) dR, \quad mAP = \frac{1}{C} \sum_{i=1}^C AP_i
$$
$$
F1 = \frac{2 \times \text{Precision} \times \text{Recall}}{\text{Precision} + \text{Recall}}
$$
where $TP$, $FP$, $TN$, $FN$ denote true positives, false positives, true negatives, and false negatives, respectively, and $C$ is the number of classes.
2.2 Experimental Results
Comparison of Attention Mechanisms: To evaluate the impact of different attention mechanisms, we conducted comparative experiments with SE, SimAM, and CA integrated into our framework. The results are summarized in Table 1. The CA mechanism, by capturing both channel and positional information, achieved a better balance, yielding superior Recall and mAP metrics, which are crucial for not missing defects on casting parts.
| Attention Mechanism | Precision (%) | Recall (%) | mAP@0.5 (%) | mAP@0.5-0.95 (%) |
|---|---|---|---|---|
| SE | 68.6 | 64.9 | 63.4 | 36.8 |
| SimAM | 71.0 | 61.4 | 61.5 | 30.5 |
| CA | 65.7 | 67.7 | 64.8 | 37.6 |
Comparison of Loss Functions: After initial improvements to YOLOv11, we evaluated different loss functions, namely DIoU, EIoU, and NWD. The results are presented in Table 2. NWD provided the highest gains across Precision, Recall, and mAP, demonstrating that its replacement makes the model more sensitive to the features of small defects common in casting parts.
| Loss Function | Precision (%) | Recall (%) | mAP@0.5 (%) | mAP@0.5-0.95 (%) |
|---|---|---|---|---|
| DIoU | 68.6 | 66.1 | 65.1 | 36.7 |
| EIoU | 67.5 | 63.4 | 61.2 | 36.3 |
| NWD | 71.5 | 68.4 | 67.4 | 39.4 |
Comparison with Other Models: To validate the performance of ACSN-YOLO, we compared it against several mainstream object detection models under the same training parameters and dataset, including YOLOv3-Tiny, YOLOv5, YOLOv6, YOLOv8, YOLOv10n, SSD, and Faster R-CNN. The results are shown in Table 3. ACSN-YOLO, through its attention mechanisms and lightweight improvements, achieves a superior balance between detection accuracy and speed, making it suitable for real-time inspection of casting parts.
| Model | Precision (%) | Recall (%) | mAP@0.5 (%) |
|---|---|---|---|
| YOLOv3-Tiny | 64.0 | 60.7 | 57.7 |
| YOLOv5 | 68.3 | 61.4 | 59.9 |
| YOLOv6 | 58.4 | 56.3 | 52.3 |
| YOLOv8 | 68.9 | 64.7 | 62.1 |
| YOLOv10n | 70.5 | 61.6 | 62.2 |
| SSD | 69.3 | 50.1 | 52.6 |
| Faster R-CNN | 49.8 | 66.2 | 60.7 |
| ACSN-YOLO | 71.9 | 70.6 | 70.4 |
Ablation Study: To assess the contribution of each proposed module, we conducted a series of ablation experiments under consistent parameters. The results are detailed in Table 4. Experiment 1 is the baseline YOLOv11. Experiment 2 introduces the ADown module, improving Recall, mAP, and FPS while reducing GFLOPs by 1.1 and parameters by 18%. Experiment 3 adds the CA mechanism on top of ADown, boosting Precision by 2.8% and mAP@0.5 by 3.2%. Experiment 4 incorporates the SEAMHead, leading to a slight mAP gain and further reductions in GFLOPs and parameters. Experiment 5, our final ACSN-YOLO model using the NWD loss, shows significant improvements across all key metrics (Precision, Recall, mAP@0.5) compared to the baseline, alongside lower computational complexity and parameter count. This confirms that the improvements are effective and efficient for the task of detecting defects on casting parts.
| Exp. | ADown | CA | SEAMHead | NWD | P(%) | R(%) | mAP@0.5(%) | mAP@0.5-0.95(%) | GFLOPs | Params (M) | FPS |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | 67.2 | 65.6 | 63.1 | 36.2 | 6.4 | 2.58 | 192 | ||||
| 2 | √ | 67.2 | 68.9 | 64.9 | 38.7 | 5.3 | 2.11 | 200 | |||
| 3 | √ | √ | 70.1 | 72.1 | 68.1 | 38.8 | 5.3 | 2.12 | 181 | ||
| 4 | √ | √ | √ | 69.0 | 69.5 | 66.8 | 39.9 | 4.8 | 2.02 | 181 | |
| 5 | √ | √ | √ | √ | 71.9 | 70.6 | 70.4 | 41.8 | 4.8 | 2.02 | 175 |
Analysis and Conclusion
To visually demonstrate the performance improvement of ACSN-YOLO over the baseline, we compared their detection results on the same set of images. In multiple examples, ACSN-YOLO focuses more accurately on key defect regions, with recognition confidence scores increasing by 2 to 13 percentage points. This indicates a more reliable identification of flaws on casting parts.
To further investigate the improvement, we generated Grad-CAM-like heatmaps for both YOLOv11 and ACSN-YOLO. The heatmaps reveal that ACSN-YOLO attends to broader and more relevant feature regions with higher confidence compared to the baseline. It shows increased focus on areas that might be partially obscured or less distinct, effectively addressing potential missed detections. The wider and more intense distribution of attention in the enhanced algorithm’s heatmap confirms its strengthened capability for defect detection on casting parts surfaces.
This paper presented ACSN-YOLO, an improved algorithm for surface defect detection on casting parts. Built upon the YOLOv11 framework, it addresses specific challenges in industrial casting inspection, such as diverse defect morphologies, difficulty in detecting small flaws, and interference from occlusions and complex backgrounds. Experimental results demonstrate that ACSN-YOLO achieves 70.4% mAP@0.5 on a self-built multi-condition dataset, outperforming YOLOv8 and YOLOv10n by 8.3 and 8.2 percentage points, respectively, with a single-image inference time of only 5.7 ms (175 FPS).
The key innovations include: (1) Replacing standard convolution blocks in the backbone with the ADown downsampling structure, which reduces computational complexity while preserving finer texture features of small defects through parameter sharing and feature reorganization. (2) Integrating the Coordinate Attention (CA) mechanism before the detection heads to enhance localization accuracy of defect regions by encoding spatial information, effectively countering interference from reflections and oxidation spots on casting parts. (3) Refining the detection head with SEAMHead to maintain high detection precision under challenging conditions like variable lighting and partial occlusion. (4) Substituting the loss function with NWD, which improves sensitivity to small defects by modeling bounding boxes as Gaussian distributions.
These improvements have practical significance, enabling more accurate assessment of the service status of casting parts and facilitating predictive maintenance. While significant progress has been made, there is still potential to further enhance Recall and average precision across different defect types. Future work will focus on expanding the dataset’s scale and diversity and exploring the algorithm’s applicability across more stages of the casting lifecycle to improve its generalizability and robustness for industrial deployment.
