3D printing defect detection method based on improved YOLOv10n

By improving the YOLOv10n network and integrating the DSMCATtn, DySample, and SHSA modules, the problems of insufficient detection accuracy for small targets and insufficient multi-scale feature fusion in 3D printing defect detection were solved, achieving efficient and accurate online industrial inspection.

CN121169830APending Publication Date: 2025-12-19XIAN UNIV OF TECH
View PDF 0 Cites 4 Cited by

Patent Information

Application Number
CN202511221878.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-08-29
Publication Date
2025-12-19

AI Technical Summary

Technical Problem

Existing 3D printing defect detection methods suffer from insufficient accuracy in detecting small targets, high computational resource consumption, and limited multi-scale feature fusion capabilities, making it difficult to meet the needs of industrial online inspection.

Method used

An improved YOLOv10n network architecture is adopted, integrating the Dynamic Scale Monte Carlo attention mechanism (DSMCAttn), the DySample dynamic upsampling mechanism, and the lightweight single-head self-attention mechanism (SHSA). By constructing a DM-YOLO network model, multi-scale feature fusion and small object detection are achieved.

Benefits of technology

It significantly improves the detection accuracy and reasoning efficiency of 3D printing defects, meets the speed and accuracy requirements of industrial online inspection, reduces the number of parameters by about 15%, and increases the detection speed by more than 300%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121169830A_ABST
    Figure CN121169830A_ABST
Patent Text Reader

Abstract

The invention discloses a 3D printing defect detection method based on improved YOLOv10n, and the method specifically comprises the steps: constructing a data set, and dividing the data set into a training set and a test set; processing the training set data; the method comprises the following steps of: constructing a DM-YOLO network model by taking YOLOv10n as a basic algorithm; the DM-YOLO network model comprises a trunk feature extraction network, a neck feature fusion network and a detection head network; training the network model by using the training set data; and inputting test set data into the trained DM-YOLO detection model, outputting category information of defect positions in the FDM printed piece, and obtaining a defect detection result. The network is deeply optimized on the basis of YOLOv10n, DSMCAttn, a DySample dynamic up-sampler and a lightweight single-head self-attention mechanism are integrated, and the detection precision and reasoning efficiency of small target defects are remarkably improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of deep learning and 3D printing, and particularly relates to a 3D printing defect detection method based on improved YOLOv10n. BACKGROUND

[0002] 3D printing technology (especially FDM process) is widely used in manufacturing, medical, aerospace and other fields, but defects such as warping deformation, interlayer cracking and spot scar may occur due to improper parameter setting, material properties or environmental factors during printing. At present, defect detection mainly relies on manual visual inspection or remote monitoring, which has problems such as low efficiency and waste of manpower.

[0003] CNN-based target detection algorithm has been widely applied in industrial detection field, but there are still the following problems when directly applied to 3D printing defect detection: 1. Insufficient small target detection accuracy: the feature extraction ability of small defects such as spot scars is weak, and it is easy to miss detection; 2. Large consumption of computing resources: in the industrial real-time detection scene, complex models are difficult to meet the requirement of inference speed of more than 100FPS; 3. Limited multi-scale feature fusion capability: traditional feature pyramid is not sufficient in integrating context information when processing multi-scale textures on the surface of 3D printed parts. In the prior art, the real-time performance of traditional machine vision method is insufficient, and the adaptability of deep learning model to multi-scale defects is poor, which leads to that the detection accuracy and efficiency cannot meet the requirements of industrial online detection. SUMMARY

[0004] The purpose of the application is to provide a 3D printing defect detection method based on improved YOLOv10n, which improves the detection accuracy of 3D printing defects.

[0005] The technical scheme adopted by the application is a 3D printing defect detection method based on improved YOLOv10n, which is implemented according to the following steps: Step S1: constructing a data set, dividing the data set into a training set and a test set; and processing the training set data; Step S2: constructing a DM-YOLO network model based on YOLOv10n as the basic algorithm; the DM-YOLO network model includes a backbone feature extraction network, a neck feature fusion network and a detection head network; Step S3: model training: training the DM-YOLO network model using the training set data; Step S4: inputting the test set data into the trained DM-YOLO detection model, outputting the category information of the position of the defect in the FDM printed part, and obtaining the defect detection result.

[0006] The application also has the characteristics of, In step S1, specifically, Step S1.1: Collect images containing surface defects of FDM 3D printed parts to form a dataset. The dataset includes images covering warping, interlayer cracking, and spot scars, and labels the categories. Divide the dataset into training set and test set. Step S1.2: Perform data augmentation on the training set image data, including image rotation, flipping, scaling, brightness adjustment, and random occlusion processing; increase the sample size of the training set data by 10 times.

[0007] In step S2, specifically: Step S2.1: The backbone feature extraction network specifically includes the C2f module, C2f_SA module, SPPF module, SCDown module, and DPSMOCA attention mechanism module; Step S2.2: Neck Feature Fusion Network: Includes DySample dynamic upsampling and an improved feature pyramid, which performs upsampling operations through a point sampling mechanism to enhance the fusion of small target features; Step S2.3: Detection head network: Decouples classification, localization and confidence prediction, outputs the defect category, bounding box and confidence, and realizes multi-scale defect detection.

[0008] In step S2.1, specifically: Step S2.1.1: C2f module and C2f_SA module: Based on CSPNet design, the expressive power is improved through residual connections and feature fusion; the C2f_SA module further introduces a single-head self-attention mechanism to optimize information interaction between channels; The input / output dimensions of layers 0 to 10 are as follows: Layer 0: Conv module, using 3×3 convolution, combined with batch normalization and SiLU activation function, to perform preliminary feature extraction on the input 640×640×3 image, and at the same time achieve the first dimensionality reduction, outputting a 320×320×16 feature map; Layer 1: Conv module, which uses 3×3 convolution + batch normalization + SiLU activation to further extract features and reduce dimensionality from the input 320×320×16 feature map, enhance the expressive power of the low-level features, and output a 160×160×32 feature map. Layer 2: The C2f module reduces the dimensionality of the input 160×160×32 feature map through 1×1 convolution, processes it through a Bottleneck sub-module with residual connections, increases the dimensionality through 1×1 convolution, and finally fuses the features through the Concat operation to output a 160×160×32 feature map. Layer 3: Conv module, 3×3 convolution + batch normalization + SiLU activation, reduces the dimensionality of the input 160×160×32 feature map to 80×80, extracts the middle layer semantic features, and outputs an 80×80×64 feature map; Layer 4: C2f module, after performing 1×1 convolution to reduce the dimension of the input 80×80×64 feature map, it is processed by two Bottleneck sub-modules with residual connections, and then 1×1 convolution to increase the dimension and Concat fusion to output an 80×80×64 feature map. Layer 5: SCDown module, 3×3 convolution + batch normalization + SiLU activation, reduces the dimensionality of the input 80×80×64 feature map to 40×40, abstracts high-level semantic features, reduces spatial dimension while increasing channel dimension, and outputs a 40×40×128 feature map. Layer 6: C2f_SA module, after performing 1×1 convolution on the input 40×40×128 feature map, divides the key channel and the direct pass channel through the Split operation, performs SHSA lightweight single-head self-attention operation only on the key channel, and finally fuses through Concat to output a 40×40×128 feature map; Layer 7: SCDown module, 3×3 convolution + batch normalization + SiLU activation; reduces the dimensionality of the 40×40×128 feature map to 20×20, and outputs a 20×20×256 feature map; Layer 8: C2f_SA module, consistent with layer 6, optimized for a 20×20 scale, outputting a 20×20×256 feature map; Step S2.1.2: SPPF module: Enhances multi-target adaptability by fusing features at different scales through multi-scale pooling; Layer 9: SPPF module, after performing 1×1 convolution on the input 20×20×256 feature map, extracts multi-scale features through parallel 5×5, 9×9, and 13×13 pooling, and finally fuses the multi-scale pooling features through Concat to output a 20×20×256 feature map. Step S2.1.3: DSMC attention mechanism: Attention fusion is performed by calculating weights through Softmax; Layer 10: The DPSMOCA module performs a 1×1 convolution on the input 20×20×256 feature map, then dynamically selects 1-3 pooling scales through DSMCATn, generates an attention map through Softmax weighted fusion, and finally integrates it through a 1×1 convolution to output a 20×20×256 feature map.

[0009] In step S2.2, the neck feature fusion network includes a DySample dynamic upsampler and a sampling point generation unit; specifically: DySample dynamic upsampler: Extracts the spatial gradient distribution of the input feature map through two 3×3 convolutional layers to identify regions with high texture variation; Feature aggregation unit: Resamples the input feature map and sample set using PyTorch's grid_sample function with specified coordinates, and generates a new feature map of a new dimension through bilinear interpolation. The input / output dimensions of layers 11 to 22 are as follows: Layer 11: DySample module, which extracts the spatial gradient distribution of the input 20×20×256 feature map through 2 layers of 3×3 convolution, generates dynamic offset, upsamples the 20×20 feature map to 40×40, preserves small target details, and outputs a 40×40×256 feature map. Layer 12: Concat module, which concatenates the 40×40×256 feature map of layer 11 and the 40×40×128 feature map of layer 6 according to the channel dimension, and merges the high-level semantic features and mid-level detail features of the 40×40 scale to output a 40×40×384 feature map. Layer 13: C2f module, consistent with layer 2, takes a 40×40×384 feature map as input, reduces the dimension to 128 channels, optimizes the feature fusion at the 40×40 scale, balances semantics and details, and outputs a 40×40×128 feature map; Layer 14: DySample module, consistent with layer 11, with an upsampling ratio of 2; upsamples the 40×40×128 feature map to 80×80 to enhance the detail restoration of small targets, and outputs an 80×80×128 feature map; Layer 15: Concat module, which concatenates the 80×80×128 feature map of layer 14 and the 80×80×64 feature map of layer 4 according to the channel dimension, and merges the mid-level features and upsampled features at the 80×80 scale to output an 80×80×192 feature map. Layer 16: C2f module, consistent with layer 2, reduces the dimensionality of the 80×80×192 feature map to 64 channels, enhances the feature representation of small targets at the 80×80 scale, and outputs an 80×80×64 feature map; Layer 17: Conv module, 3×3 convolution + batch normalization + SiLU activation; reduces the dimensionality of the 80×80×64 feature map to 40×40, and outputs a 40×40×64 feature map; Layer 18: Concat module, which concatenates the 40×40×64 feature map of layer 17 and the 40×40×128 feature map of layer 13 according to the channel dimension, and fuses the dimensionality reduction features of the 40×40 scale and the mid-level semantic features to output a 40×40×192 feature map. Layer 19: C2f module, consistent with layer 2, takes a 40×40×192 feature map as input, optimizes the feature fusion at a scale of 40×40, enhances the feature representation of the target, and outputs a 40×40×128 feature map; Layer 20: SCDown module, which reduces the dimensionality of the 40×40×128 feature map to 20×20 through 3×3 convolution + batch normalization + SiLU activation, and outputs a 20×20×128 feature map; Layer 21: Concat module, which concatenates the 20×20×128 feature map of layer 20 and the 20×20×256 feature map of layer 10 according to the channel dimension, and outputs a 20×20×384 feature map; Layer 22: The C2fCIB module performs 1×1 convolution on the 20×20×384 feature map, then processes it through the Bottleneck submodule with residual connections, and finally fuses it through Concat to output a 20×20×256 feature map.

[0010] Step S2.3 specifically includes: Layer 23: The v10Detect module processes feature maps at three scales: the 80×80×64 feature map output from Layer 16, the 40×40×128 feature map output from Layer 19, and the 20×20×256 feature map output from Layer 22. Specifically, this includes: Classification branch: Outputs the probability of 3 types of defects through 2 layers of 1×1 convolution; Localization branch: Predicts bounding box coordinates using 3×3 convolution; Confidence branch: Outputs the probability of the target's existence through a 1×1 convolution; Output dimensions: Each scale outputs the following dimensions: width × height × (3 categories + 4 coordinates + 1 confidence score), which are then integrated into the defect detection results, including: category, coordinates, and confidence score.

[0011] The beneficial effects of this invention are: The method of this invention employs a DM-YOLO (Dynamic Multi-scale YOLO) network architecture, achieving high-precision real-time detection of 3D printing defects through the innovative design of three core modules. This network is deeply optimized based on YOLOv10n, integrating a Dynamic Scale Monte Carlo attention mechanism (DSMCAttn), a DySample dynamic upsampler, and a lightweight single-head self-attention mechanism (SHSA), significantly improving the detection accuracy and inference efficiency for small target defects. Attached Figure Description

[0012] Figure 1 This is a structural diagram of the DM-YOLO network in the 3D printing defect detection method based on the improved YOLOv10n of this invention; Figure 2This is a structural diagram of the DSMCAttn attention mechanism in the 3D printing defect detection method based on the improved YOLOv10n of this invention; Figure 3 This is a structural diagram of the DySample module in the 3D printing defect detection method based on the improved YOLOv10n of this invention; Figure 4 This is a structural diagram of the C2f_SA module in the 3D printing defect detection method based on the improved YOLOv10n of this invention; Figure 5 This is a structural diagram of the SHSA module in the 3D printing defect detection method based on the improved YOLOv10n of this invention; Figure 6 This is a diagram of the original surface condition of the FDM printed part (I). Figure 7 Is Figure 6 The detection bounding box of YOLOv10n is superimposed on the original image; Figure 8 Is Figure 6 The DM-YOLO detection bounding box is superimposed on the original image; Figure 9 This is a diagram of the original surface condition of the FDM printed part (II). Figure 10 Is Figure 9 The detection bounding box of YOLOv10n is superimposed on the original image; Figure 11 Is Figure 9 The DM-YOLO detection bounding box is superimposed on the original image; Figure 12 This is a diagram of the original surface condition of the FDM printed part (Part 3); Figure 13 Is Figure 12 The detection bounding box of YOLOv10n is superimposed on the original image; Figure 14 Is Figure 12 The detection bounding box of DM-YOLO is superimposed on the original image. Detailed Implementation

[0013] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.

[0014] Example 1 This invention is based on an improved YOLOv10n 3D printing defect detection method, and is implemented according to the following steps: Step S1: Construct the dataset and process it; Step S1.1: Collect images containing surface defects of FDM 3D printed parts to form a dataset. The dataset includes images covering warping, interlayer cracking, and spot scars, and labels the categories. Divide the dataset into a training set and a test set. The test set is not augmented to evaluate performance in real-world scenarios. Step S1.2: Perform data augmentation on the training set image data, including image rotation, flipping, scaling, brightness adjustment, and random occlusion processing; increase the sample size of the training set data by 10 times; Step S2: Construct a DM-YOLO network model based on the YOLOv10n algorithm; The DM-YOLO network model includes a backbone feature extraction network, a neck feature fusion network, and a detection head network; Step S2.1: Backbone Feature Extraction Network: Based on the improved structure of CSPNet, it integrates the Dynamic Scale Monte Carlo attention mechanism (DSMCAttn) to achieve multi-scale feature extraction; The backbone feature extraction network specifically includes the C2f module and C2f_SA module, SPPF module, SCDown module, and DPSMOCA attention mechanism module; Specifically: Step S2.1.1: C2f module and C2f_SA module: Based on CSPNet (Cross-Stage Local Network) design, the expressive power is improved through residual connections and feature fusion; the C2f_SA module further introduces a single-head self-attention mechanism (SHSA) to optimize the information interaction between channels; SHSA's lightweight single-head self-attention mechanism is optimized through selective channel processing, performing attention operations only on a subset of critical channels, reducing memory access costs, and decreasing the number of parameters while maintaining accuracy. The formula is as follows:

[0015]

[0016]

[0017]

[0018] in, For attention processing channels, For direct transmission channels, in the formula: W Q , W K , W V and WO It is the projected weight. d qk This refers to the query and key dimensions, and Concat() is the join operation. Compared to multi-head attention, SHSA's lightweight single-head self-attention mechanism reduces the number of parameters by 40%, and GFLOPS decreases from 8.4 to 7.9.

[0019] The input / output dimensions of layers 0 to 10 are as follows: Layer 0: Conv module, using 3×3 convolution (stride 2), combined with batch normalization and SiLU activation function. It performs preliminary feature extraction on the input 640×640×3 training set image, capturing the basic features of the bottom edge and texture, and simultaneously performs the first dimensionality reduction, outputting a 320×320×16 feature map; Layer 1: Conv module, which uses 3×3 convolution (stride 2) + batch normalization + SiLU activation to further extract features and reduce dimensionality from the input 320×320×16 feature map, enhance the expressive power of the low-level features, and output a 160×160×32 feature map. Layer 2: The C2f module reduces the dimensionality of the input 160×160×32 feature map through 1×1 convolution, then processes it through a Bottleneck submodule with residual connections, followed by 1×1 convolution to increase the dimensionality, and finally fuses the features through a Concat operation. This enhances the local feature fusion capability, preserves detailed features at the 160×160 scale, and outputs a 160×160×32 feature map. Layer 3: Conv module, 3×3 convolution (stride 2) + batch normalization + SiLU activation. Reduces the dimensionality of the input 160×160×32 feature map to 80×80, extracts mid-level semantic features, and outputs an 80×80×64 feature map; Layer 4: C2f module, after performing 1×1 convolution to reduce the dimensionality of the input 80×80×64 feature map, it is processed by two Bottleneck sub-modules with residual connections, and then enhanced by 1×1 convolution and Concat fusion to strengthen the feature representation of the 80×80 scale, improve the ability to capture mid-level defects, and output an 80×80×64 feature map. Layer 5: SCDown module, 3×3 convolution (stride 2) + batch normalization + SiLU activation, to achieve scale compression and downsampling. It reduces the dimensionality of the input 80×80×64 feature map to 40×40, abstracts high-level semantic features, reduces spatial dimension while increasing channel dimension, and outputs a 40×40×128 feature map; Layer 6: The C2f_SA module performs 1×1 convolution on the input 40×40×128 feature map, then splits the key channel and the direct pass channel through a Split operation. Only the key channel is subjected to SHSA lightweight single-head self-attention computation, and finally, the data is fused using Concat. By introducing a self-attention mechanism, the interaction of channel information at the 40×40 scale is optimized, enhancing the feature capture of small targets and outputting a 40×40×128 feature map. Layer 7: SCDown module, 3×3 convolution (stride 2) + batch normalization + SiLU activation. Reduces the dimensionality of the 40×40×128 feature map to 20×20, further abstracts semantic features, focuses on large-scale defects, and outputs a 20×20×256 feature map; Layer 8: C2f_SA module, consistent with Layer 6, optimized for the 20×20 scale. Enhances channel attention at the 20×20 scale, improves the ability to capture the correlation of cross-regional defects (such as large-area interlayer cracks), and outputs a 20×20×256 feature map; Step S2.1.2: SPPF module: Enhances multi-target adaptability by fusing features at different scales through multi-scale pooling; Layer 9: SPPF module, after performing 1×1 convolution on the input 20×20×256 feature map, extracts multi-scale features through parallel 5×5, 9×9, and 13×13 pooling (equivalent implementation), and finally fuses the multi-scale pooling features through Concat to enhance the adaptability to defects of different sizes, and outputs a 20×20×256 feature map. Step S2.1.3: Dynamic Scale Monte Carlo (DSMC) Attention Mechanism: This mechanism not only relies on global features but also considers information at different scales. It can dynamically select 1-3 pooling scales from 1×1 to n×n pooling resolutions based on the complexity of the input features, calculating attention maps from features at multiple scales, thereby enhancing long-range semantic relevance. Assuming a given input tensor... x Attention is fused by calculating weights using Softmax, and the output attention map of DSMCATTn is obtained. Am ( x The calculation is as follows:

[0020] in, i This represents the output size of each pooling operation. k Value based on n The value of determines the number of pooling tensors. When n When <= 3, k = 1; when 3 < n <7 o'clock, k = 2; when n When >= 7,k = 3. Among them f ( x, i () represents the average pooling function; in addition, the association probability... The conditions are still met. ,and This ensures the generation of random attention maps. Dynamic multi-scale feature fusion enhances the characterization ability of cross-scale defects such as interlayer cracking.

[0021] Layer 10: The DPSMOCA module performs a 1×1 convolution on the input 20×20×256 feature map, then dynamically selects 1-3 pooling scales (1×1 to n×n) through DSMCATtn, generates an attention map through Softmax weighted fusion, and finally integrates it through a 1×1 convolution to output a 20×20×256 feature map; it strengthens long-range semantic associations through dynamic multi-scale attention and improves the ability to represent cross-scale defects.

[0022] Step S2.2: Neck Feature Fusion Network: Includes DySample dynamic upsampling and an improved feature pyramid, which performs upsampling operations through a point sampling mechanism to enhance the fusion of small target features; The neck feature fusion network includes the DySample dynamic upsampler and a sampling point generation unit; DySample dynamic upsampling unit: As a feature extraction unit, it extracts the spatial gradient distribution of the input feature map through two 3×3 convolutional layers to determine regions with high texture variation; Feature aggregation unit: Using a dimension of... Input feature map and size are sample set (Sampling grid), where the first two dimensions represent x and y Coordinates, used using PyTorch's grid_sample function. As a specified coordinate pair Resampling is performed, and dimensions are generated through bilinear interpolation. New feature map The specific formula is as follows:

[0023] Sampling point generation unit: Let the upsampling scaling factor be s, then the size generated by the linear layer is... Output offset The output and input channels are respectively and Then the offset O Adjusted by pixel shuffling algorithm Finally, the offsetO and the original sampling grid G Add them together to get the sample set. Its linear mapping process is mathematically represented as follows:

[0024]

[0025] To enhance the flexibility of the offset, a "dynamic range factor" is calculated point-by-point from the input features using linear projection. This dynamic range factor is defined in the range [0, 0.5] with a center of 0.25, and is calculated using the sigmoid function. A static factor of 0.5 is also introduced, as shown in the formula:

[0026] Where G is the standard grid and O is the dynamic offset, adaptive upsampling is achieved through bilinear interpolation. The upsampling strategy is designed from the perspective of point sampling, which can dynamically adjust the position of sampling points according to task requirements. Without increasing the computational burden, it effectively enhances the detail restoration capability in the upsampling process and significantly improves the detection accuracy of small defect targets such as spots and scars.

[0027] The input / output dimensions of layers 11 to 22 are as follows: Layer 11: The DySample module extracts the spatial gradient distribution of the input 20×20×256 feature map through two layers of 3×3 convolutions, generating a dynamic offset. It then uses bilinear interpolation to achieve upsampling (at a ratio of 2). The sampling point positions can be dynamically adjusted to upsample the 20×20 feature map to 40×40, preserving details of small targets (such as the edges of spots and scars), and outputting a 40×40×256 feature map. Layer 12: Concat module, which concatenates the 40×40×256 feature map of layer 11 and the 40×40×128 feature map of layer 6 according to the channel dimension, and fuses the high-level semantic features (DPSMOCA output) and mid-level detail features (C2f_SA output) at the 40×40 scale, outputting a 40×40×384 feature map; Layer 13: C2f module, consistent with layer 2, takes a 40×40×384 feature map as input, can reduce the dimension to 128 channels, optimizes the feature fusion at the 40×40 scale, balances semantics and details, and outputs a 40×40×128 feature map; Layer 14: DySample module, consistent with layer 11, with an upsampling ratio of 2. Upsamples the 40×40×128 feature map to 80×80 to enhance the detail restoration of small targets (spots and scars), and outputs an 80×80×128 feature map; Layer 15: Concat module, which concatenates the 80×80×128 feature map of layer 14 and the 80×80×64 feature map of layer 4 according to the channel dimension, and merges the mid-layer features (C2f output) and upsampled features (DySample output) at the 80×80 scale to output an 80×80×192 feature map; Layer 16: C2f module, consistent with Layer 2, with 192 input channels and 64 output channels. It reduces the dimensionality of the 80×80×192 feature map to 64 channels, enhances the expression of small target features (spots and scars) at the 80×80 scale, and outputs an 80×80×64 feature map; Layer 17: Conv module, 3×3 convolution (stride 2) + batch normalization + SiLU activation. Reduces the dimensionality of the 80×80×64 feature map to 40×40 to prepare features for subsequent fusion, outputting a 40×40×64 feature map; Layer 18: Concat module, which concatenates the 40×40×64 feature map of layer 17 and the 40×40×128 feature map of layer 13 according to the channel dimension, and fuses the dimensionality reduction features (layer 17) of 40×40 scale and the mid-level semantic features (layer 13) to output a 40×40×192 feature map; Layer 19: C2f module, consistent with layer 2, inputs a 40×40×192 feature map, optimizes the feature fusion at a 40×40 scale, enhances the feature representation of the target (interlayer cracking), and outputs a 40×40×128 feature map; Layer 20: SCDown module, using 3×3 convolution (stride 2) + batch normalization + SiLU activation. It reduces the dimensionality of the 40×40×128 feature map to 20×20, abstracts high-level features, and outputs a 20×20×128 feature map. Layer 21: Concat module, which concatenates the 20×20×128 feature map of layer 20 and the 20×20×256 feature map of layer 10 according to the channel dimension, and fuses the high-level semantic features (DPSMOCA output) of 20×20 scale and the dimensionality reduction features (layer 20) to output a 20×20×384 feature map; Layer 22: The C2fCIB module performs 1×1 convolution on the 20×20×384 feature map, then processes it through the Bottleneck submodule with residual connections, and finally fuses it using Concat. This enhances high-level features at the 20×20 scale and improves the feature stability of large targets (warped and deformed). Output: 20×20×256 feature map; Step S2.3: Detection Head Network (Head): Decouples classification, localization, and confidence prediction, outputs the defect category, bounding box, and confidence score, and realizes multi-scale defect detection; Layer 23: The v10Detect module processes feature maps at three scales (80×80×64 feature map from layer 16, 40×40×128 feature map from layer 19, and 20×20×256 feature map from layer 22), specifically including: Classification branch: Output the probability of three types of defects (warping, interlayer cracking, and spotting / scarring) through two 1×1 convolution layers; Localization branch: Predicts bounding box coordinates (x,y,w,h) using 3×3 convolution; Confidence branch: Outputs the probability of the target's existence through a 1×1 convolution.

[0028] Input dimensions: 80×80×64 feature map (small target) + 40×40×128 (medium target) feature map + 20×20×256 (large target) feature map; Output dimensions: each scale outputs corresponding to (width×height×(3 categories + 4 coordinates + 1 confidence score)); finally integrated into defect detection results (category, coordinates, confidence score).

[0029] Step S3: Model Training: Train the DM-YOLO network model using the training set data; The AdamW optimizer was used with an initial learning rate of 1e-4; the training period was set to 300 epochs, and the decay strategy was cosine annealing.

[0030] Step S4: Input the test set data into the trained DM-YOLO detection model, output the category information of the location of defects in the FDM print, and obtain the defect detection results.

[0031] Example 2 This invention is based on the YOLOv10n network architecture, which still includes four core parts: input, backbone, neck, and head. The input is used to receive and preprocess images, and combines normalization and data augmentation to optimize data quality, providing standardized input for subsequent feature extraction.

[0032] The backbone network is based on an enhanced CSPNet architecture, achieving efficient feature extraction through convolutional layers (Conv), C2f modules, SPPF modules, and PSA modules. Specifically, convolutional layers capture local features, the C2f module enhances feature representation capabilities, the SPPF module extracts rich information through multi-scale pooling, and the PSA module further optimizes feature representation, thereby improving the overall efficiency and effectiveness of feature extraction.

[0033] The neck network, building upon the backbone network, achieves multi-scale feature fusion and propagation through a PAN (Path Aggregation Network) layer. Its main modules include upsampling and concatenation. Upsampling increases the feature map resolution to enhance the detection capability for small targets, while concatenation fuses feature maps from different levels, integrating multi-scale information. This design allows the neck network to effectively combine shallow detail features and deep semantic features, providing richer feature inputs for the detection head.

[0034] The detection head employs a dual design: a one-to-many head and a one-to-one head, used for training and inference phases respectively. During training, the one-to-many head generates multiple predictions for each target, providing rich supervision signals to improve model accuracy. Conversely, during inference, the one-to-one head generates an optimal prediction for each target, eliminating reliance on Non-Maximum Suppression (NMS), thus reducing latency and improving efficiency. The detection head consists of convolutional layers, anchor boxes, and a prediction head. The convolutional layers further refine features, the anchor boxes match different targets using predefined sizes and proportions, and the prediction head outputs the confidence score, class probability, and bounding box coordinates for each anchor box through densely connected convolutional layers.

[0035] Example 3 The DM-YOLO network model of this invention addresses the problems of "missed detection of small targets" and "insufficient multi-scale feature fusion" in 3D printing defect detection by introducing three core modules: Dynamic Scale Monte Carlo Attention Mechanism (DSMCAttn), DySample dynamic upsampling, and Lightweight Single-Head Self-Attention Mechanism (SHSA). The specific mechanism is as follows: (1) Dynamic Scale Monte Carlo Attention Mechanism (DSMCAttn): Enhances the ability to capture multi-scale features.

[0036] Traditional YOLOv10n attention mechanisms (such as the PSA module) rely solely on single-scale pooling features, making them poorly adaptable to scenarios in 3D printing where "large-scale defects such as warping and deformation coexist with small-scale defects such as spots and scars."

[0037] The innovations of DSMCAttn are: 1. Dynamic selection of multi-scale pooling: Dynamically select 1-3 pooling scales (1×1 to n×n) according to the complexity of input features (number of pooling tensors n). For example, when n≥7, select 3 scales. Calculate attention maps through multi-scale feature fusion to enhance the representation ability of cross-scale defects; 2. Enhanced sensitivity to small targets: Through the Monte Carlo strategy, randomly select pooling tensors to force the model to focus on small-scale features such as spots and scars, solving the problem of insufficient feature extraction for small targets in traditional models.

[0038] Through ablation experiments, the mAP@0.5 of the model improved from 94.5% to 95.3% after adding DSMCATtn alone, and the accuracy of spot scar detection was particularly improved, from 85.2% to 89.1%.

[0039] (2) DySample dynamic upsampler: improves the ability to restore details of small targets.

[0040] Traditional YOLOv10n's nearest-neighbor interpolation upsampling can easily lead to the loss of details in small target features (such as freckles and scars) during scale magnification. DySample optimizes the upsampling process through the following design: 1. Dynamic point sampling mechanism: Extracts the spatial gradient distribution of input features through two 3×3 convolution layers to determine high texture variation areas such as the edges of freckles and scars. Then, dynamically adjusts the sampling point position through bilinear interpolation to accurately preserve the details of small targets; 2. Lightweight design: No dynamic convolution is required. The offset is generated only through linear layers and combined with a pixel shuffling algorithm, which improves the detail restoration capability of upsampling with almost no increase in computation.

[0041] Ablation experiments showed that adding DySample further improved the model's detection accuracy for speckled scars by 2.3%, and reduced the GFLOPs of the upsampling process from 8.4 to 8.2, balancing detection accuracy and efficiency.

[0042] (3) Lightweight single-head self-attention mechanism (SHSA): Optimizes channel information interaction.

[0043] Traditional YOLOv10n's C2f module uses a Bottleneck structure, which suffers from "redundant channel information exchange" and has limited ability to extract features from subtle defects. SHSA improves upon this by: 1. Performing self-attention operations only on a subset of key channels (the top k channels with the highest weights), reducing computational redundancy in irrelevant channels and focusing on effective channels for defect features; 2. Replacing multi-head attention with a single-head attention mechanism, reducing the number of parameters by 40% while strengthening long-range semantic connections between channels, such as continuous texture features of interlayer cracks.

[0044] Through ablation experiments, the C2f-SA module integrating SHSA reduced the number of model parameters from 2.71M to 2.34M, and further improved mAP@0.5 to 95.7%, significantly enhancing the robustness of interlaminar crack detection.

[0045] Overall model performance: Compared with YOLOv10n, the DM-YOLO network model improves mAP@0.5 from 93.5% to 95.2%, increases the detection accuracy of speckle and scar defects from 85.2% to 91.0%, and reduces the number of parameters by about 15%. It meets the dual requirements of detection speed and accuracy in industrial scenarios and improves efficiency by more than 300% compared with traditional methods.

[0046] Example 4 Dataset Construction 1. Defect Sample Generation: Using the FLSUN Super Racer Delta 3D printer, test pieces are printed under different parameters such as base plate temperature and printing speed. Target defect samples are generated by adjusting the printing parameters.

[0047] 2. Image Acquisition: An industrial camera captures side surface images of the printed part in a 360° circle with a resolution of 1280x720 pixels, acquiring a total of 913 original images.

[0048] 3. Data annotation: Use the LabelImg tool to annotate the defect locations and generate a YOLO format .txt label file, with the annotation categories being "warping deformation", "interlayer cracking", and "spotted scars".

[0049] 4. Preprocessing and Enhancement: Run the preprocessing software and perform the following operations: Batch renaming: Consistently rename filenames to "DefectType_XXXjpg" format; Similar image removal: Calculate hash values ​​and remove samples with a duplication rate > 95%; Data augmentation: Perform 10x augmentation on the training set to generate samples with transformations such as rotation, flipping, and brightness adjustment.

[0050] Model training and optimization 1. Training configuration: Input size: 640x640 pixels, training epochs: 300; Optimizer: AdamW, initial learning rate: 1e-4, cosine annealing decay; 2. Loss function: Based on the YOLOv10n loss function, the focus is on optimizing the regression weights for small objectives.

[0051] 3. Ablation Experiment: Under the same hyperparameter conditions, experiments were conducted by adding DSMCATtn, DySample, and SHSA modules one by one, as shown in Table 1, to verify the contribution of each module to the accuracy. To objectively evaluate the performance of the FDM printing defect detection model, several commonly used performance evaluation metrics were selected, mainly including Average Precision (AP), mean Average Precision (mAP), and Frames Per Second (FPS).

[0052] Table 1 Ablation Experiment Results

[0053] To further verify the advantages of DM-YOLO in online detection during FDM printing, comparative experiments were conducted using recognized high-performance models (including YOLOv5, YOLOv8, YOLOv10, and YOLOv11), as shown in Table 2; the DM-YOLO model parameters are shown in Table 3. In terms of accuracy metrics, DM-YOLO achieved the highest values ​​at mAP@0.5 and mAP@0.5~0.95, at 0.952 and 0.750 respectively. This means that DM-YOLO not only has high overall accuracy in target detection, but also maintains good performance at different IoU thresholds, making it more advantageous for scenarios with high detection accuracy requirements.

[0054] In terms of model complexity, DM-YOLO has 2.34M parameters and 7.9 GFLOPs of computation, which is significantly lower than YOLOv10m (16.49M, 64 GFLOPs) with similar detection accuracy. It even outperforms some lightweight models such as YOLOv8n (3.01M, 8.2 GFLOPs) and YOLOv10n (2.71M, 8.4 GFLOPs), indicating that DM-YOLO significantly reduces model size and computational resource consumption while maintaining high accuracy.

[0055] In terms of inference speed, YOLOv8n leads with a frame rate of 266 FPS, but its accuracy is lower than that of DM-YOLO. In practical applications, speed and accuracy often need to be balanced. For scenarios such as FDM printing defect detection, which have high accuracy requirements but not particularly stringent real-time requirements, DM-YOLO achieves a good balance between accuracy and speed.

[0056] Overall, DM-YOLO achieves a good balance between accuracy, model complexity, and speed, with advantages in high precision and lightweight design, while also enabling defect detection during high-volume printing.

[0057] Table 2 Performance Comparison of DM-YOLO with Other Models

[0058] Table 3 DM-YOLO Model Parameter Table

[0059] Example 5 Figure 6 This is an image of the original surface condition of an FDM printed part, showing the coexistence of two types of defects: interlayer cracking and spot scars. Interlayer cracking is a medium-scale defect. Spot scars are multiple irregular small protrusions (only 1-5 times the height of the printed layer), which are small-scale defects and are easily affected by background textures. Figure 7 Is Figure 6 YOLOv10n detection boxes were overlaid on the original image; interlaminar cracking: one crack defect was detected with a confidence level of 0.46, but the confidence level was low; speckled scars: no speckled scars were correctly identified, and speckled scars were mislabeled as "interlaminar cracks", while normal surface textures were also misclassified as "interlaminar cracks". Small-scale defects were ignored, and the system was susceptible to background interference, resulting in false detections. Figure 8 Is Figure 6 The detection bounding box of DM-YOLO was superimposed on the original image; interlaminar cracking: one cracking defect was accurately detected with a confidence level of 0.64, which is significantly higher than that of YOLOv10n; spot scars: two spot scars were accurately identified with a confidence level of 0.8, with no missed or false detections.

[0060] Example 6 Figure 9 This is an image of the original surface condition of the FDM printed part, which shows the coexistence of two types of defects: interlayer cracking and warping. The interlayer cracking is a linear gap, a medium-scale defect. There are three instances of warping, which are large-scale defects. Figure 10 Is Figure 9 YOLOv10n detection boxes were superimposed on the original image; only one interlaminar crack defect was detected with an accuracy of 0.4; only two warping deformations were identified, the right edge was missed, there were no erroneous annotations but there were obvious missed detections. Figure 11 Is Figure 9 The DM-YOLO detection box was superimposed on the original image, and one interlaminar crack defect was accurately detected, with an accuracy higher than that of YOLOv10n. All three warping deformations were detected without any missed defects.

[0061] Example 7 Figure 12This is an image of the original surface condition of the FDM printed part, which shows the coexistence of three types of defects: warping (3 locations), interlayer cracking, and spots / scars. These three types of defects intersect in space, and the background texture and defect features interfere with each other. Figure 13 Is Figure 12 YOLOv10n detection boxes were superimposed on the original image; two interlayer cracks and warping deformations were detected, but the small warping on the right side was missed; spot scars were not identified, but were misclassified as "interlayer cracks", indicating problems of missed detection and misclassification. Figure 14 Is Figure 12 The DM-YOLO detection box was overlaid on the original image, accurately identifying all three types of defects (2 warps, 1 crack, and 1 spot scar), with no missed or false detections.

[0062] The network of this invention is deeply optimized based on YOLOv10n, integrating Dynamic Scale Monte Carlo Attention Mechanism (DSMCAttn), DySample dynamic upsampler and lightweight single-head self-attention mechanism (SHSA), which significantly improves the detection accuracy and inference efficiency of small target defects.

Claims

1. A 3D printing defect detection method based on an improved YOLOv10n, characterized in that, The specific steps are as follows: Step S1: Construct the dataset by dividing it into a training set and a test set; and process the training set data. Step S2: Based on the YOLOv10n algorithm, construct the DM-YOLO network model; the DM-YOLO network model includes a backbone feature extraction network, a neck feature fusion network, and a detection head network; Step S3: Model Training: Train the DM-YOLO network model using the training set data; Step S4: Input the test set data into the trained DM-YOLO detection model, output the location and category information of defects in the FDM print, and obtain the defect detection results.

2. The 3D printing defect detection method based on the improved YOLOv10n as described in claim 1, characterized in that, In step S1, specifically: Step S1.1: Collect images containing surface defects of FDM 3D printed parts to form a dataset. The dataset includes images covering warping, interlayer cracking, and spot scars, and labels the categories. Divide the dataset into training set and test set. Step S1.2: Perform data augmentation on the training set image data, including image rotation, flipping, scaling, brightness adjustment, and random occlusion processing; increase the sample size of the training set data by 10 times.

3. The 3D printing defect detection method based on the improved YOLOv10n as described in claim 1, characterized in that, In step S2, specifically: Step S2.1: The backbone feature extraction network specifically includes the C2f module, C2f_SA module, SPPF module, SCDown module, and DPSMOCA attention mechanism module; Step S2.2: Neck Feature Fusion Network: Includes DySample dynamic upsampling and an improved feature pyramid, which performs upsampling operations through a point sampling mechanism to enhance the fusion of small target features; Step S2.3: Detection head network: Decouples classification, localization and confidence prediction, outputs the defect category, bounding box and confidence, and realizes multi-scale defect detection.

4. The 3D printing defect detection method based on the improved YOLOv10n as described in claim 3, characterized in that, In step S2.1, specifically: Step S2.1.1: C2f module and C2f_SA module: Based on CSPNet design, the expressive power is improved through residual connections and feature fusion; the C2f_SA module further introduces a single-head self-attention mechanism to optimize information interaction between channels; The input / output dimensions of layers 0 to 10 are as follows: Layer 0: Conv module, using 3×3 convolution, combined with batch normalization and SiLU activation function, to perform preliminary feature extraction on the input 640×640×3 image, and at the same time achieve the first dimensionality reduction, outputting a 320×320×16 feature map; Layer 1: Conv module, which uses 3×3 convolution + batch normalization + SiLU activation to further extract features and reduce dimensionality from the input 320×320×16 feature map, enhance the expressive power of the low-level features, and output a 160×160×32 feature map. Layer 2: The C2f module reduces the dimensionality of the input 160×160×32 feature map through 1×1 convolution, processes it through a Bottleneck sub-module with residual connections, increases the dimensionality through 1×1 convolution, and finally fuses the features through the Concat operation to output a 160×160×32 feature map. Layer 3: Conv module, 3×3 convolution + batch normalization + SiLU activation, reduces the dimensionality of the input 160×160×32 feature map to 80×80, extracts the middle layer semantic features, and outputs an 80×80×64 feature map; Layer 4: C2f module, after performing 1×1 convolution to reduce the dimension of the input 80×80×64 feature map, it is processed by two Bottleneck sub-modules with residual connections, and then 1×1 convolution to increase the dimension and Concat fusion to output an 80×80×64 feature map. Layer 5: SCDown module, 3×3 convolution + batch normalization + SiLU activation, reduces the dimensionality of the input 80×80×64 feature map to 40×40, abstracts high-level semantic features, reduces spatial dimension while increasing channel dimension, and outputs a 40×40×128 feature map. Layer 6: C2f_SA module, after performing 1×1 convolution on the input 40×40×128 feature map, divides the key channel and the direct pass channel through the Split operation, performs SHSA lightweight single-head self-attention operation only on the key channel, and finally fuses through Concat to output a 40×40×128 feature map; Layer 7: SCDown module, 3×3 convolution + batch normalization + SiLU activation; Reduce the dimensionality of the 40×40×128 feature map to 20×20, and output a 20×20×256 feature map; Layer 8: C2f_SA module, consistent with layer 6, optimized for a 20×20 scale, outputting a 20×20×256 feature map; Step S2.1.2: SPPF module: Enhances multi-target adaptability by fusing features at different scales through multi-scale pooling; Layer 9: SPPF module, after performing 1×1 convolution on the input 20×20×256 feature map, extracts multi-scale features through parallel 5×5, 9×9, and 13×13 pooling, and finally fuses the multi-scale pooling features through Concat to output a 20×20×256 feature map. Step S2.1.3: DSMC attention mechanism: Attention fusion is performed by calculating weights through Softmax; Layer 10: The DPSMOCA module performs a 1×1 convolution on the input 20×20×256 feature map, then dynamically selects 1-3 pooling scales through DSMCATn, generates an attention map through Softmax weighted fusion, and finally integrates it through a 1×1 convolution to output a 20×20×256 feature map.

5. The 3D printing defect detection method based on the improved YOLOv10n as described in claim 4, characterized in that, In step S2.2, the neck feature fusion network includes a DySample dynamic upsampler and a sampling point generation unit; specifically: DySample dynamic upsampling: extracts the spatial gradient distribution of the input feature map through two 3×3 convolution layers to determine regions with high texture variation; Feature aggregation unit: For the input feature map and sample set, PyTorch's grid_sample function is used to resample using specified coordinates, and bilinear interpolation is used to generate a new feature map of a new dimension; The input / output dimensions of layers 11 to 22 are as follows: Layer 11: DySample module, which extracts the spatial gradient distribution of the input 20×20×256 feature map through 2 layers of 3×3 convolution, generates dynamic offset, upsamples the 20×20 feature map to 40×40, preserves small target details, and outputs a 40×40×256 feature map. Layer 12: Concat module, which concatenates the 40×40×256 feature map of layer 11 and the 40×40×128 feature map of layer 6 according to the channel dimension, and merges the high-level semantic features and mid-level detail features of the 40×40 scale to output a 40×40×384 feature map. Layer 13: C2f module, consistent with layer 2, takes a 40×40×384 feature map as input, reduces the dimension to 128 channels, optimizes the feature fusion at the 40×40 scale, balances semantics and details, and outputs a 40×40×128 feature map; Layer 14: DySample module, consistent with layer 11, with an upsampling ratio of 2; upsamples the 40×40×128 feature map to 80×80 to enhance the detail restoration of small targets, and outputs an 80×80×128 feature map; Layer 15: Concat module, which concatenates the 80×80×128 feature map of layer 14 and the 80×80×64 feature map of layer 4 according to the channel dimension, and merges the mid-level features and upsampled features at the 80×80 scale to output an 80×80×192 feature map. Layer 16: C2f module, consistent with layer 2, reduces the dimensionality of the 80×80×192 feature map to 64 channels, enhances the feature representation of small targets at the 80×80 scale, and outputs an 80×80×64 feature map; Layer 17: Conv module, 3×3 convolution + batch normalization + SiLU activation; reduces the dimensionality of the 80×80×64 feature map to 40×40, and outputs a 40×40×64 feature map; Layer 18: Concat module, which concatenates the 40×40×64 feature map of layer 17 and the 40×40×128 feature map of layer 13 according to the channel dimension, and fuses the dimensionality reduction features of the 40×40 scale and the mid-level semantic features to output a 40×40×192 feature map. Layer 19: C2f module, consistent with layer 2, takes a 40×40×192 feature map as input, optimizes the feature fusion at a scale of 40×40, enhances the feature representation of the target, and outputs a 40×40×128 feature map; Layer 20: SCDown module, activated by 3×3 convolution + batch normalization + SiLU activation; Reduce the dimensionality of the 40×40×128 feature map to 20×20, and output a 20×20×128 feature map; Layer 21: Concat module, which concatenates the 20×20×128 feature map of layer 20 and the 20×20×256 feature map of layer 10 according to the channel dimension, and outputs a 20×20×384 feature map; Layer 22: The C2fCIB module performs 1×1 convolution on the 20×20×384 feature map, then processes it through the Bottleneck submodule with residual connections, and finally fuses it through Concat to output a 20×20×256 feature map.

6. The 3D printing defect detection method based on the improved YOLOv10n as described in claim 5, characterized in that, In step S2.3, specifically: Layer 23: The v10Detect module processes feature maps at three scales: the 80×80×64 feature map output from Layer 16, the 40×40×128 feature map output from Layer 19, and the 20×20×256 feature map output from Layer 22. Specifically, this includes: Classification branch: Outputs the probability of 3 types of defects through 2 layers of 1×1 convolution; Localization branch: Predicts bounding box coordinates using 3×3 convolution; Confidence branch: Outputs the probability of the target's existence through a 1×1 convolution; Output dimensions: Each scale outputs the following dimensions: width × height × (3 categories + 4 coordinates + 1 confidence score), which are then integrated into the defect detection results, including: category, coordinates, and confidence score.

7. The 3D printing defect detection method based on the improved YOLOv10n as described in claim 6, characterized in that, In step S3, the AdamW optimizer is used with an initial learning rate of 1e-4; the training period is set to 300 epochs, and the decay strategy is cosine annealing.

8. A storage medium containing computer-executable instructions, which, when executed by a computer processor, are used to perform the 3D printing defect detection method based on the improved YOLOv10n as described in any one of claims 1-7.

Citation Information

Cited By

  • Spatial faint target detection method based on semantic large model aided reasoning

    CN121415058A

  • A semantic large model assisted reasoning spatial dim target detection method

    CN121415058B

  • A light-weight green onion laying posture detection method for a green onion harvester

    CN122434945A

  • A lightweight method for detecting the laying posture of scallions in a scallion harvester

    CN122434945B