Defect detection method and device for CNC machined part
By using an edge differential reverse region perception network model to detect defects in CNC machined parts, the high precision, high efficiency, and high stability requirements of existing technologies are met. This enables accurate identification of minute defects and optimization of the machining process, thereby improving detection accuracy and efficiency.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- LUXCASE PRECISION TECH (YANCHENG) CO LTD
- Filing Date
- 2026-01-21
- Publication Date
- 2026-05-08
AI Technical Summary
Existing technologies are insufficient to meet the high precision, high efficiency, and high stability requirements for the appearance inspection of CNC machined parts. Both manual inspection and traditional automatic optical inspection systems have significant technical limitations.
Defect detection is performed using the Edge Differential Reverse Region Awareness Network (RRANet) model, which includes a hybrid adaptive module, an edge differential convolution module, a multi-scale adaptive module, and a reverse region awareness module. Images are acquired using a high-resolution industrial camera and an adjustable ring light source array, processed by the Edge Differential Reverse Region Awareness Network model, and the defect images are output and the defect parameters are determined.
It significantly improves the accuracy and efficiency of defect detection, enhances the stability of the detection process, can identify minute defects at the 0.05 mm level, and optimizes the processing technology through a closed-loop feedback mechanism, thereby reducing the product scrap rate.
Smart Images

Figure CN121998931A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of defect detection technology, and in particular to a method and apparatus for defect detection of CNC machined parts. Background Technology
[0002] In the field of CNC machining and manufacturing, the appearance quality of machined parts directly determines the assembly accuracy, performance and service life of products. Therefore, appearance defect detection is an indispensable key link in the production process. Its core objective is to accurately identify various defects such as burrs, edge defects, tool marks, and chipped corners to ensure product consistency and pass rate.
[0003] Currently, the methods for inspecting the appearance of CNC machined parts are mainly divided into two categories: manual inspection and traditional automated optical inspection (AOI) systems. However, both have significant technical limitations and cannot meet the industrial inspection requirements of high precision, high efficiency, and high stability.
[0004] Therefore, there is an urgent need for a CNC machining part appearance inspection technology that can overcome the above-mentioned technical bottlenecks in order to improve inspection accuracy, efficiency and stability. Summary of the Invention
[0005] This invention provides a method and apparatus for defect detection of CNC machined parts, which can significantly improve the accuracy and efficiency of defect detection, while enhancing the stability of the detection process.
[0006] According to one aspect of the present invention, a defect detection method for CNC machined parts is provided, the method comprising:
[0007] Obtain the target image of the CNC machined part;
[0008] The target image is input into an edge difference inverse region perception network model, and the target image is processed by the edge difference inverse region perception network model to output a defect image; wherein, the edge difference inverse region perception network model includes a first network branch, a second network branch, and a decoder; the first network branch is a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch is a hybrid adaptive module, a multi-scale adaptive module, and an inverse region perception module connected in sequence.
[0009] Based on the defect image, the defect parameters are determined.
[0010] According to another aspect of the present invention, a defect detection device for CNC machined parts is provided, the device comprising:
[0011] The target image acquisition unit is used to acquire the target image of the CNC machined part.
[0012] A defect image output unit is used to input the target image into an edge difference inverse region perception network model, process the target image through the edge difference inverse region perception network model, and output a defect image; wherein, the edge difference inverse region perception network model includes a first network branch, a second network branch, and a decoder; the first network branch is a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch is a hybrid adaptive module, a multi-scale adaptive module, and an inverse region perception module connected in sequence;
[0013] The defect parameter determination unit is used to determine defect parameters based on the defect image.
[0014] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0015] At least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform a defect detection method for CNC machined parts according to any embodiment of the present invention.
[0016] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement a defect detection method for a CNC machined part according to any embodiment of the present invention.
[0017] The technical solution of this invention involves acquiring a target image of a CNC machined part; inputting the target image into an edge-differential inverse region perception network model; processing the target image through the edge-differential inverse region perception network model to output a defect image; and determining defect parameters based on the defect image. This technical solution can significantly improve the accuracy and efficiency of defect detection, while enhancing the stability of the detection process.
[0018] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart of a defect detection method for CNC machined parts according to Embodiment 1 of the present invention;
[0021] Figure 2 A schematic diagram of a CNC-machined part provided in Embodiment 1 of this application;
[0022] Figure 3 This is a schematic diagram of the edge differential reverse region sensing network model provided in Embodiment 1 of this application;
[0023] Figure 4 This is a flowchart of the CNC machining part missing part detection method provided in Embodiment 1 of this application;
[0024] Figure 5 This is a schematic diagram of a CNC machined part defect detection process provided in Embodiment 2 of the present invention;
[0025] Figure 6 This is a schematic diagram of the edge difference convolution module provided in Embodiment 2 of this application;
[0026] Figure 7 A schematic diagram of the horizontal kernel weights provided in Embodiment 2 of this application;
[0027] Figure 8 A schematic diagram of the vertical kernel weights provided in Embodiment 2 of this application;
[0028] Figure 9 This is a schematic diagram of the multi-scale adaptive module provided in Embodiment 2 of this application;
[0029] Figure 10 This is a schematic diagram of the reverse region sensing module provided in Embodiment 2 of this application;
[0030] Figure 11 This is a schematic diagram of a defect detection device for CNC machined parts provided in Embodiment 3 of the present invention;
[0031] Figure 12 This is a schematic diagram of the structure of an electronic device that implements a defect detection method for CNC machined parts according to an embodiment of the present invention. Detailed Implementation
[0032] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0033] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0034] Example 1
[0035] Figure 1 This is a flowchart of a defect detection method for CNC machined parts according to Embodiment 1 of the present invention. This embodiment is applicable to defect detection of CNC machined parts. The method can be executed by a defect detection device for CNC machined parts, which can be implemented in hardware and / or software and can be configured in a device. For example, the device can be a backend server or other device with communication and computing capabilities. Figure 1 As shown, the method includes:
[0036] S110. Obtain the target image of the CNC machined part.
[0037] In this solution, CNC machined parts refer to mechanical components manufactured using Computer Numerical Control (CNC) technology. CNC machined parts can be CNC-machined aluminum alloy frames, shells, structural components, etc. Figure 2 This is a schematic diagram of a CNC-machined part provided in Embodiment 1 of this application. The specific structure of the CNC-machined part is as follows: Figure 2 As shown.
[0038] In this solution, a high-resolution industrial camera (50 megapixels) and an adjustable ring light array are used to capture CNC machined parts from multiple angles, obtaining images of the CNC machined parts to be processed. Specifically, by automatically adjusting the exposure parameters and polarization angle, surface reflections on the CNC machined parts are suppressed and edge contrast is improved.
[0039] Furthermore, grayscale equalization, reflection removal, noise suppression, and region of interest (ROI) extraction operations are sequentially performed on the image to be processed to obtain the target image.
[0040] Among them, gray-level equalization is a contrast enhancement technique based on the gray-level histogram of an image. By redistributing the gray levels of an image, it makes the originally unevenly distributed gray values uniformly cover the entire dynamic range (0-255, corresponding to black to white in a black and white image).
[0041] In this embodiment, reflection removal is an image optimization operation for highly reflective material surfaces (such as metal and paint). By separating the target signal and the reflection interference signal in the image, artifacts, light spots, or overlapping images caused by light reflection are eliminated.
[0042] In this scheme, noise suppression refers to the operation of eliminating random interference signals (i.e., image noise) generated during image acquisition, transmission, and storage. Noise is usually manifested as irregular fluctuations in pixel values, appearing as spots, grains, or stripes.
[0043] ROI extraction is an operation that segments out the target image related to the task objective from the image to be processed, excluding irrelevant background.
[0044] S120. The target image is input into the edge difference inverse region perception network model, and the target image is processed by the edge difference inverse region perception network model to output a defect image; wherein, the edge difference inverse region perception network model includes a first network branch, a second network branch and a decoder; the first network branch is a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch is a hybrid adaptive module, a multi-scale adaptive module and an inverse region perception module connected in sequence.
[0045] In this scheme, the edge difference reverse region perception network model (RRANet) can accurately segment and identify defects in the target image and output a segmentation mask representing the location and shape of the defect, i.e., the defect image.
[0046] Among them, the edge differential reverse region perception network model runs on edge AI (Artificial Intelligence) computing units such as NVIDIA Jetson Orin NX, and can be connected to MES (Manufacturing Execution System) via industrial Ethernet, thereby realizing multi-station synchronous detection and full-process traceability of detection data.
[0047] In this plan, Figure 3 This is a schematic diagram of the edge differential reverse region sensing network model provided in Embodiment 1 of this application, as shown below. Figure 3As shown, the Edge Differential Reverse Region Awareness Network model consists of an encoder, a feature enhancement module group (EDC + MSAM + RRAM), a decoder, and an output layer. Its structural logic is as follows: The encoder performs multi-layer convolutional feature extraction on the target image and introduces an Edge Differential Convolutional Module (EDC) in the shallow layer to specifically extract gradient changes in the horizontal and vertical directions to accurately capture detailed edge features such as knife marks and chipped corners; the feature enhancement module group includes a Multi-Scale Adaptive Module (MSAM) and a Reverse Region Awareness Module (RRAM). MSAM performs multi-scale modeling on high-level semantic features to expand the receptive field and enhance the model's global representation ability for defects of different sizes. RRAM, through a reverse erasure mechanism, feeds back the incorrectly predicted regions to the feature map for iterative correction, improving the consistency between edges and regions; the decoder performs upsampling and fusion operations on multi-layer features to achieve deep fusion of low-level edges and high-level semantic information, and finally generates a pixel-level defect image through the output layer.
[0048] In this embodiment, the loss function of the edge difference reverse region perception network model adopts a joint design scheme of binary cross-entropy (BCE) and Dice loss, and introduces weight coefficients for small-sized targets to ensure the segmentation accuracy of micro-defects.
[0049] Furthermore, the binary cross-entropy loss is:
[0050] ;
[0051] in, For binary cross-entropy loss, For real labels, It is the probability that the model predicts the pixel to be of the positive class.
[0052] Dice loss is;
[0053] ;
[0054] in, For Dice's loss, For real labels, It is the probability that the model predicts the pixel to be of the positive class.
[0055] The loss function of the edge difference reverse region sensing network model is:
[0056] ;
[0057] in, Let be the loss function of the edge difference reverse region perception network model. Weighting coefficients to balance the two losses
[0058] S130. Determine the defect parameters based on the defect image.
[0059] The defect parameters include area, length, boundary sharpness, and depth. Boundary sharpness refers to the clarity of the boundary between two regions of different hues or colors in an image. Depth refers to the total number of bits used to store the color information of all pixels in the defect.
[0060] In this scheme, defect parameters are calculated based on the defect image. Defect levels are then classified according to the numerical values of these parameters. The defect levels are pre-set based on the actual needs of defect detection.
[0061] Furthermore, after determining the defect parameters, they are transmitted to the CNC tool compensation system. If the detection finds that the defects are concentrated in a certain toolpath area, the system will automatically trigger the tool wear compensation or toolpath fine-tuning mechanism, thereby constructing a closed-loop control system for detection and processing, achieving effective suppression of recurring defects and a significant reduction in product scrap rate.
[0062] In this plan, Figure 4 This is a flowchart of the CNC machining part missing part detection provided in Embodiment 1 of this application, as follows: Figure 4 As shown, the CNC machining station first outputs the machined workpiece, then enters the defect detection preprocessing stage to complete image preprocessing, and then uses a deep learning segmentation detection core to accurately identify and segment workpiece defects. Next, in the defect judgment and grading output stage, the defects are qualitatively identified and graded. Finally, it enters the result feedback and process optimization stage. On the one hand, the detection results are fed back to the CNC machining station to optimize the machining parameters, and on the other hand, the defect detection algorithm is iteratively optimized based on the detection data, thus forming a closed loop of continuous optimization.
[0063] For example, the closed-loop workflow for visual inspection of aluminum alloy CNC structural parts is as follows: After CNC machining, a robotic arm transfers the workpiece to the visual inspection platform, where multi-angle industrial cameras acquire images of the workpiece edges and holes. The acquired images are then preprocessed with illumination equalization and reflection removal. The preprocessed target image is input into the RRANet model for inference, outputting a defect image. Based on the defect image, key indicators such as the defect area, shape, and length are further calculated, and the defect level is automatically determined according to the Grade 0 standard. Simultaneously, the inspection system sends the defect coordinates and level information back to the CNC control unit for toolpath compensation or tool change prompts. The inspection results and process correction records are also uploaded to the MES system for archiving, enabling full-process quality traceability. This workflow achieves fully automated closed-loop management from image acquisition to process feedback, significantly reducing manual intervention and improving the consistency and reliability of inspection results.
[0064] The technical solution of this invention involves acquiring a target image of a CNC machined part; inputting the target image into an edge-difference inverse region perception network model; processing the target image through the edge-difference inverse region perception network model to output a defect image; and determining defect parameters based on the defect image. By implementing this technical solution, and introducing an edge-difference convolution module, a multi-scale adaptive module, and an inverse region perception module, high-precision, low-latency detection and early warning of CNC machining tool marks and chipped corner defects in complex environments can be achieved. This significantly improves the accuracy and efficiency of defect detection, while enhancing the stability of the detection process.
[0065] Example 2
[0066] Figure 5 This is a schematic diagram of a defect detection process for a CNC machined part according to Embodiment 2 of the present invention. The relationship between this embodiment and the above embodiments is a detailed description of the defect detection process. Figure 5 As shown, the method includes:
[0067] S510: Obtain the target image of the CNC machined part.
[0068] S520. The target image is processed using the first network branch to generate a first feature map; and the target image is processed using the second network branch to generate a second feature map.
[0069] In this plan, such as Figure 3 As shown, the first network branch consists of a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch consists of a hybrid adaptive module, a multi-scale adaptive module, and a reverse region perception module connected in sequence.
[0070] Among them, the Hybrid Adaptive Module (HAAM) is a module in the field of deep learning that integrates channel and spatial dimension adaptive attention mechanisms. Its core lies in capturing robust features by dynamically allocating weights. This module is composed of two core sub-modules connected in series: a channel self-attention block and a spatial self-attention block. The channel self-attention block first performs average pooling and max pooling operations on the input features to extract global and discriminative information. Then, it generates a channel attention map by using an adaptive mechanism with learnable parameters for weighted fusion, realizing cross-channel information interaction and weight allocation. The spatial self-attention block generates spatial attention descriptors by grouping along the channel axis based on the generated channel attention map, thereby adaptively emphasizing key spatial regions, suppressing background noise, and optimizing the feature space distribution.
[0071] Furthermore, the HAAM workflow is as follows: the input target image first enters the channel self-attention block, and channel weights are generated through pooling and adaptive fusion. The weights are then multiplied element-wise with the original features to complete channel dimension weighting. The weighted features are then passed to the spatial self-attention block, and spatial weights are generated through grouping and spatial attention calculation to complete spatial dimension weighting. Finally, the feature map that fuses the channels and spatial attention is output.
[0072] In this scheme, the Edge Differential Convolution (EDC) module extracts edge features by introducing intensity and gradient difference operators in the horizontal and vertical directions, which can effectively characterize the start and end points of tool marks and the boundaries of tiny indentations in CNC machining textures.
[0073] The Multi-Scale Adaptive Module (MSAM) employs a multi-receptive field structure to capture defects at different scales and enhances region discrimination capabilities through context fusion of complex reflective and multi-textured regions. The MSAM consists of three improved receptive field modules (RFBs).
[0074] In this embodiment, the reverse region sensing module (RRAM) establishes a reverse constraint relationship between edges and regions to refine the preliminary prediction results, thereby avoiding the omission of minor defects.
[0075] Specifically, the target image is processed sequentially using the hybrid adaptive module and the edge difference convolution module to generate the first feature map; and the target image is processed sequentially using the hybrid adaptive module, the multi-scale adaptive module, and the reverse region perception module to generate the second feature map.
[0076] Optionally, the target image is processed using the first network branch to generate a first feature map, including:
[0077] The target image is processed based on the hybrid adaptive module to generate a third feature map;
[0078] The third feature map is processed using the edge difference convolution module to generate the first feature map.
[0079] Specifically, the target image is processed by a hybrid adaptive module to generate a third feature map, and the third feature map is further processed by an edge difference convolution module to obtain a first feature map.
[0080] By cascading the hybrid adaptive module and the edge difference convolution module, the system achieves accurate extraction of target image features and enhancement of edge details, effectively improving the representation capability of the feature map and the processing accuracy of subsequent tasks.
[0081] Optionally, the third feature map is processed using the edge difference convolution module to generate the first feature map, including:
[0082] The first pre-defined convolution kernel is convolved with the third feature map to obtain a horizontal feature map and a vertical feature map.
[0083] The horizontal feature map and the vertical feature map are fused to generate a first feature map.
[0084] In this embodiment, Figure 6 This is a schematic diagram of the edge difference convolution module provided in Embodiment 2 of this application, as shown below. Figure 6 As shown, the Edge Differential Convolutional (EDC) module extracts edge features by introducing intensity and gradient difference operators in the horizontal and vertical directions.
[0085] In this approach, traditional convolution extracts features through weighted summation, which tends to smooth out subtle details when capturing edge features and makes it difficult to distinguish subtle differences in the target object. To address this issue, this approach introduces the concept of difference from traditional image processing into convolution operations, focusing on the accurate extraction of gradient information, thereby enhancing the model's ability to represent and generalize edge features.
[0086] Specifically, Figure 7 This is a schematic diagram of the horizontal kernel weights provided in Embodiment 2 of this application. Figure 8 This is a schematic diagram of the vertical kernel weights provided in Embodiment 2 of this application. Figure 7 and Figure 8 As shown, drawing on the design concept of the Sobel operator, feature extraction convolutional layers are constructed in the vertical and horizontal directions respectively, and the weight parameters of the convolution kernel are adjusted accordingly to achieve efficient detection of the vertical and horizontal edges of CNC machined parts.
[0087] Furthermore, for the third feature map x, a 3×3 first convolution kernel is used for computation to obtain the vertical feature map. Horizontal feature map Its definition is as follows:
[0088] ;
[0089] ;
[0090] in, Indicates the position of the center pixel. This indicates the offset position of the pixels within the area covered by the convolution kernel relative to the center. and The regions traversed by vertical and horizontal convolution kernels. For learnable convolutional kernel weights, is the balance coefficient used to adjust the strength of the difference; b is the bias term. This represents the pixel value at the corresponding position in the input feature map.
[0091] Furthermore, the horizontal and vertical feature maps are fused to generate the first feature map.
[0092] By constructing horizontal and vertical feature extraction convolutional layers that draw inspiration from the Sobel operator, and introducing the concept of difference to optimize traditional convolution operations, the model accurately extracts gradient information from the edges of CNC machined parts. This solves the problem that traditional convolution easily smooths out subtle edge details and effectively enhances the model's ability to represent and generalize edge features of machined parts.
[0093] Optionally, the horizontal feature map and the vertical feature map are fused to generate a first feature map, including:
[0094] Determine the first weight corresponding to the horizontal feature map; and determine the second weight corresponding to the vertical feature map;
[0095] The difference between 1 and the first weight is used as the third weight; and the difference between 1 and the second weight is used as the fourth weight;
[0096] The horizontal feature map is weighted using the second weight and the vertical feature map is weighted using the fourth weight. The weighting results are then fused to obtain the fourth feature map.
[0097] The horizontal feature map is weighted according to the first weight and the vertical feature map is weighted according to the third weight. The weighting results are then fused to obtain the fifth feature map.
[0098] The fourth feature map and the fifth feature map are concatenated to obtain the first feature map.
[0099] In this scheme, a low-order feature set is extracted. It is then fed into the edge difference convolution module to generate a vertical feature map. Horizontal feature map If a simple feature fusion strategy is adopted without fully exploring and utilizing the inherent correlation between the two types of feature maps, it will not only waste effective feature information but also easily introduce redundant information, thus adversely affecting the final segmentation performance. To address this technical problem, this solution designs a dynamic feature fusion method. This method can fully capture the correlation features of horizontal and vertical edge information, minimizing information redundancy while significantly enhancing the model's ability to represent local details.
[0100] Specifically, the implementation of dynamic feature fusion is as follows;
[0101] ;
[0102] ;
[0103] in, As the first weight, As the second weight, This is the fourth feature map. This is the fifth feature map. This represents the Sigmoid function, which is used to normalize weights to the range [0,1].
[0104] Furthermore, and Fusion generation ;
[0105] ;
[0106] in, Let C represent the first feature map, and C denote the concatenation operation, which is the final generated feature map. It can compensate for the shortcomings of global feature maps at edges, and significantly improve the boundary representation ability and segmentation accuracy of the segmentation model.
[0107] By assigning corresponding weights to the horizontal and vertical feature maps respectively to achieve differentiated weighting and obtaining two types of weighted feature maps, the target feature map is generated after feature splicing and fusion. This effectively enhances the boundary representation ability of the segmentation model and significantly improves the segmentation accuracy of the model.
[0108] Optionally, the target image is processed using the second network branch to generate a second feature map, including:
[0109] The target image is processed based on the hybrid adaptive module to generate a sixth feature map;
[0110] The sixth feature map is processed using the multi-scale adaptive module to generate the seventh feature map;
[0111] The seventh feature map and the sixth feature map are processed by the reverse region perception module to generate the second feature map.
[0112] In this plan, Figure 9 This is a schematic diagram of the multi-scale adaptive module provided in Embodiment 2 of this application, as shown below. Figure 9 As shown, this module consists of three improved receptive field modules (RFBs). High-order features of the encoder layer. The input is fed into the multi-scale adaptive module, which outputs the seventh feature map.
[0113] In this embodiment, Figure 10This is a schematic diagram of the reverse region sensing module provided in Embodiment 2 of this application. After passing through the multi-scale adaptive module, a relatively coarse position and approximate outline are obtained. To supplement detailed region and edge information and make the segmentation of CNC machined parts more accurate, a reverse region sensing module (RRAM) is proposed, such as... Figure 10 As shown.
[0114] Furthermore, RRAM can progressively refine the global feature map by establishing relationships between regions and edge cues, and integrate high-level features to correct erroneous predictions and improve global features. Specifically, it gradually uncovers discriminative defect features by progressively erasing the foreground. Based on the global features extracted in the encoder stage, it inverts these features, retaining the unpredicted parts, and combines them with existing high-level features to learn details and correct errors. The reverse region-aware module has two inputs. One is high-level features from deep within the encoder. One is rich in semantic information, and the other is the global features output from the multi-scale adaptive module. By erasing features In the foreground part, the undetected regions of the segmented target, including edge regions, are simulated and combined with higher-order features layer by layer from bottom to top to gradually uncover the edge and regional details corresponding to the defect regions.
[0115] Optionally, the sixth feature map is processed using the multi-scale adaptive module to generate a seventh feature map, including:
[0116] The preset second convolution kernel is convolved with the sixth feature map to obtain the eighth feature map;
[0117] The ninth feature map is obtained by performing a convolution operation between the pre-defined depth separable convolution and the eighth feature map;
[0118] The ninth feature map, the eighth feature map, and the sixth feature map are fused to generate the seventh feature map.
[0119] In this scheme, the sixth feature map A 1×1 second convolution kernel is used to perform dimensionality reduction, resulting in the eighth feature map G.
[0120] .
[0121] Furthermore, the eighth feature map G is convolved using a pre-defined depthwise separable convolution to obtain the ninth feature map. .
[0122] In this scheme, the ninth feature map, the eighth feature map, and the sixth feature map are fused to generate the seventh feature map. .
[0123] The multi-scale adaptive module aggregates and fuses high-order features from multiple scales, enabling the model to obtain richer feature representations, expand the receptive field, capture long-distance dependencies, and provide relatively accurate global features for subsequent refinement of details.
[0124] Optionally, the depthwise separable convolution is composed of convolution kernels of different shapes and sizes; a ninth feature map is obtained by performing a convolution operation between the preset depthwise separable convolution and the eighth feature map, including:
[0125] The convolution operation is performed between the convolution kernels of different shapes and sizes and the eighth feature map to obtain the ninth feature map.
[0126] In this scheme, the dimensionality-reduced feature G is processed through three parallel branches. In the first branch, G first undergoes 1×3 and 3×1 depthwise separable convolutions. By combining convolution kernels of different shapes and sizes, horizontal and vertical features are captured, and these features are fused to provide the model with richer feature representations, better adapting to the complex structures and variations in medical images. Simultaneously, depthwise separable convolutions significantly reduce the number of model parameters, lowering complexity. Subsequently, a 3×3 dilated convolution is used to learn more contextual information and capture long-range dependencies to help better understand the overall semantics. Similarly, in the second branch, G first undergoes 1×5 and 5×1 depthwise separable convolutions, followed by a 5×5 dilated convolution. In the third branch, G first undergoes 1×7 and 7×1 depthwise separable convolutions, then is fed into a 7×7 dilated convolution. The formulas for this part are as follows:
[0127] ;
[0128] in, This represents the output of the i-th branch, where DSConv represents depthwise separable convolution, and r is the dilation coefficient. The value of i ranges from [1,2,3].
[0129] Finally, the features obtained from each branch are fused with the input features to generate features with richer semantic features. :
[0130] ;
[0131] High-order features at different resolutions Features with richer semantic information are obtained through the improved RFB module. These features are aggregated to obtain a seventh feature map for coarse segmentation. The expression is as follows:
[0132] .
[0133] The multi-scale adaptive module aggregates and fuses high-order features from multiple scales, enabling the model to obtain richer feature representations, expand the receptive field, capture long-distance dependencies, and provide relatively accurate global features for subsequent refinement of details.
[0134] Optionally, the seventh feature map and the sixth feature map are processed according to the reverse region perception module to generate a second feature map, including:
[0135] The seventh feature map is processed using average pooling and max pooling to obtain the tenth feature map, and then the tenth feature map is convolved using a preset third convolution kernel to generate the eleventh feature map.
[0136] The eleventh feature map is processed by an activation function to obtain an attention weight map;
[0137] The second feature map is determined based on the attention weight map and the sixth feature map.
[0138] In this scheme, the reverse region perception module has two inputs. One is high-order features from deep within the encoder. One is rich in semantic information, and the other is the seventh feature map output from the multi-scale adaptive module. By erasing features In the foreground part, the undetected regions of the segmented target, including edge regions, are simulated and combined with higher-order features layer by layer from bottom to top to gradually uncover the edge and regional details corresponding to the defect regions.
[0139] Specifically, First, the feature maps are processed using average pooling and max pooling to reduce noise while preserving edge and texture details. Then, the resulting tenth feature map is fused along the channel direction, and its shape is restored using a 3×3 convolution kernel to generate the eleventh feature map. The formula for this part is as follows:
[0140] ;
[0141] Furthermore, regarding the fusion Sigmoid activation is performed to obtain an attention weight map of fused features. This attention weight map is then subtracted from matrix E to obtain a reverse attention weight map. Through reverse attention, the details of the obtained global prediction are supplemented, and erroneous parts are removed, thereby gradually improving the segmentation accuracy. The formula for this part is as follows:
[0142] ;
[0143] ;
[0144] in, This is the second feature map. This is a reverse attention weight map. This indicates element-wise multiplication.
[0145] Output It continues to serve as input to the reverse region perception module in the previous layer, and, guided by the higher-order features on the left, continues to refine the details of edges and regions.
[0146] S530. The first feature map and the feature map are fused by the decoder to obtain a defect image.
[0147] Specifically, in the shallow layer of the decoder, the edge information extracted by edge difference convolution is fused and complemented with global features. Then, convolution is used to restore the feature map to the input size, generating the output defect image Y.
[0148] .
[0149] This top-down, deep-to-shallow strategy can guide the network to accurately capture undetected regions, refine the coarse segmentation feature map into a segmentation image with complete regions and details, improve segmentation accuracy, and thus achieve good segmentation performance.
[0150] S540. Determine the defect parameters based on the defect image.
[0151] This solution significantly improves the sensitivity of identifying micro-defects such as minute tool marks and chipped corners through edge difference mechanisms and reverse region optimization strategies; it enhances the global feature perception capability of complex structural components by leveraging multi-scale modeling technology; and it achieves automatic coordination between the inspection process and the manufacturing process through a closed-loop feedback mechanism, resulting in multi-dimensional and significant benefits.
[0152] A qualitative breakthrough in detection accuracy: It can accurately identify micro-defects such as knife marks, chipped corners, and burrs at the 0.05 mm level. Through the collaborative learning of edge and region features, it effectively reduces the false detection rate and false negative rate in the detection process.
[0153] Significant advantages in real-time performance and deployment: The lightweight model can be directly deployed on edge AI devices, with a short single-station detection cycle and support for multi-station parallel detection, perfectly matching the high-efficiency production cycle requirements of CNC production lines;
[0154] Construct a closed-loop process optimization system: Based on data-driven implementation, realize a closed-loop process of "inspection-correction-optimization-re-inspection". The inspection results can be automatically fed back to the CNC system, triggering tool wear compensation and toolpath optimization, which greatly reduces the product scrap rate;
[0155] It is highly adaptable and scalable: it can be adapted to the detection scenarios of various metal materials such as aluminum, magnesium, and titanium, and can also be extended to the defect detection of products such as anodized parts, precision structural parts and metal shells of consumer electronics;
[0156] Outstanding economic and quality benefits: Significantly improves product yield and reduces scrap rate, without requiring additional manual intervention, ensuring stable and synchronized production rhythm.
[0157] The technical solution of this invention involves acquiring a target image of a CNC machined part; processing the target image using a first network branch to generate a first feature map; processing the target image using a second network branch to generate a second feature map; and fusing the first feature map and the second feature map using a decoder to obtain a defect image. Defect parameters are then determined based on the defect image. By implementing this technical solution, and by introducing an edge difference convolution module, a multi-scale adaptive module, and a reverse region perception module, high-precision, low-latency detection and early warning of CNC machining tool marks and chipped corner defects in complex environments can be achieved. This significantly improves the accuracy and efficiency of defect detection while enhancing the stability of the detection process.
[0158] Example 3
[0159] Figure 11 This is a schematic diagram of a defect detection device for CNC machined parts provided in Embodiment 3 of the present invention. Figure 11 As shown, the device includes:
[0160] The target image acquisition unit 1110 is used to acquire the target image of the CNC machined part;
[0161] The defect image output unit 1120 is used to input the target image into an edge difference inverse region perception network model, process the target image through the edge difference inverse region perception network model, and output a defect image; wherein, the edge difference inverse region perception network model includes a first network branch, a second network branch, and a decoder; the first network branch is a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch is a hybrid adaptive module, a multi-scale adaptive module, and an inverse region perception module connected in sequence.
[0162] The defect parameter determination unit 1130 is used to determine defect parameters based on the defect image.
[0163] Optionally, the defect image output unit 1120 includes:
[0164] The feature map generation subunit is used to process the target image using the first network branch to generate a first feature map; and to process the target image using the second network branch to generate a second feature map;
[0165] The defect image is used to obtain a sub-unit, which is used to fuse the first feature map and the feature map through the decoder to obtain the defect image.
[0166] Optional, feature map generation subunit, specifically used for:
[0167] The target image is processed based on the hybrid adaptive module to generate a third feature map;
[0168] The third feature map is processed using the edge difference convolution module to generate the first feature map.
[0169] Optionally, the feature map generation subunit is also used for:
[0170] The first pre-defined convolution kernel is convolved with the third feature map to obtain a horizontal feature map and a vertical feature map.
[0171] The horizontal feature map and the vertical feature map are fused to generate a first feature map.
[0172] Optionally, the feature map generation subunit is also used for:
[0173] Determine the first weight corresponding to the horizontal feature map; and determine the second weight corresponding to the vertical feature map;
[0174] The difference between 1 and the first weight is used as the third weight; and the difference between 1 and the second weight is used as the fourth weight;
[0175] The horizontal feature map is weighted using the second weight and the vertical feature map is weighted using the fourth weight. The weighting results are then fused to obtain the fourth feature map.
[0176] The horizontal feature map is weighted according to the first weight and the vertical feature map is weighted according to the third weight. The weighting results are then fused to obtain the fifth feature map.
[0177] The fourth feature map and the fifth feature map are concatenated to obtain the first feature map.
[0178] Optionally, the feature map generation subunit is also used for:
[0179] The target image is processed based on the hybrid adaptive module to generate a sixth feature map;
[0180] The sixth feature map is processed using the multi-scale adaptive module to generate the seventh feature map;
[0181] The seventh feature map and the sixth feature map are processed by the reverse region perception module to generate the second feature map.
[0182] Optionally, the feature map generation subunit is also used for:
[0183] The preset second convolution kernel is convolved with the sixth feature map to obtain the eighth feature map;
[0184] The ninth feature map is obtained by performing a convolution operation between the pre-defined depth separable convolution and the eighth feature map;
[0185] The ninth feature map, the eighth feature map, and the sixth feature map are fused to generate the seventh feature map.
[0186] Optionally, the feature map generation subunit is also used for:
[0187] The convolution operation is performed between the convolution kernels of different shapes and sizes and the eighth feature map to obtain the ninth feature map.
[0188] Optionally, the feature map generation subunit is also used for:
[0189] The seventh feature map is processed using average pooling and max pooling to obtain the tenth feature map, and then the tenth feature map is convolved using a preset third convolution kernel to generate the eleventh feature map.
[0190] The eleventh feature map is processed by an activation function to obtain an attention weight map;
[0191] The second feature map is determined based on the attention weight map and the sixth feature map.
[0192] The defect detection device for CNC machined parts provided in this embodiment of the invention can execute the defect detection method for CNC machined parts provided in any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the method.
[0193] Example 4
[0194] Figure 12A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0195] like Figure 12 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0196] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0197] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as a defect detection method for CNC machined parts.
[0198] In some embodiments, a defect detection method for a CNC machined part may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the defect detection method for a CNC machined part described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform a defect detection method for a CNC machined part by any other suitable means (e.g., by means of firmware).
[0199] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), system-on-a-chip (SoCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transferring data and instructions to the storage system, the at least one input device, and the at least one output device.
[0200] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0201] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0202] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0203] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0204] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0205] In particular, according to embodiments of the present invention, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of the present invention include a computer program product comprising a computer program carried on a non-transitory computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication unit 19, or installed from storage unit 18, or installed from ROM 12. When the computer program is executed by processor 11, it performs the functions defined in the methods of the embodiments of the present invention.
[0206] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0207] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A defect detection method for CNC machined parts, characterized in that, include: Obtain the target image of the CNC machined part; The target image is input into an edge difference inverse region perception network model, and the target image is processed by the edge difference inverse region perception network model to output a defect image; wherein, the edge difference inverse region perception network model includes a first network branch, a second network branch, and a decoder; the first network branch is a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch is a hybrid adaptive module, a multi-scale adaptive module, and an inverse region perception module connected in sequence. Based on the defect image, the defect parameters are determined.
2. The method according to claim 1, characterized in that, The target image is input into an edge difference inverse region perception network (EDR) model. The EDR model processes the target image and outputs a defect image, including: The target image is processed using the first network branch to generate a first feature map; and the target image is processed using the second network branch to generate a second feature map. The first feature map and the feature map are fused by the decoder to obtain a defect image.
3. The method according to claim 2, characterized in that, The target image is processed using the first network branch to generate a first feature map, including: The target image is processed based on the hybrid adaptive module to generate a third feature map; The third feature map is processed using the edge difference convolution module to generate the first feature map.
4. The method according to claim 3, characterized in that, The third feature map is processed using the edge difference convolution module to generate the first feature map, including: The first pre-defined convolution kernel is convolved with the third feature map to obtain a horizontal feature map and a vertical feature map. The horizontal feature map and the vertical feature map are fused to generate a first feature map.
5. The method according to claim 4, characterized in that, The horizontal feature map and the vertical feature map are fused to generate a first feature map, including: Determine the first weight corresponding to the horizontal feature map; and determine the second weight corresponding to the vertical feature map; The difference between 1 and the first weight is used as the third weight; and the difference between 1 and the second weight is used as the fourth weight; The horizontal feature map is weighted using the second weight and the vertical feature map is weighted using the fourth weight. The weighting results are then fused to obtain the fourth feature map. The horizontal feature map is weighted according to the first weight and the vertical feature map is weighted according to the third weight. The weighting results are then fused to obtain the fifth feature map. The fourth feature map and the fifth feature map are concatenated to obtain the first feature map.
6. The method according to claim 2, characterized in that, The target image is processed using the second network branch to generate a second feature map, including: The target image is processed based on the hybrid adaptive module to generate a sixth feature map; The sixth feature map is processed using the multi-scale adaptive module to generate the seventh feature map; The seventh feature map and the sixth feature map are processed by the reverse region perception module to generate the second feature map.
7. The method according to claim 6, characterized in that, The sixth feature map is processed using the multi-scale adaptive module to generate the seventh feature map, including: The preset second convolution kernel is convolved with the sixth feature map to obtain the eighth feature map; The ninth feature map is obtained by performing a convolution operation between the pre-defined depth separable convolution and the eighth feature map; The ninth feature map, the eighth feature map, and the sixth feature map are fused to generate the seventh feature map.
8. The method according to claim 7, characterized in that, The depthwise separable convolution is composed of convolution kernels of different shapes and sizes; a ninth feature map is obtained by performing a convolution operation between the preset depthwise separable convolution and the eighth feature map, including: The convolution operation is performed between the convolution kernels of different shapes and sizes and the eighth feature map to obtain the ninth feature map.
9. The method according to claim 6, characterized in that, The reverse region perception module processes the seventh feature map and the sixth feature map to generate a second feature map, including: The seventh feature map is processed using average pooling and max pooling to obtain the tenth feature map, and then the tenth feature map is convolved using a preset third convolution kernel to generate the eleventh feature map. The eleventh feature map is processed by an activation function to obtain an attention weight map; The second feature map is determined based on the attention weight map and the sixth feature map.
10. A defect detection device for CNC machined parts, characterized in that, include: The target image acquisition unit is used to acquire the target image of the CNC machined part. A defect image output unit is used to input the target image into an edge difference inverse region perception network model, process the target image through the edge difference inverse region perception network model, and output a defect image; wherein, the edge difference inverse region perception network model includes a first network branch, a second network branch, and a decoder; the first network branch is a hybrid adaptive module and an edge difference convolution module connected in sequence; the second network branch is a hybrid adaptive module, a multi-scale adaptive module, and an inverse region perception module connected in sequence; The defect parameter determination unit is used to determine defect parameters based on the defect image.