A lightweight fabric defect detection method that can be deployed on embedded devices

By improving the YOLOv7 network structure and loss function, combined with data enhancement training, a lightweight cloth defect detection method was constructed, which solved the problem of YOLOv7 detection on embedded devices and achieved efficient cloth defect detection.

CN116188419BActive Publication Date: 2025-08-01ZHEJIANG UNIV OF TECH TONGXIANG RES INST CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310142953.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-21
Publication Date
2025-08-01
Estimated Expiration
2043-02-21

AI Technical Summary

Technical Problem

The existing YOLOv7 network model has many parameters and large calculations, making it difficult to achieve accurate and rapid detection of fabric defects on embedded devices, especially when facing extreme aspect ratios and small targets.

Method used

The MobileNetv3 structure is used as the backbone network of YOLOv7, and the 3×3 convolution in the ELAN structure is replaced with the channel shuffle convolution of ShuffleNetv2, the ECA channel attention mechanism is increased, the SPPCSPC module is replaced as Ghost convolution, combined with Ghost convolution, the improved loss function is set, and data augmentation training is carried out to build a lightweight object detection network.

Benefits of technology

While reducing the calculation parameters and calculation amount, the detection accuracy and efficiency are improved, making the lightweight target detection network suitable for edge computing scenarios, realizing accurate and rapid detection of fabric defects.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116188419B_ABST
    Figure CN116188419B_ABST
Patent Text Reader

Abstract

The present invention provides a lightweight cloth defect detection method that can be deployed on embedded devices. The method includes the following steps: constructing a lightweight object detection network model based on the YOLOv7 object detection network, using the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network, replacing the 3×3 convolution part in the ELAN structure of the YOLOv7 object detection network with a convolutional layer with channel shuffle in the ShuffleNetv2 structure, adding an ECA channel attention mechanism after each ELAN structure, and replacing the SPPCSPC module with a GhostSPPCSPC module, that is, replacing the ordinary convolution in the SPPCSPC module with Ghost convolution; obtaining an optimal lightweight object detection network model through multiple rounds of training of the lightweight object detection network model with a dataset; and inputting the cloth image to be measured into the optimal lightweight object detection network model for defect detection. The lightweight cloth defect detection method of the present invention can be deployed on embedded devices and applied to scenarios of edge computing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to a lightweight cloth defect detection method, specifically to a lightweight cloth defect detection method that can be deployed on an embedded device, and belongs to the technical field of machine vision defect detection. Background Art

[0002] During the textile production process, various defects often occur, including broken warp, broken weft, thick knots, etc. The defects on the cloth surface seriously affect its appearance and quality, reducing the qualified rate of textile production. Therefore, before the textiles leave the factory, they need to go through an inspection process to detect whether there are defects on the cloth.

[0003] Traditional cloth defect detection mainly relies on manual inspection combined with a magnifying glass. However, the speed of manually inspecting the cloth is relatively slow, generally 10 - 20 m / min, and there are problems such as high cost, low efficiency, and easy occurrence of misdetection and missed detection. In the prior art, traditional machine vision methods and other automated methods are used to achieve cloth defect detection, but traditional machine vision methods have defects such as single type of detected defects and high computational cost, and cannot meet the requirements of efficient and diversified cloth defect detection.

[0004] Among the new machine vision methods, the single-stage object detection technology represented by the YOLO series is the most typical. Although the latest YOLOv7 network model in the YOLO series can achieve a relatively fast detection speed under the condition of ensuring detection accuracy, due to the large number of parameters and high computational complexity of the YOLOv7 network model, and the two characteristics of extreme aspect ratio and small targets of cloth defects, the detection difficulty is increased. Therefore, it is not suitable for scenarios such as edge computing of embedded devices, and thus the network model cannot be deployed on embedded devices to achieve accurate, fast, real-time online detection of cloth defects. Summary of the Invention

[0005] Based on the above background, the purpose of the present invention is to provide a lightweight cloth defect detection method that can be deployed on an embedded device, which can greatly reduce the calculation parameters while ensuring a relatively high detection accuracy of the detection model for cloth defects, so that the method can be deployed on embedded devices and applied to scenarios of edge computing.

[0006] To achieve the above object of the invention, the present invention provides the following technical solutions:

[0007] A lightweight cloth defect detection method that can be deployed on an embedded device, the method includes the following steps:

[0008] Build a lightweight object detection network model based on the YOLOv7 object detection network. Use the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network. Replace the 3×3 convolution part in the ELAN structure of the YOLOv7 object detection network with a convolutional layer with channel shuffle in the ShuffleNetv2 structure. Add an ECA channel attention mechanism after each ELAN structure, and replace the SPPCSPC module with a GhostSPPCSPC module, that is, replace the ordinary convolution in the SPPCSPC module with Ghost convolution;

[0009] Set the loss function of the lightweight object detection network model. Collect the data set and divide it into a training set and a test set. Perform multiple rounds of training on the lightweight object detection network model through the data set. Calculate the loss value according to the loss function in each round of training. Train iteratively until the loss curve of the lightweight object detection network model tends to be flat in the direction of minimizing the loss value, and stop training to obtain the optimal lightweight object detection network model;

[0010] Input the image of the cloth to be measured into the optimal lightweight object detection network model for defect detection, and output the defect detection result and defect target position information of the cloth to be measured.

[0011] Preferably, using the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network includes:

[0012] The MobileNetv3 structure includes 15 linear bottleneck residual structures. Among them, the first, second, and third linear bottleneck residual structures do not use the SE-Net attention mechanism and use the ReLU6 activation function. The fourth, fifth, and sixth linear bottleneck residual structures use the SE-Net attention mechanism and use the ReLU6 activation function. The seventh, eighth, ninth, and tenth linear bottleneck residual structures do not use the SE-Net attention mechanism and use the h-swish activation function. The eleventh, twelfth, thirteenth, fourteenth, and fifteenth linear bottleneck residual structures use the SE-Net attention mechanism and use the h-swish activation function. Connect the sixth linear bottleneck residual structure of the MobileNetv3 structure to a CBS module in the head network structure of the YOLOv7 object detection network. Connect the thirteenth linear bottleneck residual structure of the MobileNetv3 structure to another CBS module in the head network structure of the YOLOv7 object detection network. Connect the fifteenth linear bottleneck residual structure of the MobileNetv3 structure to the GhostSPPCSPC module in the head network structure of the YOLOv7 object detection network.

[0013] Preferably, an ECA channel attention mechanism is added, including:

[0014] Perform global average pooling operation on the input feature map; perform 1-D convolution operation to enable information interaction between channels of each layer and adjacent layers; perform Sigmoid activation; multiply the input feature map by the feature map weight to obtain the result.

[0015] Preferably, the loss function adopts the following expression

[0016]

[0017] In the formula, is the loss function, is the localization error, is the classification error, is the confidence error;

[0018] Among them, adopts the following expression

[0019]

[0020] In the formula, n represents the number of input samples, is the actual value, is the predicted value.

[0021] Adopt method to improve the loss function, adding the error of the detection box scale and the error of the length and width of the detection box, making the predicted box more conform to the real box. Based on method's expression can assist the model to focus on high IoU targets, thereby improving the localization and detection performance of the model, and at the same time can improve the learning speed of the network.

[0022] Preferably, a data set is collected and divided into a training set and a test set, including:

[0023] Collect the original images of unqualified sample cloths, manually annotate each original image and scale it to 416×416 pixels, divide the data set into a training set and a test set according to the ratio of 85% and 15%, and perform data augmentation on the images in the training set.

[0024] Preferably, perform data augmentation on the images in the training set, including:

[0025] Annotate and crop small targets smaller than 30×30 pixels in the image, and copy them to random positions in the original image through Poisson fusion to expand the small targets; perform data augmentation on the images in the training set by using horizontal flipping, vertical flipping, random rotation in the range of -15° to +15°, and salt and pepper noise methods.

[0026] Preferably, the lightweight object detection network model is trained in multiple rounds through a data set, including:

[0027] In each round, a set number of images in the training set are input into the lightweight object detection network model for forward inference. After each round of training, a set number of images in the test set are input into the lightweight object detection network model completed in the current round for testing, so as to measure the training status of the lightweight object detection network model.

[0028] Preferably, training the lightweight object detection network model in multiple rounds through a data set further includes:

[0029] After all rounds of training are completed, the images in the test set are input into the trained lightweight object detection network model to obtain the predicted category and confidence of each image in the test set, and compare them with the manually labeled true category.

[0030] Preferably, after obtaining the predicted category and confidence of each image in the test set and comparing them with the manually labeled true category, it further includes:

[0031] Statistical lightweight object detection network model parameter number, F1 value, mean average precision and the number of images processed per second by the model; wherein, the number of parameters is the total number of parameters in the lightweight object detection network model, the F1 value is calculated using the following expression according to the precision and recall,

[0032]

[0033]

[0034]

[0035] In the formula, TP is the number of correctly predicted positive examples, FP is the number of incorrectly predicted positive examples, and FN is the number of incorrectly predicted negative examples.

[0036] Preferably, the training iterates until the loss curve of the lightweight object detection network model tends to be flat in the direction of minimizing the loss value, including:

[0037] Adopt a gradient descent strategy with a momentum term of 0.937 for optimization, and set the initial learning rate to 0.01.

[0038] Compared with the prior art, the present invention has the following advantages:

[0039] A lightweight cloth defect detection method that can be deployed on embedded devices. By using the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network and combining Ghost convolution, the number of calculation parameters is significantly reduced, and the model calculation amount is decreased. By introducing the convolution method in ShuffleNetv2 and combining it with the addition of the ECA channel attention mechanism, while ensuring the calculation efficiency, the feature learning ability of the model is improved, thereby enhancing the detection accuracy of the model. In addition, by using data augmentation methods to expand the dataset and combining data augmentation for small targets in the dataset, the contribution of the small targets to the loss function is increased, thereby enhancing the detection performance of the model. This method enables the lightweight object detection network model to be applicable to the scenario of edge computing and can be deployed on embedded devices to achieve accurate and fast cloth defect detection. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the following will briefly introduce the drawings required for use in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present invention. For those of ordinary skill in the art, without creative efforts, other drawings can also be obtained according to the provided drawings.

[0041] Figure 1 It is a schematic diagram of the steps of the lightweight cloth defect detection method that can be deployed on embedded devices according to the present invention;

[0042] Figure 2 It is a schematic diagram of the structure of the lightweight object detection network model according to the present invention;

[0043] Figure 3 It is a schematic diagram of the Inverted Residual module of the MobileNetv3 structure according to the present invention;

[0044] Figure 4 It is a schematic diagram of the ShuffleNetv2 method according to the present invention;

[0045] Figure 5 It is a schematic diagram of the ECA attention mechanism according to the present invention;

[0046] Figure 6 It is an effect diagram of small target enhancement according to the present invention;

[0047] Figure 7 It is a diagram of some datasets, enhancement methods and effect diagrams used according to the present invention;

[0048] Figure 8 It is an effect diagram of the lightweight cloth defect detection method that can be deployed on embedded devices according to the present invention. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0049] The technical solution of the present invention will be further specifically described below through specific embodiments in conjunction with the accompanying drawings. It should be understood that the implementation of the present invention is not limited to the following embodiments, and any formal modification and / or change made to the present invention will fall within the protection scope of the present invention.

[0050] In the present invention, unless otherwise specified, all parts and percentages are in weight units, and the equipment and raw materials used can be purchased from the market or are commonly used in the art. The methods in the following embodiments are all conventional methods in the art unless otherwise specified. The components or equipment in the following embodiments are all general standard components or components known to those skilled in the art, and their structures and principles can all be known by those skilled in the art through technical manuals or obtained through conventional experimental methods.

[0051] The following will make a detailed description of the embodiments of the present invention in conjunction with the accompanying drawings. In the following detailed description, for the convenience of explanation, many specific details are elaborated to provide a comprehensive understanding of the embodiments of the present invention.

[0052] An embodiment of the present invention discloses a lightweight cloth defect detection method that can be deployed on an embedded device. Refer to Figure 1 , the method includes the following steps:

[0053] S1. Build a lightweight object detection network model based on the YOLOv7 object detection network. Use the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network. Replace the 3×3 convolution part in the ELAN structure of the YOLOv7 object detection network with a convolutional layer with channel shuffle in the ShuffleNetv2 structure. Add an ECA channel attention mechanism after each ELAN structure, and replace the SPPCSPC module with a GhostSPPCSPC module, that is, replace the ordinary convolution in the SPPCSPC module with Ghost convolution;

[0054] S2. Set the loss function of the lightweight object detection network model, collect the data set and divide it into a training set and a test set. Perform multiple rounds of training on the lightweight object detection network model through the data set. Calculate the loss value according to the loss function in each round of training. Train iteratively until the loss curve of the lightweight object detection network model tends to be flat in the direction of minimizing the loss value, and stop training to obtain the optimal lightweight object detection network model;

[0055] S3. Input the image of the cloth to be measured into the optimal lightweight object detection network model for defect detection, and output the defect detection result and defect target position information of the cloth to be measured.

[0056] The following will make a detailed description of each step of the method in conjunction with the accompanying drawings.

[0057] The purpose of step S1 is to construct a lightweight object detection network model, and its structure refers to Figure 2 , and the construction steps are described in detail as follows.

[0058] S1.1 Construction and improvement of the YOLOv7 object detection network

[0059] Based on the YOLOv7 object detection network, in order to make the model lightweight, the MobileNetv3 structure is used as the backbone network of the YOLOv7 object detection network. The MobileNetv3 structure is a lightweight network structure, and the specific structure is shown in Table 1.

[0060] Table 1 MobileNetv3 structure

[0061]

[0062] Among them, Inverted Residual represents the linear bottleneck residual structure, and its structure refers to Figure 3 ; SE indicates whether to use the SE-Net attention mechanism; NL indicates the type of activation function used, where RE represents the ReLU6 activation function, and HS represents the h-swish activation function, and its expression is:

[0063] ,

[0064] The MobileNetv3 structure described in Table 1 includes 15 linear bottleneck residual structures. Among them, the 1st, 2nd, and 3rd linear bottleneck residual structures do not use the SE-Net attention mechanism and use the ReLU6 activation function. The 4th, 5th, and 6th linear bottleneck residual structures use the SE-Net attention mechanism and use the ReLU6 activation function. The 7th, 8th, 9th, and 10th linear bottleneck residual structures do not use the SE-Net attention mechanism and use the h-swish activation function. The 11th, 12th, 13th, 14th, and 15th linear bottleneck residual structures use the SE-Net attention mechanism and use the h-swish activation function.

[0065] The improvement of the YOLOv7 object detection network is to connect the 6th linear bottleneck residual structure of the MobileNetv3 structure to a CBS module in the head network structure of the YOLOv7 object detection network, connect the 13th linear bottleneck residual structure of the MobileNetv3 structure to another CBS module in the head network structure of the YOLOv7 object detection network, and connect the 15th linear bottleneck residual structure of the MobileNetv3 structure to the GhostSPPCSPC module in the head network structure of the YOLOv7 object detection network.

[0066] S1.2 Further improvement based on the YOLOv7 object detection network

[0067] The above preliminary constructed model is further improved from the following three aspects:

[0068] (1) Replace the 3×3 convolution part in the ELAN structure with a convolutional layer with channel shuffle in ShuffleNetv2;

[0069] (2) Add the ECA channel attention mechanism after each ELAN structure;

[0070] (3) Replace the original SPPCSPC module with the GhostSPPCSPC module, that is, replace the ordinary convolution in the original SPPCSPC module with Ghost convolution, so as to reduce the parameters in the module.

[0071] For the first aspect, the improvement with reference to the ShuffleNetv2 method is described as follows. Refer to Figure 4 , at the beginning of each unit, the input of c feature channels is evenly divided into two branches. One branch remains unchanged, and the other branch consists of three convolutions with the same input and output channels. Among them, the first and the third convolutions are ordinary 1×1 convolutions, and the second convolution is a 3×3 depthwise separable convolution. After the convolution operation, the two branches are connected, and then the channels shuffle operation is performed to enable information communication between the two branches. Replacing the two 3×3 convolutions in the ELAN structure with the above channel shuffle method in ShuffleNetv2 can improve the model performance while ensuring the computational efficiency.

[0072] For the second aspect, refer to Figure 5 , the specific steps to add the ECA attention mechanism are as follows: First, perform global average pooling on the input feature map; then perform 1-D convolution operation so that each layer of channels can communicate with the channels of adjacent layers; then perform Sigmoid activation; finally, multiply the input feature map by the feature map weight to obtain the result.

[0073] The role of Ghost convolution is that since there are feature maps with high similarity in the feature map, that is, feature redundancy, generating similar feature maps through linear operations on the feature map can generate more feature maps with fewer parameters. Ghost convolution first uses a 1×1 convolution to compress the number of channels of the input image, then obtains more feature maps through linear transformation and depthwise separable convolution, and finally fuses different feature maps together to form a new output to replace the ordinary convolution operation, greatly reducing the model parameters and computational overhead.

[0074] For example, to generate a feature map with n channels, first generate an identity map through traditional convolution. The number of channels is m, and the size is <n. Then, process the feature map with m channels. Each layer uses convolution to generate a feature map with m channels. Repeat the operation to generate s - 1 sets of new feature maps. Adding the original feature map, a total of s sets of feature maps are generated, and the number of channels is sm = n.

[0075] Given the input , then

[0076] ,

[0077] where * represents convolution, b is the bias, is the output feature map with n channels, is the convolution kernel, C represents the number of feature channels of the convolution kernel, k represents the size of the convolution kernel, and n is the number of convolution kernels.

[0078] All the convolutions in the network are replaced with Ghost convolutions to obtain a more lightweight network, which can effectively reduce the model parameters and computational overhead.

[0079] For example, for a feature map and linear operation, the convolution kernel of the linear operation is equal to , so for linear operations, there are different sizes and parameters. Assume that the size of the linear operation in a Ghost convolution is the same, all 3 3 or 5 5. Then, after replacing the traditional convolution with Ghost convolution, the theoretical acceleration rate is

[0080] ,

[0081] ,

[0082] The compression rate of the model

[0083] ,

[0084] The purpose of step S2 is to train the model to obtain the optimal lightweight object detection network model, and its training steps are detailed as follows.

[0085] S2.1 Set the loss function

[0086] The loss function adopts the following expression,

[0087] ,

[0088] In the formula, is the loss function, is the positioning error, is the classification error, is the confidence error.

[0089] Among them, in this embodiment, it is only required that the model can detect defects and prompt that the product is unqualified, and the defects are not classified. Therefore, the value of is 0. Adopt the expression based on the method.

[0090] Among them, adopt the following expression,

[0091] ,

[0092] In the formula, n represents the number of input samples, is the actual value, is the predicted value.

[0093] Adopt the method to improve the loss function, increase the error of the detection box scale and the error of the detection box length and width, make the prediction box more conform to the real box. Based on the method, the expression can assist the model to focus on the targets with high IoU, thereby improving the positioning and detection performance of the model, and at the same time can improve the learning speed of the network.

[0094] S2.2 Collect the dataset

[0095] The dataset is constructed by self-shooting images of unqualified sample cloth. There are 2722 original images in total. Use the LabelImg software to annotate the images. There are 3262 annotations in total. Then uniformly scale each original image to 416×416 pixels. Divide the training set and the test set according to the ratio of 85%:15%, which are 2314 and 409 respectively.

[0096] Then, data augmentation is performed on the images in the training set. Specifically: First, for the small target annotations smaller than 30×30 pixels, cut them out and randomly paste them to the position without targets in the original image through Poisson fusion to expand the small targets. The enhancement effect of the small targets is as Figure 6 shown; Second, data augmentation is performed by horizontal flipping, vertical flipping, random rotation in the range of -X°~ +X° and salt and pepper noise (2%). Randomly select 578 or 579 pictures in the training set. That is, first select 578 pictures for horizontal flipping, and then select 579 pictures in the training set processed in the above steps for vertical flipping, and so on. The augmented dataset is twice the original, that is, 4628 pictures. Part of the dataset and the enhancement effect are as Figure 7 Note: In the above translation, the value of the angle range "-15°~ +15°" in item is replaced with "-X°~ +X°" because the original text you provided has an unclear expression. You can modify it according to the actual situation.shown.

[0097] S2.3 training to obtain the optimal lightweight target detection network model

[0098] The learning rate adopts the One Cycle Policy method. The neural network is first linearly warmed up over three epochs, increasing the learning rate linearly. Then, at the start of training, the learning rate is reduced to the initial learning rate. Finally, throughout the training process, the learning rate gradually decreases to 0. The input image size is 416 × 416 pixels. Training is performed for 100 epochs using the Adam optimizer. The initial learning rate is set to 0.01, the momentum is set to 0.937, and the batch size is set to 64.

[0099] The training set is fed into the model. During training, batches of 32 images are fed into the network. Forward inference is first performed. Once the results are obtained, the loss value is calculated using the aforementioned loss function. Backpropagation is then performed using gradient descent to iterate the model parameters toward minimizing the loss function. After each round of training, the test set images are fed into the model to test the model's training status, for example, to determine whether the model is overfitting.

[0100] After completing all rounds of training, the images in the test set are input into the trained lightweight object detection network model to obtain the predicted category and confidence of each image in the test set, and compare them with the manually labeled true category.

[0101] Statistics are collected for the number of parameters, F1 value, average precision, and number of images processed per second of the lightweight object detection network model. The number of parameters refers to the total number of parameters in the lightweight object detection network model, and the F1 value is calculated based on the precision and recall using the following expression:

[0102]

[0103]

[0104]

[0105] Where TP is the number of positive examples predicted correctly, FP is the number of positive examples predicted incorrectly, and FN is the number of negative examples predicted incorrectly.

[0106] The mean average precision (mAP) is used to measure the overall detection effect of the model on different target detections. Its calculation formula is as follows:

[0107]

[0108] Among them, cls represents the total number of categories in the task. In this embodiment, cls = 1.

[0109] The number of images processed by the model per second is represented by FPS.

[0110] The optimal lightweight object detection network model is trained, and the achieved mAP and FPS are shown below.

[0111] In step S3, the image of the cloth to be measured is input into the optimal lightweight object detection network model for defect detection, and the defect detection result and defect target position information of the cloth to be measured are output. In practical applications, this method is deployed on an embedded device. The image of the cloth to be measured is collected by the embedded device, and the result can be obtained by inputting the image into the optimal lightweight object detection network model. The detection effect is for reference Figure 8 .

[0112] An ablation experiment is carried out on the lightweight object detection network model of this method to study the influence and effectiveness among various modules. The experimental results are shown in Table 2.

[0113] Table 2 Ablation experiment results

[0114]

[0115] To further verify the performance of the model in this method, a comparative experiment is carried out with YOLOv5s and YOLOv7. YOLOv5s refers to the YOLOv5 series network model mentioned in https: / / github.com / ultralytics / yolov5, and YOLOv7 refers to the YOLOv7 network model mentioned in https: / / github.com / WongKinYiu / yolov7. The comparative experiment results are shown in Table 3.

[0116] Table 3 Comparative experiment results

[0117]

[0118] The above experimental results show that under the premise of a large reduction in the number of parameters, the present invention achieves results similar to those of YOLOv5s and YOLOv7. The mAP reaches 93.7%, exceeding YOLOv5s and being on par with YOLOv7.

[0119] In this article, specific examples are used to elaborate on the principle and implementation manner of the present invention. The description of the above embodiments is only used to help understand the method and its core idea of the present invention. It should be noted that for those of ordinary skill in the art in this technical field, without departing from the principle of the present invention, several improvements and modifications can still be made to the present invention, and these improvements and modifications also fall within the protection scope of the claims of the present invention.

Claims

1. A lightweight fabric defect detection method that can be deployed on embedded devices, characterized in that: The method includes the following steps: Construct a lightweight object detection network model based on the YOLOv7 object detection network. Use the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network. Replace the 3×3 convolution part in the ELAN structure of the YOLOv7 object detection network with a convolutional layer with channel shuffle in the ShuffleNetv2 structure. Add an ECA channel attention mechanism after each ELAN structure, and replace the SPPCSPC module with a GhostSPPCSPC module, that is, replace the ordinary convolution in the SPPCSPC module with Ghost convolution; Set the loss function of the lightweight object detection network model. Collect a dataset and divide it into a training set and a test set. Perform multiple rounds of training on the lightweight object detection network model through the dataset. In each round of training, calculate the loss value according to the loss function. Train iteratively until the loss curve of the lightweight object detection network model tends to be flat in the direction of minimizing the loss value, stop training, and obtain the optimal lightweight object detection network model; Input the image of the cloth to be measured into the optimal lightweight object detection network model for defect detection, and output the defect detection result and defect target position information of the cloth to be measured.

2. The lightweight cloth defect detection method deployable to an embedded device according to claim 1, wherein: Using the MobileNetv3 structure as the backbone network of the YOLOv7 object detection network includes: The MobileNetv3 structure includes 15 linear bottleneck residual structures. Among them, the first, second, and third linear bottleneck residual structures do not use the SE-Net attention mechanism and use the ReLU6 activation function. The fourth, fifth, and sixth linear bottleneck residual structures use the SE-Net attention mechanism and use the ReLU6 activation function. The seventh, eighth, ninth, and tenth linear bottleneck residual structures do not use the SE-Net attention mechanism and use the h-swish activation function. The eleventh, twelfth, thirteenth, fourteenth, and fifteenth linear bottleneck residual structures use the SE-Net attention mechanism and use the h-swish activation function. Connect the sixth linear bottleneck residual structure of the MobileNetv3 structure to a CBS module in the head network structure of the YOLOv7 object detection network. Connect the thirteenth linear bottleneck residual structure of the MobileNetv3 structure to another CBS module in the head network structure of the YOLOv7 object detection network. Connect the fifteenth linear bottleneck residual structure of the MobileNetv3 structure to the GhostSPPCSPC module in the head network structure of the YOLOv7 object detection network.

3. A lightweight cloth defect detection method deployable on an embedded device according to claim 1, characterized in that: Adding an ECA channel attention mechanism includes: Perform global average pooling operation on the input feature map; perform 1-D convolution operation to enable information interaction between channels of each layer and adjacent layers; perform Sigmoid activation; multiply the input feature map by the feature map weight to obtain the result.

4. A lightweight cloth defect detection method deployable on an embedded device according to claim 1, characterized in that: The loss function uses the following expression , In the formula, is the loss function, is the positioning error, is the classification error, is the confidence error; Among them, the following expression is adopted, , Where n represents the number of input samples, is the actual value, is the predicted value.

5. The lightweight cloth defect detection method deployable on an embedded device according to claim 1, wherein: Collecting a dataset and dividing it into a training set and a test set includes: Collect the original images of the unqualified sample cloth, manually annotate each original image and scale it to 416×416 pixels, divide the dataset into a training set and a test set according to the ratio of 85% and 15%, and perform data augmentation on the images in the training set.

6. The lightweight cloth defect detection method deployable on an embedded device according to claim 5, characterized in that: Perform data augmentation on the images in the training set, including: Annotate and crop the small targets smaller than 30×30 pixels in the image, and copy them to random positions in the original image through Poisson fusion to expand the small targets; perform data augmentation on the images in the training set by using horizontal flipping, vertical flipping, random rotation in the range of -15° to +15°, and salt-and-pepper noise method.

7. A lightweight cloth defect detection method deployable on an embedded device according to claim 1, characterized in that: Perform multiple rounds of training on the lightweight object detection network model through the dataset, including: In each round, input a set number of images in the training set into the lightweight object detection network model for forward inference. After each round of training, input a set number of images in the test set into the lightweight object detection network model that has completed the current round for testing, so as to measure the training status of the lightweight object detection network model.

8. A lightweight cloth defect detection method deployable on an embedded device according to claim 7, characterized in that: Performing multiple rounds of training on the lightweight object detection network model through the dataset also includes: After completing all rounds of training, input the images in the test set into the trained lightweight object detection network model, obtain the predicted class and confidence of each image in the test set, and compare them with the manually annotated true classes.

9. The lightweight cloth defect detection method deployable on an embedded device according to claim 8, characterized in that: After obtaining the predicted class and confidence of each image in the test set and comparing them with the manually annotated true classes, it also includes: Statistical parameters of the lightweight object detection network model, F1 value, mean average precision and the number of images processed per second by the model; where the number of parameters is the total number of parameters in the lightweight object detection network model, and the F1 value is calculated using the following expression according to the precision rate and recall rate, , , , In the formula, P is the precision rate, R is the recall rate, TP is the number of correctly predicted positive examples, FP is the number of incorrectly predicted positive examples, and FN is the number of incorrectly predicted negative examples.

10. A lightweight cloth defect detection method deployable on an embedded device according to claim 1, characterized in that: Train iteratively until the loss curve of the lightweight object detection network model tends to be flat in the direction of minimizing the loss value, including: Use the gradient descent strategy with a momentum term of 0.937 for optimization, and set the initial learning rate to 0.01.

Citation Information

Patent Citations

  • Tobacco shred impurity detection identification method based on YOLOV7 target detection algorithm

    CN115410077A

  • Sheldrake gender classification and identification method based on target detection and classification network

    CN115471871A