A tool detection method, system, and storage medium
By performing data augmentation on the training set and combining it with an improved ECA mechanism and a Yolov5s model, and using an improved QFocalLoss loss function to optimize parameters, the problems of low robustness and accuracy in tooling detection were solved, achieving higher detection accuracy and robustness.
Patent Information
- Application Number
- CN202311251930.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-26
- Publication Date
- 2026-02-06
- Estimated Expiration
- 2043-09-26
AI Technical Summary
In existing tooling detection methods, the training set is not processed for resolution and scale transformation, the neural network model is not combined with ECA mechanism and the loss function is not improved, resulting in low robustness and accuracy of tooling detection.
By augmenting the training set with data, combining an improved ECA mechanism and the Yolov5s model, and using an improved QFocalLoss loss function to optimize model parameters, we enhance feature extraction and adjust model parameters.
It improves the detection accuracy and robustness of the tooling inspection model, enhances the model's ability to represent complex scenes and small targets, and improves the prediction performance for a few categories.
Smart Images

Figure CN117315439B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer vision, in particular to a tool detection method, system and storage medium. BACKGROUND
[0002] With the development of modern society, the park is an important place for a large number of enterprise and institution personnel to work, in some special park, such as high-precision instrument assembly workshop and hospital critical patient care room, if the staff do not wear the tool as required, not only the work can not be carried out, but also the work environment will be damaged, so the park has very strict requirements on whether the staff wear the tool, at present, most of the methods for detecting whether the worker wears the tool are based on deep learning, which has some problems, the training set used for training the neural network model is not modified in resolution and scale transformation, resulting in low robustness and accuracy of tool detection; the neural network model does not combine the ECA mechanism or combines the traditional ECA mechanism, resulting in low accuracy of tool detection; the neural network model does not improve the loss function, resulting in that the parameters of the neural network model are not optimal, resulting in low accuracy of tool detection.
[0003] The prior art discloses a clothing attribute recognition detection method based on a deep learning target detection algorithm, which comprises the following steps: labeling and classifying an original clothing image to obtain the attributes of the clothing, such as sleeves and collars; and then performing preprocessing such as flipping and translation on the clothing picture, and then using a deep learning-based target detection algorithm to recognize and detect the clothing attributes.
[0004] The preprocessing of the clothing picture refers to labeling the position of the clothing attribute of the picture and classifying it, and then using a traditional image algorithm to flip and translate the picture to achieve the effect of data augmentation. The clothing attribute recognition detection method based on the deep learning-based target detection algorithm is characterized in that: a deep convolutional neural network is used to fully extract the clothing attribute features, then a target detection algorithm feature pyramid is used to fuse the multi-layer features, and finally a full convolutional neural network is used to recognize and detect the clothing attributes. The prior art does not modify the resolution and scale transformation of the training set, resulting in low robustness and accuracy of tool detection; the neural network model does not combine the ECA mechanism or combines the traditional ECA mechanism, resulting in low accuracy of tool detection; the neural network model does not improve the loss function, resulting in that the parameters of the neural network model are not optimal, resulting in low accuracy of tool detection. SUMMARY
[0005] The purpose of the present application is to overcome the defects of the prior art, provide a tool detection method, system and storage medium, which can improve the robustness and accuracy of tool detection.
[0006] In order to achieve the above object, the present application provides a tool detection method, comprising:
[0007] Step S1: obtaining a data set;
[0008] Step S2: preprocessing the data set to obtain a training set and a validation set;
[0009] Step S3: performing data enhancement processing on the training set to obtain a processed training set;
[0010] Step S4: training an initial tool detection network model using the processed training set to obtain a trained tool detection network model, wherein the initial tool detection model is determined by combining an improved ECA mechanism and a Yolov5s model, and the improved ECA mechanism adds a convolution branch to the original convolution branch;
[0011] Step S5: optimizing the parameters of the trained tool detection network model using an improved QFocalLoss loss function to obtain an optimized tool detection model, wherein the improved QFocalLoss loss function is determined by the following formula:
[0012]
[0013] wherein, represents a loss function; represents a calculation factor of the improved focal loss function, a calculation factor of the focal loss function, a calculation factor of the focal loss function, which is determined by the following formula:
[0014]
[0015] wherein, represents a parameter in the focal loss function; represents a real label;
[0016] Step S6: performing data enhancement processing on the validation set to obtain a processed validation set, verifying the optimized tool detection model using the processed validation set to obtain a final tool detection model;
[0017] Step S7: inputting an image to be detected into the final tool detection model to obtain a detection result.
[0018] Further, the data set of step S1 includes tool pictures and other clothing pictures.
[0019] Further, the specific process of step S2 includes:
[0020] Step S2.1: labeling the tool picture with tool labels and labeling the other clothing pictures with other clothing labels;
[0021] Step S2.2: dividing the labeled pictures into a training set and a verification set in a ratio of 8:2.
[0022] Further, the data enhancement processing in step S3 adopts at least one of random scaling, up-down flipping, adding mosaics, modifying resolution, and scale transformation.
[0023] Further, the present application also provides a tool detection system, characterized in comprising:
[0024] an acquisition module for acquiring a data set;
[0025] a preprocessing module for preprocessing the data set to obtain a training set and a verification set;
[0026] a data enhancement processing module for performing data enhancement processing on the training set to obtain a processed training set;
[0027] a training module for training an initial tool detection network model using the processed training set to obtain a trained tool detection network model, wherein the initial tool detection model is determined by combining an improved ECA mechanism and a Yolov5s model, and the improved ECA mechanism adds a convolution branch to the original convolution branch;
[0028] an optimization module for optimizing the parameters of the trained tool detection network model using an improved QFocalLoss loss function to obtain an optimized tool detection model, wherein the improved QFocalLoss loss function is determined by the following formula:
[0029]
[0030] wherein, represents a loss function; represents a calculation factor of the improved focal loss function, a calculation factor of the focal loss function, a calculation factor of the focal loss function, which is determined by the following formula:
[0031]
[0032] wherein, represents a parameter in the focal loss function; represents a real label;
[0033] The verification module is used for data enhancement processing on the verification set to obtain a processed verification set, and the processed verification set is used to verify the optimized tool detection model to obtain a final tool detection model.
[0034] The detection module inputs an image to be detected into the final tool detection model to obtain a detection result.
[0035] Finally, the application further provides a computer readable storage medium, which stores a computer program of a tool detection method.
[0036] Compared with the prior art, the application has the beneficial effects that:
[0037] The application improves the detection accuracy and robustness of the tool detection model by data enhancement processing on the training set. BRIEF DESCRIPTION OF DRAWINGS
[0038] Figure 1 is a flowchart of a tool detection method according to an embodiment of the application;
[0039] Figure 2 is a block diagram of a tool detection system according to an embodiment of the application;
[0040] Figure 3 is a mosaic processing example diagram of a tool detection method according to an embodiment of the application;
[0041] Figure 4 is a comparison diagram of an improved QFocalLoss loss function and a QFocalLoss loss function accuracy of a tool detection method according to an embodiment of the application;
[0042] Figure 5 is a comparison diagram of an improved ECA attention mechanism and a traditional ECA attention mechanism box_loss of a tool detection method according to an embodiment of the application;
[0043] Figure 6 is a comparison diagram of an improved ECA attention mechanism and a traditional ECA attention mechanism training accuracy of a tool detection method according to an embodiment of the application;
[0044] Figure 7 is a tool detection model structure diagram of a tool detection method according to an embodiment of the application;
[0045] Figure 8 Figure 1 is a training result comparison chart of a tool detection method according to an embodiment of the present application. DETAILED DESCRIPTION
[0046] The specific embodiments of the present application will be further described in detail below with reference to the accompanying drawings and examples. The following examples are used to illustrate the present application, but are not used to limit the scope of the present application.
[0047] Example 1
[0048] As shown in Figure 1 , the tool detection method according to the preferred embodiment of the present application comprises:
[0049] Step S1: obtaining a data set;
[0050] Step S2: preprocessing the data set to obtain a training set and a validation set;
[0051] Step S3: performing data enhancement processing on the training set to obtain a processed training set;
[0052] Step S4: training an initial tool detection network model using the processed training set to obtain a trained tool detection network model;
[0053] Step S5: optimizing the parameters of the trained tool detection network model using an improved QFocalLoss loss function to obtain an optimized tool detection model;
[0054] Step S6: performing data enhancement processing on the validation set to obtain a processed validation set, verifying the optimized tool detection model using the processed validation set, and obtaining a final tool detection model;
[0055] Step S7: inputting an image to be detected into the final tool detection model to obtain a detection result.
[0056] The present application improves the detection accuracy and robustness of the tool detection model by performing data enhancement processing on the training set. The present application also enhances the ability of the model to extract features by combining the improved ECA mechanism and the Yolov5s model to form an initial tool detection model. The present application also improves the QFocalLoss loss function and optimizes the model using the improved QFocalLoss loss function to adjust the parameters of the model, thereby improving the detection accuracy of the model.
[0057] Example 2
[0058] As shown in Figure 1 , the tool detection method according to the preferred embodiment of the present application comprises:
[0059] Step S1: obtaining a data set;
[0060] In this embodiment, 9492 pictures are obtained as the data set by a web crawler, including tooling pictures and other clothing pictures.
[0061] Step S2: preprocessing the data set to obtain a training set and a verification set;
[0062] In this embodiment, the preprocessing of the data set includes:
[0063] Step S2.1: labeling tooling labels for tooling pictures and other clothing labels for other clothing pictures;
[0064] Step S2.2: dividing the labeled pictures into the training set and the verification set according to a ratio of 8:2.
[0065] Step S3: performing data enhancement processing on the training set to obtain a processed training set;
[0066] In this embodiment, the data enhancement processing adopts at least one of random scaling, up-down flipping, adding mosaics, modifying resolution and scale transformation. The data enhancement processing can increase the diversity of the data. The processed pictures are used to train the detection model, so that the model can better detect some targets at special angles and improve the robustness of the model.
[0067] Step S4: training an initial tooling detection network model using the processed training set to obtain a trained tooling detection network model;
[0068] In the embodiment, the initial tooling detection model is determined by the improved ECA mechanism and the Yolov5s model, the ECA (Efficient Channel Attention) attention mechanism is an attention mechanism used in computer vision tasks. Traditional attention mechanisms (such as SE attention mechanisms) usually involve computing global interactions between channels, and have high computational complexity. In contrast, the ECA attention mechanism provides a more efficient alternative. The application proposes an improved ECA attention mechanism, which is based on the traditional ECA (Efficient Channel Attention) attention mechanism and further enhances the performance of the model by introducing an additional parallel convolution branch. The traditional ECA attention mechanism is a lightweight attention module that can adaptively adjust the channel weights of the convolution feature map, thereby improving the response of important information in the feature map. Although the ECA attention mechanism performs well in target detection tasks, it still has certain limitations when dealing with certain complex scenes and target scale changes. In order to further enhance the representation ability and adaptability of the model, the application introduces a parallel convolution branch, which is parallel to the original convolution branch and performs feature fusion after convolution. This design allows the model to obtain richer feature information at different scales and semantic levels, enhancing the representation ability of complex targets and small targets. At the same time, through the operation of feature fusion, the features represented by the parallel convolution branch and the ECA attention mechanism can be better integrated, thereby further improving the performance of the model,
[0069] Specifically, first, for the 1024-channel feature map input from the previous layer, a global average pooling operation is performed to obtain the global average value of each channel;
[0070] Then, a one-dimensional convolution layer is used to map the global average value to a new dimension, so that it has the same size as the original channel number;
[0071] Next, a Sigmoid activation function is used to limit the values of the new dimension to between 0 and 1, obtaining the channel attention weight;
[0072] Finally, the attention weight is multiplied by the original feature map to obtain the feature map adjusted by the channel attention, and the feature map is input into the next convolution network.
[0073] Step S5: using the improved QFocalLoss loss function to optimize the parameters of the trained tooling detection network model, obtaining an optimized tooling detection model;
[0074] In this embodiment, QFocalLoss can effectively handle the class imbalance problem in target detection by adjusting the weights of positive and negative samples and the weights of difficult and easy samples, and improve the prediction ability of the model for minority classes. It puts more attention on difficult-to-classify samples, thereby improving the prediction effect of the model for minority classes,
[0075] The traditional QFocalLoss loss function is a loss function optimized for target detection tasks, which performs well in handling class imbalance problems. However, when the class samples are severely imbalanced or there is noise, the traditional QFocalLoss may be disturbed in the convergence process. By adding more non-linear factors to QFocalLoss, the present application improves the QFocalLoss loss function. This improvement not only retains the advantages of QFocalLoss, but also further enhances the sensitivity of the loss function to different class samples. Through squaring operation, we make the loss function more smooth and stable when dealing with rare classes and noise data, which helps to optimize the training process of the model.
[0076] Specifically, the expression of QFocalLoss is as follows:
[0077]
[0078]
[0079]
[0080]
[0081] wherein is the nn.BCEWithLogitsLoss loss function for binary classification problems. It combines the sigmoid function and binary cross-entropy loss, suitable for output without activation function; is the adjustment factor in the calculation of the focal loss function, represents the parameter alpha in the focal loss function, the default value is 0.25; represents the true label. Wherein is the adjustment factor in the calculation of the focal loss function, according to the true label , the predicted probability value and the gamma parameter are calculated.
[0082] The alpha_factor in the expression is improved by adding its non-linear factor, and the improved alpha_factor is:
[0083]
[0084] wherein is a factor in calculating the improved focal loss function. .
[0085] Therefore, the improved QFocalLoss loss function is:
[0086]
[0087] Step S6: data augmentation processing is performed on the verification set to obtain a processed verification set, the processed verification set is used to verify the optimized tool detection model, and a final tool detection model is obtained.
[0088] In this embodiment, the verification set is used to verify whether the tool detection model meets the requirements.
[0089] Step S7: inputting an image to be detected into the final tool detection model to obtain a detection result.
[0090] In this embodiment, the detection result can be obtained by only inputting the image to be detected into the tool detection model.
[0091] The present application improves the detection accuracy and robustness of the tool detection model by performing data augmentation processing on the training set; the present application also enhances the feature extraction capability of the model by combining the improved ECA mechanism and the Yolov5s model to form an initial tool detection model, the present application also improves the QFocalLoss loss function, and uses the improved QFocalLoss loss function to optimize the model, adjusts the parameters of the model, thereby improving the detection accuracy of the model.
[0092] Embodiment three
[0093] The embodiment also provides a computer readable storage medium, which stores a computer program of a tool detection method, and the computer program of the tool detection method is processed to realize the steps of the tool detection method.
[0094] In summary, the present application improves the detection accuracy and robustness of the tool detection model by performing data augmentation processing on the training set; the present application also enhances the feature extraction capability of the model by combining the improved ECA mechanism and the Yolov5s model to form an initial tool detection model, the present application also improves the QFocalLoss loss function, and uses the improved QFocalLoss loss function to optimize the model, adjusts the parameters of the model, thereby improving the detection accuracy of the model.
[0095] The above merely describes the preferred embodiments of the present application, and it should be pointed out that, for those skilled in the art, several improvements and replacements can be made without departing from the technical principles of the present application, and these improvements and replacements should also be considered as the protection scope of the present application.
Claims
1. A tooling inspection method, characterized in that, include: Step S1: Obtain the dataset; Step S2: Preprocess the dataset to obtain the training set and validation set; Step S3: Perform data augmentation on the training set to obtain the processed training set; Step S4: Train the initial tooling detection network model using the processed training set to obtain the trained tooling detection network model. The initial tooling detection model is determined by combining the improved ECA mechanism and the Yolov5s model. The improved ECA mechanism adds a convolutional branch to the original convolutional branch. Step S5: Optimize the parameters of the trained tooling detection network model using the improved QFocalLoss loss function to obtain the optimized tooling detection model. The improved QFocalLoss loss function is determined by the following formula: in, express Loss function; This indicates the calculation of the improved focus loss function. factor; This represents the adjustment factor in the calculation of the focus loss function. Determined by the following formula: in, Represents the parameters in the focus loss function ; Indicates the true label; Step S6: Perform data augmentation processing on the validation set to obtain the processed validation set. Use the processed validation set to verify the optimized tooling detection model to obtain the final tooling detection model. Step S7: Input the image to be detected into the final tooling detection model to obtain the detection result.
2. The tooling inspection method according to claim 1, characterized in that, The dataset mentioned in step S1 contains images of workwear and other clothing.
3. The tooling inspection method according to claim 2, characterized in that, The specific process of step S2 includes: Step S2.1: Label the workwear image with a workwear label, and label the other clothing images with other clothing labels; Step S2.2: Divide the labeled images into training and validation sets in an 8:2 ratio.
4. The tooling inspection method according to claim 3, characterized in that, The data augmentation process described in step S3 employs at least one of the following: random scaling, flipping, adding mosaic, modifying resolution, and scaling transformation.
5. A tooling inspection system, characterized in that, include: Acquisition module: Used to acquire datasets; Preprocessing module: used to preprocess the dataset to obtain the training set and validation set; Data augmentation processing module: used to perform data augmentation processing on the training set to obtain the processed training set; Training module: used to train the initial tool detection network model using the processed training set, and obtain the trained tool detection network model. The initial tool detection model is determined by combining the improved ECA mechanism and the Yolov5s model. The improved ECA mechanism adds a convolutional branch to the original convolutional branch. Optimization module: Used to optimize the parameters of the trained tooling detection network model using the improved QFocalLoss loss function, resulting in an optimized tooling detection model. The improved QFocalLoss loss function is determined by the following formula: in, express Loss function; This indicates the calculation of the improved focus loss function. factor; This represents the adjustment factor in the calculation of the focus loss function. Determined by the following formula: in, Represents the parameters in the focus loss function ; Indicates the true label; Verification module: used to perform data augmentation processing on the verification set to obtain a processed verification set, and use the processed verification set to verify the optimized tooling inspection model to obtain the final tooling inspection model; Detection module: Inputs the image to be detected into the final tooling detection model to obtain the detection result.
6. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer stored program is executed by the processor, it implements the tooling inspection method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Improved Scaled-YOLOv4 fabric defect detection method
CN114549507A
Communication maintenance tool identification method based on YOLO V5
CN114972888A
Factory tooling detection method and system based on neural network target detection
CN115131339A