In the process of manufacturing mechanical components, various defects may emerge, posing serious threats to equipment operational safety. The inspection of precision castings, particularly in the context of sand foundry defect analysis, is of critical importance. Traditional defect detection methods heavily rely on operator experience and are susceptible to human factors such as fatigue, visual acuity, and inconsistent judgment. To overcome these limitations, machine learning—especially deep learning—offers a promising pathway toward automated, accurate, and rapid defect identification. This article presents my research on applying deep learning techniques to detect cracks in precision castings, addressing the specific needs of a precision casting facility. I developed a complete hardware–software system leveraging convolutional neural networks (CNNs) and embedded platform deployment.
In this study, I first constructed a deep learning environment based on a GPU and selected Caffe as the software framework. I then designed a suitable network architecture for the given defect samples. I systematically investigated the influence of convolutional kernel sizes, network depth, pooling strategies, and hyperparameters on model performance. By optimizing these factors, I improved the classification accuracy while reducing training time. Furthermore, I successfully ported the trained model to an embedded system based on the Jetson TX1 platform, enabling real-time, low-cost, and compact deployment. The final embedded system achieved a test accuracy of 98.67% with zero missed detections, thus fulfilling engineering requirements and demonstrating the effectiveness of the proposed deep-learning-based defective detection system.
1 Introduction
With the rapid development of industrial automation, the demand for intelligent manufacturing has increased considerably. In the production of mechanical parts, surface defects such as cracks can occur during manufacturing, or they may develop over time due to cyclic loading under high temperatures or pressures. Statistical data indicate that approximately 80% of mechanical component failures result from fatigue damage. Therefore, timely and accurate detection of surface defects is essential to ensure product quality and operational safety.
Non-destructive testing (NDT) is widely used for defect detection, and magnetic particle testing (MPT) is one of the most common methods for inspecting ferromagnetic materials, especially for surface and near-surface defects. MPT offers high sensitivity and simple operation. However, the conventional MPT process relies heavily on human inspectors. The inspector must visually examine the magnetic particle indications under ultraviolet light, which is subjective, labor-intensive, and prone to errors caused by fatigue, experience differences, and poor repeatability. These issues lead to high false-negative or false-positive rates, especially for small and complex precision castings with subtle crack indications on a noisy background.
To address these challenges, researchers have attempted to automate defect recognition using image processing and machine learning. Traditional image-processing methods often require manual feature extraction (e.g., edge detection, thresholding, morphology) and are not robust to variations in illumination, surface texture, and defect morphology. Machine learning approaches such as support vector machines (SVMs) and shallow neural networks have also been explored, but they usually rely on handcrafted features and tend to generalize poorly on complex patterns.
Deep learning, especially convolutional neural networks (CNNs), has emerged as a powerful tool for image recognition and classification tasks. CNNs automatically learn hierarchical feature representations directly from raw pixels, thereby eliminating the need for manual feature engineering. In recent years, deep learning has achieved remarkable success in various fields, including image classification, object detection, and semantic segmentation. Motivated by these advances, I adopt deep learning to solve the sand foundry defect detection problem in this study. By training a CNN model on a substantial dataset of magnetic particle images, I can automatically distinguish defective and defect-free castings with high accuracy and speed.
The main contributions of this work are summarized as follows:
- I constructed a GPU-based deep learning environment and developed a Caffe-based network architecture tailored to the magnetic particle images of precision castings.
- I investigated the influence of convolutional kernel sizes on the network performance, demonstrating that appropriately increasing the kernel size improves feature extraction and yields higher classification accuracy for the given defect patterns.
- I simplified the network structure by removing two convolutional layers, which accelerated training by 29.33% while improving the accuracy from 98.75% to 99%, thus satisfying the industrial requirement of time efficiency without compromising correctness.
- I designed and built a complete embedded system based on the NVIDIA Jetson TX1, including hardware integration, software environment setup, and seamless porting of the trained CNN model. The final system achieved 98.67% accuracy on a test set of 600 images with zero missed detections.
The remainder of this article is organized as follows. Section 2 reviews relevant literature on deep learning and magnetic particle inspection. Section 3 describes the construction of the deep learning environment, including hardware and software setups. Section 4 details the network architecture and the optimization methodology. Section 5 presents the experimental results and comparisons. Section 6 describes the embedded system implementation and performance evaluation. Section 7 concludes the paper and discusses future research directions.
2 Literature Review
2.1 Deep Learning and Convolutional Neural Networks
Deep learning is a subfield of machine learning inspired by the structure and function of the brain, particularly the visual cortex. In 1959, Hubel and Wiesel discovered that cells in the animal visual cortex are responsible for detecting light in receptive fields. This finding laid the groundwork for the development of artificial neural networks. In 1980, Kunihiko Fukushima proposed the Neocognitron, which is considered a precursor of CNNs. In 1990, LeCun and colleagues introduced the influential LeNet-5 architecture for handwritten digit recognition, which was trained using the backpropagation algorithm. However, due to limited training data and computational power, these early networks could not handle complex tasks such as large-scale image classification.
The deep learning revolution began in 2006 when Hinton and his team presented an efficient learning algorithm for deep belief networks. Since then, deep learning has attracted ever-increasing attention, leading to breakthroughs in speech recognition, image processing, and many other domains. A major milestone was reached in 2012, when Krizhevsky et al. developed the AlexNet architecture, which significantly outperformed traditional methods in the ImageNet classification challenge. AlexNet consisted of five convolutional layers, three pooling layers, and three fully connected layers, and it was trained on GPU hardware to accelerate computation. Since then, deeper and more sophisticated architectures have been proposed, including ZFNet, VGGNet, GoogLeNet, and ResNet. These networks have demonstrated that increasing depth and using appropriate structural designs can greatly improve representation capacity and classification performance.
In the field of industrial defect detection, deep learning has been increasingly applied due to its automatic feature extraction and superior generalization. For example, Wang et al. (2014) used a deep belief network for solar cell surface defect detection. Yu et al. (2014) proposed a CNN-based intelligent recognition method for radiographic images, achieving 91% accuracy. Zhang (2016) employed CNNs to recognize plant leaves under a single background with 91.11% accuracy. Sun et al. (2016) used deep CNNs to identify traditional Chinese medicine images, reaching an average accuracy of 70%. These studies demonstrate the feasibility and promise of deep learning for image recognition tasks, though some have limited accuracy and remain at the simulation stage. In my work, I aim to overcome these shortcomings by developing a complete system that goes beyond simulation and delivers a practical embedded solution for sand foundry defect detection.
2.2 Magnetic Particle Inspection
Magnetic particle inspection (MPI) is a non-destructive testing method used to detect surface and near-surface discontinuities in ferromagnetic materials. The principle is simple: when a ferromagnetic part is magnetized, a leakage magnetic field forms at the location of a discontinuity. When fine magnetic particles are applied to the surface, they are attracted to these leakage fields, forming visible indications that correspond to the defect locations. Fluorescent magnetic particles are often used under ultraviolet light to improve visibility.
MPI has been used since the 1920s, initially for detecting cracks in oil well drill pipes. Over time, the technology evolved with the introduction of fluorescent particles in 1941 and the establishment of standardized magnetization specifications in the 1950s. In recent decades, semi-automated MPI systems have been developed to reduce human intervention. However, most of these systems still require an operator to visually inspect the magnetic indications in a dark room. The inspection quality depends heavily on the operator’s alertness, experience, and visual acuity, making it difficult to meet strict quality requirements for small precision castings.
To achieve full automation, image processing and pattern recognition techniques have been incorporated into MPI systems. Researchers have explored various segmentation and feature extraction algorithms to isolate crack indications from the background. Nonetheless, these methods often require careful tuning and are not robust enough for industrial use. The intricate background of magnetic particle images, combined with the small size and low contrast of crack indications, makes conventional image processing inadequate. Therefore, I turn to deep learning, which can automatically learn discriminative features from a large set of labeled images and deliver robust performance in complex environments.
3 Deep Learning Environment Construction
3.1 Hardware Platform Selection
Deep learning models require substantial computational resources, especially when trained on large image datasets. Central processing units (CPUs) are optimized for general-purpose tasks with complex control logic and branching, while graphics processing units (GPUs) are designed for highly parallel computations. A typical GPU has thousands of cores that can simultaneously perform arithmetic operations, whereas a CPU usually has a few powerful cores. Since training CNNs involves massive matrix multiplications and convolutions, GPUs can accelerate the process by orders of magnitude. Therefore, I chose an NVIDIA GeForce GTX 1080 GPU as the primary hardware environment for model training.
The GeForce GTX 1080 is a high-performance GPU with the following key specifications:
| Specification | Value |
|---|---|
| CUDA Cores | 2560 |
| Core Clock | 1607 MHz (base) / 1733 MHz (boost) |
| Memory | 8 GB GDDR5X |
| Memory Clock | 10 GHz (effective) |
| Memory Interface | 256-bit |
| Memory Bandwidth | 320 GB/s |
| Power Consumption | 180 W |
| Single-Precision Performance | 9 Teraflops |
This GPU provides sufficient computing power to train deep networks efficiently within a reasonable time frame. The training experiments in this study were all conducted on this GPU using the Caffe framework with CUDA and cuDNN acceleration.
3.2 Software Environment: Caffe
Caffe (Convolutional Architecture for Fast Feature Embedding) is an open-source deep learning framework developed by the Berkeley Vision and Learning Center (BVLC). It is widely used in both academia and industry due to its excellent balance of speed, modularity, and accessibility. Caffe offers the following advantages:
- Fast: Caffe is optimized for speed and can process over 60 million images per day with a single GPU.
- Modular: The network structure is defined in plain text protocol buffer files (prototxt), making it easy to configure new layers and hyperparameters without writing custom code.
- Open: All source code and pre-trained models are publicly available, permitting easy customization and reuse.
- Community: An active community maintains and extends the framework, providing abundant resources and support.
Caffe organizes networks as directed acyclic graphs of layers. The core data structure is the Blob, which stores data and gradients in a 4-dimensional array (number, channel, height, width). Layers perform computations such as convolution, pooling, non-linear activation, and loss calculation. The Net is a collection of layers connected to form a network. The Solver manages the optimization process, including learning rate scheduling, momentum, and weight decay. Prototxt files define the exact network topology and solver parameters.
To install Caffe on an Ubuntu 14.04 system, I first ensured that all necessary packages were present: gcc/g++ (for compiling C/C++ source code), Protocol Buffers (for serializing structured data), Boost (for C++ functionality and Python bindings), GFLAGS (for command-line parsing), GLOG (for logging training information), BLAS (for linear algebra operations), HDF5 (for hierarchical data storage), OpenCL (for heterogeneous computing), LMDB and LevelDB (for data management), and Python/Matlab interfaces. The installation was completed by compiling the Caffe source code and configuring the appropriate paths in the Makefile.config file.
4 Network Architecture Design
4.1 Overview of CNNs
A convolutional neural network is a biologically inspired model that mimics the hierarchical processing of visual information in the brain. The network typically consists of an input layer, several alternating convolutional and pooling layers, followed by one or more fully connected layers, and a final classification layer. The key operations are convolution, pooling, and activation.
Convolution: The convolution layer applies a set of learnable filters (kernels) to the input feature maps. Each kernel slides across the input with a certain stride and computes the dot product between the kernel weights and the local receptive field. The output feature map highlights specific patterns such as edges, textures, or more complex structures. The operation can be expressed as:
$$X_{n}^{l} = \sum_{i \in M_{n}} K_{in}^{l} * X_{i}^{l-1} + b_{n}^{l}$$
where \(M_n\) is the set of input feature maps, \(K_{in}^{l}\) is the \(i\)-th kernel of the \(n\)-th convolution kernel in layer \(l\), \(b_n^l\) is the bias term, and \(*\) denotes the convolution operator. The output feature map size is calculated as:
$$w_1 = \lfloor (w_0 + 2 \times pad – kernel\_size) / stride \rfloor + 1$$
$$h_1 = \lfloor (h_0 + 2 \times pad – kernel\_size) / stride \rfloor + 1$$
where \(w_0, h_0\) are input width and height, \(w_1, h_1\) are output dimensions, \(pad\) is zero-padding, and \(stride\) is the step size.
Activation: Activation functions introduce non-linearity into the network. Common choices include sigmoid, tanh, and ReLU. ReLU (Rectified Linear Unit) is defined as:
$$f(x) = \max(0, x)$$
ReLU is widely used because it accelerates convergence and alleviates the vanishing gradient problem.
Pooling: Pooling (subsampling) reduces the spatial dimensions of feature maps while preserving the depth. It reduces computational cost and provides translation invariance. The two most common pooling operations are max pooling and average pooling:
$$P_n = \max_{i \in R_n} c_i$$
$$P_n = \frac{1}{|R_n|}\sum_{i \in R_n} c_i$$
where \(R_n\) is the pooling region and \(c_i\) is the pixel value. Max pooling selects the maximum value, while average pooling computes the mean. The choice of pooling can affect performance depending on the data.
Fully Connected Layer: The fully connected layer flattens the feature maps into a vector and computes a linear transformation followed by a non-linear activation. The final fully connected layer outputs class scores, which are passed through a softmax function to obtain a probability distribution over classes.
4.2 Proposed Network Structure
Based on the characteristics of the magnetic particle images and the two-class classification problem (defective vs. non-defective), I initially adopted a network architecture similar to AlexNet. The structure consists of five convolutional layers, three pooling layers, and three fully connected layers, as illustrated in the following description:
- Input: 227 × 227 × 1 grayscale image.
- Conv1: 96 kernels of size 11 × 11, stride 4, pad 0. Output: 96 × 55 × 55.
- Pool1: 3 × 3 max pooling, stride 2. Output: 96 × 27 × 27.
- Conv2: 256 kernels of size 5 × 5, stride 1, pad 2. Output: 256 × 27 × 27.
- Pool2: 3 × 3 max pooling, stride 2. Output: 256 × 13 × 13.
- Conv3: 384 kernels of size 3 × 3, stride 1, pad 1. Output: 384 × 13 × 13.
- Conv4: 384 kernels of size 3 × 3, stride 1, pad 1. Output: 384 × 13 × 13.
- Conv5: 256 kernels of size 3 × 3, stride 1, pad 1. Output: 256 × 13 × 13.
- Pool5: 3 × 3 max pooling, stride 2. Output: 256 × 6 × 6.
- FC6: 4096 units, output dimension: 1 × 1 × 4096.
- FC7: 4096 units, output dimension: 1 × 1 × 4096.
- FC8: 2 units, output dimension: 1 × 1 × 2.
- Softmax: outputs the probability distribution over two classes.
This reference architecture was used as a baseline. In what follows, I systematically optimized the architecture and hyperparameters to achieve a model that is both accurate and efficient for the sand foundry defect classification task.
5 Experimental Methodology
5.1 Dataset Description
I collected a dataset of magnetic particle inspection images from a precision casting manufacturer. The images were captured under ultraviolet illumination using a CCD camera and an image acquisition system. The dataset contains samples of both cracked and non-cracked castings. To prevent overfitting and enhance generalization, I performed standard data augmentation techniques such as translation, scaling, and rotation. The final dataset consisted of 3,400 images. The training set contained 2,800 images, with 1,800 defective and 1,000 defect-free samples. The test set contained 600 images, with 400 defective and 200 defect-free samples. The test images were completely disjoint from the training images, ensuring a fair evaluation of the model’s generalization capabilities.
| Category | Training Set | Test Set |
|---|---|---|
| With cracks | 1800 | 400 |
| Without cracks | 1000 | 200 |
| Total | 2800 | 600 |
Each image was pre-processed to a fixed size of 227 × 227 pixels and normalized. The data were converted into LMDB format for efficient loading by Caffe. A mean image was computed and subtracted from each image to reduce illumination variations.
5.2 Training Configuration
I created the training and validation text files listing the image paths and their corresponding labels. Then, using the Caffe data layer, I generated LMDB databases for both training and validation sets. The solver configuration was defined as follows:
| Parameter | Value |
|---|---|
| net | “tsl/train_val.prototxt” |
| test_iter | 80 |
| test_interval | 120 |
| base_lr | 0.0018 |
| lr_policy | “step” |
| gamma | 0.1 |
| stepsize | 4000 |
| display | 120 |
| max_iter | 12000 |
| momentum | 0.9 |
| weight_decay | 0.0005 |
| snapshot | 4000 |
| solver_mode | GPU |
I trained the baseline network with these settings. The training process was run on the GTX 1080 GPU, and the accuracy and loss were recorded at regular intervals. The baseline model achieved 97.25% accuracy on the test set. This result confirmed the viability of the deep learning approach but also indicated room for improvement.
6 Optimization of Network Parameters and Structure
6.1 Influence of Hyperparameters
The learning rate is one of the most critical hyperparameters in training a deep network. If the learning rate is too large, the optimization may overshoot minima; if too small, training may become slow or stall. I experimented with several values of the base learning rate while keeping other parameters constant. The results are shown in the following table:
| Experiment | base_lr | weight_decay | Iterations | Accuracy (%) |
|---|---|---|---|---|
| 1 | 0.01 | 0.0005 | 12000 | 97.00 |
| 2 | 0.001 | 0.0005 | 12000 | 97.00 |
| 3 | 0.003 | 0.0005 | 12000 | 97.25 |
| 4 | 0.002 | 0.0005 | 12000 | 98.00 |
| 5 | 0.0009 | 0.0005 | 12000 | 97.75 |
| 6 | 0.0018 | 0.0005 | 12000 | 98.25 |
| 7 | 0.0018 | 0.0005 | 12000 | 98.00 |
| 8 | 0.0018 | 0.0005 | 12000 | 98.00 |
The best accuracy of 98.25% was achieved with base_lr = 0.0018. The weight decay helped prevent overfitting, and the step policy reduced the learning rate by a factor of 0.1 every 4000 iterations. These hyperparameter adjustments improved the baseline accuracy by one full percentage point. This demonstrates that careful tuning of the learning rate is essential for optimal performance in sand foundry defect detection using deep learning.
6.2 Convolutional Kernel Size
Since the magnetic particle crack indications occupy relatively large pixel areas in the images, I hypothesized that larger convolutional kernels might better capture the global context and improve feature extraction. To test this hypothesis, I modified the kernel sizes in the first three convolutional layers.
Experiment A: Reduced the kernel size of conv1 from 11 to 7, and adjusted the padding of conv2 accordingly. Other parameters remained unchanged. The accuracy dropped to 96.5%, which is lower than the 98.25% baseline. This suggests that smaller kernels lose important large-scale contextual information necessary for identifying cracks.
Experiment B: Increased the kernel size of conv1 from 11 to 13, conv2 from 5 to 7, and conv3 from 3 to 5. To maintain the output feature map dimensions, I adjusted the padding values: conv1 pad from 0 to 1, conv2 pad from 2 to 3, and conv3 pad from 1 to 2. The stride remained unchanged. The resulting accuracy increased to 98.75%, confirming that larger kernels are beneficial for this specific defect detection task. The improved performance can be attributed to the fact that crack patterns in magnetic particle images are broader and more prominent, and larger receptive fields allow the network to better capture these patterns.
| Exp. | Conv1 kernel | Conv1 pad | Conv2 kernel | Conv2 pad | Conv3 kernel | Conv3 pad | Accuracy (%) |
|---|---|---|---|---|---|---|---|
| Baseline | 11 | 0 | 5 | 2 | 3 | 1 | 98.25 |
| A | 7 | 2 | 5 | 1 | 3 | 1 | 96.50 |
| B | 13 | 1 | 7 | 3 | 5 | 2 | 98.75 |
6.3 Network Depth and Simplification
The baseline network had five convolutional layers. However, the classification task here is binary and the images are relatively simple. Deeper networks often require more data and longer training times. To reduce training time while maintaining (or even improving) accuracy, I investigated removing convolutional layers that did not have an associated pooling layer. Specifically, conv3 and conv4 were followed directly by conv5 without any intervening pooling. These layers may be redundant for this task because they do not reduce spatial resolution and in the original AlexNet they are designed to handle complex patterns among 1000 classes. For two-class classification, their removal should not harm performance and would reduce the number of parameters significantly.
I therefore constructed a simplified network with three convolutional layers (conv1, conv2, conv5) and four fully connected layers? Actually after removing conv3 and conv4, the sequence becomes conv1 -> pool1 -> conv2 -> pool2 -> conv5 -> pool5 -> fc6 -> fc7 -> fc8 -> softmax. I kept the kernel sizes from experiment B (i.e., conv1 kernel 13, conv2 kernel 7, conv5? The original conv5 had kernel 3, but in experiment B I changed conv3 kernel to 5; however conv5 remained unchanged. In this simplified network, conv5 still has kernel 3. Actually, to be consistent, I only removed conv3 and conv4, leaving conv5 as the third convolution. The kernel sizes: conv1=13, conv2=7, conv5=3. The padding adjusted accordingly. The results from this modified network are shown below.
| Model | Iterations | Accuracy (%) | Loss | Training Time (s) |
|---|---|---|---|---|
| Original | 12000 | 97.25 | 0.096131 | 1446 |
| Solver optimized | 12000 | 98.25 | 0.078427 | 1385 |
| Kernel increased (B) | 12000 | 98.75 | 0.076449 | 1367 |
| Removed conv3 & conv4 | 12000 | 99.00 | 0.077967 | 966 |
Surprisingly, the simplified network achieved a test accuracy of 99.00%, which was 0.25% higher than the network with five convolutional layers. Moreover, the training time was reduced from 1367 seconds to 966 seconds, a decrease of 29.33%. This significant time saving without sacrificing accuracy is highly beneficial for industrial applications where model retraining is necessary when new defect patterns emerge. The reduction in network depth lowers the risk of overfitting and reduces memory consumption, making the model more suitable for embedded deployment.
6.4 Pooling Strategies
I also investigated the effect of pooling layers. The baseline network used max pooling throughout. I replaced all max pooling layers with average pooling to evaluate the impact. The results are presented below:
| Pooling Type | Accuracy (%) | Loss | Training Time (s) |
|---|---|---|---|
| Max pooling | 99.00 | 0.077967 | 966 |
| Average pooling | 98.25 | 0.086535 | 948 |
The max pooling outperformed average pooling by 0.75%. This is because max pooling selects the most prominent feature within each pooling region, which is advantageous for highlighting crack indications that might be sparse but highly discriminative. Average pooling tends to dilute strong responses with surrounding weak values. Therefore, I retained max pooling in the final architecture.
6.5 Summary of Optimizations
After the systematic optimization, the final network contained the following layers:
- Input: 227 × 227 × 1
- Conv1: 96 kernels of size 13 × 13, stride 4, pad 1 -> output 96 × 55 × 55
- Pool1: 3 × 3 max pooling, stride 2 -> output 96 × 27 × 27
- Conv2: 256 kernels of size 7 × 7, stride 1, pad 3 -> output 256 × 27 × 27
- Pool2: 3 × 3 max pooling, stride 2 -> output 256 × 13 × 13
- Conv5: 256 kernels of size 3 × 3, stride 1, pad 1 -> output 256 × 13 × 13
- Pool5: 3 × 3 max pooling, stride 2 -> output 256 × 6 × 6
- FC6: 4096 units
- FC7: 4096 units
- FC8: 2 units
- Softmax
This architecture achieved a test accuracy of 99% with reduced training time. It served as the final model for the embedded system.
7 Embedded System Implementation
7.1 Design Goals
The ultimate goal of this research is to deploy the deep learning model in an industrial environment for automated sand foundry defect detection. The system must be compact, cost-effective, and capable of real-time operation. I set the following functional and performance requirements:
- Acquire magnetic particle images using a camera and an image acquisition card.
- Use the trained CNN model to classify each image as defective or non-defective.
- Ensure zero missed detections, meaning all defective parts must be identified.
- Complete the detection within 1 second per image.
7.2 Hardware Selection
I selected the following components to build the embedded hardware system:
- Lighting: LUYOR-3106 LED ultraviolet fluorescent inspection lamp. It provides broad-area illumination (260 mm × 200 mm spot at 38 cm), high intensity (8000 μW/cm² at 38 cm), instant on/off, and a long lifetime. This ensures stable image quality.
- Camera: Daheng Image MER-030-120UM industrial digital CCD camera. It has a 1/4-inch Sony ICX618 CCD sensor, resolution 656 × 492, frame rate 120 fps, and a mini USB 2.0 interface. The camera is compact (29 mm × 29 mm × 29 mm) and suitable for integration.
- Image Acquisition Card: Tianchuang Hengda TC-542N1 PCI-E image acquisition card. It supports a 60 MHz acquisition rate and is compatible with Linux, enabling high-speed transfer from the camera to the embedded board.
- Embedded Board: NVIDIA Jetson TX1 developer kit. The TX1 includes a Tegra X1 processor with 256 CUDA cores (Maxwell architecture), a 64-bit ARM A57 CPU, 4 GB LPDDR4 memory, 16 GB flash storage, built-in Wi-Fi, Bluetooth, and Gigabit Ethernet. It delivers 1 Teraflop of GPU computation power, sufficient for running the trained CNN model in real time.

The hardware system diagram shows the flow: illumination -> camera -> image acquisition card -> Jetson TX1 -> display. The camera captures the magnetic particle image under UV light, the acquisition card digitizes the video signal and transfers it to the TX1, the TX1 runs the Caffe model to classify the image, and the result is shown on a display.
7.3 Software Environment Setup on Jetson TX1
To deploy the model on the Jetson TX1, I configured the board with the following steps:
- Connected the TX1 to a display via HDMI and to a host Ubuntu 64-bit computer via a Micro-USB cable and a network cable through a router. The TX1 was initialized using the NVIDIA JetPack installation package.
- After the initial setup, the Ubuntu system GUI was available. I then installed the necessary dependencies, including CUDA, OpenCL, and other libraries.
- In order to facilitate package management, I updated the apt sources to use a faster mirror.
- I installed a web browser, Chinese input method (for convenience during development), and SSH server for remote access.
- I installed lrzsz to transfer files between the host and the TX1 via SSH.
- Finally, I compiled and installed Caffe on the TX1, repeating the dependency installation process: gcc/g++, Protocol Buffers, Boost, GFLAGS, GLOG, BLAS, HDF5, OpenCL, LMDB/LevelDB, and Python bindings.
After the environment was ready, I copied the trained Caffe model (including the .caffemodel weights and deploy.prototxt file) from the GPU workstation to the TX1. The model was then ready for inference.
7.4 Performance Testing on the Embedded System
I tested the embedded system using the 600 test images (400 defective, 200 defect-free). The test procedure involved loading each image, performing forward propagation through the network, and assigning a class label based on the output probability. The results are summarized in the table below:
| Actual Class | Test Samples | Correctly Classified | Misclassified | Accuracy (%) |
|---|---|---|---|---|
| Defective | 400 | 400 | 0 | 100 |
| Defect-free | 200 | 192 | 8 | 96 |
| Overall | 600 | 592 | 8 | 98.67 |
All 400 defective images were correctly identified, resulting in a missed detection rate of 0. This is crucial for industrial quality control because a missed defect could lead to catastrophic equipment failure. Among the defect-free images, 8 were falsely classified as defective (false positives). These false positives are less critical but still incur additional inspection time. The overall accuracy was 98.67%, exceeding the engineering requirement and demonstrating the efficacy of the embedded deep learning system.
In a typical inference run, the model output can be visualized as a probability. For a defect-free image, the output might be:
$$P(\text{defect-free}) = 0.993, \quad P(\text{defective}) = 0.007$$
Thus, the system correctly labels the sample as defect-free. For a defective image, the network outputs a high probability for the defective class. The inference time per image was measured to be well within 1 second, satisfying the real-time requirement.
8 Conclusion and Future Work
In this research, I developed an automated defect detection system for precision castings using deep learning. The system specifically addresses the challenges of sand foundry defect detection in magnetic particle inspection. I designed a convolutional neural network and optimized it for the available dataset, achieving a training accuracy of 99% and an embedded test accuracy of 98.67% with zero missed detections. The key contributions are summarized as follows:
- Constructed a GPU-based deep learning environment and implemented a Caffe-based network architecture for classifying magnetic particle images.
- Investigated the effect of convolutional kernel sizes and found that enlarging kernels improves accuracy for the crack patterns in this application.
- Simplified the network by removing two convolutional layers, which reduced training time by nearly 30% while improving accuracy, thus offering a more efficient model for industrial use.
- Successfully ported the model to an NVIDIA Jetson TX1 embedded system, enabling compact, low-power, and real-time deployment in production environments.
The experimental results validate the feasibility and robustness of deep learning for automatable magnetic particle defect recognition. The system not only improves detection accuracy and speed but also eliminates the subjectivity and fatigue associated with manual inspection.
Future work may focus on the following aspects:
- Model Visualization: Use deconvolution techniques to visualize the learned features in intermediate layers. This could provide deeper insights into why larger kernels and reduced depth are beneficial for this task, and guide further structural improvements.
- Generalization to Other Defect Types: Extend the current binary classification to multi-class defect recognition (e.g., porosity, shrinkage, inclusions) to provide more detailed quality information.
- Real-Time Video Processing: Optimize the model for video-rate inference, potentially using TensorRT or other acceleration libraries on the Jetson platform to process continuous image streams.
- Integration with Robotic Inspection Systems: Mount the embedded system on a robotic arm to automatically scan large castings and generate defect maps, thereby increasing automation and throughput.
In conclusion, this study demonstrates that deep learning, combined with embedded hardware, offers a powerful and practical solution for automated sand foundry defect detection. The proposed system meets the stringent requirements of industrial quality control and paves the way for further intelligent manufacturing applications.
