A multi-target screw bending defect detection method with adaptive slicing

CN122134727BActive Publication Date: 2026-08-07NANCHANG HANGKONG UNIVERSITY
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
NANCHANG HANGKONG UNIVERSITY
Filing Date
2026-05-06
Publication Date
2026-08-07

AI Technical Summary

Technical Problem

[0004]本发明的目的在于提供一种自适应切片的多目标螺丝弯曲缺陷检测方法,以改善现有技术因目标密集、尺寸小、缺陷特征微弱导致的漏检率高、检测精度不足的问题

Benefits of technology

[0032]与现有技术相比,本发明具有如下优点:通过“自适应重叠切片”策略,将高分辨率图像中的目标转换为子图中的主要目标,极大提升了模型对螺丝弯曲缺陷的感知能力,有效缓解了密集和目标漏检的行业难题。重叠率根据螺丝密度动态调整,在保证检测完整性的同时,避免了固定重叠率可能造成的计算资源浪费或覆盖不足,实现了效率与效果的优化平衡。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122134727B_ABST
    Figure CN122134727B_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of industrial automation detection, and more particularly to a self-adaptive slice multi-target screw bending defect detection method, comprising model construction training, pre-processing of the image to be detected, model inference and fusion and output of the detection result. Through the "self-adaptive overlapping slice" strategy, the target in the high-resolution image is converted into the main target in the subgraph, greatly improving the perception ability of the model to the screw bending defect, effectively alleviating the industry problem of dense and target missing detection. The overlapping rate is dynamically adjusted according to the screw density, which avoids the waste of computing resources or insufficient coverage caused by the fixed overlapping rate while ensuring the integrity of the detection, and realizes the optimized balance of efficiency and effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of industrial automation inspection technology, and in particular to an adaptive slicing method for multi-objective screw bending defect detection. Background Technology

[0002] In the large-scale assembly of screws, consistent quality is crucial for ensuring the reliability of downstream products. Among these defects, minute bending of the screw shank, especially the tip, is a common and highly detrimental flaw. If undetected, this defect can lead to jamming, stripping, and even damage to expensive raw materials and assembly equipment, causing production line downtime and material waste. Currently, the detection of bending defects in densely packed screws in discs faces the following technical bottlenecks: 1) Dense target density and small size: Screws are tightly arranged within the disc, resulting in a small individual target proportion in the overall image, making it a typical small target detection problem that general detection models are prone to missing; 2) Difficulty in capturing subtle defects: "Slight bending" is a minute morphological deformation with extremely weak features, easily interfered with by the background and nearby targets in the overall image, making it difficult for the model to learn effective discriminative features; 3) The contradiction between detection efficiency and accuracy: High-resolution cameras are needed to see screw details clearly, but directly processing large images requires high computational resources, is slow, and reduces the model's sensitivity to small features.

[0003] Existing solutions, such as traditional machine vision methods based on thresholding and template matching, suffer from poor robustness and cannot adapt to changes in lighting and subtle pose variations. Furthermore, general-purpose deep learning object detection methods experience significant performance degradation when handling such densely packed small object scenarios. Therefore, there is an urgent need for an innovative solution capable of efficiently and accurately detecting minute bending defects in densely packed disc screws. Summary of the Invention

[0004] The purpose of this invention is to provide an adaptive slice multi-target screw bending defect detection method to improve the problems of high missed detection rate and insufficient detection accuracy caused by dense targets, small size and weak defect features in the existing technology.

[0005] This invention is implemented as follows: an adaptive slicing method for multi-objective screw bending defect detection, comprising the following steps:

[0006] Model building and training: Collect training images of disc screws and preprocess them. Perform adaptive overlapping slicing on the preprocessed training images and manually label them. Build an improved YOLOv8 model with embedded CBAM attention mechanism. Divide the labeled slice sub-images into training set, validation set and test set according to 7:2:1. Input them into the model to complete training, validation and testing. Save the detection model with the best accuracy.

[0007] Preprocessing of the image to be tested: Using the same hardware parameters and processing methods as the training image, the image of the disc screw to be detected is acquired and preprocessed. Then, the preprocessed image to be tested is subjected to adaptive overlapping slicing consistent with the training image to obtain an unlabeled sub-image.

[0008] Model inference: Input the unlabeled sub-images of the image to be tested into the improved YOLOv8 model for inference. The model outputs the local coordinates of the bounding box of the screw in each sub-image and the classification confidence of "normal / bent".

[0009] The detection results are fused and output as follows: The local coordinates of the screw bounding boxes in the sub-image are converted into the global coordinates of the original image to be tested. The non-maximum suppression algorithm is used to remove duplicates of the overlapping detection boxes, and the optimal detection result is retained for each screw. Finally, the result image with the defect location marked is output and a detection report containing the number and location of defects is generated.

[0010] More preferably, the acquisition parameters for the training images are as follows: an industrial-grade CMOS camera with a resolution of no less than 5 million pixels, a ring light source, an acquisition distance of 50cm, and the acquired high-resolution image is 5472×3648 pixels and stored in RGB format; the training image preprocessing includes sequentially performing random horizontal / vertical flipping, random rotation from -5° to +5°, brightness / contrast adjustment, and 5×5 pixel median filtering.

[0011] More preferably, the adaptive overlapping slicing of both the training image and the test image includes four sub-steps: edge detection to obtain a binary edge map, calculation of contour density based on the binary edge map, dynamic adjustment of slice overlap rate and sliding step size, and sliding window slicing; wherein the specific process of edge detection to obtain a binary edge map is as follows:

[0012] ① Calculate the intensity of grayscale change at each point: Let the image be... Width is The height is Two 3×3 Sobel convolution kernels are used to compute the image respectively. Gradient components in the horizontal and vertical directions and Calculate pixel points using Euclidean distance Total gradient magnitude: , For image X at point The intensity of grayscale change, i.e., gradient magnitude;

[0013] ② Filtering true edge points: Traverse each pixel along the gradient direction Examine the gradient magnitude of neighboring pixels, and only... Pixels with local maxima are selected as edge points;

[0014] ③ Distinguish between identifying objects and interference: Find the optimal threshold as the high threshold by maximizing the inter-class variance. The formula for calculating the inter-class variance is: ,in, It is the variance between classes. It is the candidate threshold. and , These are the gradient magnitudes. Less than or equal to And greater than Pixel ratio and average amplitude; low threshold , Determine the binary edge map based on high and low thresholds. ,when ,or And when there is a path leading to the edge point, Other cases .

[0015] More preferably, the specific process for calculating the contour density based on the binary edge map is as follows:

[0016] Divide the binary boundary map into indivual pixel edge submap The number of rows and columns, and the number of pixels, are the sub-patterns obtained after partitioning the binary edge map. The corresponding grid index is Wherein, the side length of the sub-plot ;

[0017] Grid blocks contour density value ;

[0018] Then, bilinear interpolation is used to... Upsampling is compared with the original image Coordinate-aligned continuous density: ;

[0019] in, This represents the bilinear interpolation function.

[0020] More preferably, the specific process of dynamically adjusting the slice overlap rate and sliding step size is as follows: based on continuous density Calculate the overlap rate ,in, =0.1, Calculate the sliding window step size based on the overlap rate. Sub-image size The resolution is fixed at 640×640 pixels; the sliding window starts from the top left corner of the image, and after each image extraction, the window is positioned relative to the current window center coordinates in both the horizontal and vertical axes. corresponding The sliding window moves in steps until it covers the entire original image, and the resulting sub-images are all 640×640 pixels in size.

[0021] More preferably, the improved YOLOv8 model is constructed using YOLOv8n as the baseline model, and the specific process is as follows:

[0022] Using YOLOv8n as the baseline model, a Convolutional Block Attention Module (CBAM) is embedded after each C2f module in the feature fusion path of the neck network. The CBAM includes a channel attention module and a spatial attention module. The channel attention module compresses the input sub-image in the spatial dimension, generates average pooling and max pooling channel description values, sums them after passing through a shared multilayer perceptron, and then generates channel weights through a sigmoid activation function. The spatial attention module takes the channel attention-weighted feature map as input, performs average pooling and max pooling in the channel dimension, concatenates the results into a dual-channel feature map, and generates a spatial weight matrix through convolutional layers and a sigmoid function.

[0023] The original feature pyramid structure FPN+PAN of YOLOv8n is deepened by adding one level of upsampling and convolution operation in both the top-down and bottom-up paths to construct a DenseFPN containing layers P2-P5, where the P2 layer has a resolution of 160×160, resulting in an improved YOLOv8 model consisting of a trunk, neck, and head.

[0024] More preferably, the specific method of model training is as follows: a 640×640 pixel labeled sub-image is input into the improved YOLOv8 model. The backbone network downsamples the input layer by layer to extract feature maps at scales P2-P5. The neck network fuses the feature maps from top to bottom and from bottom to top, and the features are weighted by the CBAM module after each fusion step. The head network predicts screw bounding boxes and class probabilities at four scales and removes overlapping boxes by non-maximum suppression. During training, gradient backpropagation is performed on the training set to update the model weights. The validation set is used to evaluate the model performance, monitor overfitting, and adjust hyperparameters after each epoch. The test set is used to evaluate the final detection performance of the model. Finally, the detection model with the best accuracy is saved.

[0025] More preferably, the specific process of converting the local coordinates of the screw bounding box in the sub-image into the global coordinates of the original image to be tested is as follows: record the coordinates of the top left corner of the sub-image in the original image ( Let the local coordinates of the screw bounding box in the sub-image be... The corresponding global coordinates of the original image are ; , The coordinates of the top-left corner of the bounding box. The coordinates of the bottom right corner of the bounding box are recorded, along with the category and corresponding confidence score for each bounding box.

[0026] More preferably, the specific process of deduplication of overlapping detection boxes by the non-maximum suppression algorithm is as follows:

[0027] a. Sort all bounding boxes in the global coordinates of the original images from highest to lowest confidence score;

[0028] b. Select the detection box with the highest confidence level and add it to the final output list, and remove the box from the list of remaining detection boxes;

[0029] c. Calculate the intersection-union ratio (IoU) between the highest confidence detection box and all remaining detection boxes;

[0030] d. Remove all bounding boxes with an IoU value greater than 0.5. Repeat steps bd until the list of remaining bounding boxes is empty. For each screw, retain the unique bounding box with the highest confidence.

[0031] More preferably, the screws are pointed screws, and in each image of the disc-shaped screws to be inspected, the screws are laid out flat, without stacking or obstruction.

[0032] Compared with existing technologies, this invention has the following advantages: By employing an "adaptive overlapping slicing" strategy, targets in high-resolution images are transformed into primary targets in sub-images, greatly enhancing the model's ability to perceive screw bending defects and effectively alleviating the industry challenge of missing dense and undetected targets. The overlap rate is dynamically adjusted according to screw density, ensuring detection integrity while avoiding the waste of computational resources or insufficient coverage that may result from a fixed overlap rate, thus achieving an optimal balance between efficiency and effectiveness.

[0033] Furthermore, this invention specifically optimizes the deep learning model by introducing an attention mechanism and a feature pyramid, enabling the model to more accurately focus on the subtle bending features of the screw, significantly improving recognition accuracy. The method of this invention has a clear workflow and can be efficiently integrated into existing production lines to achieve AI-powered automatic detection, eliminate defective products, and help enterprises improve product quality and reduce rework and raw material waste costs. Attached Figure Description

[0034] Figure 1 This is a flowchart of the bending defect detection method of the present invention.

[0035] Figure 2 This is a flowchart illustrating the structure of the present invention.

[0036] Figure 3 This is an example of the screw bending detection results of the present invention. It can be seen that the bent screw was successfully identified by the red box, while the green box was identified by the model as an incorrect screw, and the recognition effect is good.

[0037] Figure 4 The training-validation loss curve of this invention shows that the training loss (orange) and validation loss (blue) decrease with the number of training rounds, and the gap between the training and validation loss curves is not large. The proposed model demonstrates good generalization performance and is innovative, practical, and applicable. Detailed Implementation

[0038] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention. Unless otherwise defined, the technical or scientific terms used herein should have the ordinary meaning understood by those skilled in the art. The terms "comprising" and similar expressions used herein mean that the element or object preceding the word covers the element or object listed after the word and its equivalents, but does not exclude other elements or objects.

[0039] Example 1: This example provides an adaptive slicing method for detecting multi-objective screw bending defects, such as... Figures 1-4 As shown, it includes the following steps:

[0040] S1: High-resolution images (5472×3648 pixels) of the top of the disc-shaped screws are acquired using a camera as training images. Specifically, an industrial-grade CMOS camera with a resolution of no less than 5 megapixels is used, equipped with a ring light source to alleviate shadows and reflections and ensure uniform illumination of the image. The image acquisition distance is 50cm to cover the entire screw disc. After acquisition, the images are stored in RGB format. To improve the robustness of the model, random horizontal / vertical flipping, random rotation from -5° to +5°, brightness / contrast adjustment, and median filtering are performed sequentially for image preprocessing. The filter size is 5×5 pixels to remove noise while preserving edge details. In each image of the disc-shaped screws to be detected, the screws are laid flat without stacking or occlusion.

[0041] Next, the adaptive overlapping slicing stage is entered, where an adaptive sliding window is used to divide the image into grids. The specific steps are as follows:

[0042] S101. First, find the edges in the processed image. This can be divided into three steps: calculate the intensity of grayscale change at each point; filter out the true edge points; and distinguish between objects and interference.

[0043] ① Calculate the intensity of grayscale change at each point: Let the image be... Its width is The height is Two 3×3 Sobel convolution kernels are used to compute the image. Two gradient components in the horizontal and vertical directions and After obtaining the two gradient components, the pixel point The total gradient magnitude is calculated using Euclidean distance:

[0044] ;

[0045] For image X at point The intensity of grayscale change, i.e., gradient magnitude; the larger the value, the more pronounced the grayscale change. The higher the probability of it being an edge point, For pixels The gradient in the horizontal direction, For pixels The gradient in the vertical direction.

[0046] ② Filtering true edge points: Traverse each pixel along the gradient direction Check the gradient magnitude of neighboring pixels, when If the value is a local maximum, the point is selected as an edge point; otherwise, it will be suppressed.

[0047] ③ Distinguish between identifying objects and interference: Find the optimal threshold by maximizing the inter-class variance.

[0048] ;

[0049] in, It is the inter-class variance, which is a metric that measures "how different the two classes of pixels are after thresholding". It is the candidate threshold. and , These are the gradient magnitudes. Less than or equal to And greater than The pixel ratio and average amplitude are determined; by maximizing the inter-class variance formula, the optimal threshold that can distinguish between "identifiable objects" and "interference" in grayscale intensity is found, and this threshold is used as the high threshold. The low threshold is derived from the high threshold by an empirical proportion, i.e. ,in Finally, the binary edge map is determined by high and low thresholds:

[0050] ;

[0051] in, This is a binary edge map with gradient magnitude. The candidate points are established as edge points and assigned a value of 1. Candidate points are selected based on their potential. If there is no path leading to an edge point, it is considered an edge point and assigned a value of 1. All other candidate points are assigned a value of 0 and are not considered edge points.

[0052] S102. After finding the edges of the image, the image is segmented, specifically including:

[0053] The resulting binary edge map is divided into An edge subgraph, The number of rows and columns of the sub-plots obtained after partitioning the binary edge map, and the size of each sub-plot. for For any pixel in the edge map Their corresponding grid indices are respectively ,in Each grid block The contour density value is:

[0054] ;

[0055] Among them, contour density For the first The proportion of edge pixels within the grid, and the outline density. The larger the value, the more edges there are in the grid, and the higher the probability that it is a screw area.

[0056] The resulting profile density is then obtained through bilinear interpolation. Upsampling is compared with the original image Coordinate-aligned continuous density:

[0057] ;

[0058] Among them, bilinear interpolation function The implementation is a standard technique in this field, and its input parameter is the coordinates of the point to be found in the original image. With known probability density .

[0059] S103. Next, the overlap rate of the slices is intelligently controlled, and the overlap rate is based on the continuous density. Dynamic calculations ensure that higher density areas have a greater overlap rate, guaranteeing that critical areas like screws are completely cut out.

[0060] ;

[0061] in, The overlap rate, Defined as 0.1, .

[0062] Next, calculate the step size for slice movement. The sliding window step size is based on the overlap rate. calculate:

[0063] ;

[0064] in, The sub-image size is fixed at 640×640.

[0065] S104. Finally, perform image slicing and annotation: In the actual slicing process, the sliding window starts from the top left corner of the image, and after each image extraction, the window moves in the horizontal direction. 1 pixel, of which The coordinates are the center coordinates of the current window. Similarly, the same step size calculation method is used when moving in the vertical direction. The movement process is repeated until the entire image is covered. Areas with edges less than 640×640 pixels are filled with a fill pixel value of 0 to ensure that the size of the sliced ​​sub-image always remains 640×640. Then, an experienced quality inspector labels the bounding box and category ("normal" or "bent") of the screws in each sub-image to obtain the labeled sliced ​​sub-image.

[0066] Then, the sub-images are fed into a YOLOv8 model incorporating the CBAM attention mechanism for transfer learning and inference. The model outputs the bounding box of the screw and the classification confidence score for "normal / bent" in each sub-image. This model embeds the CBAM attention mechanism module into its neck network and constructs a denser feature pyramid, thus better capturing the directional features of the screw tip and the straightness features of the shank. The model improvements and training specifically include the following aspects:

[0067] The YOLOv8 model is an improvement upon the YOLOv8n baseline model, primarily optimizing its neck and head networks to enhance its ability to capture minute bending features of screws. In the feature fusion path of the neck network, a convolutional block attention module (CBAM) is embedded after each C2f module.

[0068] CBAM is a sequential attention mechanism comprising a channel attention module and a spatial attention module. The channel attention module compresses the input sub-image in the spatial dimension, generating channel descriptor group values ​​based on average pooling and max pooling respectively. These values ​​are then summed after passing through a shared multilayer perceptron (MLP) and finally processed by a sigmoid activation function to generate channel weights. This process enables the model to autonomously learn and enhance important feature channels related to screw bending defects. The spatial attention module takes the channel attention-weighted feature map as input, first performing average pooling and max pooling simultaneously in the channel dimension, concatenating the results into a dual-channel feature map, and then passing it through a standard convolutional layer and a sigmoid function to generate a spatial weight matrix. This module can focus on key regions such as the screw tip and shank in the image. Through the concatenated channel and spatial attention, the model can more effectively suppress background interference and concentrate computational resources on discriminative regions.

[0069] To alleviate the problem that some screw targets in the sub-images have relatively small curvature, the original feature pyramid structure (FPN+PAN) was deepened. One level of upsampling and convolution operation was added to both the top-down and bottom-up paths to construct a denser feature pyramid. This enhanced the fusion of shallow high-resolution features and deep semantic features, enabling the model to utilize richer multi-scale information, especially improving the ability to represent subtle deformation features such as screw tip direction deviation and shank straightness.

[0070] The optimized model consists of three parts: the backbone, the neck, and the head. DenseFPN (P2-P5) adds a P2 (160x160 resolution) layer compared to the standard YOLOv8n model to preserve the extremely small geometric features of screw edges that are only a few pixels wide. The model structure is as follows... Figure 2 As shown.

[0071] The model consists of three parts: a backbone network, a neck network, and a detection head. The input sub-image size is 640×640. The backbone network sequentially passes through Conv convolutional layers, Conv downsampling layers, C2f modules, and SPPF spatial pyramid pooling layers, downsampling layer by layer to extract feature maps at different scales (P2-P5). P2 is a high-resolution feature map used to capture subtle bending defects in the screw, while P5 is a low-resolution feature map used to capture the overall outline and positional features of the screw. The SPPF spatial pyramid pooling layer performs multi-scale pooling on the P5 feature map to fuse features from different receptive fields, improving the model's ability to detect defects. Robustness of screws of the same size; the neck network adopts the CBAM attention mechanism and DenseFPN structure, and performs bidirectional fusion of the P2-P5 feature maps output by the backbone network from top to bottom and bottom to top. In the top-down path, the P5 feature map is first upsampled and concatenated with the P4 feature map. After processing by the C2f_N1 module and the CBAM attention module, it is upsampled again and concatenated with the P3 feature map. After processing by the C2f_N2 module and the CBAM attention module, a new P2 path is added. After upsampling, it is concatenated with the high-resolution P2 feature map. After processing by the C2f_N3 module and the CBAM attention module. The process yields P2-scale fused features. In the bottom-up path, the P3 fused features are downsampled and concatenated with the P4 feature map. These are then processed by the C2f_N4 module and the CBAM attention module to obtain P4-scale fused features. Next, the P4 fused features are downsampled and concatenated with the P5 feature map. These are then processed by the C2f_N5 module and the CBAM attention module to obtain P5-scale fused features. Finally, the P5 fused features are downsampled and processed by the C2f_N6 module and the CBAM attention module to supplement deeper features. After each feature fusion step, the features are weighted by the CBAM attention module to enhance the screw bending defect. The detection head effectively extracts and suppresses background noise to improve the model's ability to detect subtle defects. The detection head makes predictions at four scales: P2, P3, P4, and P5. The P2 detection head is responsible for detecting small screws, and the P5 detection head is responsible for detecting large screws. Each detection head outputs a tensor with three dimensions: bounding box, confidence, and category. The bounding box vector contains the coordinates of the center point relative to the subgraph, width, and height. The confidence is the probability that the model judges that the box contains a screw. In the category, 0 represents a normal screw and 1 represents a bent screw. Finally, non-maximum suppression (NMS) is used to remove overlapping boxes and output the final detection result.

[0072] It should be clarified that the labeled slice images are divided into training, test, and validation sets in a 7:2:1 ratio. The training set is used for backpropagation of gradients to update the model's weight parameters. A dual strategy of maximum iteration count and early stopping is employed for training termination: training automatically terminates after 300 epochs or if the validation set accuracy shows no improvement for 10 consecutive epochs. A momentum of 0.937 is used to accelerate gradient descent convergence and improve training stability; a weight decay of 0.0005 is used to apply regularization constraints to the model weights to suppress overfitting. This invention uses the SGD optimizer for model training, with an initial learning rate of 0.01. The learning rate is dynamically adjusted using a cosine annealing decay strategy, gradually decreasing with each training epoch to ensure stable model convergence and improve detection accuracy. The validation set is used at the end of each epoch to evaluate the model, adjust hyperparameters, monitor for overfitting, and save the best model; it does not participate in weight updates during validation. The confidence threshold is set to 0.25; the IOU threshold is set to 0.45. The test set is used after training is complete to evaluate the model's final performance on completely unseen real data.

[0073] S2: Using the same hardware parameters and processing methods as the training images, acquire images of disc screws to be detected and complete preprocessing. Then, perform adaptive overlapping slicing on the preprocessed images to be tested, consistent with the training images, to obtain unlabeled sub-images.

[0074] S3: Input the unlabeled sub-images of the image to be tested into the improved YOLOv8 model for inference. The model outputs the local coordinates of the bounding box of the screw in each sub-image and the classification confidence of "normal / bent".

[0075] S4: Based on the model output of S3, transform the coordinates of the detection boxes in all sub-images back to the original large image coordinate system. Due to overlapping slices, the same screw may be detected by multiple sub-images, generating multiple detection boxes. In this case, a non-maximum suppression algorithm is used to deduplicate the detection boxes based on their coordinate overlap and classification confidence, retaining an optimal detection result for each screw. The specific steps are as follows:

[0076] S401: Since the size of each sub-image is a fixed value of 640×640, it is only necessary to record the first... The coordinates of the top left corner of Zhang Zitu in the original image (5472×3648) are ( ),in Represented as the label index of each subgraph, Let be the total number of subimages. For each bounding box detected in a subimage, its coordinates are local coordinates relative to the subimage, specifically relative to the top-left corner (0,0) of the subimage. Let the local coordinates be... These correspond to the top-left and bottom-right corner coordinates of the bounding box detected in the sub-image, respectively. The corresponding global coordinates for the original large image are:

[0077] ;

[0078] ;

[0079] in These are the coordinates of the top-left and bottom-right corners of the bounding boxes identified in the original image. Simultaneously, the category (normal or curved) of each bounding box and its corresponding confidence level are recorded.

[0080] S402: Due to slice overlap, the same screw may be detected by multiple sub-images, resulting in multiple overlapping bounding boxes in the global coordinate system. The goal of the NMS algorithm is to select the optimal box (i.e., the box with the highest confidence) from these overlapping boxes and suppress other overlapping boxes. After NMS processing, each screw ultimately retains only one detection box with the highest confidence. The steps are as follows:

[0081] a. Sort all detected global coordinates of the original large image from high to low according to their confidence scores.

[0082] b. Select the bounding box with the highest confidence level, add it to the final output list, and then remove it from the list of remaining bounding boxes.

[0083] c. Calculate the IoU (Intersection over Union) between this highest confidence bounding box and all other bounding boxes.

[0084] d. Remove all bounding boxes with an IoU value greater than the threshold of 0.5, meaning these boxes highly overlap with the currently selected box and are considered to be detecting the same object. Repeat steps b to d until the remaining bounding box list is empty.

[0085] Finally, the system outputs a result image marked with the defect locations and generates an inspection report containing information such as the number and location of defects.

[0086] Example 2: Based on Example 1, this example uses the above detection method. The test set consists of 400 images, each containing multiple pointed screws of different lengths, thicknesses, and whether they are normal or bent. It should be noted that this patent is specifically designed for special factory scenarios. The number of screws to be identified is a maximum of 6 pointed screws per attempt, depending on product requirements. If more than 6 screws are identified, they will cause some obstruction and affect the identification effect, requiring manual removal. Therefore, the number of screws to be identified is set to 6.

[0087] like Figure 3As shown, during the test, 4-6 randomly selected screws were placed in a tray simultaneously in each captured image for inspection. The hardware platform used for the test was: a 12th generation Intel Core i7 processor + ASUS NVIDIA RTX 4060 dedicated graphics card, with Ubuntu 20.04 operating system and Python 3.10.

[0088] Table 1 Generalization Ablation Experiment

[0089] Base Algorithm (yolov8n, CBAM) 0.923 0.883 0.937 Base algorithm (yolov8n, CBAM) + adaptive slicing (the algorithm proposed in this application) 0.948 0.887 0.948

[0090] Table 1 shows the accuracy and generalization metrics, all of which are satisfactory. Compared to the base algorithm (yolov8n, CBAM), the algorithm proposed in this application, by introducing an adaptive slicing method, improves the ACC (accuracy) from 0.923 to 0.948, effectively reducing the false positive rate for screw defect samples and improving the overall reliability of identification; the recall rate increases from 0.883 to 0.887, further reducing the missed detection of real defect samples and ensuring the completeness of defect detection; the mAP50 increases from 0.937 to 0.948, enhancing the overall detection accuracy and robustness of the model under different confidence thresholds, resulting in a significant improvement in overall performance. The experimental results demonstrate that the algorithm proposed in this application exhibits outstanding recognition performance advantages in screw defect detection tasks.

[0091] Table 2. Multi-model comparison experiment

[0092] yolov8n 0.914 0.872 0.913 Yolov10 0.907 0.867 0.909 Yolov11 0.912 0.863 0.921 Base algorithm (yolov8n, CBAM) + adaptive slicing (the algorithm proposed in this application) 0.948 0.887 0.948

[0093] Table 2 shows the accuracy and generalization evaluation results of various advanced algorithm models. In comparison with several validated and commonly used advanced algorithm models, the method proposed in this application demonstrates outstanding performance in key indicators such as accuracy and generalization. Specifically, the accuracy of the algorithm in this application reaches 94.8%. This shows that the algorithm proposed in this application exhibits excellent recognition performance in screw defect detection tasks, significantly outperforming the comparative models and demonstrating its current application innovation advantages.

[0094] The prediction results obtained from the embodiments of the present invention have an extremely important decision support role for non-destructive testing of parts. By using adaptive "image slicing" technology, the difficult-to-perceive bending target is magnified into the main target in the sub-image. Combined with a deep learning model with an attention mechanism, it can effectively capture the small bending deformation of the screw shaft and tip, significantly reducing missed detections and false detections.

[0095] While embodiments of the present invention have been described in detail above, it will be apparent to those skilled in the art that various modifications and variations can be made to these embodiments. However, it should be understood that such modifications and variations fall within the scope and spirit of the invention as defined in the claims. Furthermore, the invention described herein may have other embodiments and can be implemented or carried out in various ways.

Claims

1. A method for detecting multi-objective screw bending defects using adaptive slicing, characterized in that, Includes the following steps: Model Construction and Training: Training images of disc screws were acquired and preprocessed. Adaptive overlapping slicing and manual annotation were performed on the preprocessed training images to construct an improved YOLOv8 model. The improved YOLOv8 model used YOLOv8n as the baseline model. A convolutional block attention module (CBAM) was embedded after each C2f module in the feature fusion path of the neck network. The original FPN+PAN feature pyramid structure of YOLOv8n was deepened to construct a DenseFPN structure containing P2-P5 layers. The annotated sliced ​​sub-images were divided into training, validation, and test sets according to a 7:2:1 ratio. The images were input into the model to complete training, validation, and testing. The detection model with the best accuracy was saved. Preprocessing of the image to be tested: Using the same hardware parameters and processing methods as the training image, the image of the disc screw to be detected is acquired and preprocessed. Then, the preprocessed image to be tested is subjected to adaptive overlapping slicing consistent with the training image to obtain an unlabeled sub-image. The adaptive overlapping slicing of the training image and the image to be tested both include four sub-steps: edge detection to obtain a binary edge map, calculation of contour density based on the binary edge map, dynamic adjustment of slice overlap rate and sliding step size, and sliding window slicing. The specific process of dynamically adjusting the slice overlap rate and sliding step size is based on continuous density. Calculate the overlap rate ,in, =0.1, Calculate the sliding window step size based on the overlap rate. Sub-image size The resolution is fixed at 640×640 pixels; the sliding window starts from the top left corner of the image, and after each image extraction, the window is positioned relative to the current window center coordinates in both the horizontal and vertical axes. corresponding The sliding window moves in steps until it covers the entire original image, and the resulting sub-images after slicing are all 640×640 pixels in size. Model inference: Input the unlabeled sub-images of the image to be tested into the improved YOLOv8 model for inference. The model outputs the local coordinates of the bounding box of the screw in each sub-image and the classification confidence of "normal / bent". The detection results are fused and output as follows: The local coordinates of the screw bounding boxes in the sub-image are converted into the global coordinates of the original image to be tested. The non-maximum suppression algorithm is used to remove duplicates of the overlapping detection boxes, and the optimal detection result is retained for each screw. Finally, the result image with the defect location marked is output and a detection report containing the number and location of defects is generated.

2. The adaptive slicing multi-objective screw bending defect detection method according to claim 1, characterized in that, The acquisition parameters for the training images are as follows: an industrial-grade CMOS camera with a resolution of no less than 5 million pixels, a ring light source, an acquisition distance of 50cm, and high-resolution images of 5472×3648 pixels stored in RGB format; the preprocessing of the training images includes random horizontal / vertical flipping, random rotation from -5° to +5°, brightness / contrast adjustment, and 5×5 pixel median filtering.

3. The adaptive slicing multi-objective screw bending defect detection method according to claim 2, characterized in that, The specific process of obtaining a binary edge map through edge detection is as follows: ① Calculate the intensity of grayscale change at each point: Let the image be... Width is The height is Two 3×3 Sobel convolution kernels are used to compute the image respectively. Gradient components in the horizontal and vertical directions and Calculate pixel points using Euclidean distance Total gradient magnitude: , For image X at point The intensity of grayscale change, i.e., gradient magnitude; ② Filtering true edge points: Traverse each pixel along the gradient direction Examine the gradient magnitude of neighboring pixels, and only... Pixels with local maxima are selected as edge points; ③ Distinguish between identifying objects and interference: Find the optimal threshold as the high threshold by maximizing the inter-class variance. The formula for calculating the inter-class variance is: ,in, It is the variance between classes. It is the candidate threshold. and , These are the gradient magnitudes. Less than or equal to And greater than Pixel ratio and average amplitude; low threshold , Determine the binary edge map based on high and low thresholds. ,when ,or And when there is a path leading to the edge point, Other cases .

4. The adaptive slicing multi-objective screw bending defect detection method according to claim 3, characterized in that, The specific process for calculating contour density based on binary edge maps is as follows: Divide the binary boundary map into indivual pixel edge submap The number of rows and columns, and the number of pixels, are the sub-patterns obtained after partitioning the binary edge map. The corresponding grid index is Wherein, the side length of the sub-plot ; Grid blocks contour density value ; Then, bilinear interpolation is used to... Upsampling is compared with the original image Coordinate-aligned continuous density: ; in, This represents the bilinear interpolation function.

5. The adaptive slicing method for multi-objective screw bending defect detection according to claim 4, characterized in that, The Convolutional Block Attention (CBAM) module includes a channel attention module and a spatial attention module. The channel attention module compresses the input sub-image in the spatial dimension, generates average pooling and max pooling channel description values, sums them after passing through a shared multilayer perceptron, and then generates channel weights through a sigmoid activation function. The spatial attention module takes the channel attention-weighted feature map as input, performs average pooling and max pooling in the channel dimension, concatenates the results into a dual-channel feature map, and generates a spatial weight matrix through a convolutional layer and a sigmoid function. The DenseFPN structure adds one level of upsampling and convolution operation in both the top-down and bottom-up paths, with the P2 layer having a resolution of 160×160.

6. The adaptive slicing method for multi-objective screw bending defect detection according to claim 5, characterized in that, The specific training method for the model is as follows: a 640×640 pixel labeled sub-image is input into the improved YOLOv8 model. The backbone network downsamples the input layer by layer to extract feature maps at scales P2-P5. The neck network fuses the feature maps from top to bottom and from bottom to top. After each fusion step, the features are weighted by the CBAM module. The head network predicts screw bounding boxes and class probabilities at four scales and removes overlapping boxes by non-maximum suppression. During training, gradient backpropagation is performed on the training set to update the model weights. The validation set is used to evaluate the model performance, monitor overfitting, and adjust hyperparameters after each epoch. The test set is used to evaluate the final detection performance of the model. Finally, the detection model with the best accuracy is saved.

7. The adaptive slicing multi-objective screw bending defect detection method according to claim 6, characterized in that, The specific process of converting the local coordinates of the screw bounding box in the sub-image to the global coordinates of the original image to be tested is as follows: record the coordinates of the top left corner of the sub-image in the original image ( Let the local coordinates of the screw bounding box in the sub-image be... The corresponding global coordinates of the original image are ; , The coordinates of the top-left corner of the bounding box. The coordinates of the bottom right corner of the bounding box are recorded, along with the category and corresponding confidence score for each bounding box.

8. The adaptive slicing method for multi-objective screw bending defect detection according to claim 7, characterized in that, The specific process of deduplication of overlapping detection boxes using the nonmaximum suppression algorithm is as follows: a. Sort all bounding boxes in the global coordinates of the original images from highest to lowest confidence score; b. Select the detection box with the highest confidence level and add it to the final output list, and remove the box from the list of remaining detection boxes; c. Calculate the intersection-union ratio (IoU) between the highest confidence detection box and all remaining detection boxes; d. Remove all bounding boxes with an IoU value greater than 0.

5. Repeat steps bd until the list of remaining bounding boxes is empty. For each screw, retain the unique bounding box with the highest confidence.

9. The adaptive slicing method for multi-objective screw bending defect detection according to claim 8, characterized in that, The screws are pointed screws, and in each image of the disc-shaped screws to be inspected, the screws are laid out flat, without stacking or obstruction.

Citation Information

Patent Citations

  • Steel workpiece surface defect detection method based on multiple attention mechanisms

    CN121482033A

  • Vision-based stamping part defect detection method

    CN121860923A