An image optimization method and optimization system based on YOLOv5 network model
Through lightweight improvements and channel pruning of the YOLOv5 network model, the problem of low detection accuracy and limited computing power of hardware devices in facial expression recognition in complex environments has been solved, achieving efficient recognition effects and applicability.
Patent Information
- Application Number
- CN202311862633.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-29
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2043-12-29
AI Technical Summary
Existing facial expression recognition methods have low detection accuracy in complex environments, and cannot operate properly when hardware devices have limited computing power, resulting in poor detection results.
The image optimization method based on the YOLOv5 network model is adopted, and lightweight improvements are made to the model, including replacing the C3 module with the C3-faster module, introducing the GSConvns module, constructing the VOV-GSCSP module, and performing channel pruning and fine-tuning on the model to reduce calculations quantity and parameter quantity while maintaining recognition accuracy.
It achieves a high recognition accuracy while reducing operating pressure, is suitable for hardware devices with a variety of performances, and greatly reduces the amount of calculation and parameters through model channel pruning. At the same time, the average accuracy is small, and low-loss pruning is achieved.
Smart Images

Figure CN117744745B
Abstract
Description
Technical Field
[0001] The present application relates to the field of machine vision and deep learning technology, and specifically to an image optimization method and optimization system based on a YOLOv5 network model. Background Art
[0002] With the rapid development of machine learning and machine vision technology, facial expression recognition is a hot research topic today. By recognizing facial expressions, many human characteristics can be identified.
[0003] There are many relatively mature expression recognition methods at present, such as local binary pattern (LBP), histogram of oriented gradients (HOG), Gabor wavelet transform, etc. First, facial features are manually extracted to obtain the gradient features of the sample to realize the detection of facial expressions.
[0004] However, in the prior art, although various methods can be used to acquire and recognize facial expressions, when the person being detected is in a complex environment, traditional methods will have problems with detection accuracy, resulting in poor detection results. In addition, most methods require a lot of computing power resources for face recognition, and when the computing power of the hardware equipment is limited, it usually cannot proceed normally.
[0005] Therefore, it is necessary to provide an image optimization method and optimization system based on the YOLOv5 network model to solve the above problems.
[0006] It should be noted that the above information disclosed in this background technology section is only for understanding the background technology of the present application concept, and therefore, it may contain information that does not constitute the prior art. Summary of the invention
[0007] Based on the above problems existing in the prior art, the problem to be solved by the present application is: to provide an image optimization method and optimization system based on the YOLOv5 network model, so as to achieve the effect of lightweight improvement of the model and improve operating efficiency.
[0008] The technical solution adopted by the present application to solve the technical problem is: an image optimization method based on the YOLOv5 network model, the method comprising:
[0009] Receiving a first image set collected from a collection device, the first image set including at least three types of driver expression pictures;
[0010] Preprocessing the first image set, and preparing the preprocessed images into a standard data set, the standard data set including a training set, a validation set, and a test set;
[0011] The original YOLOv5 network model is used to train the standard data set, and the training parameters are adjusted during the training process to improve the training effect;
[0012] Analyze the network structure and make lightweight improvements to the backbone network part of the original YOLOv5 network model.
[0013] During the implementation of the technical solution of the present application, the model is lightweighted to reduce the operating pressure while ensuring that the model performance loss is small, thereby maintaining a high recognition accuracy rate and being suitable for hardware devices with various performances.
[0014] Furthermore, the backbone network of the original YOLOv5 network model is light-weighted and improved, including:
[0015] The FasterNet Block in the FasterNet network is used to replace the Bottleneck module in the C3 module that affects the calculation amount and parameter amount of the overall model to form the C3-faster module.
[0016] Furthermore, the FasterNet Block consists of a partial convolutional layer (PConv) and two 1×1 convolutional layers, wherein the partial convolutional layer (PConv) performs regular convolution on only part of the input channels.
[0017] Furthermore, the method also includes:
[0018] Introduce the GSConv module, improve the GSConv module, generate the GSConvns module, and replace some convolution modules in the YOLOv5 network model with the GSConvns module;
[0019] Construct the VOV-GSCSP module based on the GSConvns module to replace the C3 module in the neck network of the YOLOv5 network model;
[0020] Perform model channel pruning on the lightweight YOLOv5 model;
[0021] Fine-tune the pruned model to compensate for the performance loss caused by the pruning operation.
[0022] Furthermore, the construction method of the GSConvns module is as follows:
[0023] After concatenating the output results of the two convolutions of the GSConv module, a convolution module and an activation function are used to replace the shuffle operation in the GSConv module to form a GSConvns module, and a convolution layer and an activation function are added at the same time.
[0024] Furthermore, model channel pruning of the lightweight YOLOv5 model further includes:
[0025] First, the overall model is sparsely trained to distinguish different channels in order to identify redundant channels;
[0026] A scaling factor is introduced into the BN layer in the convolution module of the network model. The output of each channel is positively correlated with the channel factor, and the channel identification and screening are performed based on the size of the scaling factor.
[0027] The scaling factors of some channels in the BN layer are made to approach zero, and the channels that approach zero are pruned.
[0028] Furthermore, the iterative process of the BN layer includes the following formula:
[0029]
[0030]
[0031]
[0032]
[0033] where μ B and σ B is the mean and standard deviation of the input, m is the current mini-batch size, and ε is the regularization parameter added to prevent the standard deviation from being zero. Reconstruct the input to get Z out , β is the bias term, γ is the scaling factor introduced by the BN layer, and the output of each channel is positively correlated with the scaling factor, so channel identification and screening can be performed by the size of the scaling factor.
[0034] An image optimization system based on a YOLOv5 network model, the system comprising:
[0035] An image receiving module, used for receiving a first image set collected from a collection device, the first image set comprising at least three types of driver expression pictures;
[0036] A preprocessing module, used to preprocess the first image set and make the preprocessed images into a standard data set, where the standard data set includes a training set, a validation set and a test set;
[0037] The training module is used to train the standard data set using the original YOLOv5 network model and adjust the training parameters during the training process to improve the training effect;
[0038] The network structure analysis module is used to analyze the network structure and make lightweight improvements to the backbone network part of the original YOLOv5 network model.
[0039] Furthermore, the system also includes:
[0040] Model improvement module, which is used to introduce and improve the GSConv module, generate the GSConvns module, and replace some convolution modules in the YOLOv5 network model with the GSConvns module;
[0041] Replacement module, used to construct VOV-GSCSP module based on GSConvns module to replace C3 module in the neck network of YOLOv5 network model;
[0042] Channel pruning module, used to prune the model channels of the lightweight YOLOv5 model;
[0043] The fine-tuning module is used to fine-tune the pruned model to compensate for the performance loss caused by the pruning operation.
[0044] The beneficial effects of the present application are as follows: the present application provides an image optimization method and optimization system based on the YOLOv5 network model, which reduces the operating pressure while ensuring a small loss in model performance by lightweight settings of the model, thereby maintaining a high recognition accuracy rate, and is suitable for hardware devices of various performances. The overall model is pruned through model channels, and the amount of model calculation and parameters is greatly reduced while the average accuracy is small, thereby achieving low-loss pruning.
[0045] In addition to the above-described purposes, features and advantages, the present application also has other purposes, features and advantages. The present application will be further described in detail with reference to the drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The drawings in the specification, which constitute a part of the present application, are used to provide further understanding of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute improper limitations on the present application.
[0047] In the attached picture:
[0048] Figure 1 This is a schematic diagram of the overall process of an image optimization method based on the YOLOv5 network model in this application;
[0049] Figure 2 This is a schematic diagram of the comparison of indicators before and after improvement;
[0050] Figure 3 This is a module diagram of an image optimization system based on the YOLOv5 network model in this application. DETAILED DESCRIPTION
[0051] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0052] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.
[0053] Embodiment 1:
[0054] like Figure 1 As shown, the present application provides an image optimization method based on the YOLOv5 network model, which is used to optimize the facial expression images generated by the driver during driving. In this field, the driver's attention, fatigue, stress and emotional state can be understood by analyzing the driver's facial expression images, and the driver's behavior analysis and monitoring can be realized. The driver can be identified and authenticated, and the driving environment can be intelligently adjusted by analyzing the driver's facial expression images. In this embodiment, the specific purpose is not limited, and only the image optimization process is described. Specifically, the method includes the following steps:
[0055] Step S1: receiving a first image set collected from a collection device, the first image set including at least three types of driver expression pictures;
[0056] Among them, the three types of driver expression pictures are happy, neutral and painful, and the three types of expression pictures can reflect the three driving states of the driver. It should be noted that there are multiple groups of the three types of driver expression pictures, and multiple groups of pictures of the same type constitute an image set of one type;
[0057] The acquisition device may be a vehicle-mounted camera or a road camera, which is not limited in this embodiment;
[0058] Step S2: preprocessing the first image set, and making the preprocessed images into a standard data set, where the standard data set includes a training set, a validation set, and a test set;
[0059] After obtaining the first image set consisting of the driver's expression pictures, it is necessary to preprocess them and generate a training set, a validation set and a test set, wherein the ratio of the training set, the validation set and the test set is 8:1:1. Specifically, the method for preprocessing the first image set can refer to the prior art, or refer to the method for processing the image in the Chinese invention patent with publication number CN115512331A, which will not be repeated in this embodiment;
[0060] The preprocessed first image set is divided into training set, validation set and test set. These separated standard data sets can be used for training the YOLO network.
[0061] Step S3: Use the original YOLOv5 network model to train the standard data set, and adjust the training parameters during the training process to improve the training effect;
[0062] The YOLOv5 network model is a target detection algorithm, which is the latest version of the YOLO (You Only Look Once) series. The model adopts a single-stage target detection algorithm, that is, a single forward propagation can complete the target detection task. Its core idea is to divide the image into grids, predict the bounding box and category of the target in each grid, and use a convolutional neural network to achieve real-time target detection. It is an efficient, accurate and easy-to-use target detection algorithm, suitable for various target detection scenarios, such as intelligent monitoring, autonomous driving, industrial detection, etc. In this embodiment, training of standard data sets can be achieved;
[0063] Step S4: Analyze the network structure and make lightweight improvements to the backbone network part of the original YOLOv5 network model;
[0064] The YOLOv5 network model includes a backbone network and a C3 module. The performance of the target detection algorithm depends largely on the selected backbone network. The backbone network is a deep convolutional neural network responsible for extracting features from the input image. These features will be used for subsequent target detection tasks, while the C3 module is a special module in the YOLOv5 network model for extracting image features. It consists of a series of convolutional layers and residual connections. The main purpose of the C3 module is to increase the depth of the network, thereby improving the representation ability of features. The structure of the C3 module is similar to the residual block, but there are some differences. It contains two consecutive convolutional layers and a residual connection. In the C3 module, the output of the first convolutional layer is added to the input instead of directly performing a residual connection, thereby achieving the effect of increasing the nonlinear expression ability of the network;
[0065] FasterNet is an efficient backbone network designed specifically for target detection tasks and optimized for speed and accuracy. FasterNet consists of multiple groups of FasterNet Blocks and is a lightweight backbone network.
[0066] In this embodiment, the C3-faster module is formed by combining FasterNet Block with the C3 module in the YOLOv5 network to replace the original C3 module, thereby reducing the parameter amount and calculation amount of the backbone network part. Specifically, the Bottleneck module in the C3 module that affects the calculation amount and parameter amount of the overall model is replaced by the FasterNet Block in the FasterNet network to form a C3-faster module;
[0067] The FasterNet Block consists of a partial convolution layer (PConv) and two 1×1 convolution layers. The partial convolution layer (PConv) performs regular convolution on only some input channels to extract spatial features while keeping the remaining channels unchanged, effectively reducing model calculation redundancy and improving algorithm efficiency.
[0068] The calculation formulas for the amount of computation of ordinary convolution and PConv are as follows:
[0069] FLOPs = h × w × k 2 ×c 2
[0070]
[0071] Where h, w, c represent the height, width and number of channels, k is the filter, c p Represents the network channel of PConv. It can be calculated by the formula that when c p When / c=1 / 4, the computational complexity of PConv is only 1 / 16 of that of ordinary convolution, thus achieving lightweight and improving algorithm efficiency;
[0072] Step S5: Introduce the GSConv module, improve the GSConv module, generate the GSConvns module, and replace some convolution modules in the YOLOv5 network model with the GSConvns module;
[0073] The GSConv module is a variant module used in convolutional neural networks (CNNs) and is often used in target detection;
[0074] The GSConv module is mainly composed of a standard convolution and a depth-wise separable convolution. After splicing the output results of the two convolutions of the GSConv module, a convolution module and an activation function are used to replace the shuffle operation in the GSConv module to form a GSConvns module. At the same time, adding convolution layers and activation functions helps to introduce nonlinearity and better capture and represent complex features in the data.
[0075] Then, some convolution modules in the original YOLOv5 network are replaced with GSConvns modules. By replacing the shuffle operation, the number of model parameters and the amount of computation are reduced, making the model more friendly to mobile hardware with limited computing resources.
[0076] Among them, in the GSConvns module, the calculation formula for the calculation amount of ordinary convolution and depth-separable convolution is:
[0077] GFLOPs = W × H × K × K × C 1 ×C 2
[0078] GFLOPs 1 =W×H×K×K×C 1 +W×H×1×1×C 1 ×C 2
[0079] Compared with ordinary convolution, the computational complexity of depth-separable convolution is reduced. The calculation process is:
[0080]
[0081] Step S6: construct a VOV-GSCSP module based on the GSConvns module to replace the C3 module in the neck network of the YOLOv5 network model;
[0082] The VOV-GSCSP module is constructed based on the GSConvns module. Its structure is a lightweight module consisting of the GSConvns module and the standard convolution module. This module is used to replace the C3 module in the neck network of the YOLOv5 network model, which reduces the complexity of the model while speeding up the reasoning speed and improving the accuracy.
[0083] Step S7: Pruning the model channel of the lightweight designed YOLOv5 model;
[0084] After the above steps, the YOLOv5 model undergoes a series of replacements to achieve lightweight. However, in actual application, there are still a large number of parameters and calculations, so further optimization is required. In this embodiment, the model channel pruning is performed on the YOLOv5 model after lightweight design to improve the reasoning speed and performance of the model. Specifically, the model channel pruning of the YOLOv5 model after lightweight design further includes:
[0085] Step 701: firstly, sparse training is performed on the overall model to distinguish different channels so as to identify redundant channels;
[0086] Sparse training is a technique used to reduce the number of model parameters, further reducing the size and computation of the model by identifying and removing redundant channels;
[0087] Step 702: introducing a scaling factor into the BN layer in the convolution module in the network model, the output of each channel is positively correlated with the channel factor, and channel identification and screening are performed according to the size of the scaling factor;
[0088] Batch Normalization (BN) is a commonly used regularization technique for deep learning models. It is used to accelerate network training and improve the robustness and generalization ability of the model. The main idea of BN is to normalize the input data of each batch so that its mean is close to 0 and its standard deviation is close to 1. This can reduce the internal covariate shift problem in the middle layer of the network and make the network easier to train.
[0089] Step 703: Make the scaling factors of some channels of the BN layer approach zero, and perform pruning operations on the channels approaching zero;
[0090] After sparse training, the scaling factors of some channels in the BN layer will tend to 0, which means that these channels will have almost no effect on the subsequent output, so these channels are pruned;
[0091] Among them, the BN layer iteration process is:
[0092]
[0093]
[0094]
[0095]
[0096] where μ B and σ Bis the mean and standard deviation of the input, m is the current mini-batch size, and ε is the regularization parameter added to prevent the standard deviation from being zero. Reconstruct the input to get Z out , the calculation formula is as follows, β is the bias term, γ is the scaling factor introduced by the BN layer, and the output of each channel is positively correlated with the scaling factor, so channel identification and screening can be performed by the size of the scaling factor.
[0097] Step S8: fine-tune the pruned model to compensate for the performance loss of the model caused by the pruning operation;
[0098] After pruning the model, although the model parameters are not adjusted, the pruning operation will cause a certain degree of change to the network structure of the original model. Therefore, the pruned network model will have some performance losses. After fine-tuning, the model performance can be compensated and nearly lossless pruning can be achieved.
[0099] Specifically, the fine-tuning operation of the pruned model can refer to the Chinese invention patent with publication number CN113762505B, which will not be repeated in this embodiment;
[0100] like Figure 2 Shown is a comparison chart of indicators before and after improvement.
[0101] Embodiment 2:
[0102] like Figure 3 As shown, this embodiment discloses an image optimization system based on a YOLOv5 network model, the system runs the optimization method in embodiment 1, and the system includes:
[0103] An image receiving module, used for receiving a first image set collected from a collection device, the first image set comprising at least three types of driver expression pictures;
[0104] A preprocessing module, used to preprocess the first image set and make the preprocessed images into a standard data set, where the standard data set includes a training set, a validation set and a test set;
[0105] The training module is used to train the standard data set using the original YOLOv5 network model and adjust the training parameters during the training process to improve the training effect;
[0106] The network structure analysis module is used to analyze the network structure and make lightweight improvements to the backbone network of the original YOLOv5 network model.
[0107] Model improvement module, which is used to introduce and improve the GSConv module, generate the GSConvns module, and replace some convolution modules in the YOLOv5 network model with the GSConvns module;
[0108] Replacement module, used to construct VOV-GSCSP module based on GSConvns module to replace C3 module in the neck network of YOLOv5 network model;
[0109] Channel pruning module, used to prune the model channels of the lightweight YOLOv5 model;
[0110] The fine-tuning module is used to fine-tune the pruned model to compensate for the performance loss caused by the pruning operation.
[0111] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.
Claims
1. An image optimization method based on the YOLOv5 network model, characterized in that: The method includes: Receiving a first image set collected from a collection device, the first image set including at least three types of driver expression pictures; Preprocessing the first image set, and making the preprocessed images into a standard data set, the standard data set including a training set, a validation set, and a test set; The original YOLOv5 network model is used to train the standard data set, and the training parameters are adjusted during the training process to improve the training effect; Analyze the network structure and make lightweight improvements to the backbone network of the original YOLOv5 network model; the method also includes: Introduce the GSConv module, improve the GSConv module, generate the GSConvns module, and replace some convolution modules in the YOLOv5 network model with the GSConvns module; Construct the VOV-GSCSP module based on the GSConvns module to replace the C3 module in the neck network of the YOLOv5 network model; Perform model channel pruning on the lightweight YOLOv5 model; Fine-tune the pruned model to compensate for the performance loss caused by the pruning operation; The construction method of the GSConvns module is: After concatenating the output results of the two convolutions of the GSConv module, a convolution module and an activation function are used to replace the shuffle operation in the GSConv module to form a GSConvns module, and a convolution layer and an activation function are added at the same time.
2. An image optimization method based on the YOLOv5 network model according to claim 1, characterized in that: The lightweight improvements to the backbone network of the original YOLOv5 network model include: The FasterNet Block in the FasterNet network is used to replace the Bottleneck module in the C3 module that affects the calculation amount and parameter amount of the overall model to form the C3-faster module.
3. An image optimization method based on the YOLOv5 network model according to claim 2, characterized in that: The FasterNet Block consists of a partial convolutional layer (PConv) and two 1×1 convolutional layers, where the partial convolutional layer (PConv) performs regular convolution on only part of the input channels.
4. The image optimization method based on the YOLOv5 network model according to claim 1, characterized in that: Model channel pruning for the lightweight YOLOv5 model further includes: First, the overall model is sparsely trained to distinguish different channels in order to identify redundant channels; A scaling factor is introduced into the BN layer in the convolution module of the network model. The output of each channel is positively correlated with the channel factor, and the channel identification and screening are performed based on the size of the scaling factor. The scaling factors of some channels in the BN layer are made to approach zero, and the channels that approach zero are pruned.
5. The image optimization method based on the YOLOv5 network model according to claim 4, characterized in that: The iterative process of the BN layer includes the following formula: where μ B and σ B is the mean and standard deviation of the input, m is the current mini-batch size, and ε is the regularization parameter added to prevent the standard deviation from being zero. Reconstruct the input to get Z out , β is the bias term, γ is the scaling factor introduced by the BN layer, and the output of each channel is positively correlated with the scaling factor, so channel identification and screening can be performed by the size of the scaling factor.
6. An image optimization system based on the YOLOv5 network model, characterized in that: The system includes: An image receiving module, used for receiving a first image set collected from a collection device, the first image set comprising at least three types of driver expression pictures; A preprocessing module, used to preprocess the first image set and make the preprocessed images into a standard data set, where the standard data set includes a training set, a validation set and a test set; The training module is used to train the standard data set using the original YOLOv5 network model and adjust the training parameters during the training process to improve the training effect; The network structure analysis module is used to analyze the network structure and make lightweight improvements to the backbone network of the original YOLOv5 network model. The system also includes: Model improvement module, which is used to introduce and improve the GSConv module, generate the GSConvns module, and replace some convolution modules in the YOLOv5 network model with the GSConvns module; Replacement module, used to construct VOV-GSCSP module based on GSConvns module to replace C3 module in the neck network of YOLOv5 network model; Channel pruning module, used to prune the model channels of the lightweight YOLOv5 model; The fine-tuning module is used to fine-tune the pruned model to compensate for the performance loss caused by the pruning operation. The construction method of the GSConvns module is: After concatenating the output results of the two convolutions of the GSConv module, a convolution module and an activation function are used to replace the shuffle operation in the GSConv module to form a GSConvns module, and a convolution layer and an activation function are added at the same time.
