# Real-Time Detection of Hole-Type Defects on Industrial Components Using Raspberry Pi 5
## 3 Materials and Methods
### Training and Validation Approach  
The methodology employs convolutional neural networks (CNNs) and specialized image preprocessing techniques. The computational system was configured with an i9-11900 processor (Intel, Santa Clara, CA, USA), operating at a base frequency of 2.50 GHz, supported by 16 logical cores. The device was equipped with 64 GB of DDR4 RAM, ensuring optimal performance for memory-intensive operations. Graphical computations and rendering were facilitated by an NVIDIA GeForce RTX 3080 Ti GPU (Santa Clara, CA, USA), with 12 GB of dedicated memory and 32 GB of shared memory, delivering accelerated processing capabilities for graphical and machine learning applications. For GPU-intensive simulations, NVIDIA CUDA libraries and the NVENC API were utilized. Analytical workflows were developed using Python 3.10, ensuring compatibility with the DirectX-12 and OpenCL 3.0 frameworks pre-installed on the system. To standardize input dimensions and ensure compatibility across deep learning architectures, all grayscale BMP images were resized to 224 \(\times\) 224 pixels. Pixel normalization  
Figure 4: Distribution of images across classes in the dataset. Figure 5: Random sample images from each class with image counts representing each defect class in the dataset. The red circles are manually annotated to indicate the specific spatial location of the defect on the component surface. These annotations highlight where each defect typically occurs. was performed using mean and standard deviation values to align with common pre-processing standards in computer vision. The dataset comprised 43,482 images of metal components, exhibiting a notable class imbalance, with the No_Defect category alone accounting for approximately 27.6% of the data. To improve the model's resilience to real-world variations, an extensive data augmentation strategy was implemented using the Albumentations library. This pipeline incorporated a variety of transformations to simulate environmental and operational inconsistencies, including random rotations, horizontal flips, brightness and contrast adjustments, Gaussian noise, motion blur, and optical distortions. Additional augmentations such as random shadows, coarse dropout, and JPEG compression artifacts were applied to mimic occlusions and sensor degradation. Post augmentation, images were converted to three-channel tensors to conform with standard input formats. For binary classification, the dataset was restructured into two categories:  
* The OK class included only the No_Defect samples, representing components free of visual anomalies. * The Defective class encompassed all remaining defect types, including shape irregularities, misalignments, missing holes, and dimensional deviations. To address class imbalance, class weighting was applied during training, calculated based on the inverse frequency of class occurrences. The learning process employed dynamic learning rate scheduling to facilitate stable convergence and prevent overfitting. Regularization techniques such as early stopping, weight decay, and stochastic dropout were utilized to enhance generalization on unseen data. The training workflow also supported mixed-precision computation to optimize performance on resource-constrained environments, and quantization strategies were optionally explored to enable efficient deployment on edge devices. For binary classification purposes, all defect classes including Irregular_Large_Hole, Aligned_Large_Hole, Misaligned_Large, Misaligned_Small, and Aligned_Small_Hole are consolidated into a single Defective category. The No_Defect samples are labeled as being in the OK (non-defective) category. This binary grouping aligns directly with practical quality control goals in automated industrial inspection, where the priority is reliably identifying the presence or absence of defects rather than distinguishing specific defect types.