Light-weight small target detection method based on feature sparse converter
Through the design of the feature sparse transformer model, the problems of low accuracy and high resource consumption in small object detection are solved, and efficient small object detection in resource-constrained environments are achieved, which improves detection accuracy and efficiency .
Patent Information
- Application Number
- CN202411203213.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-29
- Publication Date
- 2024-12-20
AI Technical Summary
Traditional object detection models have low detection accuracy and high computing resources when processing small targets, making it difficult to effectively deploy on resource-constrained devices, especially in complex backgrounds that are prone to false detection and missed detection.
A lightweight small object detection method based on feature sparse transformer was designed. By constructing a feature sparse transformer model, the sparse attention mechanism was used to filter out features important to the detection task, reducing unnecessary computing overhead, and realizing The model is lightweight and efficiently run.
While maintaining high detection accuracy, it significantly reduces the computing resource requirements of the model, improves the efficiency and accuracy of small object detection, and is suitable for small object detection requirements in many complex scenarios.
Smart Images

Figure BDA0005018308410000023 
Figure BDA0005018308410000032 
Figure BDA0005018308410000051
Abstract
Description
Technical Field
[0001] The present invention relates to a lightweight small target detection method based on a feature sparse transformer, which is suitable for small target detection in various complex environments. The method aims to improve the efficiency and accuracy of small target detection through the lightweight design of a feature sparse transformer model, belongs to the field of computer vision, and also involves the application technology of machine learning and deep learning. Background Art
[0002] With the continuous advancement of deep learning technology, small target detection plays an increasingly important role in many fields such as autonomous driving, drone monitoring, and medical image analysis. However, traditional target detection models often face the problems of low detection accuracy and high computing resource consumption when dealing with small targets. The size of small targets is relatively small, and they are easily disturbed by other objects in complex backgrounds, resulting in false detection and missed detection. In addition, existing models usually require a lot of computing resources and storage space, making them difficult to deploy effectively on resource-constrained devices. Therefore, how to design a lightweight and efficient small target detection model has become an urgent problem to be solved in the current technical field.
[0003] In recent years, China has made significant progress in the field of computer vision, especially in target detection and recognition technology. With the development of artificial intelligence technology, more and more research is focused on how to improve the accuracy and efficiency of small target detection. However, many existing methods still rely on large neural network models, which usually require expensive hardware resources for training and deployment, limiting their widespread promotion in practical applications. Especially in resource-constrained edge devices and embedded systems, traditional large models are difficult to meet the needs of real-time detection and processing. Therefore, developing a small target detection model that can significantly reduce the demand for computing resources while ensuring high accuracy has become one of the important directions of relevant research in China.
[0004] The present invention designs a lightweight small target detection method based on a feature sparsifying transformer, and realizes accurate recognition and positioning of small targets by constructing a feature sparsifying transformer model. By introducing a sparsifying mechanism, the method effectively reduces the computational complexity of the model while maintaining high detection accuracy, so that the model can still run efficiently in a resource-constrained environment. Specifically, the model uses feature sparsifying technology to screen out the most important features for the detection task, reduce unnecessary computational overhead, and thus realize the lightweight design of the model. Experimental results show that the method of the present invention performs well in small target detection tasks, not only improving the detection accuracy, but also significantly reducing the computational resource requirements of the model, and is suitable for small target detection needs in a variety of complex scenarios. Summary of the invention
[0005] In order to solve the above problems, the present invention proposes a lightweight small target detection method based on feature sparse transformer. The method realizes accurate detection of small targets in complex environments by constructing a feature sparse transformer model and combining the training and prediction of small target image data sets. Specifically, the model effectively filters out unimportant features through a sparse attention mechanism, reduces the amount of calculation, and improves the accuracy of small target detection. Compared with traditional target detection methods, the present invention has significant advantages in model lightweight and detection accuracy, and can effectively improve detection performance in resource-constrained environments.
[0006] A lightweight small target detection method based on feature sparse transformer is characterized by comprising four parts: small target image dataset construction, feature sparse transformer detection model establishment, feature sparse transformer detection model training, and feature sparse transformer detection model prediction:
[0007] (1) Construction of small object image dataset
[0008] Collect small target image data. The definition of a small target is that the ratio of the width and height of the target bounding box to the width and height of the image is less than 0.1. Divide the small target image data into training set, validation set, and test set, with the ratio of the number of images being 4:1:1. Each element of is normalized to [0,1] to obtain the normalized input feature matrix
[0009] (2) Establishment of feature sparse transformer detection model
[0010] The feature sparse transformer detection model includes five modules: image feature extraction, feature encoding and decoding, image detection box generation, feature sparseness, and loss calculation;
[0011] ① Image feature extraction
[0012] Construct an image feature extraction module. The module input is the normalized input feature matrix X. The image feature extraction module consists of 7 stages: the first stage consists of a convolution layer with a convolution kernel of 7×7, a batch normalization processing layer, an activation function layer, and a 3×3 maximum pooling layer. The first stage outputs the feature matrix X′. The second, third, fourth, and fifth stages are composed of 3, 4, 6, and 3 identical bottleneck structures respectively. The formula of the first bottleneck structure is as follows:
[0013] Y1=G(X′)+R(X′,O1)(1)
[0014]
[0015] In formula (1), X′ is the feature input of the first bottleneck structure, Y1 is the output of the first bottleneck structure, G(X′) is the direct linear mapping of X′, including convolution operation, R(X′,O1) is the nonlinear mapping, which includes three convolution operations, three batch normalizations and two activation functions, O1 is the standard convolution kernel parameter, formula (2) is the bottleneck structure output activation function, Y1′ is the activation function output and the second bottleneck structure feature input, σ(Y1) is the activation function of the first bottleneck structure output, and the output of the fifth stage is the feature matrix Y1′6; The sixth stage consists of a 3×3 convolution layer and a group normalization layer, and the output is X″; the seventh stage is the post-processing module, which includes four steps: multi-scale extraction, dimension alignment, feature deformation, and feature splicing. First, multi-scale extraction extracts the three-dimensional features output by the third, fourth, fifth, and sixth stages (the three dimensions are length, width, and dimension, respectively). Then, dimension alignment uses 1×1 convolution to unify the dimensions of the four feature maps to 256. Then, feature deformation transforms the three-dimensional feature map into a two-dimensional feature map by merging the length and width. Finally, feature splicing splices the four feature maps and finally outputs the feature map. Where N is the sum of the number of pixels in the four feature maps;
[0016] ②Feature encoding and decoding
[0017] Construct a feature encoding and decoding module, with the feature map F as input; the feature decoding encoding module consists of 6 encoders and 6 decoders connected in series, and the encoder structure includes input embedding, self-attention mechanism, feedforward neural network, and layer normalization in sequence; input embedding inputs the feature map F into the encoder, and the self-attention mechanism formula is:
[0018]
[0019] Among them, Q=K=V=F is the input of the feature encoding and decoding module, Q is the encoder input query, K is the encoder input key, V is the encoder input value, softmax(·) represents the activation function, and the feedforward neural network structure expression formula is:
[0020]
[0021] Among them, Z is the input feature, is the first layer linear transformation weight matrix, is the first layer bias, is the linear transformation weight matrix of the second layer, is the bias of the second layer, GELU(·) represents the activation function, and finally the six encoders are connected in series to output the feature map processed by the self-attention mechanism. The decoder structure includes query embedding, self-attention mechanism, cross-attention mechanism, feedforward neural network, and layer normalization. The decoder self-attention mechanism input is a random initialization vector The output is The cross attention expression formula is:
[0022]
[0023] Where Q′=F′ d is the output of the decoder self-attention mechanism, K′=V′=F′ is the output feature of the sixth encoder, Q′ is the decoder cross-attention input query, K′ is the decoder cross-attention input key, V′ is the decoder cross-attention input value, and finally the six decoders are connected in series to output the feature representation of the target query
[0024] ③ Image detection frame generation
[0025] Build an image detection generation module, with the input being the feature representation of the target query The image detection generation module contains two parallel fully connected layers for predicting the target category and detection box respectively. The decoder outputs the feature representation of the target query Input to 2 fully connected layers: the first fully connected layer is used to predict the category of each target, and outputs the probability distribution of each category by performing linear transformation and softmax operation on the feature vector; the second fully connected layer is used to predict the bounding box coordinates of each target, and outputs the four coordinate values of the bounding box by performing linear transformation and activation function operation on the feature vector
[0026] ④ Feature sparsification
[0027] Construct a feature sparsification module, with the input being the feature map F, and the structure being a multilayer perceptron. The multilayer perceptron structure consists of 4 layers, and the expression formula for the first layer is:
[0028] H1=GELU(W1·LN(F)+b1) (6)
[0029] Among them, LN(·) represents the layer normalization function, is the weight matrix, is the bias term, is the first hidden layer feature, and the second layer expression formula is:
[0030] H2=GELU(W2·CA(H1)+b2) (7)
[0031] Among them, CA(·) represents the channel attention function, which means averaging and weighting the feature map along the last dimension, i.e., the channel. is the weight matrix, is the bias term, is the second hidden layer feature, and the third layer expression formula is:
[0032] H3=GELU(W3·H2+b3) (8)
[0033] in, is the weight matrix, is the bias term, is the third hidden layer feature, and the fourth layer expression formula is:
[0034] H4=W4·H3+b4 (9)
[0035] in, is the weight matrix, is the bias term, is the set of real numbers, To output the feature scores, extract the positions corresponding to the top 20% scores of H4 and construct the mask matrix The high-score position in the mask matrix is 1, and the other positions are 0. According to the mask matrix, a sparse attention mechanism is constructed to replace the encoder self-attention mechanism in feature encoding and decoding. The expression formula of the sparse attention mechanism is:
[0036]
[0037] Among them, Q = K = V = F is the input of the feature encoding and decoding module, and the mask matrix M is used as a local query of the query variable Q;
[0038] ⑤Loss calculation
[0039] Construct a loss calculation module, including feature sparsification loss and detection box generation loss. The feature sparsification loss function formula is:
[0040]
[0041] Where N is the number of elements in H4 used for feature sparsification, is the nth output feature score; the detection box generation loss function includes the category loss function and the bounding box regression function. The category loss function formula is:
[0042]
[0043] Among them, 900 represents the feature representation Q of the target query output by the decoder d is the number of queries, C is the number of categories in the dataset, is the predicted probability of the mth target query for the cth class, The one-hot encoding of the true category of the mth target query. The loss function formula for the detection box generation is:
[0044]
[0045] Among them, d m are the predicted bounding box coordinates of the mth object query, are the ground-truth bounding box coordinates of the mth object query, is the intersection area of the predicted bounding box and the true bounding box, is the union area of the predicted bounding box and the true bounding box, z m is the minimum enclosing area containing the predicted bounding box and the true bounding box, is the area in the minimum closure region that is not covered by the two bounding boxes;
[0046] (3) Feature Sparse Transformer Detection Model Training
[0047] The loss function is used to train the feature sparsification transformer detection model. The feature sparsification loss function and the detection box generation loss function are summed to obtain the total loss value. The model is trained using the total loss value and the back propagation algorithm. The back propagation algorithm expression formula is:
[0048]
[0049] Among them, w new is the updated neuron parameter, w old is the existing neuron parameter, E is the total loss value, The partial derivative of the total loss value for all neuron parameters of the convolutional neural network is calculated; the number of model training iterations is set to 30. After the training reaches the number of iterations, the training is terminated, the weight parameters of the last training are saved, and the model training is completed;
[0050] (4) Feature Sparse Transformer Detection Model Prediction
[0051] After completing the model training, the complete model weights of the last training are loaded into the model. The input of the model is the test set of the small target image dataset. The model predicts the image data in the test set, obtains the image detection frame, and outputs the image with the detection frame to complete the detection. DETAILED DESCRIPTION
[0052] The present invention is characterized in that it includes four parts, namely, small target image data set construction, feature sparse transformer detection model establishment, feature sparse transformer detection model training, and feature sparse transformer detection model prediction. The specific steps are as follows:
[0053] (1) Construction of small object image dataset
[0054] Collect small target image data. The definition of a small target is that the ratio of the width and height of the target bounding box to the width and height of the image is less than 0.1. Divide the small target image data into training set, validation set, and test set, with the ratio of the number of images being 4:1:1. Each element of is normalized to [0,1] to obtain the normalized input feature matrix
[0055] (2) Establishment of feature sparse transformer detection model
[0056] The feature sparse transformer detection model includes five modules: image feature extraction, feature encoding and decoding, image detection box generation, feature sparseness, and loss calculation;
[0057] ① Image feature extraction
[0058] Construct an image feature extraction module. The module input is the normalized input feature matrix X. The image feature extraction module consists of 7 stages: the first stage consists of a convolution layer with a convolution kernel of 7×7, a batch normalization processing layer, an activation function layer, and a 3×3 maximum pooling layer. The first stage outputs the feature matrix X′. The second, third, fourth, and fifth stages are composed of 3, 4, 6, and 3 identical bottleneck structures respectively. The formula of the first bottleneck structure is as follows:
[0059] Y1=G(X′)+R(X′,O1)(1)
[0060]
[0061] In formula (1), X′ is the feature input of the first bottleneck structure, Y1 is the output of the first bottleneck structure, G(X′) is the direct linear mapping of X′, including convolution operation, R(X′,O1) is the nonlinear mapping, which includes three convolution operations, three batch normalizations and two activation functions, O1 is the standard convolution kernel parameter, formula (2) is the bottleneck structure output activation function, Y1′ is the activation function output and the second bottleneck structure feature input, σ(Y1) is the activation function of the first bottleneck structure output, and the output of the fifth stage is the feature matrix Y1′6; The sixth stage consists of a 3×3 convolution layer and a group normalization layer, and the output is X″; the seventh stage is the post-processing module, which includes four steps: multi-scale extraction, dimension alignment, feature deformation, and feature splicing. First, multi-scale extraction extracts the three-dimensional features output by the third, fourth, fifth, and sixth stages (the three dimensions are length, width, and dimension, respectively). Then, dimension alignment uses 1×1 convolution to unify the dimensions of the four feature maps to 256. Then, feature deformation transforms the three-dimensional feature map into a two-dimensional feature map by merging the length and width. Finally, feature splicing splices the four feature maps and finally outputs the feature map. Where N is the sum of the number of pixels in the four feature maps;
[0062] ②Feature encoding and decoding
[0063] Construct a feature encoding and decoding module, with the feature map F as input; the feature decoding encoding module consists of 6 encoders and 6 decoders connected in series, and the encoder structure includes input embedding, self-attention mechanism, feedforward neural network, and layer normalization in sequence; input embedding inputs the feature map F into the encoder, and the self-attention mechanism formula is:
[0064]
[0065] Among them, Q=K=V=F is the input of the feature encoding and decoding module, Q is the encoder input query, K is the encoder input key, V is the encoder input value, softmax(·) represents the activation function, and the feedforward neural network structure expression formula is:
[0066]
[0067] Among them, Z is the input feature, is the first layer linear transformation weight matrix, is the first layer bias, is the linear transformation weight matrix of the second layer, is the bias of the second layer, GELU(·) represents the activation function, and finally the six encoders are connected in series to output the feature map processed by the self-attention mechanism. The decoder structure includes query embedding, self-attention mechanism, cross-attention mechanism, feedforward neural network, and layer normalization. The decoder self-attention mechanism input is a random initialization vector The output is The cross attention expression formula is:
[0068]
[0069] Where Q′=F′ d is the output of the decoder self-attention mechanism, K′=V′=F′ is the output feature of the sixth encoder, Q′ is the decoder cross-attention input query, K′ is the decoder cross-attention input key, V′ is the decoder cross-attention input value, and finally the six decoders are connected in series to output the feature representation of the target query
[0070] ③ Image detection frame generation
[0071] Build an image detection generation module, with the input being the feature representation of the target query The image detection generation module contains two parallel fully connected layers for predicting the target category and detection box respectively. The decoder outputs the feature representation of the target query Input to 2 fully connected layers: the first fully connected layer is used to predict the category of each target, and outputs the probability distribution of each category by performing linear transformation and softmax operation on the feature vector; the second fully connected layer is used to predict the bounding box coordinates of each target, and outputs the four coordinate values of the bounding box by performing linear transformation and activation function operation on the feature vector
[0072] ④ Feature sparsification
[0073] Construct a feature sparsification module, with the input being the feature map F, and the structure being a multilayer perceptron. The multilayer perceptron structure consists of 4 layers, and the expression formula for the first layer is:
[0074] H1=GELU(W1·LN(F)+b1) (6)
[0075] Among them, LN(·) represents the layer normalization function, is the weight matrix, is the bias term, is the first hidden layer feature, and the second layer expression formula is:
[0076] H2=GELU(W2·CA(H1)+b2) (7)
[0077] Among them, CA(·) represents the channel attention function, which means averaging and weighting the feature map along the last dimension, i.e., the channel. is the weight matrix, is the bias term, is the second hidden layer feature, and the third layer expression formula is:
[0078] H3=GELU(W3·H2+b3) (8)
[0079] in, is the weight matrix, is the bias term, is the third hidden layer feature, and the fourth layer expression formula is:
[0080] H4=W4·H3+b4(9)
[0081] in, is the weight matrix, is the bias term, is the set of real numbers, To output the feature scores, extract the positions corresponding to the top 20% scores of H4 and construct the mask matrix The high-score position in the mask matrix is 1, and the other positions are 0. According to the mask matrix, a sparse attention mechanism is constructed to replace the encoder self-attention mechanism in feature encoding and decoding. The expression formula of the sparse attention mechanism is:
[0082]
[0083] Among them, Q = K = V = F is the input of the feature encoding and decoding module, and the mask matrix M is used as a local query of the query variable Q;
[0084] ⑤Loss calculation
[0085] Construct a loss calculation module, including feature sparsification loss and detection box generation loss. The feature sparsification loss function formula is:
[0086]
[0087] Where N is the number of elements in H4 used for feature sparsification, is the nth output feature score; the detection box generation loss function includes the category loss function and the bounding box regression function. The category loss function formula is:
[0088]
[0089] Among them, 900 represents the feature representation Q of the target query output by the decoder d is the number of queries, C is the number of categories in the dataset, is the predicted probability of the mth target query for the cth class, The one-hot encoding of the true category of the mth target query. The loss function formula for the detection box generation is:
[0090]
[0091] Among them, d m are the predicted bounding box coordinates of the mth object query, are the ground-truth bounding box coordinates of the mth object query, is the intersection area of the predicted bounding box and the true bounding box, is the union area of the predicted bounding box and the true bounding box, z m is the minimum enclosing area containing the predicted bounding box and the true bounding box, is the area in the minimum closure region that is not covered by the two bounding boxes;
[0092] (3) Feature Sparse Transformer Detection Model Training
[0093] The loss function is used to train the feature sparsification transformer detection model. The feature sparsification loss function and the detection box generation loss function are summed to obtain the total loss value. The model is trained using the total loss value and the back propagation algorithm. The back propagation algorithm expression formula is:
[0094]
[0095] Among them, w newis the updated neuron parameter, w old is the existing neuron parameter, E is the total loss value, The partial derivative of the total loss value for all neuron parameters of the convolutional neural network is calculated; the number of model training iterations is set to 30. After the training reaches the number of iterations, the training is terminated, the weight parameters of the last training are saved, and the model training is completed;
[0096] (4) Feature Sparse Transformer Detection Model Prediction
[0097] After completing the model training, the complete model weights of the last training are loaded into the model. The input of the model is the test set of the small target image dataset. The model predicts the image data in the test set, obtains the image detection frame, and outputs the image with the detection frame to complete the detection.
Claims
1. A lightweight small target detection method based on feature sparse transformer, characterized in that: It includes four parts: small target image dataset construction, feature sparse transformer detection model establishment, feature sparse transformer detection model training, and feature sparse transformer detection model prediction. The specific steps are as follows: (1) Construction of small object image dataset Collect small target image data. The definition of a small target is that the ratio of the width and height of the target bounding box to the width and height of the image is less than 0.
1. Divide the small target image data into training set, validation set, and test set, with the ratio of the number of images being 4:1:
1. Each element of is normalized to [0,1] to obtain the normalized input feature matrix (2) Establishment of feature sparse transformer detection model The feature sparse transformer detection model includes five modules: image feature extraction, feature encoding and decoding, image detection box generation, feature sparseness, and loss calculation; ① Image feature extraction Construct an image feature extraction module. The module input is the normalized input feature matrix X. The image feature extraction module consists of 7 stages: the first stage consists of a convolution layer with a convolution kernel of 7×7, a batch normalization processing layer, an activation function layer, and a 3×3 maximum pooling layer. The first stage outputs the feature matrix X′. The second, third, fourth, and fifth stages are composed of 3, 4, 6, and 3 identical bottleneck structures respectively. The formula of the first bottleneck structure is as follows: Y1=G(X′)+R(X′,O1)(1) In formula (1), X′ is the feature input of the first bottleneck structure, Y1 is the output of the first bottleneck structure, G(X′) is the direct linear mapping of X′, including convolution operation, R(X′,O1) is the nonlinear mapping, which includes three convolution operations, three batch normalizations and two activation functions, O1 is the standard convolution kernel parameter, formula (2) is the bottleneck structure output activation function, Y1′ is the activation function output and the second bottleneck structure feature input, σ(Y1) is the activation function of the first bottleneck structure output, and the output of the fifth stage is the feature matrix Y1′6; The sixth stage consists of a 3×3 convolution layer and a group normalization layer, and the output is X″; the seventh stage is the post-processing module, which includes four steps: multi-scale extraction, dimension alignment, feature deformation, and feature splicing. First, multi-scale extraction extracts the three-dimensional features output by the third, fourth, fifth, and sixth stages (the three dimensions are length, width, and dimension, respectively). Then, dimension alignment uses 1×1 convolution to unify the dimensions of the four feature maps to 256. Then, feature deformation transforms the three-dimensional feature map into a two-dimensional feature map by merging the length and width. Finally, feature splicing splices the four feature maps and finally outputs the feature map. Where N is the sum of the number of pixels in the four feature maps; ②Feature encoding and decoding Construct a feature encoding and decoding module, with the feature map F as input; the feature decoding encoding module consists of 6 encoders and 6 decoders connected in series, and the encoder structure includes input embedding, self-attention mechanism, feedforward neural network, and layer normalization in sequence; input embedding inputs the feature map F into the encoder, and the self-attention mechanism formula is: Among them, Q=K=V=F is the input of the feature encoding and decoding module, Q is the encoder input query, K is the encoder input key, V is the encoder input value, softmax(·) represents the activation function, and the feedforward neural network structure expression formula is: Among them, Z is the input feature, is the first layer linear transformation weight matrix, is the first layer bias, is the second layer linear transformation weight matrix, is the bias of the second layer, GELU(·) represents the activation function, and finally the six encoders are connected in series to output the feature map processed by the self-attention mechanism. The decoder structure includes query embedding, self-attention mechanism, cross-attention mechanism, feedforward neural network, and layer normalization. The decoder self-attention mechanism input is a random initialization vector The output is The cross attention expression formula is: Where Q′=F′ d is the output of the decoder self-attention mechanism, K′=V′=F′ is the output feature of the sixth encoder, Q′ is the decoder cross-attention input query, K′ is the decoder cross-attention input key, V′ is the decoder cross-attention input value, and finally the six decoders are connected in series to output the feature representation of the target query ③ Image detection frame generation Build an image detection generation module, with the input being the feature representation of the target query The image detection generation module contains two parallel fully connected layers for predicting the target category and detection box respectively; the decoder outputs the feature representation of the target query Input to 2 fully connected layers: the first fully connected layer is used to predict the category of each target, and outputs the probability distribution of each category by performing linear transformation and softmax operation on the feature vector; the second fully connected layer is used to predict the bounding box coordinates of each target, and outputs the four coordinate values of the bounding box by performing linear transformation and activation function operation on the feature vector ④ Feature sparsification Construct a feature sparsification module, with the input being the feature map F, and the structure being a multilayer perceptron. The multilayer perceptron structure consists of 4 layers, and the expression formula for the first layer is: H1=GELU(W1·LN(F)+b1)(6)where LN(·) represents the layer normalization function, is the weight matrix, is the bias term, is the first hidden layer feature, and the second layer expression formula is: H2=GELU(W2·CA(H1)+b2)(7) Among them, CA(·) represents the channel attention function, which means averaging and weighting the feature map along the last dimension, i.e., the channel. is the weight matrix, is the bias term, is the second hidden layer feature, and the third layer expression formula is: H3=GELU(W3·H2+b3) (8) in, is the weight matrix, is the bias term, is the third hidden layer feature, and the fourth layer expression formula is: H4=W4·H3+b4 (9) in, is the weight matrix, is the bias term, is the set of real numbers, To output the feature scores, extract the positions corresponding to the top 20% scores of H4 and construct the mask matrix The high-score position in the mask matrix is 1, and the other positions are 0. According to the mask matrix, a sparse attention mechanism is constructed to replace the encoder self-attention mechanism in feature encoding and decoding. The expression formula of the sparse attention mechanism is: Among them, Q = K = V = F is the input of the feature encoding and decoding module, and the mask matrix M is used as a local query of the query variable Q; ⑤Loss calculation Construct a loss calculation module, including feature sparsification loss and detection box generation loss. The feature sparsification loss function formula is: Where N is the number of elements in H4 used for feature sparsification, is the nth output feature score; the detection box generation loss function includes the category loss function and the bounding box regression function. The category loss function formula is: Among them, 900 represents the feature representation Q of the target query output by the decoder d is the number of queries, C is the number of categories in the dataset, is the predicted probability of the mth target query for the cth class, One-hot encoding of the true category of the mth target query; the loss function formula for detection box generation is: Among them, d m are the predicted bounding box coordinates of the mth object query, are the ground-truth bounding box coordinates of the mth object query, is the intersection area of the predicted bounding box and the true bounding box, is the union area of the predicted bounding box and the true bounding box, z m is the minimum enclosing area containing the predicted bounding box and the true bounding box, is the area in the minimum closure region that is not covered by the two bounding boxes; (3) Feature Sparse Transformer Detection Model Training The loss function is used to train the feature sparsification transformer detection model. The feature sparsification loss function and the detection box generation loss function are summed to obtain the total loss value. The model is trained using the total loss value and the back propagation algorithm. The back propagation algorithm expression formula is: Among them, w new is the updated neuron parameter, w old is the existing neuron parameter, E is the total loss value, The partial derivative of the total loss value for all neuron parameters of the convolutional neural network is calculated; the number of model training iterations is set to 30. After the training reaches the number of iterations, the training is terminated, the weight parameters of the last training are saved, and the model training is completed; (4) Feature Sparse Transformer Detection Model Prediction After completing the model training, the complete model weights of the last training are loaded into the model. The input of the model is the test set of the small target image dataset. The model predicts the image data in the test set, obtains the image detection frame, and outputs the image with the detection frame to complete the detection.
Citation Information
Cited By
X-ray security inspection machine picture object detection method
CN119600389A
A method for detecting objects in images of X-ray security inspection machines
CN119600389B
Security radar target data processing method
CN119620032A
Text classification method based on layer-by-layer unfreezing progressive training model
CN120086369A
A text classification method based on a layer-by-layer thawing progressive training model
CN120086369B
