Edge-Ready Casting Defect Detection

I approach casting defect detection as a machine-vision problem that must satisfy two opposing demands at the same time: the model must be accurate enough to reveal subtle casting defects, and it must be compact enough to run on edge devices inside an industrial line. Casting defects such as cracks, porosity, sand holes, shrinkage cavities, excess material, and inclusions can reduce fatigue life, weaken load-bearing capacity, and create safety risks in downstream assemblies. In my work, I therefore treat casting defects not as a single visual class but as a family of morphology-dependent patterns whose scale, contrast, and boundary regularity vary widely. This variation is precisely why a generic object detector often fails when it is transferred directly to casting defect detection. I focus on a lightweight, high-precision detector that can preserve small casting defects while reducing parameter count and floating-point operations.

I begin from the observation that casting defects are often small, low-contrast, and partially hidden by metallic reflection, sand texture, oil stains, or machining marks. A crack may appear as a thin dark curve with a width of only a few pixels. Porosity may appear as a cluster of small dark spots whose edges blend into the surrounding surface. Excess material may have a larger area but an irregular boundary. Inclusion or abnormal structure may be confused with local texture noise. Because these casting defects occupy few pixels and have weak boundaries, traditional downsampling can erase the very evidence that distinguishes one class from another. I therefore design a model in which spatial detail is retained longer, redundant neck computation is reduced, attention is applied without adding parameters, and bounding-box regression is dynamically reweighted.

Industrial Motivation. Manual visual inspection of casting defects is slow, inconsistent, and highly dependent on operator experience. A human inspector can detect obvious defects, but fine casting defects are easily missed after long shifts. Conventional machine-vision pipelines usually include image preprocessing, handcrafted feature extraction, template matching, and classification. These pipelines can work in controlled lighting, but they struggle when casting defects change in scale, shape, and contrast. Deep learning offers a stronger alternative because it can learn hierarchical features directly from images. However, the largest and most accurate detectors are rarely suitable for edge deployment. My objective is therefore not simply to maximize accuracy, but to find a balanced operating point for casting defect detection under real industrial constraints.

Problem Formulation. I formulate casting defect detection as a dense prediction problem over an input image \(I\). For each image, the detector predicts a set of bounding boxes \(B=\{b_1,b_2,\ldots,b_m\}\), class labels \(C=\{c_1,c_2,\ldots,c_m\}\), and confidence scores \(S=\{s_1,s_2,\ldots,s_m\}\). The ground truth is \(G=\{g_1,g_2,\ldots,g_n\}\). The quality of a predicted box \(b_p\) relative to a ground-truth box \(b_g\) is measured by intersection over union:

$$ \mathrm{IoU}(b_p,b_g)=\frac{|b_p\cap b_g|}{|b_p\cup b_g|}. $$

I use precision, recall, and mean average precision to quantify detection quality. Precision measures how many predicted casting defects are true positives. Recall measures how many true casting defects are found. Mean average precision summarizes the precision-recall behavior across classes and IoU thresholds.

$$ \mathrm{Precision}=\frac{N_{TP}}{N_{TP}+N_{FP}} $$

$$ \mathrm{Recall}=\frac{N_{TP}}{N_{TP}+N_{FN}} $$

$$ \mathrm{PmA}=\frac{1}{n}\sum_{k=1}^{n}\int_{0}^{1}P_k(R_k)\,dR_k $$

For edge deployment, accuracy is only one part of the objective. I also consider parameter count \(M\), floating-point operations \(G\), and inference speed \(v\). I express the design goal as a multi-objective trade-off:

$$ \min_{\theta}\left(-\lambda_1 \mathrm{PmA}+\lambda_2 M+\lambda_3 G+\lambda_4 L_{\mathrm{latency}}\right), $$

where \(\theta\) denotes model parameters, \(L_{\mathrm{latency}}\) denotes inference latency, and \(\lambda_1,\lambda_2,\lambda_3,\lambda_4\) control the relative importance of accuracy, size, computation, and delay. In my experiments, I keep the network structure fixed after design and measure the trade-off directly.

Symbol Meaning Role in casting defect detection
\(I\) Input surface image Contains casting defects under industrial illumination
\(b_p\) Predicted bounding box Localizes a suspected casting defect
\(b_g\) Ground-truth bounding box Defines the annotated defect region
\(\mathrm{IoU}\) Intersection over union Measures localization overlap
\(M\) Parameter count Indicates memory footprint on edge devices
\(G\) Floating-point operations Indicates computational cost
\(v\) Frames per second Indicates real-time capability

Baseline and Design Direction. I select a compact single-stage detector as the baseline because single-stage detectors are usually faster and simpler to deploy than two-stage detectors. The baseline has a backbone, a neck, and a detection head. It performs well on general objects, but I observe three weaknesses when it is used for casting defects. First, the neck contains redundant feature-fusion paths that increase memory traffic and reduce parallel efficiency on edge accelerators. Second, repeated downsampling removes high-frequency information that is essential for small casting defects. Third, the regression loss does not explicitly handle the low-quality samples that are common when casting defects are blurred, reflected, or partially occluded. I address these weaknesses with a lightweight neck, a parameter-free attention mechanism, a space-to-depth convolution module, and a dynamic Wise-IoUv3 loss.

Overall Architecture. I name the resulting model SAFE-YOLO. It retains the standard backbone-neck-head organization but replaces several components to improve the edge-deployment profile. The backbone extracts multi-scale features. The neck fuses features from different levels. The head predicts classes and boxes. The key modifications are as follows: I use SlimNeck structures built from GSConv and VoV-GSCSP to reduce neck redundancy; I insert SimAM attention at the connections between the backbone and the neck; I replace selected convolutional downsampling blocks with SPDConv feature re-extraction modules; and I replace the default CIoU regression loss with Wise-IoUv3. These changes are intended to work together rather than independently.

Component Baseline choice My choice Expected effect on casting defects
Neck fusion PAN-FPN with C2f blocks SlimNeck with GSConv and VoV-GSCSP Lower computation and memory traffic while preserving multi-scale fusion
Attention None at backbone-neck links SimAM at three connection points Focus on defect-like regions without adding parameters
Downsampling Standard CBS downsampling SPDConv for selected blocks Retain fine spatial information for small casting defects
Regression loss CIoU Wise-IoUv3 Suppress harmful gradients from low-quality samples and improve convergence

SlimNeck for Lightweight Fusion. The neck in a detector is responsible for combining high-level semantic features with low-level spatial features. This is especially important for casting defects because a porosity cluster may need shallow detail to be localized, while a long crack may need deeper context to be classified. However, a heavy neck creates many fragmented operations. On edge hardware, fragmented operations often cause frequent data movement between compute units and memory, which reduces the benefit of theoretical FLOPs reduction. I therefore introduce SlimNeck, which combines GSConv and VoV-GSCSP. GSConv mixes standard convolution and depthwise convolution, then applies channel shuffle to improve information exchange across channels. The computational cost of GSConv is much lower than that of a standard convolution with the same input and output channels.

$$ \mathrm{FLOPs}_{\mathrm{standard}} \approx k^2 C_{in} C_{out} H W $$

$$ \mathrm{FLOPs}_{\mathrm{DWConv}} \approx k^2 C_{in} H W $$

$$ \mathrm{FLOPs}_{\mathrm{GSConv}} \approx \frac{1}{2}\left(k^2 C_{in} C_{out} H W + k^2 C_{in} H W\right) $$

In my design, GSConv replaces selected standard convolution blocks in the neck. VoV-GSCSP replaces the repeated C2f-style fusion blocks. VoV-GSCSP uses a one-time aggregation strategy and a cross-stage partial design to reduce parameter redundancy. I observe that this change substantially reduces model size and computation. In the ablation study, the parameter count drops from \(2.8\times 10^6\) to \(1.7\times 10^6\), and the floating-point operations drop from \(8.3\) GFLOPs to \(5.6\) GFLOPs. The inference speed rises from \(83\) FPS to \(112\) FPS. The mean average precision at IoU \(0.5:0.95\) decreases slightly by \(0.6\) percentage points at this stage, but this small accuracy reduction creates computational space for the later modules that recover and surpass the baseline accuracy. I view SlimNeck as a necessary efficiency stage rather than an isolated accuracy improvement.

Neck design property Heavy fusion neck SlimNeck in my model
Basic convolution Standard convolution GSConv with depthwise convolution and channel shuffle
Fusion block C2f-style multi-branch block VoV-GSCSP with one-time aggregation
Parameter count tendency Higher Lower
Memory traffic More fragmented More compact
Suitability for casting defects Accurate but expensive Lightweight while preserving multi-scale cues

SimAM Attention for Defect Saliency. Casting defects often occur in cluttered backgrounds. A gas hole may look like a dark sand grain, and a shallow crack may look like a scratch. I therefore need an attention mechanism that can emphasize locally abnormal regions without increasing model size. SimAM is attractive because it is parameter-free. It estimates an energy function for each neuron and uses that energy to assign attention weights. The energy function can be written as:

$$ e_{ij}=\frac{4(\mu^2+\sigma^2)}{(x_{ij}-\mu)^2+2\sigma^2+\epsilon}, $$

where \(x_{ij}\) is the pixel value or feature value at position \((i,j)\), \(\mu\) is the mean, \(\sigma^2\) is the variance, and \(\epsilon\) is a small constant for numerical stability. A lower energy indicates that a neuron is more distinct from its surrounding neurons, so it receives a stronger attention weight. I insert SimAM at the three backbone-to-neck connection locations because these locations carry multi-scale features before fusion. By applying attention before concatenation, I allow the network to suppress irrelevant background responses and enhance defect-relevant responses.

$$ \tilde{x}_{ij}=\frac{x_{ij}}{1+e_{ij}} $$

Unlike channel attention or spatial attention modules that add learnable parameters, SimAM does not introduce additional weights. It therefore improves feature selectivity while preserving the lightweight property of the model. In my ablation study, adding SimAM improves the mean average precision at IoU \(0.5:0.95\) from \(77.0\%\) to \(77.8\%\), while the parameter count remains \(2.2\times 10^6\) and the computational cost remains approximately \(6.1\) GFLOPs. This is a small but meaningful gain for casting defect detection because the attention mechanism helps separate weak defect signals from complex surface textures.

Attention mechanism Learnable parameters Main idea Edge friendliness
SE Yes Channel recalibration Moderate
CBAM Yes Channel and spatial attention Moderate
SimAM No Energy-based neuron importance High

SPDConv for Fine Spatial Retention. The most damaging operation for small casting defects is aggressive downsampling. A standard strided convolution reduces spatial resolution and may discard the thin structures of micro-cracks or the small dark cores of porosity. I therefore introduce SPDConv as a feature re-extraction module. The core idea is space-to-depth transformation. Given an input feature map \(X\in\mathbb{R}^{S\times S\times C_1}\), SPD rearranges spatial blocks into the channel dimension:

$$ X\in\mathbb{R}^{S\times S\times C_1}\rightarrow X’\in\mathbb{R}^{\frac{S}{2}\times\frac{S}{2}\times 4C_1}. $$

After this rearrangement, a \(1\times 1\) convolution maps the channel dimension from \(4C_1\) to \(C_2\):

$$ \mathrm{SPDConv}(X)=\mathrm{Conv}_{1\times1}\left(\mathrm{SPD}(X)\right). $$

This operation performs downsampling without simply throwing away spatial information. Instead, it moves spatial detail into the channel dimension and then compresses it with a pointwise convolution. For casting defects, this means that fine structures such as micro-cracks, small pores, and irregular inclusion boundaries are more likely to survive into deeper layers. In my ablation, replacing selected standard downsampling blocks with SPDConv improves the mean average precision at IoU \(0.5:0.95\) from \(73.8\%\) to \(77.0\%\), an increase of \(3.2\) percentage points over the SlimNeck-only model. This is the largest single accuracy gain among my modules, and it confirms that spatial detail retention is crucial for casting defect detection.

Property Traditional strided convolution SPDConv
Resolution reduction Direct Space-to-depth rearrangement
Information loss Higher for fine structures Lower because detail moves to channels
Kernel size Usually larger than \(1\times1\) \(1\times1\) convolution after SPD
Effect on small casting defects May erase weak evidence Preserves weak evidence for later layers
Deployment cost Moderate Lightweight and controllable

Wise-IoUv3 for Robust Regression. Bounding-box regression is difficult when casting defects have irregular shapes. The default CIoU loss considers overlap, center distance, and aspect ratio. It is effective for regular objects, but it can be less stable for elongated cracks, diffuse porosity clusters, and partially occluded inclusions. I therefore move to Wise-IoUv3. Wise-IoUv1 introduces a distance-attention term:

$$ \mathcal{L}_{\mathrm{Wise-IoUv1}}=\mathcal{L}_{\mathrm{IoU}}\exp\left(\frac{(x-x_g)^2+(y-y_g)^2}{W_c^2+H_c^2}\right), $$

where \((x,y)\) is the predicted box center, \((x_g,y_g)\) is the ground-truth box center, and \(W_c,H_c\) are the width and height of the smallest enclosing rectangle. Wise-IoUv3 further introduces a dynamic focusing coefficient \(r\). I define the outlier degree \(\beta\) as:

$$ \beta=\frac{\mathcal{L}_{\mathrm{IoU}}^*}{\mathcal{L}_{\mathrm{IoU}}}, $$

and the focusing coefficient as:

$$ r=\frac{\beta}{\delta\alpha^{\beta-\delta}}, $$

where \(\alpha\) and \(\delta\) are hyperparameters. The final regression loss is:

$$ \mathcal{L}_{\mathrm{Wise-IoUv3}}=r\mathcal{L}_{\mathrm{Wise-IoUv1}}. $$

This design gives high-quality predicted boxes a stronger gradient contribution and suppresses harmful gradients from low-quality boxes. In casting defect detection, low-quality boxes often arise from reflection, blur, or complex sand texture. By reducing the influence of these poor matches, Wise-IoUv3 makes training more stable and improves convergence. In my ablation, it raises the mean average precision at IoU \(0.5:0.95\) from \(77.8\%\) to \(78.2\%\) and helps achieve the highest recall and speed in the final model.

Loss Main terms Strength Weakness for casting defects
IoU Overlap only Simple No center or aspect ratio guidance
GIoU Overlap and enclosing area Handles non-overlap Weak for irregular defect shapes
DIoU Overlap and center distance Better localization Does not fully handle low-quality samples
CIoU Overlap, center, aspect ratio Good general regression Less robust to blurred or irregular casting defects
Wise-IoUv3 Dynamic focusing and distance attention Stable and generalizable Requires hyperparameter selection

Dataset Construction. I build a surface-defect dataset from castings used in electric vehicle front-fork production. The dataset includes four common categories: excess material, porosity, crack, and inclusion or abnormal structure. I acquire images from multiple viewpoints to increase robustness against illumination changes, reflection, and perspective variation. I use a camera-based acquisition setup and manual annotation with tight bounding boxes. To address class imbalance, I apply dynamic augmentation, including horizontal and vertical mirroring, rotation within a limited range, translation, scaling, brightness adjustment, contrast adjustment, and saturation adjustment. The original set contains 874 annotated images, and augmentation expands it to 2,148 images. I split the dataset into training, validation, and test subsets in a \(7:2:1\) ratio.

Defect category Images Defect instances Small-target instances Small-target share Complex-background samples
Excess material 473 496 348 70.2% 87
Porosity 526 551 456 82.8% 121
Crack 583 594 443 74.6% 114
Inclusion or abnormal structure 566 582 395 67.9% 96

I define a small target as an object whose pixel area is less than \(32\times32\), following common evaluation practice. The table shows that small-target casting defects dominate the dataset. Porosity has the highest small-target share, which explains why recall is often lower for porosity than for excess material. Complex-background samples are also numerous. These samples contain metallic reflection, dense sand texture, oil stains, or machining traces that resemble casting defects. I therefore evaluate the model not only on clean images but also on difficult samples where visual evidence is weak.

Dataset property Value Implication for casting defect detection
Original images 874 Limited raw data require augmentation
Augmented images 2,148 Improved generalization across viewpoints
Classes 4 Multi-class casting defects with different morphologies
Training split 70% Used for parameter optimization
Validation split 20% Used for model selection
Test split 10% Used for final comparison

Experimental Setup. I run experiments under a fixed environment to ensure fair comparison. The training batch size is 16, the optimizer is stochastic gradient descent, and the learning rate follows cosine annealing. I enable adaptive anchor generation and train for 150 epochs. I use a GPU-accelerated workstation for training and measure inference speed on the same hardware. I keep input resolution, augmentation policy, and evaluation protocol consistent across all compared models. This is important because casting defect detection results are sensitive to resolution and augmentation.

Setting Value
Batch size 16
Optimizer SGD
Learning-rate schedule Cosine annealing
Epochs 150
Anchor mode Adaptive
Evaluation thresholds IoU \(0.5:0.95\)

Evaluation Metrics. I report precision, recall, mean average precision, parameter count, floating-point operations, and frames per second. Precision and recall are defined earlier. For mean average precision, I compute the area under the precision-recall curve for each class and average over classes. For edge deployment, parameter count estimates memory footprint, GFLOPs estimates computational workload, and FPS estimates real-time capability. I also consider the balance among these metrics rather than optimizing a single metric in isolation.

Metric Definition Why I use it for casting defects
Precision True positives divided by all predicted positives Reduces false alarms caused by surface noise
Recall True positives divided by all ground-truth positives Reduces missed casting defects
PmA@0.5:0.95 Mean average precision over multiple IoU thresholds Measures localization and classification quality
\(M\) Parameter count Indicates memory demand on edge devices
\(G\) GFLOPs Indicates compute demand
\(v\) FPS Indicates real-time inspection capability

Ablation Study. I conduct an ablation study to isolate the contribution of each module. Model A is the baseline. Model B adds SlimNeck. Model C adds SPDConv. Model D adds SimAM. SAFE-YOLO adds Wise-IoUv3. The results show a clear pattern. SlimNeck reduces parameter count and computation dramatically, although it causes a slight accuracy drop. SPDConv recovers accuracy and surpasses the baseline by a large margin because it preserves fine spatial evidence. SimAM adds a small accuracy gain without increasing model size. Wise-IoUv3 further improves accuracy, recall, and speed. The final model achieves \(88.3\%\) precision, \(85.4\%\) recall, and \(78.2\%\) PmA@0.5:0.95, while reducing parameters by \(21.4\%\) and GFLOPs by \(26.5\%\) compared with the baseline.

Model Precision Recall PmA@0.5:0.95 \(M\) (\(10^6\)) \(G\) (GFLOPs) \(v\) (FPS)
A: baseline 85.6% 83.1% 74.4% 2.8 8.3 83
B: A + SlimNeck 85.2% 82.9% 73.8% 1.7 5.6 112
C: B + SPDConv 87.4% 82.5% 77.0% 2.2 5.9 103
D: C + SimAM 88.1% 84.7% 77.8% 2.2 6.1 101
SAFE-YOLO: D + Wise-IoUv3 88.3% 85.4% 78.2% 2.2 6.1 104

The ablation results also reveal important interactions. SlimNeck alone reduces computation but slightly lowers accuracy because aggressive lightweight fusion may sacrifice some representational capacity. SPDConv then restores and improves accuracy by retaining fine detail. SimAM improves the separation between casting defects and complex background. Wise-IoUv3 improves the regression of irregular defect boundaries. I interpret the final model as a balanced system in which each module addresses a specific bottleneck: SlimNeck addresses computation, SPDConv addresses small-target information loss, SimAM addresses background distraction, and Wise-IoUv3 addresses low-quality regression samples.

Change Accuracy effect Efficiency effect My interpretation
Add SlimNeck Small decrease Large gain in speed, lower \(M\) and \(G\) Creates budget for other modules
Add SPDConv Large increase Small increase in \(M\) and \(G\) Critical for small casting defects
Add SimAM Moderate increase Almost no cost Improves defect saliency in clutter
Add Wise-IoUv3 Small increase and better recall No parameter cost Stabilizes regression for irregular shapes

Comparison with Mainstream Detectors. I compare SAFE-YOLO with several representative detectors under the same dataset and training protocol. These include compact YOLO variants, a transformer-based detector, a two-stage detector, and a single-stage SSD detector. The comparison shows that two-stage and transformer-based detectors can be accurate in general settings but are much larger and slower. Compact YOLO variants are faster but have lower mean average precision on casting defects. SAFE-YOLO achieves the best balance. Its PmA@0.5:0.95 is higher than all compared models, and its parameter count and GFLOPs remain low. Its FPS is slightly lower than one very small variant, but the accuracy gain is substantial.

Model Precision Recall PmA@0.5:0.95 \(M\) (\(10^6\)) \(G\) (GFLOPs) \(v\) (FPS)
YOLOv12n 85.6% 83.1% 75.8% 3.0 7.4 78
YOLOv7-tiny 81.2% 76.9% 68.8% 1.8 3.8 125
YOLOv5n 84.4% 81.5% 73.5% 1.9 4.5 96
DETR 83.1% 78.7% 72.8% 45.7 93.2 43
Faster R-CNN 82.0% 77.4% 65.4% 51.3 176.9 16
SSD 78.6% 74.5% 68.2% 28.5 125.6 56
SAFE-YOLO 88.3% 85.4% 78.2% 2.2 6.1 104

I place particular emphasis on the relationship between speed and accuracy. A detector that runs at high FPS but misses small casting defects is not useful for quality control. A detector that is accurate but too large to deploy cannot satisfy edge requirements. SAFE-YOLO reaches \(104\) FPS while maintaining \(78.2\%\) PmA@0.5:0.95. This operating point is practical for inline inspection, where multiple images may be captured per part. It also leaves headroom for downstream post-processing, such as tracking, alarm generation, or robotic sorting.

Deployment criterion Requirement SAFE-YOLO behavior
Memory footprint Low enough for embedded memory \(2.2\times10^6\) parameters
Compute load Low enough for edge accelerators \(6.1\) GFLOPs
Real-time speed At least camera frame rate \(104\) FPS
Small-defect recall High recall for porosity and cracks \(85.4\%\) overall recall
Background robustness Resistance to reflection and texture SimAM and SPDConv improve selectivity

Visual and Convergence Behavior. I examine feature-map responses to understand why SPDConv helps casting defect detection. With traditional downsampling, the response around a small defect becomes weak and diffuse. With SPDConv, the response remains more concentrated and stronger in the defect region. This is consistent with the space-to-depth principle: spatial information is not discarded but reorganized. I also compare training behavior between CIoU and Wise-IoUv3. The Wise-IoUv3 model converges faster, produces a smoother loss curve, and reaches a higher performance plateau. This is important because casting defect datasets are often small and noisy. A loss function that suppresses harmful gradients from low-quality samples makes the training process more robust.

Observation CIoU behavior Wise-IoUv3 behavior
Convergence speed Slower Faster
Loss fluctuation Larger Smaller
Final plateau Lower Higher
Response to low-quality boxes Less controlled Dynamically suppressed
Suitability for irregular casting defects Moderate Strong

Why the Modules Work Together. I do not view SlimNeck, SimAM, SPDConv, and Wise-IoUv3 as independent tricks. They form a coordinated pipeline. SlimNeck reduces the cost of feature fusion, which creates computational space for SPDConv. SPDConv preserves fine spatial information, which gives SimAM more reliable detail to attend to. SimAM enhances defect-relevant responses before fusion, which improves the quality of features entering the detection head. Wise-IoUv3 then improves the regression of boxes around irregular casting defects. This sequence is important. If I applied SPCDConv without SlimNeck, the model might become too heavy. If I applied SimAM without SPDConv, attention might operate on features that have already lost small-defect detail. If I used Wise-IoUv3 without better features, the regression loss would have less useful information to work with.

Module Primary bottleneck addressed Interaction with other modules
SlimNeck High computation and memory traffic Creates efficiency budget for SPDConv
SPDConv Loss of fine spatial detail Provides stronger features for SimAM
SimAM Background distraction Improves feature quality for the head
Wise-IoUv3 Unstable regression on irregular defects Converts better features into better boxes

Edge Deployment Perspective. Edge devices in a casting inspection cell may include embedded GPUs, NPUs, or specialized inference accelerators. These devices often have limited memory bandwidth, limited power, and limited cooling. A model with many parameters may not fit, and a model with many fragmented operators may not run efficiently. SAFE-YOLO is designed with these constraints in mind. Its parameter count is \(2.2\times10^6\), its computation is \(6.1\) GFLOPs, and its inference speed is \(104\) FPS. These values suggest that the model can be deployed on a range of edge platforms without excessive compression. The use of GSConv and VoV-GSCSP also reduces fragmented computation in the neck, which is beneficial for NPU scheduling and memory movement.

Edge constraint Risk with heavy detectors SAFE-YOLO response
Limited RAM Model may not fit or may swap \(2.2\times10^6\) parameters
Limited compute Frame rate drops below line speed \(6.1\) GFLOPs and \(104\) FPS
Memory bandwidth Frequent data movement lowers utilization SlimNeck reduces redundant fusion
Thermal limit High power reduces sustained throughput Lower computation and parameter count
Small-defect sensitivity Downsampling removes evidence SPDConv retains spatial detail

Robustness to Complex Backgrounds. I find that complex backgrounds are a major source of false positives in casting defect detection. Reflection can create bright or dark streaks that resemble cracks. Sand texture can create small dark spots that resemble porosity. Oil stains can create irregular regions that resemble inclusions. SimAM helps because it computes neuron importance from local statistics. A region that is statistically distinct from its surroundings receives more attention, while a uniform texture region receives less. This does not solve all false positives, but it improves the separation between true casting defects and surface noise. In my ablation, the addition of SimAM increases precision from \(87.4\%\) to \(88.1\%\), which indicates fewer false alarms.

Small-Defect Recall. Recall is critical because a missed casting defect can cause a safety failure. In the dataset, porosity has the highest proportion of small targets. Standard downsampling often reduces recall for porosity because small dark pores merge with surrounding texture. SPDConv improves recall by preserving fine spatial information. The final model reaches \(85.4\%\) recall, which is higher than the baseline and higher than all compared lightweight models. I attribute this improvement primarily to SPDConv, with additional support from SimAM and Wise-IoUv3. The combination allows the detector to localize small casting defects with boxes that better match their true extent.

Defect family Main visual challenge Most helpful module in my design Expected effect
Excess material Irregular boundary and variable area Wise-IoUv3 Better box regression for non-rectangular regions
Porosity Small size and low contrast SPDConv Retains tiny dark structures
Crack Thin elongated shape and weak continuity SPDConv and SimAM Preserves thin responses and suppresses background
Inclusion or abnormal structure Texture similarity and diffuse boundary SimAM and Wise-IoUv3 Improves saliency and regression stability

Class Imbalance and Augmentation. Casting defects are naturally imbalanced. Cracks and porosity may be more common than severe inclusions, and small-target instances dominate certain classes. I use augmentation to reduce overfitting and improve generalization. Mirroring helps with viewpoint variation. Rotation and translation help with position variation. Brightness, contrast, and saturation changes help with illumination variation. However, augmentation cannot replace real data. I therefore keep the validation and test sets free from augmented duplicates of training images. This gives a more honest estimate of how the model performs on unseen casting defects.

Augmentation Purpose Benefit for casting defects
Horizontal and vertical mirroring Viewpoint invariance Handles different camera orientations
Rotation within a limited range Orientation invariance Handles cracks at different angles
Translation Position invariance Handles defects near image borders
Scaling Scale invariance Handles small and large casting defects
Brightness, contrast, saturation Photometric robustness Handles reflection and illumination changes

Training Stability. I observe that the default CIoU loss can produce uneven updates when many low-quality boxes are present. This is common in casting defect detection because annotations near diffuse boundaries may have small localization shifts. Wise-IoUv3 addresses this by using the outlier degree \(\beta\) to modulate the loss. When \(\beta\) indicates a low-quality sample, the focusing coefficient \(r\) reduces its contribution. When \(\beta\) indicates a high-quality sample, \(r\) remains close to one, so the sample contributes normally. This dynamic behavior makes training more stable and improves the final mAP. The convergence curves confirm that the Wise-IoUv3 model reaches a higher plateau with less fluctuation.

Comparison with Two-Stage and Transformer Detectors. I include two-stage and transformer-based detectors to test whether their higher capacity translates into better casting defect detection. In general, they can model long-range dependencies and complex contexts, but they are much larger and slower. Their parameter counts are more than an order of magnitude higher than SAFE-YOLO, and their FPS is far lower. For an industrial line, this is often unacceptable. The comparison supports my decision to stay within a compact single-stage design and improve the feature and loss functions instead of increasing model size.

Model family Strength Weakness in edge casting inspection My design choice
Single-stage compact detector Fast and deployable May miss small casting defects Use as baseline and improve feature flow
Two-stage detector Accurate region proposals Large and slow Reject for edge deployment
Transformer detector Global context modeling High memory and compute Reject for real-time edge use
SSD-style detector Simple multi-scale prediction Lower accuracy on small defects Use only as comparison

Hyperparameter Sensitivity. Wise-IoUv3 introduces hyperparameters \(\alpha\) and \(\delta\) that control the shape of the focusing function. I keep these values moderate so that the loss does not over-suppress low-quality samples. If \(\alpha\) and \(\delta\) are too aggressive, the model may ignore difficult casting defects. If they are too mild, the loss behaves like the original IoU-based loss. I find that a balanced setting improves stability without harming recall. The same principle applies to augmentation strength. Too little augmentation leads to overfitting, while too much augmentation can blur the visual signature of small casting defects.

Hyperparameter Role Risk if too low Risk if too high
\(\alpha\) Shapes focusing coefficient Weak dynamic focusing Over-suppression of difficult samples
\(\delta\) Controls outlier transition Unstable gradient weighting Slow adaptation to sample quality
Augmentation scale Controls visual diversity Overfitting Loss of small-defect texture
Input resolution Controls detail retention Missed small casting defects Higher compute and latency

Deployment Pipeline. In a practical edge pipeline, I would connect the camera to a pre-processing node, run SAFE-YOLO on an embedded accelerator, and pass detections to a rule engine for alarm or sorting. The model must be small enough to load once and run continuously. It must also avoid operator fragmentation that causes memory stalls. My model addresses this by using GSConv and VoV-GSCSP in the neck, SPDConv in selected downsampling positions, and parameter-free SimAM attention. These choices reduce the gap between theoretical FLOPs and actual latency. I would further apply quantization or pruning only after verifying that small casting defects remain detectable. Aggressive compression can remove the very features that distinguish porosity from sand texture.

Pipeline stage Function Consideration for casting defects
Image capture Acquire surface images Lighting and angle affect defect contrast
Pre-processing Resize and normalize Must not blur small casting defects
Inference Run SAFE-YOLO Balance FPS and PmA@0.5:0.95
Post-processing NMS and thresholding Reduce false positives from surface texture
Decision Alarm, reject, or sort Recall is critical for safety-related casting defects

Interpretation of the Final Results. The final model improves PmA@0.5:0.95 by \(3.8\) percentage points over the baseline. It increases speed by \(25.3\%\), reduces parameter count by \(21.4\%\), and reduces GFLOPs by \(26.5\%\). These numbers matter because they show that lightweight design and high accuracy are not mutually exclusive when the architecture is carefully balanced. The largest accuracy gain comes from SPDConv, which confirms that small casting defects require preserved spatial detail. The most efficient gain comes from SlimNeck, which confirms that neck redundancy is a major deployment bottleneck. SimAM adds accuracy at almost no cost. Wise-IoUv3 improves convergence and recall. Together, they produce a model that is suitable for edge-based casting defect detection.

Final model property Relative or absolute value Interpretation
PmA@0.5:0.95 gain +3.8 percentage points Better localization and classification of casting defects
Speed gain +25.3% More suitable for inline inspection
Parameter reduction -21.4% Lower memory demand
GFLOPs reduction -26.5% Lower compute demand
Final FPS 104 Real-time capable on edge hardware

Limitations I Acknowledge. My study focuses on a specific casting family and a curated dataset. Casting defects in other materials, geometries, or lighting conditions may differ. The dataset is augmented, but real production data may contain more severe imbalances and more types of casting defects. The model also assumes that images are captured under controlled conditions. In a real foundry, dust, vibration, and lens contamination can change image statistics. I would address these issues with periodic recalibration, robust pre-processing, and active learning. I would also validate the model on multiple cameras and production lines before large-scale deployment.

Limitation Potential impact on casting defects Future response
Single casting family Limited generalization Expand to multiple geometries and alloys
Augmented data May not match real variation Collect more production images
Controlled lighting Performance may drop under dust or vibration Add robust pre-processing and calibration
Fixed threshold May trade precision and recall differently by line Use adaptive thresholding
No temporal tracking Single-frame false positives remain Add tracking across consecutive frames

Future Work. I plan to extend this work in several directions. First, I will test the model on a broader set of casting defects, including shrinkage cavities, cold shuts, misruns, and flash. Second, I will evaluate quantization and pruning carefully to preserve small-defect recall. Third, I will integrate temporal information from multiple frames to reduce false positives and improve defect tracking. Fourth, I will explore lightweight knowledge distillation from a larger teacher model to improve the student model without increasing deployment cost. Fifth, I will deploy the model on embedded hardware and measure real power consumption, memory bandwidth, and sustained FPS. These steps will move casting defect detection from a controlled experimental setting toward a robust industrial solution.

Future direction Expected benefit Risk to manage
Broader defect taxonomy Better coverage of casting defects Increased class imbalance
Quantization-aware training Lower memory and faster inference Loss of small-defect detail
Temporal tracking Fewer false positives Higher pipeline complexity
Knowledge distillation Higher accuracy at low cost Teacher-student capacity gap
Embedded deployment Real-world validation Hardware-specific optimization

My Conclusion. I designed an edge-oriented detector for casting defects and evaluated it on a challenging dataset of casting surface images. The model combines SlimNeck, SimAM, SPDConv, and Wise-IoUv3 within a compact single-stage framework. SlimNeck reduces neck redundancy and computation. SimAM improves defect saliency without adding parameters. SPDConv preserves fine spatial information that is essential for small casting defects. Wise-IoUv3 stabilizes regression and accelerates convergence. The final model achieves \(88.3\%\) precision, \(85.4\%\) recall, and \(78.2\%\) PmA@0.5:0.95, while reducing parameters by \(21.4\%\) and GFLOPs by \(26.5\%\) and increasing speed by \(25.3\%\) compared with the baseline. I conclude that lightweight and high-precision casting defect detection can be achieved through coordinated architecture and loss design, and that such a model is well suited for edge deployment in industrial casting inspection.

Design principle Implementation Outcome for casting defects
Reduce redundancy before adding capacity SlimNeck with GSConv and VoV-GSCSP Lower \(M\), lower \(G\), higher FPS
Preserve spatial detail SPDConv replaces selected downsampling Higher accuracy on small casting defects
Increase saliency without parameters SimAM at backbone-neck links Better focus in complex backgrounds
Stabilize regression Wise-IoUv3 with dynamic focusing Faster convergence and better recall
Optimize for deployment Balance accuracy, size, computation, and speed Practical edge inference for casting defects

I believe that casting defect detection will continue to benefit from lightweight architectures that respect the physics of the inspection problem. The visual evidence of a casting defect is often subtle, local, and fragile. A detector must therefore avoid destroying that evidence too early. It must also avoid spending computation on redundant feature fusion. SAFE-YOLO reflects this philosophy. It reduces unnecessary complexity, preserves fine detail, enhances relevant responses, and improves bounding-box regression. In my evaluation, these choices produce a model that is both accurate and deployable. I will continue to refine the approach with more production data, broader defect categories, and embedded hardware validation, because casting defects remain a central quality and safety concern in modern manufacturing.

Scroll to Top