A method for detecting violations based on improved YOLOv8n
By improving the YOLOv8n network and introducing a feature fusion module with channel rearrangement and attention mechanisms, the problem of difficult identification of small targets in the cigarette packaging workshop was solved, thus improving detection accuracy and recognition precision.
Patent Information
- Application Number
- CN202310877673.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-07-18
- Publication Date
- 2025-12-26
- Estimated Expiration
- 2043-07-18
AI Technical Summary
In the cigarette packaging workshop, there are many pieces of equipment, complex image backgrounds, and cameras installed at high positions, making it difficult to identify small targets. Existing YOLO series detection algorithms have poor recognition performance, especially for some categories.
The YOLOv8n network is improved by introducing a channel rearrangement mechanism and an attention mechanism to construct a feature fusion module, replacing the original C2f module and splicing module, thereby enhancing the feature extraction capability.
It improves the accuracy of small target recognition and overall detection precision, and solves the problem of YOLOv8n's difficulty in recognizing targets in complex backgrounds.
Smart Images

Figure FDA0004343268820000021 
Figure FDA0004343268820000022 
Figure FDA0004343268820000023
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the field of deep learning computer vision, and particularly relates to a method for detecting illegal behavior based on improved YOLOv8n. BACKGROUND
[0002] The production equipment and important production instruments in the park are gradually increasing, and safety production has become the most important problem at present.
[0003] Deep learning target detection algorithm is divided into two-stage target detection and single-stage target detection, two-stage target detection is slow and difficult to train. Single-stage target detection algorithm is divided into YOLO series and SSD series, YOLO series uses regression algorithm to regress the position of prior box and the category of the last feature map, SSD series uses different scale feature maps to detect different scale targets. YOLO series has fast detection speed, simple training and can realize real-time detection, so it is widely used and has become the most popular detection framework at present. This paper takes the latest version YOLOv8n of YOLO series as the basis network and improves it. SUMMARY
[0004] 1. Invention purpose:
[0005] Due to the large number of equipment, complex image background, and installation regulations in the cigarette factory, it is difficult to install the camera high, and small target recognition is difficult, and the recognition effect of some categories is poor.
[0006] 2. Technical scheme:
[0007] 1. A method for detecting illegal behavior based on improved YOLOv8n, characterized in that it comprises the following steps:
[0008] Step 1: use a camera to obtain a video of illegal behavior, use a video processing tool FFMPEG to decode the video into pictures, use Labelimg software to label the data set, and the label file format after labeling is txt format;
[0009] Step 2: divide the data set obtained in step 1 into training set, verification set and test set;
[0010] Step 3: The original YOLOv8n network is divided into Backbone and Head two parts, including convolution module, C2f module, SPPF module, up-sampling module and splicing module, wherein the BottleNeck module is used to construct the C2f module, and the BottleNeck module is divided into BottleNeck1 module and BottleNeck2 module; the Backbone part of YOLOv8n network uses BottleNeck1 module to construct C2f module, and Head uses BottleNeck2 module to construct C2f module; the channel rearrangement mechanism is used to improve the C2f module, and the improved C2f module is called C2fg module;
[0011] (1) BottleNeck1 module and BottleNeck2 module, including the following structure:
[0012] First, the two-dimensional convolution layer with a convolution kernel of 3, the normalization layer and the SiLU activation function are used to extract the feature values of the input feature values; then the two-dimensional convolution layer with a convolution kernel of 3, the normalization layer and the SiLU activation function are used to extract the feature values to form the intermediate feature values; the BottleNeck1 module finally uses residual connection to add the input feature values and the intermediate feature values to form the output feature values; the BottleNeck1 module formula is:
[0013] X bout1 =X bin1 +SiLU(Bn2d(Conv2d k=3 (SiLU(Bn2d(Conv2d k=3 (X bin1 ))))))
[0014] Wherein X bin1 , X bout1 represent the input and output feature values of BottleNeck1 module, Conv2d k=3 represents the two-dimensional convolution layer with a convolution kernel of 3, Bn2d(·) represents the two-dimensional normalization layer, and SiLU(•) represents the SiLU activation function;
[0015] (2) BottleNeck2 module does not use residual connection at the end, and directly outputs, BottleNeck2 module formula is:
[0016] X bout2 =SiLU(Bn2d(Conv2d k=3 (SiLU(Bn2d(Conv2d k=3 (X bin2 ))))))
[0017] Wherein X bin2 , Xbout2 represents the input and output feature values of the BottleNeck2 module;
[0018] The formula of the channel rearrangement mechanism is:
[0019] X cout = CS(X cin ) = Concat(S1, S2,... S n )
[0020] S n = Concat(L 1n , L 2n ,... L nn )
[0021] wherein X cin , X cout represent the input and output feature values of the channel rearrangement, X out is divided into n groups n = 2, the nth group of feature values of X out is S n , S n is also divided into n groups, the nth group of feature values of S n is L nn ; S n is a b x c h x w matrix, b is the Batchsize size, b ∈ (1, 16); c is the number of channels of the feature values, represents the floor function; h, w are the width and height of the feature values, h, w ∈ (20, 640), L nn is a b x c h x w matrix, b is the Batchsize size, b ∈ (1, 16); c is the number of channels of the feature values, h, w are the width and height of the feature values, h, w ∈ (20, 640); CS(·) represents the channel rearrangement operation, Concat(·) represents the concatenation operation in the channel dimension, and the operation formula of Concat is as follows:
[0022]
[0023] In the formula, X and Y are feature value maps of the channel input, X and Y are b x c h x w matrices, b is the Batchsize size, b ∈ (1, 16); c is the number of channels of the feature values, c ∈ (32, 1536); h, w are the width and height of the feature values, h, w ∈ (20, 640); k represents the number of channels of the input feature value map X, k ∈ (32, 1536), d is the number of channels of the input feature value map Y, d ∈ (32, 1536), i ∈ [1, k], j ∈ [1, d];
[0024] The C2fg module described above comprises the following structure:
[0025] First, the input feature value channel is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function, and the channel-adjusted feature values are rearranged in the channel; then, the channel dimension is divided to form feature values X1 and X2, X2 is output through n BottleNeck modules, and n e (1, 6); finally, the feature values X1 and X2 and the n output feature values are spliced in the channel to form the output feature value X3, and the X3 channel is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function to form the final output feature value X4; X1, X2, X3 and X4 are b x c h x w matrices, b is the Batchsize size, b e (1, 16); c is the number of channels of the feature value, c e (32, 1536); h and w are the width and height of the feature value, h and w e (20, 640);
[0026] Step 4: Use the idea of attention mechanism to construct a feature fusion module, which comprises the following structure:
[0027] First, the two input feature values X c1 and X c2 are channel-adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function, and the two channel-adjusted feature values are downsampled to have the same dimension to form X c3 and X c4 ; then, the two feature values are multiplied, the multiplied feature values are reduced in dimension using global average pooling, and the reduced feature values are learned using a Sigmoid activation function layer to learn two parameters a0 and a1; finally, X c4 is subjected to feature value extraction using a two-dimensional convolution layer with a convolution kernel of 3, a normalization layer, and a SiLU activation function to form X c5 , the product of X c3 and a0 is added to the product of X c5 and a1, and then the result is subjected to channel adjustment using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function to form the final output X cout ; the formula of the feature fusion module is:
[0028] X c3 = sample (SiLU (Bn2d (Conv2d k=1 (X c1 )))
[0029] X c4 = sample (SiLU (Bn2d (Conv2d k=1 (X c2))))
[0030] X c5 = SiLU(Bn2d(Conv2d k=3 (X c4 )))
[0031] a0 = Sigmod(GAP(X c3 ·X c4 ))
[0032] a1 = 1 - a0
[0033] X cout = SiLU(Bn2d(Conv2d k=1 (X c3 ⊙a0 + X c5 ⊙a1))
[0034] In the formula, X c1 , X c2 is an input feature value, X c3 , X c4 , X c5 is an intermediate feature value, X cout is an output feature value, X c1 , X c2 , X c3 , X c4 , X c5 and X cout are bxc h*w matrices, b is the Batchsize size, b∈(1, 16); c is the number of feature channels, c∈(32, 1536); h, w are the width and height of the feature value, h, w∈(20, 640); sample(·) represents a sampling operation, including up-sampling and down-sampling, a0 and a1 are channel weight parameters, both of which are bxc h*w matrices, b is the Batchsize size, b∈(1, 16); c is the number of feature channels, c∈(32, 1536); h, w are the width and height of the feature value, h=1, w=1; GAP is a global average pooling operation, and ⊙ represents channel-level multiplication;
[0035] Step 5: replace the original C2f module with the C2fg module, and replace the channel concatenation module with the feature fusion module to construct an improved YOLOv8n violation behavior detection model;
[0036] Step 6: Train the improved YOLOv8n violation behavior detection model constructed in step 5 using the training set of step 2, and verify it using the validation set; set the training parameters, set the training batch size B, B [1, 16], set the learning rate L, L (0, 1), set the momentum Momentum, Momentum (0.9, 0.95), set the training iteration number Epoch, Epoch [100, 500]; save the parameter model with the highest average accuracy rate in the validation set; save the parameter model with the highest average accuracy rate as P, P i represents the network parameters at the i-th training, mAP i represents the average accuracy rate of the i-th training, i [1, Epoch]; Map represents the highest accuracy rate; the update of P is according to the following formula:
[0037]
[0038] Step 7: After training, the parameter model with the highest average accuracy rate obtained in step 6 is imported into the network, and the test set of step 2 is used for testing.
[0039] 3. Innovation points:
[0040] Compared with the prior art, the improved YOLOv8n-based violation behavior detection method can obtain the following beneficial effects:
[0041] (1) The channel rearrangement mechanism is added to solve the problem that there is no connection between different groups, the learned features are limited, and information loss is easily caused;
[0042] (2) The feature fusion module based on attention mechanism is used instead of the Concate module, so that the feature fusion is more sufficient, and the recognition accuracy is further improved.
[0043] 4. Beneficial effects:
[0044] The improved YOLOv8n-based violation behavior detection method is disclosed, which improves the feature extraction capability and detection accuracy of the model by improving the C2f module and using the attention mechanism to construct the feature fusion module instead of the Concate module. BRIEF DESCRIPTION OF DRAWINGS
[0045] Figure 1A flowchart of a rule violation detection method based on an improved YOLOv8n, first uses a camera to collect worker rule violation video dataset, uses the FFMPEG tool to decode the video into pictures; then uses the Labelimg labeling tool for labeling, divides the labeled pictures into training set, test set and validation set; finally, input the training set and validation set into the improved YOLOv8n network for training, load the trained weight parameters, and use the validation set for detection;
[0046] Figure 2 For the channel rearrangement operation, the features are grouped in the channel dimension, and in the figure, they are divided into 3 groups in the channel dimension, each group is divided into 3 parts, and each group is rearranged, and each group of channels after rearrangement contains the corresponding part of the 3 groups before rearrangement;
[0047] Figure 3 BottleNeck module, used to deepen the network and provide more rich gradient information, including BottleNeck1 module and BottleNeck2 module, where CBS represents a unit composed of convolution, pooling and SILU activation function, and BottleNeck2 module does not use residual connection;
[0048] Figure 4 C2fg module, i.e. improved C2f module, which Figure 2 The channel rearrangement mechanism is added in front of Split, and the channel rearrangement is divided into two groups, one group is output after n BottleNeck modules, and the other group uses residual connection;
[0049] Figure 5 Feature fusion module with channel attention mechanism, YOLOv8n from different network layers has the same dimension in feature space, but different dimensions in channel, sampling operation includes upsampling and downsampling, using sampling operation to adjust the two feature dimensions to the same size, using channel attention mechanism to adjust channel weight, using convolution kernel 1 convolution to adjust channel number, realizing feature fusion;
[0050] Figure 6 Figure 1 Improved YOLOv8n model in the flowchart, including Backbone and Head two parts, using Figure 5 Feature fusion module instead of Concate module, using C2fg module instead of C2f module, C2fg module of Backbone part is constructed using BottleNeck1 module, and C2fg module of Head part is constructed using BottleNeck2 module;
[0051] Figure 7 For the detection of species and label abbreviations, the self-made cigarette factory cigarette packaging workshop worker violation detection dataset is detected for the species and labels of the dataset;
[0052] Figure 8 For the improved YOLOv8n model detection effect diagram;
[0053] Figure 9 For the improved YOLOv8n model detection confusion matrix. DETAILED DESCRIPTION
[0054] In order to make the purpose, technical scheme and beneficial effects of the present application clearer, the present application will be further described in detail below in combination with the drawings and examples. It should be understood that the specific examples described herein are only used to explain the present application and do not limit the present application, i.e. the described examples are only a part of the embodiments of the present application, but not all the embodiments.
[0055] Referring to Figure 1 , the present application provides a kind of based on the method for detecting illegal behavior of improved YOLOv8n, specific implementation is as follows:
[0056] Step 1: use the camera to obtain the video of illegal behavior, use the video processing tool FFMPEG to decode the video into pictures, adopt Labelimg software to mark the dataset, and the file format of the label after marking is txt format;
[0057] Step 2: the dataset obtained in step 1 is divided into training set, verification set and test set according to the ratio of 6:2:2;
[0058] Step 3: the original YOLOv8n network is divided into Backbone and Head two parts, including convolution module, C2f module, SPPF module, up-sampling module and splicing module, wherein BottleNeck module is used to construct C2f module, BottleNeck module is divided into BottleNeck1 module and BottleNeck2 module; YOLOv8n network Backbone part uses BottleNeck1 module to construct C2f module, Head uses BottleNeck2 module to construct C2f module; the channel rearrangement mechanism is used to improve C2f module, and the improved C2f module is called C2fg module;
[0059] (1) BottleNeck1 module and BottleNeck2 module, including the following structure:
[0060] First, the input feature values are extracted using a two-dimensional convolution layer with a convolution kernel of 3, a normalization layer, and a SiLU activation function; then the feature values are extracted using a two-dimensional convolution layer with a convolution kernel of 3, a normalization layer, and a SiLU activation function to form intermediate feature values; the BottleNeck1 module finally uses residual connection to add the input feature values and the intermediate feature values to form output feature values; the BottleNeck1 module formula is:
[0061] X bout1 = X bin1 + SiLU(Bn2d(Conv2d k=3 (SiLU(Bn2d(Conv2d k=3 (X bin1 ))))))
[0062] wherein X bin1 , X bout1 represent the input and output feature values of the BottleNeck1 module, Conv2d k=3 represents a two-dimensional convolution layer with a convolution kernel of 3, Bn2d(·) represents a two-dimensional normalization layer, and SiLU(·) represents a SiLU activation function;
[0063] (2) The BottleNeck2 module does not use residual connection at the end and directly outputs, and the BottleNeck2 module formula is:
[0064] X bout2 = SiLU(Bn2d(Conv2d k=3 (SiLU(Bn2d(Conv2d k=3 (X bin2 ))))))
[0065] wherein X bin2 , X bout2 represent the input and output feature values of the BottleNeck2 module;
[0066] The above channel rearrangement mechanism formula is:
[0067] X cout = CS(X cin ) = Concat(S1, S2,... S n )
[0068] S n = Concat(L 1n , L 2n ,... L nn )
[0069] wherein X cin , X coutdenotes the channel rearrangement input and output eigenvalues, X out is divided into n groups n = 2, X out The nth group eigenvalue of S n is divided into n groups, S n The nth group eigenvalue of S n is L nn ; S n is a bxc h x w matrix, b is the Batchsize size, b ∈ (1, 16); c is the number of eigenvalues, denotes the floor function; h, w are the width and height of the eigenvalue, h, w ∈ (20, 640), L nn is a bxc h x w matrix, b is the Batchsize size, b ∈ (1, 16); c is the number of eigenvalues, h, w are the width and height of the eigenvalue, h, w ∈ (20, 640); CS(·) denotes the channel rearrangement operation, Concat(·) represents the concatenation operation in the channel dimension, and the operation formula of Concat is as follows:
[0070]
[0071] In the formula, X and Y are eigenvalue maps of the channel input, X and Y are bxc h x w matrices, b is the Batchsize size, b ∈ (1, 16); c is the number of eigenvalues, c ∈ (32, 1536); h, w are the width and height of the eigenvalue, h, w ∈ (20, 640); k represents the number of input eigenvalue maps X, k ∈ (32, 1536), d is the number of input eigenvalue maps Y, d ∈ (32, 1536), i ∈ [1, k], j ∈ [1, d];
[0072] The C2fg module described above includes the following structure:
[0073] First, the input feature value channel is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function, and the channel-adjusted feature values are rearranged in the channel; then, the channel dimension is segmented to form feature values X1 and X2, and X2 is output through n BottleNeck modules to output n feature values, n∈(1,6); finally, the feature values X1 and X2 and the output n feature values are spliced in the channel to form the output feature value X3, and the channel of X3 is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function to form the final output feature value X4; X1, X2, X3 and X4 are all b×c h×w matrices, b is the Batchsize size, b∈(1,16); c is the number of channels of the feature value, c∈(32,1536); h and w are the width and height of the feature value, h,w∈(20,640);
[0074] Step 4: Use the idea of attention mechanism to construct a feature fusion module, which includes the following structure:
[0075] First, the input two feature values X c1 and X c2 are channel-adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function, and the two channel-adjusted feature values are downsampled to make the two feature values have the same dimension size to form X c3 and X c4 ; then, the two feature values are multiplied, the multiplied feature values are reduced in dimension using global average pooling, and the reduced feature values are learned using a Sigmoid activation function layer to learn two parameters a0 and a1; finally, X c4 is passed through a two-dimensional convolution layer with a convolution kernel of 3, a normalization layer, and a SiLU activation function to extract feature values to form X c5 , the product of X c3 and a0 is added to the product of X c5 and a1, and then the channel is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function to form the final output X cout ; the formula of the feature fusion module is:
[0076] X c3 =sample(SiLU(Bn2d(Conv2d k=1 (X c1 ))))
[0077] X c4 =sample(SiLU(Bn2d(Conv2d k=1 (X c2 ))))
[0078] Xc5 = SiLU(Bn2d(Conv2d k=3 (X c4 )))
[0079] a0 = Sigmod(GAP(X c3 ·X c4 ))
[0080] a1 = 1 - a0
[0081] X cout = SiLU(Bn2d(Conv2d k=1 (X c3 ⊙a0 + X c5 ⊙a1))
[0082] In the formula, X c1 , X c2 are input feature values, X c3 , X c4 , X c5 are intermediate feature values, X cout is an output feature value, X c1 , X c2 , X c3 , X c4 , X c5 and X cout are bxc h x w matrices, b is the Batchsize size, b e (1, 16); c is the number of channels of the feature value, c e (32, 1536); h, w are the width and height of the feature value, h, w e (20, 640); sample (·) represents a sampling operation, including up-sampling and down-sampling, a0 and a1 are channel weight parameters, both of which are bxc h x w matrices, b is the Batchsize size, b e (1, 16); c is the number of channels of the feature value, c e (32, 1536); h, w are the width and height of the feature value, h = 1, w = 1; GAP is a global average pooling operation, and represents channel-level multiplication;
[0083] Step 5: Replace the original C2f module with the C2fg module, and replace the channel splicing module with the feature fusion module to construct an improved YOLOv8n violation behavior detection model;
[0084] Step 6: Train the improved YOLOv8n violation behavior detection model constructed in step 5 using the training set of step 2 and validate it using the validation set; set the training parameters, set the training batch size B, B = 16, set the learning rate L, L = 0.01, set the momentum Momentum, Momentum = 0.937, set the training iteration number Epoch, Epoch = 200; save the parameter model with the highest average accuracy rate in the validation set; save the parameter model with the highest average accuracy rate as P, P i represents the network parameters at the i-th round of training, and mAP i represents the average accuracy rate of the i-th round of training, i ∈ [1, Epoch]; Map represents the highest accuracy rate; the update of P is according to the following formula:
[0085]
[0086] Step 7: After training is completed, the parameter model with the highest average accuracy rate obtained in step 6 is imported into the network, and the test set of step 2 is used for testing.
[0087] Table 1 shows the average accuracy rate of the network model proposed in the present patent compared with other network models.
[0088] Table 1 Comparison of recognition accuracy of the method of the present patent and different models
[0089] Tab.1 Our method improves the recognition rate of various models
[0090]
Claims
1. An improved YOLOv8n-based method for detecting violations, characterized in that The method comprises the following steps: Step 1: acquire the video of the violation behavior using a camera, decode the video into pictures using a video processing tool FFMPEG, and label the dataset using Labelimg software, wherein the label file format after labeling is txt format; Step 2: divide the dataset obtained in step 1 into a training set, a verification set and a test set; Step 3: the original YOLOv8n network is divided into a Backbone and a Head two parts, including a convolution module, a C2f module, a SPPF module, an up-sampling module and a splicing module, wherein the BottleNeck module is used to construct the C2f module, the BottleNeck module is divided into a BottleNeck1 module and a BottleNeck2 module; the C2f module of the Backbone part of the YOLOv8n network is constructed using the BottleNeck1 module, and the C2f module of the Head is constructed using the BottleNeck2 module; the channel rearrangement mechanism is used to improve the C2f module, and the improved C2f module is called a C2fg module; (1) the BottleNeck1 module and the BottleNeck2 module comprise the following structure: First, a two-dimensional convolution layer with a convolution kernel of 3, a normalization layer and a SiLU activation function are used to extract feature values; then a two-dimensional convolution layer with a convolution kernel of 3, a normalization layer and a SiLU activation function are used to extract feature values to form intermediate feature values; the BottleNeck1 module finally uses residual connection to add the input feature values and the intermediate feature values to form output feature values; the BottleNeck1 module formula is: X bout1 = X bin1 + SiLU(Bn2d(Conv2d k=3 (SiLU(Bn2d(Conv2d k=3 (X bin1 )))))) wherein X bin1 , X bout1 represents the input and output feature values of the BottleNeck1 module, Conv2d k=3 represents a two-dimensional convolution layer with a kernel of 3, Bn2d(·) represents a two-dimensional normalization layer, and SiLU(·) represents a SiLU activation function. (2) the BottleNeck2 module does not use residual connection at the end and directly outputs, and the BottleNeck2 module formula is: X bout2 = SiLU(Bn2d(Conv2d k=3 (SiLU(Bn2d(Conv2d k=3 (X bin2 )))))) wherein X bin2 , X bout2 represents the input and output feature values of the BottleNeck2 module; The above channel rearrangement mechanism formula: X cout = CS(X cin ) = Concat(S1, S2,.... Sn n ) S n = Concat(L 1n , L 2n ,...L nn ) wherein X cin , X cout represents channel rearrangement input and output eigenvalues, X out is divided into n groups n = 2, the nth group eigenvalue of X out is S n , S n is also divided into n groups, the nth group eigenvalue of S n is L nn ; S n is a b x c h x w matrix, b is the Batchsize size, b ∈ (1, 16); c is the number of eigenvalues, represents rounding down; h, w are the width and height of the eigenvalue, h, w ∈ (20, 640), L nn is a b x c h x w matrix, b is the Batchsize size, b ∈ (1, 16); c is the number of eigenvalues, h, w are the width and height of the eigenvalue, h, w ∈ (20, 640); CS(·) represents a channel rearrangement operation, Concat(·) represents a concatenation operation in the channel dimension, and the operation formula of Concat is as follows: In the formula, X and Y are feature value graphs input by the channel, X and Y are bxc h x w matrices, b is the Batchsize size, b [1, 16]; c is the channel number of the feature value, c [32, 1536]; h and w are the width and height of the feature value, h and w [20, 640]; k represents the channel number of the input feature value graph X, k [32, 1536], d is the channel number of the input feature value graph Y, d [32, 1536], i [1, k], j [1, d]; The above C2fg module comprises the following structure: First, the input feature value channel is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function, and the channel-adjusted feature values are rearranged in the channel; then, the channel dimension is segmented to form feature values X1 and X2, and X2 is output through n BottleNeck modules to output n feature values, n∈(1,6); finally, the feature values X1 and X2 are spliced with the output n feature values in the channel to form the output feature value X3, and the X3 channel is adjusted using a two-dimensional convolution layer with a convolution kernel of 1, a normalization layer, and a SiLU activation function to form the final output feature value X4; X1, X2, X3 and X4 are all b×c h×w matrices, b is the Batchsize size, b∈(1,16); c is the number of channels of the feature value, c∈(32,1536); h and w are the width and height of the feature value, h,w∈(20,640); Step 4: Use the idea of attention mechanism to construct a feature fusion module, which includes the following structure: First, the two input feature values X c1 and X c2 are adjusted in channel using a two-dimensional convolution layer with a kernel of 1, a normalization layer, and a SiLU activation function, and the two adjusted feature values are down-sampled to have the same dimension, forming X c3 and X c4 ; then the two feature values are multiplied, the multiplied feature values are reduced in dimension using global average pooling, and the reduced feature values are used to learn two parameters a0 and a1 using a Sigmoid activation function layer; finally, X c4 is extracted as a feature value using a two-dimensional convolution layer with a kernel of 3, a normalization layer, and a SiLU activation function, forming X c5 , the product of X c3 and a0 is added to the product of X c5 and a1, and then the sum is adjusted in channel using a two-dimensional convolution layer with a kernel of 1, a normalization layer, and a SiLU activation function to form the final output X cout ; the formula of the feature fusion module is: X c3 = sample(SiLU(Bn2d(Conv2d k=1 (X c1 )))) X c4 = sample(SiLU(Bn2d(Conv2d k=1 (X c2 )))) X c5 = SiLU(Bn2d(Conv2d k=3 (X c4 ))) a0 = Sigmod(GAP(X c3 • X c4 )) a1=1-a0 X cout = SiLU(Bn2d(Conv2d k=1 (X c3 ⊙a0+X c5 ⊙a1))) In the formula, X c1 , X c2 is an input feature value, X c3 , X c4 , X c5 is an intermediate feature value, X cout is an output feature value, X c1 , X c2 , X c3 , X c4 , X c5 and X cout are each bxc h*w matrices, b is a Batchsize size, b∈(1, 16); c is a channel number of the feature value, c∈(32, 1536); h and w are width and height of the feature value, h, w∈(20, 640); sample(·) represents a sampling operation, including up-sampling and down-sampling, a0 and a1 are channel weight parameters, which are each bxc h*w matrices, b is a Batchsize size, b∈(1, 16); c is a channel number of the feature value, c∈(32, 1536); h and w are width and height of the feature value, h=1, w=1; GAP is a global average pooling operation, and represents channel-level multiplication; Step 5: Replace the original C2f module with C2fg module, and replace the channel splicing module with the feature fusion module to construct the improved YOLOv8n violation behavior detection model; Step 6: Train the improved YOLOv8n violation behavior detection model constructed in step 5 using the training set of step 2, and verify it using the validation set; Set the training parameters, set the training batch size B, B ∈ [1, 16], set the learning rate L, L ∈ (0, 1), momentum Momentum, Momentum ∈ (0.9, 0.95), training iteration number Epoch, Epoch ∈ [100, 500]; save the parameter model with the highest average accuracy rate of the validation set; save the parameter model with the highest average accuracy rate as P, P i Network parameters at the i-th round of training, mAP i The average accuracy rate of the i-th round of training, i ∈ [1, Epoch]; Map represents the highest accuracy rate; the update of P is according to the following formula: Step 7: Complete the training, import the parameter model with the highest average accuracy obtained in step 6 into the network, and test it using the test set of step 2.
Citation Information
Patent Citations
System and method to detect road anomalies
US20250292541A1