A workpiece surface micro-defect detection method based on an improved SSD algorithm
By improving the SSD algorithm and combining it with multi-scale convolutional feature fusion and non-maximum suppression algorithm, the efficiency and accuracy problems of detecting minute defects on the workpiece surface are solved, and efficient and accurate automated detection is achieved.
Patent Information
- Application Number
- CN202211053520.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-08-31
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-08-31
AI Technical Summary
Existing technologies are inefficient and have large errors in the detection of surface defects on workpieces, making it difficult to quickly and accurately detect minute defects. Traditional machine vision methods cannot meet the needs of automated inspection.
An improved SSD algorithm with multi-scale convolutional feature fusion is adopted. By modifying the VGG16 backbone feature extraction network, an effective feature layer is added to construct an improved SSD network with multi-scale feature fusion. A weighted sum loss function of confidence loss and location loss is used, and a prior box set is generated by non-maximum suppression algorithm to improve detection accuracy.
It improves the accuracy and efficiency of detecting minute defects on workpiece surfaces, enhances the model's ability to detect small targets, and improves detection performance and generalization ability.
Smart Images

Figure CN115937077B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to a method for detecting defects in workpieces, and more particularly to a method for detecting minute defects on the surface of workpieces based on an improved SSD algorithm. Background Technology
[0002] During the manufacturing process of workpieces, various defects such as scratches, pits, and cracks may appear on the workpiece surface due to the influence of production and processing technology. These defects have a great impact on the quality and performance of the product. Therefore, surface defect detection of workpieces is one of the important links in the workpiece production process. However, most of the surface defects of workpieces are small, and the efficiency of manual or physical detection is low and the error is large. Therefore, there is a need for a detection method that can quickly and accurately detect small defects on the surface of workpieces to meet the current needs of automated defect detection.
[0003] Traditional manual visual inspection methods rely on human experience and are easily influenced by subjective factors, leading to inaccurate test results and failing to meet current automated inspection requirements. Machine vision inspection methods, on the other hand, offer advantages such as high automation, fast recognition speed, and non-contact inspection, gradually becoming the mainstream method for workpiece surface defect detection. Compared to traditional machine vision, deep learning has superior capabilities in target recognition and image processing. In target detection, deep learning methods extract deep features that better represent target characteristics than traditional machine learning methods that extract manually. Deep learning methods, by constructing neural network models, can automatically extract features from low-level input data, thereby identifying and classifying workpiece surface defects. Commonly used models include YOLO (You Only Look Once), Faster R-CNN (Faster Regions with Convolutional Neural Networks), and the SSD model. SSD's design philosophy borrows from Faster R-CNN's region-based concept, extracting feature maps of different scales for detection, and the regression idea of the YOLO detection algorithm. It directly regresses the object's category and location within the network model, significantly improving the recognition speed and performance of the SSD detection algorithm. This invention is based on the traditional SSD target detection algorithm, improves the original backbone AGG16 network, and adopts the idea of multi-scale convolutional feature fusion, so that the model can learn more target information with small and medium proportions. This method can meet the current needs for workpiece surface defect detection. Summary of the Invention
[0004] This invention discloses an improved SSD algorithm proposed using the idea of multi-scale convolutional feature fusion to detect minute defects on the surface of a workpiece.
[0005] To solve the above-mentioned technical problems, the present invention adopts the following technical solution:
[0006] A method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm, characterized by the following steps:
[0007] Step S1. Acquire images of the surface of the defective workpiece;
[0008] Step S2. Preprocess the acquired images to create a dataset;
[0009] Step S3. Modify the VGG16 backbone feature extraction network to add an effective feature layer;
[0010] Step S4. Construct an improved SSD network with multi-scale feature fusion. The loss function adopts confidence loss Lconf and location loss Lloc. The total loss is the weighted sum of the two loss functions.
[0011] Step S5. Construct multiple different prior boxes on the fused feature layer, and suppress some overlapping or incorrect prior boxes using the non-maximum suppression algorithm to generate the final prior box set.
[0012] Step S6. Train the SSD network model using the dataset to obtain the weight file;
[0013] Step S7. After preprocessing, the image to be detected is input into the trained SSD network model to obtain the surface defect results of the circular workpiece, including the defect location and category.
[0014] Furthermore, in step S1, an industrial CCD camera is used to acquire images of the surface of the defective workpiece.
[0015] Further, in step S2, the acquired images are preprocessed to create a dataset, specifically as follows:
[0016] Data augmentation operations are performed on the dataset, including four methods: rotation, horizontal migration, vertical migration, and scaling.
[0017] Mark the location of defects on the workpiece surface. The marking information includes the location and type of the defect. The types of defects on the workpiece surface include pits, scratches, and cracks.
[0018] Finally, the dataset is divided into training and test sets according to a certain ratio.
[0019] Furthermore, in step S3, the VGG backbone feature extraction network is modified as follows:
[0020] (1) Replace the FC6 and FC7 fully connected layers of VGG16 with a convolutional network with a first-order convolutional kernel of [3,3] and a convolutional network with a first-order convolutional kernel of [1,1], and name them Conv6 and Conv7 layers to further extract network features;
[0021] (2) Remove the original Dropout layer and FC8 layer of VGG16 and add Conv8, Conv9, Conv10 and Conv11 layers to extract deeper network features.
[0022] Furthermore, compared to the original SSD object detection algorithm, Conv3_3 is added as an effective feature layer. The specific effective feature layers selected are Conv3_3, Conv4_3, Conv7, Conv8_2, Conv9_2, Conv10_2 and Conv11_2, a total of seven layers, which yield seven feature maps with sizes of 75*75, 38*38, 19*19, 10*10, 5*5, 3*3 and 1*1. Multi-scale feature fusion is then performed among the seven effective feature layers.
[0023] Furthermore, an improved SSD network with multi-scale feature fusion is constructed, specifically as follows:
[0024] Multi-scale feature fusion includes dilated convolution downsampling and deconvolution upsampling operations. The formula for calculating the receptive field of the convolution kernel is:
[0025]
[0026] In the formula, di (dilation) represents different dilation values during dilated convolution, and F di Different receptive fields are represented; the feature map can be restored to the original image size through deconvolution operation, and the calculation formula is:
[0027] I = p(o + 2q - w) + 1
[0028] In the formula, I represents the input image size, o represents the output image size, q represents edge augmentation, w represents the convolution kernel size, and p represents the stride.
[0029] Furthermore, the newly fused Conv3_3_y layer consists of two parts. The first part is 256 75*75 feature maps obtained by Conv3_3 convolution operation, using a convolution kernel with dilation of 1, stride of 1, and size of 3*3. The second part is 256 75×75 feature maps obtained by deconvolution upsampling operation of Conv4_3, using a convolution kernel with dilation of 1, stride of 2, and size of 3*3.
[0030] The newly fused feature layer Conv4_3_y consists of three parts. The first part generates 256 38×38 feature maps by Conv3_3 through dilated convolution downsampling, using a convolution kernel with a dilation value of 2, a stride of 2, and a size of 3×3. The second part is 512 38×38 feature maps obtained by the convolution operation of Conv4_3, using a convolution kernel with a dilation value of 1, a stride of 1, and a size of 3×3. The third part is 256 38×38 feature maps obtained by Conv7 through deconvolution upsampling, using a convolution kernel with a dilation value of 0, a stride of 2, and a size of 2*2.
[0031] The newly fused Conv7_y and Conv8_2_y layers are similar to the Conv4_3_y layer. The first part consists of 256 19*19 and 256 10*10 feature maps generated by dilated convolution downsampling operations of Cconv4_3 and Conv7, respectively, using convolutional kernels with a dilation value of 2, a stride of 2, and a size of 3×3. The second part consists of 512 19*19 and 512 10*10 feature maps generated by convolutions of Conv7 and Conv8_2, respectively, using convolutional kernels with a dilation value of 1, a stride of 1, and a size of 3×3. The third part consists of 256 19*19 and 256 10*10 feature maps generated by deconvolution upsampling operations of Conv8_2 and Conv9_2, respectively, using convolutional kernels with a dilation value of 0, a stride of 2, and a size of 2×2. No feature fusion is performed on other feature layers.
[0032] Furthermore, feature fusion is achieved through concatenation, which merges the feature maps to be fused by channel merging, so that the fused feature map can have abstract semantic information and specific information about small targets.
[0033] Furthermore, the loss function adopts confidence loss L. conf and position loss L loc The total loss is a weighted sum of the two loss functions, specifically:
[0034] Total loss
[0035]
[0036] N represents the number of prior boxes that match the ground truth boxes; c represents the confidence score of the prior box category; l represents the location parameter of the predicted box; g represents the location parameter of the ground truth box; α is the weight value used to adjust the ratio of confidence loss to regression loss, the default value is 1; x represents the input image, and the location loss generally uses smoothness... L1 Calculations show that L conf (x,c) represents the confidence loss, L loc(x,l,g) represents the position loss;
[0037] Confidence loss L conf
[0038]
[0039]
[0040] The value can be 0 or 1, where i represents the i-th preselected box, j represents the j-th real box, and p represents the p-th class. This represents the matching coefficient between the i-th preselected box and category p in the j-th real box; it is 1 if they match and 0 if they do not. It is the confidence score of category p of the i-th preselected box. It is a softmax confidence regression of the class confidence of the i-th positive sample prior box. is the confidence score of the background class of the i-th prior box, where Pos represents the set of positive samples and Neg represents the set of negative samples;
[0041] Position loss L loc
[0042]
[0043]
[0044]
[0045]
[0046]
[0047] x represents the input image. This indicates whether the i-th predicted bounding box matches the j-th ground truth bounding box with respect to category k; a match is 1, and a non-match is 0. l is the position parameter of the predicted bounding box. Let m represent the position value of the i-th predicted bounding box; g is the position parameter of the ground truth bounding box. This represents the value at position m of the j-th real bounding box. represents the offset from the position m of the j-th ground truth bounding box; d represents the position parameter of the prior bounding box. This represents the m-th position value of the i-th default box; cx and cy represent the position coordinates of the center point of the box; w and h represent the width and height, and m is a variable that takes the values of cx, cy, w, and h.
[0048] Furthermore, multiple different prior boxes are constructed on the fused feature layer. A non-maximum suppression algorithm is used to suppress some overlapping or incorrect prior boxes, generating the final set of prior boxes, specifically:
[0049] The SSD detector performs target classification and localization on seven fused feature layers of different sizes. The predicted number of prior bounding boxes in the feature maps is 4, 6, 6, 6, 4, 4, 4, respectively. The Conv3_3_y size is set separately, with a minimum size of 15 and a maximum size of 30. The size of the subsequent prior bounding boxes is calculated according to a formula, where n represents the number of feature maps, k represents the current feature layer being calculated, and S... k This indicates the ratio of the prior bounding box size to the image size:
[0050]
[0051] The Soft-NMS algorithm, an improved version of the nonmaximum suppression algorithm, has the following specific expression for its linear function:
[0052]
[0053] In the formula, S i For each bounding box, M is the bounding box with the highest current score, and b i For some remaining bounding box, N t The threshold value is set to 0.45.
[0054] Compared with the prior art, the present invention has at least the following beneficial effects:
[0055] 1. Add Conv3_3 from VGG16 as an effective feature layer and introduce a lower-level convolutional feature map. Since the lower-level convolution extracts detailed information such as the texture of the target object, the method of introducing the lower-level convolutional feature map improves the feature map's ability to represent the features of the target object, thereby improving the detection performance of the entire network.
[0056] 2. Dilated convolution is used. Dilated convolution can expand the receptive field of the convolution kernel while keeping the number of parameters unchanged. Feature layers that undergo dilated convolution will learn more contextual semantic information.
[0057] 3. By using deconvolution, higher-level feature layers with richer semantics are integrated into shallower feature layers, thereby improving the model's feature representation capabilities.
[0058] 4. Using the idea of multi-scale feature fusion, the shallow visual feature layer and the high-level semantic feature layer are fused together, so that the new feature map has both the semantic information of deep features and high resolution, thereby enabling the model to learn more feature information and improve the model's generalization ability.
[0059] 5. Adjust the prior box size of the SSD model to effectively avoid the problem that the object's true label cannot find a corresponding prior box to match it during training due to the small size of the detection target, thereby improving the model's ability to detect small targets. Attached Figure Description
[0060] Figure 1 This is a flowchart of the method of the present invention;
[0061] Figure 2 This is a network construction diagram of the present invention. Detailed Implementation
[0062] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0063] It should be noted that, unless otherwise specified, the experimental methods described in the following embodiments are all conventional methods, and the reagents and materials described are all commercially available unless otherwise specified. In the description of this invention, the terms "lateral", "longitudinal", "up", "down", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inner", and "outer" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are only for the convenience of describing this invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.
[0064] Furthermore, terms such as "horizontal," "vertical," and "sag" do not imply that components must be absolutely horizontal or suspended, but rather that they can be slightly tilted. For example, "horizontal" simply means that its direction is more horizontal relative to "vertical," and does not mean that the structure must be completely horizontal, but can be slightly tilted.
[0065] In the description of this application, it should also be noted that, unless otherwise expressly specified and limited, the terms "set up," "install," "connect," and "link" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in this application based on the specific circumstances.
[0066] like Figure 1As shown, this invention discloses a method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm, specifically as follows:
[0067] (1) Acquire images of the surface of the defective workpiece;
[0068] (2) Preprocess the acquired images to create a dataset;
[0069] (3) Modify the VGG16 backbone feature extraction network to add an effective feature layer;
[0070] (4) Construct an improved SSD network for multi-scale feature fusion. The loss function adopts confidence loss Lconf and location loss Lloc. The total loss is the weighted sum of the two loss functions.
[0071] (5) Construct multiple different prior boxes on the fusion feature layer, and suppress some overlapping or incorrect prior boxes by non-maximum suppression algorithm to generate the final prior box set.
[0072] (6) Train the SSD network model using the dataset to obtain the weight file;
[0073] (7) After preprocessing the image to be detected, input it into the trained SSD network model to obtain the surface defect results of the circular workpiece, including the defect location and category.
[0074] like Figure 2 As shown, the workpiece surface micro-defect detection method based on the improved SSD algorithm of the present invention includes the following steps:
[0075] Step 1: Acquire images of the surface of the defective circular workpiece.
[0076] Images of surface defects on workpieces are acquired using an industrial CCD camera.
[0077] Step 2: Preprocess the acquired images to create a dataset.
[0078] This includes data augmentation operations on the dataset. The main data augmentation operations are rotation, horizontal migration, vertical migration, and scaling, and the specific implementation methods are shown in the table below:
[0079] Data augmentation methods
[0080]
[0081] The Labelimg tool was used to mark the location of defects on the workpiece surface. The marking information included the defect location and type. The main types of defects on the workpiece surface were pits, scratches, and cracks. Finally, the dataset was divided into a training set and a test set, with the training set accounting for 70% of the total dataset and the test set accounting for 30% of the total dataset.
[0082] Step 3: Modify the VGG16 backbone feature extraction network to add effective feature layers.
[0083] Compared to a regular VGG network, its main modifications include:
[0084] (1) Replace the FC6 and FC7 fully connected layers of VGG16 with a convolutional network with a first-order convolutional kernel of [3,3] and a convolutional network with a first-order convolutional kernel of [1,1], and name them Conv6 and Conv7 layers to further extract network features;
[0085] (2) The original Dropout layer and FC8 layer were removed, and Conv8, Conv9, Conv10 and Conv11 layers were added to extract deeper network features.
[0086] Compared to the original SSD object detection algorithm, Conv3_3 is added as an effective feature layer. The specific effective feature layers selected are Conv3_3, Conv4_3, Conv7, Conv8_2, Conv9_2, Conv10_2 and Conv11_2, a total of seven layers, which result in seven feature maps with sizes of 75*75, 38*38, 19*19, 10*10, 5*5, 3*3 and 1*1. Multi-scale feature fusion is then performed among the seven effective feature layers.
[0087] Step 4: Construct an improved SSD network with multi-scale feature fusion
[0088] Multi-scale feature fusion includes dilated convolution downsampling and deconvolution upsampling operations. The formula for calculating the receptive field of the convolution kernel is:
[0089]
[0090] In the formula, di (dilation) represents different dilation values during dilated convolution, and F di These represent different receptive fields. The feature map can be restored to its original image size using deconvolution; the calculation formula is:
[0091] I = p(o + 2q - w) + 1
[0092] In the formula, I represents the input image size, o represents the output image size, q represents edge augmentation, w represents the convolution kernel size, and p represents the stride.
[0093] The newly fused Conv3_3_y layer consists of two parts. The first part is the Conv3_3 convolution operation that produces 256 75×75 feature maps, using a convolution kernel with a dilation of 1, a stride of 1, and a size of 3*3. The second part is the deconvolution upsampling operation of Conv4_3 that produces 256 75×75 feature maps, using a convolution kernel with a dilation of 1, a stride of 2, and a size of 3*3.
[0094] The newly fused feature layer, Conv4_3_y, consists of three parts. The first part generates 256 38×38 feature maps from Conv3_3 through dilated convolution downsampling, using a convolution kernel with a dilation of 2, a stride of 2, and a size of 3×3. The second part generates 512 38×38 feature maps from Conv4_3 through convolution operations, using a convolution kernel with a dilation of 1, a stride of 1, and a size of 3×3. The third part generates 256 38×38 feature maps from Conv7 through deconvolution upsampling, using a convolution kernel with a dilation of 0, a stride of 2, and a size of 2*2.
[0095] The newly fused Conv7_y and Conv8_2_y layers are similar to the Conv4_3_y layer. The first part uses dilated convolution downsampling operations from Conv4_3 and Conv7 to generate 256 19*19 and 256 10*10 feature maps, respectively, using convolutional kernels with a dilation of 2, a stride of 2, and a size of 3×3. The second part uses convolutions from Conv7 and Conv8_2 to generate 512 19*19 and 512 10*10 feature maps, respectively, using convolutional kernels with a dilation of 1, a stride of 1, and a size of 3×3. The third part uses deconvolution upsampling operations from Conv8_2 and Conv9_2 to generate 256 19*19 and 256 10*10 feature maps, respectively, using convolutional kernels with a dilation of 0, a stride of 2, and a size of 2×2. No further feature fusion is performed on other feature layers.
[0096] Feature fusion is achieved through concatenation, which merges feature maps into one another by merging channels, so that the merged feature map can have both abstract semantic information and specific information about the small target.
[0097] The loss function uses confidence loss L. conf and position loss L loc The total loss is a weighted sum of the two loss functions.
[0098] Total loss
[0099]
[0100] N represents the number of prior boxes that match the ground truth boxes; c represents the confidence score of the prior box category; l represents the location parameter of the predicted box; g represents the location parameter of the ground truth box; α is the weight value used to adjust the ratio of confidence loss to regression loss, the default value is 1; x represents the input image, and the location loss generally uses smoothness... L1 Calculations show that L conf (x,c) represents the confidence loss, L loc (x,l,g) represents the position loss.
[0101] Confidence loss L conf
[0102]
[0103]
[0104] The value can be 0 or 1, where i represents the i-th preselected box, j represents the j-th real box, and p represents the p-th class. This represents the matching coefficient between the i-th preselected box and category p in the j-th real box; it is 1 if they match and 0 if they do not. It is the confidence score of category p of the i-th preselected box. It is a softmax confidence regression of the class confidence of the i-th positive sample prior box. is the confidence score of the background class of the i-th prior box, Pos represents the set of positive samples, and Neg represents the set of negative samples.
[0105] Position loss L loc
[0106]
[0107]
[0108]
[0109]
[0110]
[0111] x represents the input image. This indicates whether the i-th predicted bounding box matches the j-th ground truth bounding box with respect to category k; a match is 1, and a non-match is 0. l is the position parameter of the predicted bounding box. Let m represent the position value of the i-th predicted bounding box; g is the position parameter of the ground truth bounding box. This represents the value at position m of the j-th real bounding box. represents the offset from the position m of the j-th ground truth bounding box; d represents the position parameter of the prior bounding box. This represents the m-th position value of the i-th default box; cx and cy represent the position coordinates of the center point of the box; w and h represent the width and height, and m is a variable that takes the values of cx, cy, w, and h.
[0112] Step 5: Construct prior boxes of different scales on the fused feature layer, and suppress some overlapping or incorrect prior boxes using a non-maximum suppression algorithm to generate the final prior box set, specifically:
[0113] The SSD detector performs target classification and localization on seven fused feature layers of different sizes. The predicted number of prior bounding boxes in the feature maps is 4, 6, 6, 6, 4, 4, 4, respectively. The Conv3_3_y size is set separately, with a minimum size of 15 and a maximum size of 30. The size of the subsequent prior bounding boxes is calculated according to a formula, where S is selected. min =0.1, S max =0.9, which effectively avoids the problem that the true label cannot find a corresponding prior box to match it during the training phase due to the target being too small. n represents the number of feature maps, k represents the current feature layer being calculated, and S k This indicates the ratio of the prior bounding box size to the image size:
[0114]
[0115] The dimensions of the prior frame are shown in the table.
[0116]
[0117] The Soft-NMS algorithm, an improved version of the nonmaximum suppression algorithm, has the following specific expression for its linear function:
[0118]
[0119] In the formula, S i For each bounding box, M is the bounding box with the highest current score, and b i For some remaining bounding box, N t The threshold value is set to 0.45.
[0120] (1) Sort the generated prediction boxes from high to low according to their confidence level, and select the prediction box with the highest score;
[0121] (2) If the area of intersection of the remaining prediction boxes with the prediction box with the highest confidence is greater than a certain threshold, the score of the corresponding box is reduced until it is lower than a certain threshold.
[0122] (3) Finally, a prediction box will be obtained, and the algorithm will end.
[0123] Step 6: Train the SSD network model using the dataset to obtain the weight file.
[0124] The experiment was set with an input image resolution of 300*300, a batch size of 32, an initial learning rate of 0.001, an initial learning rate decay factor of 0.2, an IOU threshold of 0.5, and a total of 65,000 iterations.
[0125] Step 7: After preprocessing, the image to be detected is input into the trained SSD network model to obtain the surface defect results of the workpiece, including the defect location and category.
[0126] Output the location and category information of surface defects on the workpiece.
[0127] The embodiments described above are merely preferred embodiments of the present invention and are not intended to limit the concept and scope of the present invention. Various modifications and improvements made to the technical solutions of the present invention by those skilled in the art without departing from the inventive concept should fall within the protection scope of the present invention. All technical contents for which protection is sought in this invention are fully described in the claims.
Claims
1. A method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm, characterized in that, Includes the following steps: Step S1. Acquire images of the surface of the defective workpiece; Step S2. Preprocess the acquired images to create a dataset; Step S3. Modify the VGG16 backbone feature extraction network to add an effective feature layer; the VGG backbone feature extraction network is modified as follows: (1) Use a convolutional network with a first-order convolutional kernel of [3,3] and a convolutional network with a first-order convolutional kernel of [1,1] to replace the FC6 and FC7 fully connected layers of VGG16, and name them Conv6 and Conv7 layers to further extract network features; (2) The original Dropout layer and FC8 layer of VGG16 were removed, and Conv8, Conv9, Conv10 and Conv11 layers were added to extract deeper network features. Compared with the original SSD object detection algorithm, Conv3_3 was added as an effective feature layer. The specific effective feature layers selected are Conv3_3, Conv4_3, Conv7, Conv8_2, Conv9_2, Conv10_2 and Conv11_2, a total of seven layers, which are used to obtain seven feature maps with sizes of 75*75, 38*38, 19*19, 10*10, 5*5, 3*3 and 1*1. Multi-scale feature fusion is performed between the seven effective feature layers. Step S4. Construct an improved SSD network for multi-scale feature fusion, using confidence loss L as the loss function. conf and position loss L loc The total loss is a weighted sum of the two loss functions; Step S5. Construct multiple different prior boxes on the fusion feature layer, and suppress some overlapping or incorrect prior boxes using the non-maximum suppression algorithm to generate the final prior box set; Step S6. Train the SSD network model using the dataset to obtain the weight file; Step S7. After preprocessing, the image to be detected is input into the trained SSD network model to obtain the surface defect results of the circular workpiece, including the defect location and category.
2. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 1, characterized in that, In step S1, an industrial CCD camera is used to acquire images of the surface of the defective workpiece.
3. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 1, characterized in that, In step S2, the acquired images are preprocessed to create a dataset, specifically as follows: Data augmentation operations are performed on the dataset, including four methods: rotation, horizontal migration, vertical migration, and scaling. Mark the location of defects on the workpiece surface. The marking information includes the location and type of the defect. The types of defects on the workpiece surface include pits, scratches, and cracks. Finally, the dataset is divided into training and test sets according to a certain ratio.
4. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 1, characterized in that, An improved SSD network with multi-scale feature fusion is constructed as follows: Multi-scale feature fusion includes dilated convolution downsampling and deconvolution upsampling operations. The formula for calculating the receptive field of the convolution kernel is: In the formula, di (dilation) represents different dilation values during dilated convolution operations. Indicates different sensory fields; The feature map can be restored to its original image size using deconvolution. The calculation formula is as follows: In the formula, I represents the input image size, o represents the output image size, q represents edge augmentation, w represents the convolution kernel size, and p represents the stride.
5. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 4, characterized in that, The newly fused Conv3_3_y layer consists of two parts. The first part is 256 75×75 feature maps obtained by Conv3_3 convolution operation, using a convolution kernel with a dilation of 1, a stride of 1, and a size of 3*3. The second part is 256 75×75 feature maps obtained by deconvolution upsampling operation of Conv4_3, using a convolution kernel with a dilation of 1, a stride of 2, and a size of 3*3. The newly fused feature layer Conv4_3_y consists of three parts. The first part generates 256 38×38 feature maps from Conv3_3 through dilated convolution downsampling, using a convolution kernel with a dilation value of 2, a stride of 2, and a size of 3×3. The second part generates 512 38×38 feature maps from the convolution operation of Conv4_3, using a convolution kernel with a dilation value of 1, a stride of 1, and a size of 3×3. The third part generates 256 38×38 feature maps from Conv7 through deconvolution upsampling, using a convolution kernel with a dilation value of 0, a stride of 2, and a size of 2*2. The newly fused Conv7_y and Conv8_2_y layers are similar to the Conv4_3_y layer. The first part is formed by Cconv4_3 and Conv7 through dilated convolution downsampling operations to create 256 19*19 and 256 10*10 feature maps, respectively, using convolution kernels with a dilation value of 2, a stride of 2, and a size of 3×3. The second part is formed by convolution of Conv7 and Conv8_2 to create 512 19*19 and 512 10*10 feature maps, respectively, using convolution kernels with a dilation value of 1, a stride of 1, and a size of 3×3. The third part is formed by deconvolution upsampling operations of Conv8_2 and Conv9_2 to create 256 19*19 and 256 10*10 feature maps, respectively, using convolution kernels with a dilation value of 0, a stride of 2, and a size of 2×2. Other feature layers will no longer undergo feature fusion.
6. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 5, characterized in that, Feature fusion is achieved through concatenation, which merges feature maps into one another by merging channels, so that the merged feature map can have both abstract semantic information and specific information about the small target.
7. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 1, characterized in that, The loss function uses confidence loss. and position loss The total loss is a weighted sum of the two loss functions, specifically: Total loss N represents the number of prior boxes that match the ground truth boxes; c represents the confidence score of the prior box category; l represents the location parameters of the predicted boxes; g represents the location parameters of the ground truth boxes; α is a weight value used to adjust the ratio of confidence loss to regression loss, with a default value of 1; x represents the input image, and the location loss is generally calculated using... Calculations show that Indicates confidence loss. Indicates position loss; Confidence loss The value can be 0 or 1, where i represents the i-th preselected box, j represents the j-th real box, and p represents the p-th class. This represents the matching coefficient between the i-th preselected box and category p in the j-th real box; it is 1 if they match and 0 if they do not. It is the confidence score of category p of the i-th preselected box. It is a softmax confidence regression of the class confidence of the i-th positive sample prior box. Pos represents the confidence score of the background class of the i-th prior box, where Pos represents the set of positive samples and Neg represents the set of negative samples. Location loss x represents the input image. This indicates whether the i-th predicted bounding box matches the j-th ground truth bounding box with respect to category k; a match is 1, and a non-match is 0. l is the position parameter of the predicted bounding box. Let m represent the position value of the i-th predicted bounding box; g is the position parameter of the ground truth bounding box. This represents the value at position m of the j-th real bounding box. d represents the offset from the position m of the j-th ground truth bounding box; d represents the position parameters of the prior bounding box. This represents the value at position m of the i-th default box; cx and cy This represents the coordinates of the center point of the box; w and h represent the width and height, and m is a variable... cx,cy, The variables w and h.
8. The method for detecting minute defects on the surface of a workpiece based on an improved SSD algorithm according to claim 7, characterized in that, Multiple different prior boxes are constructed on the fusion feature layer. A non-maximum suppression algorithm is used to suppress some overlapping or incorrect prior boxes, generating the final set of prior boxes. Specifically: The SSD detector performs object classification and localization on seven fused feature layers of different sizes. The predicted number of prior bounding boxes in the feature maps is 4, 6, 6, 6, 4, 4, 4, respectively. The size of Conv3_3_y is set separately, with a minimum size of 15 and a maximum size of 30. The size of subsequent prior bounding boxes is calculated according to a formula, where n represents the number of feature maps and k represents the current feature layer being calculated. This indicates the ratio of the prior bounding box size to the image size: The Soft-NMS algorithm, an improved version of the nonmaximum suppression algorithm, has the following specific expression for its linear function: In the formula, For each bounding box, there is a score, where M is the bounding box with the highest score. For one of the remaining bounding boxes, To set a threshold.
Citation Information
Patent Citations
Target detection method and device based on BSSD
CN109858547A
Method, apparatus, and device for fusing features applied to small target detection, and storage medium
US20210224581A1