1. Introduction
CNC machining is pivotal in modern manufacturing for the production of high-precision components in the aerospace, automotive, and electronics industries (
Figure 1).
However, maintaining stringent quality standards presents challenges due to potential defects arising from machining operations. Frequently observed defects include crashes (caused by manually falling), abnormal outlines (stemming from incorrect G-code), sloping surfaces (due to tool misalignment), and dark color changes (a result of tool wear or overheating) [
1]. These types of defects are illustrated in
Figure 2.
Automated quality control systems have been increasingly important, and AOI systems have been widely adopted. These systems leverage advanced computer vision and machine learning technologies to replace traditional manual inspections, prone to inconsistency and inefficiency. You Only Look Once (YOLO) is an object detection framework for balancing high-speed inference with competitive accuracy. This algorithm is ideal for CNC machining where real-time monitoring is essential [
2].
Research in industrial defect detection demonstrates the advantages of YOLO-based models in complex production environments. Study results showed high accuracy and efficiency in detecting defects such as cracks, scratches, and surface irregularities across various materials [
3]. Moreover, enhanced YOLO models, such as YOLOv5 and YOLOv8, are promising solutions for multi-scale feature extraction as they improve detection even in dynamic and noisy environments [
4]. The application of these models in CNC machining offers the potential for defect detection and the data-driven optimization of machining parameters. Therefore, we integrated the system to monitor CNC output, detect defects, and recommend adjustments to G-code in order to improve production quality and efficiency.
2. Methods
2.1. YOLO Algorithm
YOLO is a deep learning-based framework designed for high-speed and accurate object detection in real time. The primary innovation of YOLO lies in treating object detection as a regression problem. Unlike traditional detection algorithms that perform classification and localization through multiple passes, YOLO processes the entire image in a single neural network pass. This approach dramatically improves the speed of detection, making it ideal for industrial applications such as CNC defect detection, where real-time monitoring is critical. YOLO divides an input image into an S × S grid, where each cell predicts bounding boxes and associated class probabilities. If the center of an object falls within a particular grid cell, that cell is responsible for detecting the object. This architecture allows YOLO to handle object localization and classification simultaneously, ensuring speed and accuracy [
2].
The framework in this study consists of the backbone, neck, and head. The backbone, such as cross-stage partial darknet (CSPDarknet) used in YOLOv4, extracts features from the input image through convolutional layers. The neck includes feature pyramid networks (FPNs) to detect objects at different scales, and the head generates predictions, including bounding boxes and confidence scores. One of YOLO’s strengths is its ability to detect multiple objects within a single image, regardless of their size and position, a feature crucial for identifying different types of CNC defects simultaneously. This makes the algorithm especially well suited for CNC processes, where defects such as crashes, sloping surfaces, and color deviations can occur at varying scales and positions [
5].
2.2. System Architecture
These experiments were performed by using a CNC machine (GLS-2800YS, manufactured by Goodway Corp., Taichung, Taiwan) with a Simens 828D controller (
Figure 3). The dimensions of the workpiece are depicted in
Figure 4.
The system architecture integrates the following components. For image capture and data collection, a high-resolution camera is used to monitor workpieces in machining and collect images of defects such as crashes, abnormal outlines, surface slope deviations, and color shifts. A YOLO model, pre-trained and fine-tuned with additional defect images, is used to perform real-time defect recognition. The training dataset includes images labeled according to the aforementioned defect types, ensuring accurate classification even under varied lighting and environmental conditions [
2]. The detected defects are cross-referenced with the corresponding G-code parameters to identify potential causes, such as incorrect feed rates or tool misalignments. Machine learning algorithms generate recommendations to prevent recurring issues, minimize downtime, and enhance product quality [
3].
2.3. Model Training and Tuning
Training the YOLO algorithm for CNC defect detection involves dataset preparation, annotation, model training, and evaluation. The first step is to collect high-resolution images of CNC workpieces with labeled defects, such as abnormal outlines, tool alignment issues, and surface discolorations. For CNC-specific applications, transfer learning is employed to fine-tune a pre-trained YOLO model, reduce the amount of data required, and accelerate the training process [
3]. By labeling the images with bounding boxes for each defect, the model learns to localize defects accurately during the training phase. Once the data are prepared, the model undergoes hyperparameter tuning, where parameters such as batch size, learning rate, and anchor box sizes are adjusted to achieve optimal performance. The loss function in YOLO, typically a combination of localization and classification losses, plays a crucial role in minimizing errors. In training, the model iteratively updates its weights by minimizing this loss, using optimization algorithms such as stochastic gradient descent (SGD) or Adam. After training, the model is evaluated using metrics such as mean average precision (mAP), precision, recall, and inference speed to ensure it meets industrial standards for real-time defect detection [
6].
In CNC machining, the trained YOLO model continuously monitors workpieces in real time by capturing images after each machining process. The model analyzes these images, detects defects, and provides instant feedback to the G-code optimization module to diagnose potential causes such as tool misalignment or programming errors. The seamless integration of YOLO within the CNC process enables the quick identification and resolution of issues, reducing downtime, and improving production quality. The YOLO framework’s adaptability allows for incremental learning, where the model is retrained periodically with new defect data to enhance its performance and robustness over time [
2].
3. Results and Discussion
The platform was tested with different CNC machines, including lathes and milling machines, and processing materials such as aluminum, steel, and composite fibers. In total, 600 workpieces were inspected to evaluate the system’s accuracy and robustness. The YOLO-based system achieved a defect detection accuracy of 91%, with 94% accuracy for crashes (falling), 89% for abnormal outlines, 90% for sloping surfaces, and 92% for dark color. The AI-driven optimization module reduced defect recurrence by 80%, significantly improving machining efficiency. The system also minimized production downtime by 25%, thanks to real-time feedback on machining parameters and automated tool adjustments. These results confirm the effectiveness of the proposed system in achieving high-quality production standards.
4. Conclusions
We present an integrated platform for CNC machining quality control by combining AOI with YOLO-based defect detection and AI-driven G-code optimization. The system automates defect detection and identifies issues such as crashes, misaligned surfaces, and tool wear. With a 91% defect detection accuracy and a substantial reduction in defect recurrence, the platform demonstrates huge potential in enhancing CNC machining processes. Future research is necessary to integrate predictive maintenance capabilities and make the system handle more complex machining operations. The system aligns with the objectives of Industry 4.0 for improved efficiency and quality in intelligent manufacturing technologies.
Author Contributions
Conceptualization, Q.-R.L.; methodology, B.-C.H.; software, Q.-R.L. and B.-C.H.; validation, L.-Y.K.; formal analysis, T.-Y.S.; investigation, B.-C.H.; resources, L.-Y.K. All authors have read and agreed to the published version of the manuscript.
Funding
This research received no external funding.
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
The original data are unavailable due to privacy or ethical restrictions.
Conflicts of Interest
The authors declare no conflict of interest.
References
- Adeyemi, T. Defect detection in manufacturing: An integrated deep learning approach. J. Comput. Commun. 2024, 12, 153–176. [Google Scholar] [CrossRef]
- Gui, Z.; Geng, J. YOLO-ADS: An improved YOLOv8 algorithm for metal surface defect detection. Electronics 2024, 13, 3129. [Google Scholar] [CrossRef]
- Li, J.; Chen, M. DEW-YOLO: An efficient algorithm for steel surface defect detection. Appl. Sci. 2024, 14, 5171. [Google Scholar] [CrossRef]
- Zou, Z.; Dong, J.H.; Gao, Y.; Wu, Z.Z. HyperDefect-YOLO: Enhance YOLO with HyperGraph Computation for Industrial Defect Detection. arXiv 2024, arXiv:2412.03969. [Google Scholar] [CrossRef]
- Chen, P.-C.; Lin, Y.-T.; Truong, C.-M.; Chen, P.-S.; Chiang, H.-K. Development of an Automated Optical Inspection System for Rapidly and Precisely Measuring Dimensions of Embedded Microchannel Structures in Transparent Bonded Chips. Sensors 2021, 21, 698. [Google Scholar] [CrossRef] [PubMed]
- Li, L.; Zhang, R.P.; Xie, T.J.; He, Y.S.; Zhou, H.; Zhang, Y.Z. Experimental Design of Steel Surface Defect Detection Based on MSFE-YOLO—An Improved YOLOV5 Algorithm with Multi-Scale Feature Extraction. Electronics 2024, 13, 3783. [Google Scholar] [CrossRef]
| Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).