In my work on industrial visual inspection, I address the problem of automatic surface quality evaluation for castings. A casting defect is not a single visual pattern; it can appear as incomplete geometry, porosity, shrinkage depression, crack, blowhole, protrusion, scratch, or dross hole. Each casting defect has its own scale, contrast, boundary property, and formation mechanism. Because castings are produced under complex thermal and metallurgical conditions, the surface texture is often rough, reflective, and non-uniform. These properties make casting defect detection different from ordinary object detection. I therefore developed a lightweight and high-accuracy detection framework, named FSD-DETR, for casting defect detection in industrial environments. The method is designed to balance three requirements: recognition accuracy for small casting defects, computational efficiency for real-time inference, and deployability on resource-constrained embedded platforms.

I begin from the observation that manual visual inspection is still common in many foundries, but it suffers from fatigue, inconsistent attention, subjective judgment, and low throughput. Non-destructive testing techniques such as penetrant testing, eddy current testing, and ultrasonic testing provide valuable physical information, yet they are often difficult to integrate into high-speed automated surface inspection lines. Machine vision offers a non-contact and scalable alternative. Early vision methods based on thresholding, edge detection, morphology, or hand-crafted features can detect some casting defects, but their performance is sensitive to illumination, surface roughness, and parameter tuning. Deep learning has changed this situation because convolutional and transformer-based detectors can learn discriminative representations directly from images. However, many high-performance detectors are too large or too slow for embedded industrial use. My objective is therefore to design a casting defect detector that is accurate, compact, and fast enough for practical deployment.
Dataset Construction for Casting Defect Detection
I constructed a multi-class casting defect dataset from industrial images. A stereo camera and on-site imaging were used to collect more than fifteen thousand raw images at a resolution of 1280 by 1280 pixels. The raw data covered eight casting defect categories: incomplete, porosity, shrinkage, crack, blowhole, protrusion, scratch, and dross hole. These categories represent common surface casting defects in actual production. To improve data reliability, I applied a systematic cleaning pipeline. First, perceptual hashing was used to remove highly duplicated images. The Hamming distance threshold was set to 5. Second, blurry images were removed using Laplacian variance and fast Fourier transform analysis. The Laplacian threshold was set to 60, and the FFT score threshold was set to 6. Third, images with local overexposure were corrected using a QuickShift-based illumination correction procedure. The method detected reflective regions, refined the mask through superpixel segmentation, and applied mean filtering for local repair. After cleaning, I retained four thousand high-quality images as the core dataset.
To increase diversity without changing the semantic meaning of each casting defect, I applied three augmentation strategies. Horizontal flipping was used to reduce orientation bias. Color jittering was used to simulate illumination and color variation; the brightness, contrast, and saturation factors were 0.3, 0.4, and 0.5, respectively. A slight perspective transform with a scale of 0.1 was used to simulate viewing-angle changes. After augmentation, the dataset contained 4168 images. I annotated all images in YOLO format using a bounding box representation. Each target instance was recorded as a class index, a normalized center coordinate, and normalized width and height.
| Defect Category | Label Count | Main Visual Characteristic |
|---|---|---|
| Incomplete | 1535 | Missing local geometry or incomplete contour |
| Porosity | 2124 | Small cavities or gas pores |
| Shrinkage | 659 | Depression caused by solidification shrinkage |
| Crack | 873 | Elongated fracture or line-like discontinuity |
| Blowhole | 501 | Large cavity related to trapped gas |
| Protrusion | 746 | Abnormal local elevation |
| Scratch | 686 | Linear surface damage |
| Dross Hole | 815 | Hole associated with slag or inclusion |
I split the dataset into training, validation, and test subsets at a ratio of 7:2:1. This casting defect dataset, which I refer to as CSDD, provides a reliable basis for training and evaluating casting defect detectors. The class distribution is imbalanced, which is natural in industrial casting defect detection. Porosity and incomplete defects appear more frequently, while blowhole and shrinkage defects are less frequent. This imbalance makes the detection task more difficult and motivates the use of robust feature aggregation and loss design.
Baseline Detector and Its Limitations
As a baseline, I studied RT-DETR because it combines a transformer-based end-to-end detection paradigm with real-time inference ability. RT-DETR avoids non-maximum suppression and anchor generation, which simplifies the detection pipeline. The RT-DETR-r18 variant uses a ResNet-18 backbone, a hybrid encoder with attention-based intra-scale feature interaction and cross-scale feature fusion, and a decoder with IoU-aware query selection. The baseline achieves strong performance on general object detection, but for casting defect detection I observed several limitations. First, small casting defects such as fine cracks and tiny porosity are easily lost after repeated downsampling. Second, complex surface texture and reflections can dominate the feature response. Third, the parameter count and computational cost of the original backbone are not ideal for embedded deployment. Fourth, GIoU regression loss is not sufficiently sensitive when the predicted box and ground-truth box have small overlap, which frequently occurs for tiny casting defects. These observations motivated my improvements.
Proposed FSD-DETR for Casting Defect Detection
I propose FSD-DETR, a lightweight detector for casting defect detection. The architecture consists of a backbone, a hybrid encoder, and a transformer decoder. I redesigned the backbone using a star-operation network and frequency channel attention, improved feature aggregation with a geometry-aware module, and replaced the regression loss with PIoU. The overall goal is to improve small casting defect recognition while reducing parameters and floating-point operations.
Fstar Block with StarNet and Frequency Channel Attention
I replaced the original ResNet-18 backbone with StarNet because StarNet uses element-wise multiplication to map features into a high-dimensional nonlinear space without a large increase in width or depth. This star operation creates a rich representation through cross-channel interaction. I then inserted a frequency channel attention mechanism into the depthwise convolution stage, forming the Fstar Block. Frequency channel attention transforms features into the frequency domain using discrete cosine transform, selects representative frequency components, and recalibrates channel weights. This helps the detector suppress repetitive background texture and enhance subtle casting defect responses.
The frequency channel attention procedure can be summarized as follows. For an input feature map, I first apply a transform to obtain frequency-domain features. I then compress the channel dimension by a reduction ratio, apply a nonlinear activation, and restore the original channel dimension. A sigmoid function produces channel weights, which are multiplied element-wise with the input feature. This operation strengthens informative channels and reduces redundant background channels. In my experiments, this module improved the detection of small casting defects without materially increasing model size.
FRA Feature Aggregation Module
I designed a feature-aware relation aggregation module, called FRA, to improve multi-scale feature fusion. The module uses 1 by 1 convolutions at the front and back to compress and restore channel dimensions. Between them, I embed a DSConv module that adapts its receptive field to the geometry of the target. This is important for casting defects because cracks, scratches, and shrinkage depressions often have elongated, curved, or irregular shapes. A fixed square convolution kernel is not always optimal for such geometries. DSConv decomposes convolution into a variable quantized kernel and distribution shifts, including kernel distribution shift and channel distribution shift. The iterative offset mechanism enables the kernel to follow linear and curved structures more accurately. A residual connection is also used to preserve information flow and ease optimization.
I define the iterative geometric adjustment of the kernel as follows. Along the x-axis, the kernel positions are updated by accumulated offsets:
$$K_{i\pm c} =
\begin{cases}
(x_{i+c}, y_{i+c}) = \left(x_i + c, y_i + \sum \Delta y_{i+c}^{i}\right),\\
(x_{i-c}, y_{i-c}) = \left(x_i – c, y_i + \sum \Delta y_{i-c}^{i}\right).
\end{cases}$$
Along the y-axis, the corresponding update is:
$$K_{j\pm c} =
\begin{cases}
(x_{j+c}, y_{j+c}) = \left(x_j + \sum \Delta x_{j+c}^{j}, y_j + c\right),\\
(x_{j-c}, y_{j-c}) = \left(x_j + \sum \Delta x_{j-c}^{j}, y_j – c\right).
\end{cases}$$
This geometry-aware aggregation allows the detector to represent casting defect boundaries more faithfully, especially for thin and curved defects.
PIoU Loss for Casting Defect Localization
I replaced the original GIoU regression loss with PIoU. The motivation is that GIoU provides weak gradient feedback when the predicted box and the ground-truth box barely overlap. Small casting defects often produce exactly this situation. PIoU incorporates pixel-level overlap, angular information, and region consistency. It is more sensitive to small overlapping regions and can improve localization quality. I define the pixel membership function as:
$$F(p_{i,j}|b)=K(d_{i,j}^{w}, w)K(d_{i,j}^{h}, h).$$
The kernel function is a smooth step:
$$K(d,s)=1-\frac{1}{1+e^{-k(d-s)}}.$$
The intersection and union areas of two oriented rectangles are approximated as:
$$S_{b\cap b’} \approx \sum_{p_{i,j}\in B_{b,b’}} F(p_{i,j}|b)F(p_{i,j}|b’),$$
$$S_{b\cup b’} \approx wh + w’h’ – S_{b\cap b’}.$$
The PIoU value and loss are:
$$PIoU(b,b’) = \frac{S_{b\cap b’}}{S_{b\cup b’}},$$
$$L_{piou} = \frac{-\sum_{(b,b’)\in M}\ln PIoU(b,b’)}{|M|}.$$
This loss improves the localization of casting defects with small size, weak contrast, or irregular orientation.
Experimental Environment and Evaluation Metrics
I conducted all experiments under a unified environment. The operating system was Ubuntu 22.04. The hardware included a Xeon 8362 processor, 45 GB memory, and an NVIDIA RTX 3090 GPU with 24 GB memory. The software stack used CUDA 12.1 and PyTorch 2.3.0. I trained models for 120 epochs with a batch size of 8 and an input size of 640 by 640. No pretrained weights were loaded unless otherwise stated. I used precision, recall, AP, mAP@50, mAP@50:95, parameters, GFLOPs, and FPS as evaluation metrics.
The metrics are defined as follows:
$$P = \frac{TP}{TP+FP},$$
$$R = \frac{TP}{TP+FN},$$
$$AP = \int_0^1 P(R)\,dR,$$
$$mAP = \frac{1}{N}\sum_{i=1}^{N} AP_i.$$
Here, TP is the number of true positives, FP is the number of false positives, FN is the number of false negatives, and N is the number of casting defect categories. Higher mAP indicates better casting defect detection accuracy. Parameters and GFLOPs indicate model size and computational complexity. FPS indicates real-time inference capability.
Backbone Comparison for Casting Defect Detection
I compared StarNet with several lightweight backbones, including EfficientViT, MobileNet, RepViT, and UniRepLKNet. The results show that StarNet provides the best balance between accuracy and model size on the casting defect dataset.
| Backbone | Parameters (M) | mAP@50 (%) | mAP@50:95 (%) |
|---|---|---|---|
| ResNet18 | 19.9 | 94.4 | 65.3 |
| EfficientViT | 10.7 | 91.8 | 59.4 |
| MobileNet | 11.3 | 90.7 | 60.6 |
| RepViT | 13.3 | 91.8 | 61.7 |
| UniRepLKNet | 12.7 | 91.0 | 59.8 |
| StarNet | 12.0 | 95.0 | 65.7 |
StarNet reduced parameters by about 39.7 percent compared with ResNet18 while improving mAP@50 and mAP@50:95 to 95.0 percent and 65.7 percent. This confirms that the star operation is effective for casting defect feature extraction.
Attention Fusion in the Backbone
I also evaluated different attention modules in the backbone. The comparison included CA, GC, ECA, and FCA. The FCA module achieved the best mAP@50:95 among the tested variants and improved the baseline StarNet without a meaningful increase in parameters.
| Model | Parameters (M) | mAP@50 (%) | mAP@50:95 (%) |
|---|---|---|---|
| StarNet | 12.00 | 95.0 | 65.7 |
| StarNet + CA | 12.03 | 91.9 | 60.8 |
| StarNet + GC | 12.12 | 95.5 | 65.4 |
| StarNet + ECA | 12.00 | 95.8 | 65.8 |
| StarNet + FCA | 12.03 | 95.7 | 66.5 |
The FCA module increased mAP@50 and mAP@50:95 by 0.7 percent and 0.8 percent over StarNet. This improvement is valuable for casting defect detection because frequency-domain weighting can suppress periodic texture and enhance weak defect signals.
Loss Function Comparison
I compared GIoU, CIoU, DIoU, EIoU, SIoU, and PIoU. PIoU achieved the best mAP@50:95 while maintaining strong mAP@50 performance. This demonstrates its advantage for casting defect localization.
| Loss | mAP@50 (%) | mAP@50:95 (%) |
|---|---|---|
| GIoU | 94.4 | 65.3 |
| CIoU | 94.6 | 65.9 |
| DIoU | 94.9 | 65.5 |
| EIoU | 95.2 | 66.1 |
| SIoU | 95.2 | 66.2 |
| PIoU | 95.2 | 66.4 |
The improvement from PIoU is especially important for high-quality localization. A casting defect may occupy only a few pixels, so a loss that is sensitive to tiny overlaps gives more useful gradients.
Hyperparameter Analysis
I studied batch size, learning rate, and training epochs. The best configuration used batch size 8, learning rate 0.0001, and 120 epochs with AdamW. This setting provided the best mAP@50 and mAP@50:95 while maintaining reasonable training time.
| Group | Batch Size | Learning Rate | Epochs | Optimizer | Training Time (h) | mAP@50 (%) | mAP@50:95 (%) |
|---|---|---|---|---|---|---|---|
| 1 | 4 | 0.0001 | 120 | AdamW | 4.920 | 95.2 | 65.9 |
| 2 | 8 | 0.0001 | 120 | AdamW | 2.936 | 96.1 | 67.4 |
| 3 | 16 | 0.0001 | 120 | AdamW | 2.384 | 95.5 | 66.2 |
| 4 | 8 | 0.001 | 120 | AdamW | 3.021 | 93.0 | 61.3 |
| 5 | 8 | 0.0005 | 120 | AdamW | 2.918 | 94.7 | 65.1 |
| 6 | 8 | 0.00005 | 120 | AdamW | 3.120 | 95.6 | 65.5 |
| 7 | 8 | 0.0001 | 100 | AdamW | 2.392 | 95.6 | 66.3 |
| 8 | 8 | 0.0001 | 150 | AdamW | 3.614 | 95.9 | 67.0 |
Group 2 gave the best overall performance. Although a larger batch size reduced training time, it slightly reduced accuracy. A larger learning rate caused unstable convergence. Therefore, I selected batch size 8, learning rate 0.0001, and 120 epochs for the final casting defect detector.
Comparison with Mainstream Detectors
I compared FSD-DETR with YOLOv5m, YOLOv8m, YOLOv10m, YOLO11m, and RT-DETR-L on the casting defect dataset. FSD-DETR achieved the highest mAP@50 and mAP@50:95 while using far fewer parameters and GFLOPs than most competing models.
| Model | Parameters (M) | GFLOPs (G) | Precision (%) | Recall (%) | mAP@50 (%) | mAP@50:95 (%) | FPS |
|---|---|---|---|---|---|---|---|
| YOLOv5m | 25.05 | 64.0 | 91.7 | 85.8 | 91.9 | 61.8 | 103.5 |
| YOLOv8m | 25.84 | 78.7 | 93.4 | 87.3 | 92.7 | 63.2 | 87.2 |
| YOLOv10m | 16.46 | 63.5 | 89.3 | 80.7 | 89.3 | 61.6 | 87.6 |
| YOLO11m | 20.04 | 67.7 | 91.6 | 84.8 | 92.1 | 61.9 | 87.7 |
| RT-DETR-L | 32.00 | 103.5 | 93.4 | 89.7 | 94.0 | 64.7 | 53.5 |
| FSD-DETR | 13.09 | 37.1 | 94.8 | 93.2 | 96.1 | 67.4 | 92.3 |
FSD-DETR reduced parameters by 34.2 percent and GFLOPs by 34.9 percent compared with RT-DETR-r18, while improving mAP@50 from 94.4 percent to 96.1 percent. The inference speed reached 92.3 FPS, which is suitable for real-time casting defect detection.
Per-Class Casting Defect Detection Results
I further evaluated per-class performance. The proposed model achieved strong results for incomplete, porosity, shrinkage, crack, blowhole, protrusion, scratch, and dross hole. The largest gains appeared for crack and scratch, which are thin and easily missed by ordinary detectors.
| Model | Incomplete (%) | Porosity (%) | Shrinkage (%) | Crack (%) | Blowhole (%) | Protrusion (%) | Scratch (%) | Dross Hole (%) |
|---|---|---|---|---|---|---|---|---|
| YOLOv5m | 96.4 | 77.4 | 93.4 | 92.8 | 96.8 | 93.4 | 86.3 | 98.4 |
| YOLOv8m | 96.6 | 79.3 | 96.2 | 93.7 | 97.1 | 93.7 | 87.0 | 98.1 |
| YOLOv10m | 95.0 | 74.5 | 90.9 | 87.0 | 95.3 | 91.2 | 82.7 | 98.1 |
| YOLO11m | 97.3 | 78.0 | 91.9 | 94.2 | 96.9 | 94.6 | 85.1 | 99.0 |
| RT-DETR-L | 98.3 | 83.9 | 96.3 | 93.5 | 97.3 | 93.7 | 89.8 | 99.5 |
| FSD-DETR | 98.7 | 86.5 | 98.5 | 97.6 | 97.3 | 95.9 | 95.0 | 99.4 |
For casting defect detection, the improvement on crack and scratch is particularly meaningful because these defects can compromise sealing, fatigue life, and structural safety. The model also improved porosity detection, which is often difficult because pores vary greatly in size and contrast.
Ablation Study
I performed an ablation study to quantify the contribution of each component. The components were StarNet, FCA, FRA, and PIoU. The final FSD-DETR model achieved the best mAP@50:95 and a strong balance between accuracy and efficiency.
| Model | StarNet | FCA | FRA | PIoU | Parameters (M) | GFLOPs (G) | mAP@50 (%) | mAP@50:95 (%) |
|---|---|---|---|---|---|---|---|---|
| Baseline | No | No | No | No | 19.88 | 57.0 | 94.4 | 65.3 |
| A | Yes | No | No | No | 12.00 | 31.8 | 95.0 | 65.7 |
| B | Yes | Yes | No | No | 12.03 | 31.8 | 95.7 | 66.5 |
| C | Yes | No | Yes | No | 13.06 | 37.1 | 95.9 | 66.7 |
| D | Yes | No | No | Yes | 12.00 | 31.8 | 95.8 | 66.4 |
| E | Yes | Yes | Yes | No | 13.09 | 37.1 | 96.2 | 66.7 |
| FSD-DETR | Yes | Yes | Yes | Yes | 13.09 | 37.1 | 96.1 | 67.4 |
The ablation results show that StarNet reduces parameters and computation while improving accuracy. FCA improves channel selectivity. FRA improves multi-scale and geometry-aware feature aggregation. PIoU improves localization. When all components are combined, FSD-DETR achieves 96.1 percent mAP@50 and 67.4 percent mAP@50:95 while reducing parameters and GFLOPs by 34.2 percent and 34.9 percent compared with the baseline.
Generalization on an External Casting Defect Dataset
To test generalization, I evaluated the model on the NEU-DET steel surface defect dataset. This dataset contains crazing, patches, inclusion, pitted surface, rolled-in scale, and scratches. It has different textures and class distributions from my casting defect dataset. FSD-DETR achieved 74.6 percent mAP@50, outperforming several mainstream methods.
| Model | Crazing (%) | Patches (%) | Inclusion (%) | Pitted Surface (%) | Rolled-in Scale (%) | Scratches (%) | mAP@50 (%) |
|---|---|---|---|---|---|---|---|
| YOLOv5 | 47.0 | 92.2 | 78.2 | 77.1 | 44.9 | 71.0 | 65.7 |
| Faster R-CNN | 37.6 | 85.3 | 80.2 | 81.5 | 54.0 | 89.2 | 71.3 |
| RetinaNet | 45.9 | 91.1 | 84.2 | 74.7 | 43.5 | 81.6 | 70.2 |
| Multi-Scale YOLOv5 | 34.5 | 89.8 | 76.8 | 82.5 | 61.6 | 86.8 | 72.0 |
| Fine-YOLO | – | – | – | – | – | – | 73.1 |
| NHD-YOLOx | – | – | – | – | – | – | 74.3 |
| RT-DETR-r18 | 24.3 | 91.1 | 78.8 | 75.2 | 59.9 | 86.7 | 69.3 |
| FSD-DETR | 51.5 | 84.9 | 81.7 | 76.7 | 61.8 | 91.1 | 74.6 |
The improvement over RT-DETR-r18 was 5.3 percentage points in mAP@50. This suggests that the proposed casting defect detector learns robust features that transfer beyond the original casting defect dataset. I also tested different illumination conditions on the casting defect dataset. The detection results remained stable under left-side and right-side lighting, indicating good resistance to illumination variation.
Model Compression through Pruning
Although FSD-DETR is already lightweight, I further compressed it for embedded deployment. I compared L1 pruning, Group Hessian pruning, Group Taylor pruning, and LAMP pruning. The pruning coefficient is defined as:
$$P = \frac{F}{F’},$$
where F is the computational cost before pruning and F’ is the computational cost after pruning. I evaluated pruning coefficients of 1.2, 1.4, and 1.6.
| Model | P | Parameters (M) | GFLOPs (G) | mAP@50 (%) | FPS |
|---|---|---|---|---|---|
| RT-DETR-r18 baseline | – | 19.9 | 57.0 | 94.4 | 90.1 |
| FSD-DETR | – | 13.1 | 37.1 | 96.1 | 92.3 |
| FSD-DETR + L1 | 1.2 | 10.7 | 30.4 | 94.6 | 138.9 |
| FSD-DETR + L1 | 1.4 | 9.1 | 26.0 | 92.7 | 333.3 |
| FSD-DETR + L1 | 1.6 | 7.6 | 22.2 | 92.8 | 233.0 |
| FSD-DETR + Group Hessian | 1.2 | 9.9 | 30.1 | 96.0 | 175.4 |
| FSD-DETR + Group Hessian | 1.4 | 8.8 | 26.1 | 95.9 | 370.4 |
| FSD-DETR + Group Hessian | 1.6 | 7.9 | 22.9 | 95.0 | 238.1 |
| FSD-DETR + Group Taylor | 1.2 | 9.7 | 30.0 | 96.0 | 181.8 |
| FSD-DETR + Group Taylor | 1.4 | 8.5 | 26.0 | 95.4 | 153.8 |
| FSD-DETR + Group Taylor | 1.6 | 7.4 | 22.3 | 95.4 | 322.6 |
| FSD-DETR + LAMP | 1.2 | 9.6 | 30.0 | 96.1 | 166.7 |
| FSD-DETR + LAMP | 1.4 | 8.3 | 25.8 | 96.1 | 370.4 |
| FSD-DETR + LAMP | 1.6 | 7.4 | 21.9 | 96.0 | 400.0 |
LAMP pruning achieved the best overall result. The LAMP score is computed as:
$$score(u,w) = \frac{w(u)^2}{\sum_{v\ge u} w(v)^2}.$$
This score ranks weights globally and adaptively allocates pruning ratios across layers. At P=1.6, LAMP reduced parameters to 7.4 M and GFLOPs to 21.9 while keeping mAP@50 at 96.0 percent and increasing FPS to 400. This is a strong result for real-time casting defect detection.
Knowledge Distillation for Accuracy Recovery
Pruning can cause slight accuracy loss, so I applied channel-wise distillation to recover performance. I used the full FSD-DETR as the teacher model and the LAMP-pruned FSD-DETR as the student model. Channel-wise distillation aligns channel-level feature distributions between teacher and student. A 1 by 1 convolution is used to match channel dimensions when necessary. Softmax normalization is applied to channel activations, and KL divergence measures the distribution difference:
$$L_{CWD} = \frac{1}{C}\sum_{c=1}^{C} D_{KL}\left(\sigma(T_c/\tau) \| \sigma(S_c/\tau)\right).$$
I set the distillation weight to 0.06 after testing values in the range of 0.02 to 0.06. The results are shown below.
| Model | Parameters (M) | GFLOPs (G) | mAP@50 (%) | FPS |
|---|---|---|---|---|
| Teacher: FSD-DETR | 13.1 | 37.1 | 96.1 | 92.3 |
| Student: FSD-DETR-LAMP | 7.4 | 21.9 | 96.0 | 400.0 |
| FSD-DETR-LAMP-CWD | 7.4 | 21.9 | 96.1 | 397.0 |
After distillation, the student model recovered mAP@50 to 96.1 percent with almost no loss in speed. Compared with the original baseline, the final compressed model reduced parameters by 62.8 percent and GFLOPs by 61.6 percent. This demonstrates that LAMP pruning combined with channel-wise distillation is an effective strategy for lightweight casting defect detection.
Embedded Deployment and Visual Inspection System
I deployed the compressed model on an embedded platform to validate engineering practicality. The deployment platform used a low-power edge computing board with an ARM CPU, an embedded GPU, 4 GB memory, and multiple input-output interfaces. A high-resolution CMOS camera was connected through a MIPI CSI-2 interface for image acquisition. A monitor was connected through HDMI for visualization and debugging. I installed the operating system from a JetPack image, configured Python, PyTorch, OpenCV, and the required inference dependencies, and verified GPU acceleration. The deployment process included image acquisition, preprocessing, model inference, postprocessing, and result display.
I developed a visual casting defect detection system using PyQt5. The system includes a login module, parameter configuration, image detection, real-time camera detection, result saving, and safe exit. The login module performs user authentication and registration. The detection interface allows the operator to adjust the confidence threshold and IoU threshold, load a model configuration, import a casting image, open a camera stream, start detection, save results, and exit. The interface displays the original casting image on one side and the annotated detection result on the other side. Bounding boxes and class labels indicate the location and type of each casting defect. A log panel reports the image name, detection status, total number of targets, and per-class counts.
The result saving function writes both annotated images and structured detection records to a specified folder. This supports quality traceability, statistical analysis, and later model improvement. The exit function releases camera resources, closes database connections, and clears temporary detection folders after user confirmation. I verified the system with static images and live camera streams. The embedded system maintained stable operation and real-time inference, confirming that the lightweight casting defect detector can be integrated into an industrial inspection workflow.
Discussion
My results show that casting defect detection benefits from a detector designed specifically for small, irregular, and low-contrast targets. The Fstar Block improves feature extraction while reducing parameters. The FRA module enhances geometric representation for cracks, scratches, and shrinkage depressions. PIoU improves regression for tiny casting defects. LAMP pruning and channel-wise distillation further reduce model size and increase speed without sacrificing accuracy. The final model is suitable for embedded deployment and can support real-time visual inspection of industrial castings.
I also note several remaining challenges. Casting defect appearances can vary across alloys, molds, cooling conditions, and surface treatments. Extreme illumination, oil contamination, dust, and vibration can still affect image quality. Very small casting defects and rare defect classes remain difficult. Future work can explore low-bit quantization, structural reparameterization, adaptive sparse inference, multimodal fusion with acoustic emission, three-dimensional point clouds, thermal information, and process parameters. Online learning and active learning could allow the system to adapt continuously to new casting defect samples from production lines.
Conclusion
I presented a lightweight and high-accuracy method for industrial casting surface defect detection. I constructed a multi-class casting defect dataset, proposed the FSD-DETR detector with StarNet, frequency channel attention, FRA aggregation, and PIoU loss, compressed the model using LAMP pruning and channel-wise distillation, and deployed the final model on an embedded platform with a PyQt5-based inspection interface. The method achieved 96.1 percent mAP@50 with only 7.4 M parameters and 21.9 GFLOPs after compression, while reaching 397 FPS. These results demonstrate that accurate, real-time, and deployable casting defect detection is feasible for industrial applications. The approach provides a practical foundation for intelligent quality control in foundries and supports further development of automated casting defect inspection systems.
