Lightweight object detection method based on multi-receptive field and attention feature pyramid
By using the MobileNetv2 network, lightweight multi-receptive field module and attention feature pyramid in the lightweight target detection method, the problems of slow detection speed and large number of parameters in the existing technology are solved, and the system is realized on resource-constrained devices. Efficient target detection improves detection accuracy and speed.
Patent Information
- Application Number
- CN202210489413.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-06
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2042-05-06
AI Technical Summary
Existing lightweight target detection methods have slow detection speeds when deploying applications on resource-constrained devices, and it is difficult to reduce the amount of model parameters while maintaining detection accuracy, making it impossible to achieve real-time detection.
The MobileNetv2 network is used as the backbone network, combined with lightweight multi-receptive field modules and attention feature pyramids, to enhance feature extraction and information fusion through hole residual networks and spatial attention mechanisms, and build a deep learning network to improve detection speed and accuracy.
Efficient target detection is achieved on devices with limited resources. The detection speed is improved and high detection accuracy is maintained. The number of parameters is reduced, and it can be deployed in scenarios that require rapid detection.
Smart Images

Figure CN114937151B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of target detection, and further relates to a lightweight target detection method, which can be used for pedestrian detection, face recognition, intelligent monitoring, and industrial detection. Background Art
[0002] Object detection is one of the most important topics in the field of computer vision. Its application scenarios include pedestrian detection, face recognition, intelligent monitoring, industrial detection, etc. The most popular object detection algorithm is based on deep learning, which automatically marks the location and category of the target object in a natural scene picture or video. In actual application scenarios, large-scale detection models are difficult to deploy on devices with limited computing resources and cannot achieve real-time detection in scenarios that require rapid detection. Therefore, it is necessary to design a lightweight object detection method.
[0003] South China University of Technology disclosed a real-time multi-scale target detection method based on lightweight convolutional neural network in the patent document with application number 202010619209.1. The method first uses a clustering algorithm to cluster the aspect ratio and area scale coefficient of the sample target of the training data set, and the cluster center is used to optimize the anchor box setting; a lightweight convolutional neural network is used as the backbone network of the RetinaNet framework to reduce the complexity of the model; at the same time, the residual module is used to enhance the multi-scale feature map, and the adaptive cross-layer feature fusion is performed on some enhanced multi-scale feature maps. Finally, the generated fusion feature pyramid is used to replace the feature pyramid to improve the model's detection accuracy for small and medium-sized targets. The shortcoming of this method is that the designed residual module uses 3 layers of standard convolution, which is applied to the four-layer feature maps of C3, C4, C5, and C6, which increases the number of model parameters and reduces the detection speed. At the same time, the high-level feature map already contains enough semantic information, and adding a residual module will interfere with the original information and reduce the detection accuracy.
[0004] The Hefei Institutes of Physical Science, Chinese Academy of Sciences, disclosed a lightweight target detection method for smart terminals in a patent document with application number 202111315378.7. This method first constructs a lightweight target detection network model, which includes a backbone network and a detection head network. The backbone network design adopts dense connection and hierarchical feature extraction, including a primary feature extraction module, an intermediate feature extraction module and a dense connection module; the detection head is composed of pyramid pooling SPP and path aggregation network PANet, and outputs two layers of target detection results. Although this method reduces the number of model parameters, it enhances the information fusion between feature maps and realizes multi-size target detection frame recognition. However, due to the use of a bidirectional path aggregation network PANet in the detection head part, the information transmission speed is slow, which reduces the detection speed. At the same time, since its backbone network design still uses standard convolution, the number of parameters is still large, making it difficult to deploy applications in resource-constrained devices, and further reduces the detection speed. Its detection speed is only 22.6FPS, which does not reach the real-time detection speed. Summary of the invention
[0005] The purpose of the present invention is to address the deficiencies of the above-mentioned prior art and propose a lightweight target detection method based on multiple receptive fields and attention feature pyramids to improve the detection speed and improve the detection accuracy while reducing the number of target model parameters.
[0006] The technical solutions for achieving the purpose of the present invention include the following:
[0007] (1) Obtain an object detection image dataset containing a training set, a validation set, and a test set from the Internet;
[0008] (2) Based on the fully convolutional one-stage object detection FCOS framework, the MobileNetv2 network is used as the backbone network to extract basic features of the image and generate multi-scale feature maps C3, C4, and C5, which correspond to the 8, 16, and 32 downsampling ratios of the original image respectively;
[0009] (3) Construct a lightweight multi-receptive field module and use this module to process feature maps C3 and C4:
[0010] (3a) Building a dilated residual network consisting of a standard convolutional layer, a channel-by-channel dilated convolutional layer, and a point-by-point convolutional layer, and serially cascading three layers of the dilated residual network to form a lightweight multi-receptive field module;
[0011] (3b) setting the parameters of each layer network of the lightweight multi-receptive field module corresponding to the first scale feature map C3, then inputting C3 into the lightweight multi-receptive field module, and outputting the first scale enhanced feature map C3′;
[0012] (3c) setting the parameters of each layer network of the lightweight multi-receptive field module corresponding to the second-scale feature map C4, then inputting C4 into the lightweight multi-receptive field module, and outputting the second-scale enhanced feature map C4′;
[0013] (4) Constructing an attention feature pyramid:
[0014] (4a) A convolution layer with a convolution kernel size of 1×1, a convolution kernel channel number of 1280, and a total number of convolution kernels of 256 is used to reduce the dimension of the third-scale feature map C5 to obtain the third-scale reduced-dimensional feature map C5 * ;
[0015] (4b) The third scale dimensionality reduction feature map C5 * Perform nearest neighbor interpolation upsampling, and use a convolution layer with a convolution kernel size of 1×1, 96 convolution kernel channels, and 256 convolution kernels to transform the dimension of the second scale enhanced feature map C4′, and perform element-by-element addition operation on the two for fusion, and then pass through a convolution layer with a convolution kernel size of 3×3, 256 convolution kernel channels, and 256 convolution kernels to obtain the second scale fused feature map P4;
[0016] (4c) The second-scale fusion feature map P4 is upsampled by nearest neighbor interpolation, and the enhanced first-scale enhancement feature map C3′ is transformed by a convolution layer with a convolution kernel of 1×1, 32 convolution kernel channels, and 256 convolution kernels. The two are fused by element-by-element addition, and then the convolution kernel is passed through a convolution layer with a convolution kernel of 3×3, 256 convolution kernel channels, and 256 convolution kernels to obtain the first-scale fusion feature map P3;
[0017] (4d) A convolution layer with a convolution kernel size of 1×1, a convolution kernel channel number of 256, and a total number of convolution kernels of 256 is used to reduce the dimension of the third scale feature map C5. * Enhanced to obtain the third scale enhanced feature map P5;
[0018] (4e) The spatial attention SE adjusts the feature information of each channel of the third-scale enhanced feature map P5, and passes through a convolution layer with a step size of 2, a convolution kernel of 3×3, a number of convolution kernel channels of 256, and a total number of convolution kernels of 256 to obtain a fourth-scale enhanced feature map P6 with a size reduced by half;
[0019] (4f) The spatial attention SE adjusts the global feature information of the fourth-scale enhanced feature map P6, and sequentially passes through the RELU activation layer and the convolution layer with a step size of 2, a convolution kernel of 3×3, a convolution kernel channel number of 256, and a total number of convolution kernels of 256 to obtain the fifth-scale enhanced feature map P7 with a size reduced by half;
[0020] (4g) Arrange the feature maps P3, P4, P5, P6, and P7 obtained from (4a) to (4f) from bottom to top to obtain a multi-scale attention feature pyramid;
[0021] (5) Based on the fully convolutional one-stage object detection FCOS framework, the MobileNetv2 network, lightweight multi-receptive field module, attention feature pyramid, and prediction module are combined into a deep learning network;
[0022] (6) Training deep learning network:
[0023] (6a) Use the pre-trained model on the ImageNet dataset to initialize the MobileNetv2 network, and use the normal distribution N(0,0.01) to initialize the weight parameters of the remaining layers of the deep learning network;
[0024] (6b) Preprocessing training sample set: resize the image to 512×512 and perform data augmentation;
[0025] (6c) Set the deep learning network training hyperparameters: set the number of iterations to 72k, the learning rate of the MobileNetv2 network to 0.00067, and the learning rate of the remaining networks to 0.002. At the 50k and 60k iterations, the learning rate is reduced to 0.1 times the current learning rate. The number of images input at a time is set to 8 batches.
[0026] (6d) Input the batch of images in the training sample set into the deep learning network for forward propagation to obtain the predicted category and predicted box coordinates;
[0027] (6e) Adopt an adaptive training sample allocation strategy to assign positive and negative samples to each prediction box;
[0028] (6f) Use the generalized focal loss function to calculate the loss value between the predicted box and the corresponding sample;
[0029] (6g) Back-propagating the loss value in the deep learning network, and using the gradient descent method to update the weight parameters of each network node until the loss value converges to obtain a trained deep learning network;
[0030] (7) Target Detection
[0031] (7a) The images in the test sample set are resized to 512×512 and input into the trained deep learning network for forward propagation to obtain the predicted category and predicted box coordinates of each image;
[0032] (7b) The non-maximum suppression method is used to filter the overlapping prediction boxes and obtain the final prediction category and prediction box coordinates.
[0033] Compared with the prior art, the present invention has the following advantages:
[0034] First, since the present invention uses the MobileNetv2 network as the backbone network, replacing the original heavyweight network, the number of parameters of the deep learning network is reduced, so that the present invention can be deployed on resource-constrained devices and has the advantage of higher detection speed.
[0035] Second, since the lightweight multi-receptive field module constructed by the present invention adopts deep separable convolution instead of ordinary convolution layer, it can be added to the deep learning network without computational burden; on the other hand, this module also adopts residual network and void convolution to obtain multiple receptive fields, which adds surrounding scene information to the target detection of shallow feature map, overcomes the problem of insufficient shallow feature map information responsible for small target detection, increases the adaptability of the present invention and improves the detection performance in small target scenes.
[0036] Third, due to the attention feature pyramid constructed by the present invention, an attention mechanism is added in the process of transmitting feature map information upward. Faced with the feature map responsible for current layer detection and transmitting multiple tasks of information upward or downward, the information required for each task is explicitly highlighted, overcoming the problem of inconsistent information required for each task. The present invention further improves the detection performance of the target. BRIEF DESCRIPTION OF THE DRAWINGS
[0037] Figure 1 It is a flow chart of the implementation of the present invention;
[0038] Figure 2 It is a structural diagram of the lightweight multi-receptive field module in the present invention;
[0039] Figure 3 It is the attention feature pyramid network structure diagram in the present invention;
[0040] Figure 4 This is the overall framework diagram of the deep learning network constructed by the present invention. DETAILED DESCRIPTION
[0041] The present invention will be further described below in conjunction with the accompanying drawings.
[0042] Reference Figure 1 , the implementation steps of the example of the present invention are as follows:
[0043] Step 1: Obtain the training set and test set of target detection images.
[0044] The PASCAL VOC dataset is obtained from the Internet. The dataset includes two versions: PASCAL VOC2007 dataset and PASCAL VOC2012 dataset, which contain 20 categories in natural scenes.
[0045] This example divides the training set and validation set of the PASCAL VOC2007 dataset and the PASCAL VOC2012 dataset into a training sample set containing 16,551 images.
[0046] The test set of the PASCAL VOC2007 dataset is divided into a test sample set containing 4952 images.
[0047] Step 2: Select the backbone network.
[0048] The backbone network is used to extract basic features of the input image, and can be selected from lightweight convolutional neural networks such as PeleeNet, ShuffleNetv2, and MobileNetv2. In this embodiment, the MobileNetv2 network is selected as the backbone network but is not limited to it.
[0049] The MobileNetv2 network consists of the first convolutional layer, the first to seventh bottleneck layers, the second convolutional layer, the average pooling layer, and the third convolutional layer in sequence. The third bottleneck layer, the fifth bottleneck layer, and the second convolutional layer output a set of multi-scale feature maps C3, C4, and C5, respectively. The number of channels of this set of feature maps is 32, 96, and 1280, and the downsampling ratio relative to the image is 8, 16, and 32.
[0050] Step 3: Build a lightweight multi-receptive field module.
[0051] 3.1) Build a dilated residual network consisting of a standard convolutional layer, a channel-by-channel dilated convolutional layer, and a point-by-point convolutional layer cascaded in sequence.
[0052] 3.2) Cascade three layers of the dilated residual network in series to form a lightweight multi-receptive field module, such as Figure 2 shown.
[0053] The parameters of each layer of the hole residual network are set as follows:
[0054] Standard convolution layer, whose convolution kernel size is set to 1×1;
[0055] Channel-by-channel atrous convolution layer, the size of the convolution kernel is set to 3×3;
[0056] In the point-by-point convolution layer, the size of the convolution kernel is set to 1×1.
[0057] Step 4: Obtain the corresponding two scale enhanced feature maps C3′ and C4′ through the lightweight receptive field module.
[0058] 4.1) Set the parameters of each layer of the lightweight multi-receptive field module corresponding to the first scale feature map C3:
[0059] In each layer of the dilated residual network, the number of channels of the convolution kernel of the standard convolution layer is set to 32, and the total number of convolution kernels is 192;
[0060] In each layer of the dilated residual network, the number of channels of the convolution kernel of the channel-by-channel dilated convolution layer is set to 192, and the total number of convolution kernels is 192;
[0061] In each layer of the dilated residual network, the number of channels of the convolution kernel of the point-by-point convolution layer is set to 192, and the total number of convolution kernels is 32;
[0062] The dilation rates of channel-by-channel dilated convolutions in the first, second, and third dilated residual networks are set to 1, 2, and 3, respectively.
[0063] 4.2) Input the first-scale feature map C3 into the corresponding lightweight multi-receptive field module and output the first-scale enhanced feature map C3′.
[0064] 4.3) Set the parameters of each layer of the lightweight multi-receptive field module corresponding to the second scale feature map C4:
[0065] In each layer of the dilated residual network, the number of channels of the convolution kernel of the standard convolution layer is set to 96, and the total number of convolution kernels is 576;
[0066] In each layer of the dilated residual network, the number of channels of the convolution kernel of the channel-by-channel dilated convolution layer is set to 576, and the total number of convolution kernels is 576;
[0067] In each layer of the dilated residual network, the number of channels of the convolution kernel of the point-by-point convolution layer is set to 576, and the total number of convolution kernels is 96;
[0068] The dilation rates of channel-by-channel dilated convolutions in the first, second, and third dilated residual networks are set to 1, 2, and 3, respectively.
[0069] 4.4) Input the first-scale feature map C4 into the corresponding lightweight multi-receptive field module and output the first-scale enhanced feature map C4′.
[0070] Step 5: Build an attention feature pyramid.
[0071] 5.1) A convolution layer with a convolution kernel size of 1×1, a convolution kernel channel number of 1280, and a total number of convolution kernels of 256 is used to reduce the dimension of the third-scale feature map C5 to obtain the third-scale reduced-dimensional feature map C5 * .
[0072] 5.2) Reduce the dimension of the third scale feature map C5 *The nearest neighbor interpolation upsampling is performed, and a convolution layer with a convolution kernel size of 1×1, 96 convolution kernel channels, and 256 convolution kernels is used to transform the dimension of the second-scale enhanced feature map C4′. The two are fused by element-by-element addition, and then a convolution layer with a convolution kernel size of 3×3, 256 convolution kernel channels, and 256 convolution kernels is used to obtain the second-scale fused feature map P4.
[0073] 5.3) The second-scale fused feature map P4 is upsampled by nearest neighbor interpolation, and the enhanced first-scale enhanced feature map C3′ is transformed in dimension by a convolution layer with a convolution kernel of 1×1, 32 convolution kernel channels, and 256 convolution kernels in total. The two are fused by element-by-element addition, and then passed through a convolution layer with a convolution kernel of 3×3, 256 convolution kernel channels, and 256 convolution kernels in total to obtain the first-scale fused feature map P3.
[0074] 5.4) A convolution layer with a convolution kernel size of 1×1, a convolution kernel channel number of 256, and a total number of convolution kernels of 256 is used to reduce the dimension of the third scale feature map C5. * The enhancement is performed to obtain the third-scale enhanced feature map P5.
[0075] 5.5) The spatial attention module SE adjusts the feature information of each channel of the third-scale enhanced feature map P5, that is, the global pooling layer is used to compress the input feature map, and then the first fully connected layer, RELU activation layer, second fully connected layer, and Sigmoid activation layer are used in sequence to obtain the weight of each channel of the feature map, and then the input feature map is weighted by this weight, and after a convolution layer with a step size of 2, a convolution kernel of 3×3, a convolution kernel channel number of 256, and a total number of convolution kernels of 256, a fourth-scale enhanced feature map P6 with a size reduced by half is obtained.
[0076] 5.6) The spatial attention SE is used to adjust the global feature information of the fourth-scale enhanced feature map P6, that is, the global pooling layer is used to compress the input feature map, and then the first fully connected layer, RELU activation layer, second fully connected layer, and Sigmoid activation layer are used in sequence to obtain the weight of each channel of the feature map, and then the input feature map is weighted by this weight, and it passes through the RELU activation layer and the convolution layer with a step size of 2, a convolution kernel of 3×3, a convolution kernel channel number of 256, and a total number of convolution kernels of 256 to obtain the fifth-scale enhanced feature map P7 with its size reduced by half.
[0077] 5.7) Arrange the feature maps P3, P4, P5, P6, and P7 obtained in 5.1) to 5.6) from bottom to top to obtain a multi-scale attention feature pyramid, such as Figure 3 shown.
[0078] Step 6: Build a deep learning network.
[0079] 6.1) The prediction module of the fully convolutional one-stage target detection FCOS framework is selected, which includes a classification subnetwork and a regression subnetwork. Both subnetworks contain 5 serially cascaded convolutional layers; the convolution kernel size of the first, second, third, and fourth convolutional layers of the classification subnetwork and the regression subnetwork is set to 3×3, the number of convolution kernel channels is 256, and the total number of convolution kernels is 256; the convolution kernel size of the fifth convolutional layer of the classification subnetwork is set to 3×3, the number of convolution kernel channels is 256, and the total number of convolution kernels is the number of categories of the image dataset; the convolution kernel of the fifth convolutional layer of the regression subnetwork is set to 3×3, the number of convolution kernel channels is 256, and the total number of convolution kernels is 4×(regmax+1), and the parameter regmax is 16.
[0080] 6.2) Based on the fully convolutional one-stage target detection FCOS framework, a deep learning network is composed of the MobileNetv2 network, the lightweight multi-receptive field module, the attention feature pyramid, and the prediction module. The structural relationship is as follows: the MobileNetv2 network is connected to the lightweight multi-receptive field module and the attention feature pyramid respectively; the lightweight multi-receptive field module is connected to the attention feature pyramid; the attention feature pyramid is connected to the prediction module to complete the construction of the deep learning network, such as Figure 4 shown.
[0081] Step 7: Train the deep learning network.
[0082] 7.1) Use the pre-trained model on the ImageNet dataset to initialize the MobileNetv2 network, and use the normal distribution N(0, 0.01) to initialize the weight parameters of the remaining layers of the deep learning network.
[0083] 7.2) Preprocessing training sample set: resize the image to 512×512, and use random rotation, random adjustment of image brightness, contrast, saturation, hue, standardization and padding operations for data augmentation.
[0084] 7.3) Set the deep learning network training hyperparameters: set the number of iterations to 72k, the learning rate of the MobileNetv2 network to 0.00067, and the learning rate of the remaining networks to 0.002. At the 50k and 60k iterations, the learning rate is reduced to 0.1 times the current learning rate, and the number of images input at a time is set to 8 batches.
[0085] 7.4) Input the batch of images in the training sample set into the deep learning network for forward propagation to obtain the predicted category and predicted box coordinates.
[0086] 7.5) Adopt an adaptive training sample allocation strategy to allocate positive and negative samples to each prediction box:
[0087] 7.5.1) Construct an anchor box for each prediction box. The center point of the anchor box is the coordinate point corresponding to the prediction box on the original image. The size of the anchor box is the product of the step size corresponding to the prediction box on the original image and the parameter scale_factor. The parameter scale_factor is 4.
[0088] 7.5.2) Calculate the Euclidean distance between each true box and all anchor boxes, and select the k anchor boxes with the smallest Euclidean distance, and the parameter k is 9.
[0089] 7.5.3) Calculate the mean and standard deviation of the IOU between the real box and the corresponding k anchor boxes, and add the mean and standard deviation as the IOU threshold.
[0090] 7.5.4) Filter k anchor boxes corresponding to the real box according to the IOU threshold: the anchor boxes larger than the IOU threshold are taken as positive samples, and the anchor boxes smaller than the IOU threshold are taken as negative samples.
[0091] 7.6) Define the generalized focal loss function GFL and calculate the loss value between the predicted box and the corresponding sample.
[0092] The generalized focal loss function GFL is composed of the classification loss function QFL, the bounding box regression loss function L GIOU , and the bounding box distribution loss function DFL, which is defined as follows:
[0093]
[0094] Among them, N pos represents the sum of the number of positive samples corresponding to all prediction boxes, z represents the prediction box, and the hyperparameters λ0 and λ1 are 2, Indicates the positive or negative sample corresponding to the prediction box, If If , it is 1, otherwise it is 0. The loss functions are expressed as follows:
[0095] QFL(σ)=-|q-σ| β ((1-q)log(1-σ)+qlog(σ))
[0096]
[0097]
[0098] In the formula, q is the IOU value of the predicted box and the true box, σ is the predicted category score, the hyperparameter β is 2, y and z represent the true box and the predicted box respectively, r represents the minimum rectangular box surrounding the true box and the predicted box, and z i and z i+1is the left and right coordinate value closest to y in the prediction box,
[0099] 7.8) Back-propagate the loss value GFL in the deep learning network, and use the gradient descent method to update the weight parameters of each network node until the loss value converges to obtain a trained deep learning network.
[0100] Step 8: Target detection.
[0101] 8.1) The images in the test sample set are resized to 512×512 and input into the trained deep learning network for forward propagation to obtain the predicted category and predicted box coordinates of each image.
[0102] 8.2) Use the non-maximum suppression method to filter out overlapping prediction boxes, and use the final prediction box to mark the location and category of the target on the image:
[0103] 8.2.1) Set the screening threshold N.
[0104] 8.2.2) Use all prediction boxes to form the initial prediction box set B.
[0105] 8.2.3) Create the final prediction box set D and initialize it to an empty set.
[0106] 8.2.4) Multiply the IOU value of the predicted box and the true box and the predicted category probability as the confidence, and sort the predicted boxes in set B in descending order according to the confidence.
[0107] 8.2.5) Select the first predicted box, add it to set D, and then delete it from set B.
[0108] 8.2.6) Traverse all the prediction boxes in set B and calculate their IOU values with the final prediction boxes in set D. If the IOU value is greater than the threshold N, delete it from set B.
[0109] 8.2.7) Repeat steps 8.2.5) to 8.2.6) until set B is empty.
[0110] 8.2.8) Output the elements in the set D as the final prediction box, and use the final prediction box to mark the location and category of the target in the image to complete the target detection.
[0111] The effect of the present invention is further illustrated by the following simulation experiment.
[0112] 1. Simulation experiment conditions:
[0113] The simulation experiment hardware platform of the present invention is Intel Core i7 8700K@3.7GHz CPU, 64GB RAM, NVIDIA GeForce GTX1080Ti GPU, and the simulation experiment software platform is Ubuntu 18.04.5, Python 3.8.5 and Pytorch1.7.1.
[0114] 2. Simulation experiment content and result analysis:
[0115] On the above-mentioned PASCAL VOC dataset, the method of the present invention and four target detection methods of the prior art are used for simulation to obtain the detection frame and category of the target. Then, the average accuracy mAP of the detection frame of all targets is calculated, the number of frames processed per second FPS is counted, the number of deep learning network parameters is counted, and the detection accuracy, detection speed, and model size of each method are evaluated to obtain the detection results of five simulation experiments, as shown in Table 1.
[0116] Table 1 Test results of the present invention and prior art in simulation experiments
[0117] method Input size Parameter quantity mAP(%) FPS The present invention 512×512 11.77M 78.0 56 SSD 300×300 26.30M 77.2 36 Faster RCNN 600×1000 14.80M 73.2 5 SqueezeNet SSD 300×300 4.89M 72.7 55 YOLOv3 416×416 106M 80 28
[0118] As can be seen from Table 1, when the difference in parameter quantity is small, the detection accuracy mAP of the present invention reaches 78.0%, which is 0.8%, 4.8%, and 5.3% higher than the existing SSD, Faster RCNN, and SqueezeNet SSD methods, respectively, and the detection speed is higher, reaching 56FPS. Compared with YOLOv3, although the detection accuracy of the present invention is slightly reduced, the detection speed is increased by 28FPS, and the number of parameters is greatly reduced, which is more lightweight and can be deployed on resource-constrained devices. Therefore, compared with the existing methods, when the input image size is similar, the present invention has advantages to varying degrees in the comprehensive performance of model size, detection accuracy, and detection speed.
Claims
1. A lightweight object detection method based on multi-receptive fields and attention feature pyramid, characterized in that: These include: (1) Obtain an object detection image dataset containing a training set, a validation set, and a test set from the Internet; (2) Based on the fully convolutional one-stage object detection FCOS framework, the MobileNetv2 network is used as the backbone network to extract basic features of the image and generate multi-scale feature maps C3, C4, and C5, which correspond to the 8, 16, and 32 downsampling ratios of the original image respectively; (3) Construct a lightweight multi-receptive field module and use this module to process feature maps C3 and C4: (3a) Building a dilated residual network consisting of a standard convolutional layer, a channel-by-channel dilated convolutional layer, and a point-by-point convolutional layer, and serially cascading three layers of the dilated residual network to form a lightweight multi-receptive field module; (3b) setting the parameters of each layer network of the lightweight multi-receptive field module corresponding to the first scale feature map C3, then inputting C3 into the lightweight multi-receptive field module, and outputting the first scale enhanced feature map C3′; (3c) setting the parameters of each layer network of the lightweight multi-receptive field module corresponding to the second-scale feature map C4, then inputting C4 into the lightweight multi-receptive field module, and outputting the second-scale enhanced feature map C4′; (4) Constructing an attention feature pyramid: (4a) A convolution layer with a convolution kernel size of 1×1, a convolution kernel channel number of 1280, and a total number of convolution kernels of 256 is used to reduce the dimension of the third-scale feature map C5 to obtain the third-scale reduced-dimensional feature map C5 * ; (4b) The third scale dimensionality reduction feature map C5 * Perform nearest neighbor interpolation upsampling, and use a convolution layer with a convolution kernel size of 1×1, 96 convolution kernel channels, and 256 convolution kernels to transform the dimension of the second scale enhanced feature map C4′, and perform element-by-element addition operation on the two for fusion, and then pass through a convolution layer with a convolution kernel size of 3×3, 256 convolution kernel channels, and 256 convolution kernels to obtain the second scale fused feature map P4; (4c) The second-scale fusion feature map P4 is upsampled by nearest neighbor interpolation, and the enhanced first-scale enhancement feature map C3′ is transformed by a convolution layer with a convolution kernel of 1×1, 32 convolution kernel channels, and 256 convolution kernels. The two are fused by element-by-element addition, and then the convolution kernel is passed through a convolution layer with a convolution kernel of 3×3, 256 convolution kernel channels, and 256 convolution kernels to obtain the first-scale fusion feature map P3; (4d) A convolution layer with a convolution kernel size of 1×1, a convolution kernel channel number of 256, and a total number of convolution kernels of 256 is used to reduce the dimension of the third scale feature map C5. * Enhanced to obtain the third scale enhanced feature map P5; (4e) The spatial attention SE adjusts the feature information of each channel of the third-scale enhanced feature map P5, and passes through a convolution layer with a step size of 2, a convolution kernel of 3×3, a number of convolution kernel channels of 256, and a total number of convolution kernels of 256 to obtain a fourth-scale enhanced feature map P6 with a size reduced by half; (4f) The spatial attention SE adjusts the global feature information of the fourth-scale enhanced feature map P6, and sequentially passes through the RELU activation layer and the convolution layer with a step size of 2, a convolution kernel of 3×3, a convolution kernel channel number of 256, and a total number of convolution kernels of 256 to obtain the fifth-scale enhanced feature map P7 with a size reduced by half; (4g) Arrange the feature maps P3, P4, P5, P6, and P7 obtained from (4a) to (4f) from bottom to top to obtain a multi-scale attention feature pyramid; (5) Based on the fully convolutional one-stage object detection FCOS framework, the MobileNetv2 network, lightweight multi-receptive field module, attention feature pyramid, and prediction module are combined into a deep learning network; (6) Training deep learning network: (6a) Use the pre-trained model on the ImageNet dataset to initialize the MobileNetv2 network, and use the normal distribution N(0,0.01) to initialize the weight parameters of the remaining layers of the deep learning network; (6b) Preprocessing training sample set: resize the image to 512×512 and perform data augmentation; (6c) Set the deep learning network training hyperparameters: set the number of iterations to 72k, the learning rate of the MobileNetv2 network to 0.00067, and the learning rate of the remaining networks to 0.
002. At the 50k and 60k iterations, the learning rate is reduced to 0.1 times the current learning rate. The number of images input at a time is set to 8 batches. (6d) Input the batch of images in the training sample set into the deep learning network for forward propagation to obtain the predicted category and predicted box coordinates; (6e) Adopt an adaptive training sample allocation strategy to assign positive and negative samples to each prediction box; (6f) Use the generalized focal loss function to calculate the loss value between the predicted box and the corresponding sample; (6g) Back-propagating the loss value in the deep learning network, and using the gradient descent method to update the weight parameters of each network node until the loss value converges to obtain a trained deep learning network; (7) Target Detection (7a) The images in the test sample set are resized to 512×512 and input into the trained deep learning network for forward propagation to obtain the predicted category and predicted box coordinates of each image; (7b) The non-maximum suppression method is used to filter the overlapping prediction boxes and obtain the final prediction category and prediction box coordinates.
2. The method according to claim 1, characterized in that: The parameters of each layer of the hollow residual network in (3a) are set as follows: Standard convolution layer, whose convolution kernel size is set to 1×1; Channel-by-channel atrous convolution layer, the size of the convolution kernel is set to 3×3; In the point-by-point convolution layer, the size of the convolution kernel is set to 1×1.
3. The method according to claim 1, characterized in that: The parameters of each layer network of the lightweight multi-receptive field module corresponding to the first scale feature map C3 in (3b) are set as follows: In each layer of the dilated residual network, the number of channels of the convolution kernel of the standard convolution layer is set to 32, and the total number of convolution kernels is 192; In each layer of the dilated residual network, the number of channels of the convolution kernel of the channel-by-channel dilated convolution layer is set to 192, and the total number of convolution kernels is 192; In each layer of the dilated residual network, the number of channels of the convolution kernel of the point-by-point convolution layer is set to 192, and the total number of convolution kernels is 32; The dilation rates of channel-by-channel dilated convolutions in the first, second, and third layers of the dilated residual networks are set to 1, 2, and 3, respectively.
4. The method according to claim 1, characterized in that: The parameters of each layer network of the lightweight multi-receptive field module corresponding to the second scale feature map C4 in (3c) are set as follows: In each layer of the dilated residual network, the number of channels of the convolution kernel of the standard convolution layer is set to 96, and the total number of convolution kernels is 576; In each layer of the dilated residual network, the number of channels of the convolution kernel of the channel-by-channel dilated convolution layer is set to 576, and the total number of convolution kernels is 576; In each layer of the dilated residual network, the number of channels of the convolution kernel of the point-by-point convolution layer is set to 576, and the total number of convolution kernels is 96; The dilation rates of channel-by-channel dilated convolutions in the first, second, and third layers of the dilated residual networks are set to 1, 2, and 3, respectively.
5. The method according to claim 1, characterized in that: The connection relationship between the modules in the deep learning network in (5) is as follows: the MobileNetv2 network is connected to the lightweight multi-receptive field module and the attention feature pyramid respectively; the lightweight multi-receptive field module is connected to the attention feature pyramid; The attention feature pyramid is connected with the prediction module.
6. The method according to claim 1, characterized in that: In (6e), an adaptive training sample allocation strategy is adopted to allocate positive and negative samples to each prediction box, which is implemented as follows: (6e1) Construct an anchor frame for each prediction frame. The center point of the anchor frame is the coordinate point corresponding to the prediction frame on the original image. The size of the anchor frame is the product of the step size corresponding to the prediction frame on the original image and the parameter scale_factor. The parameter scale_factor is 4. (6e2) Calculate the Euclidean distance between each true box and all anchor boxes, and select the k anchor boxes with the smallest Euclidean distance, and the parameter k is 9; (6e3) Calculate the mean and standard deviation of the IOU between the real box and the corresponding k anchor boxes, and add the mean and standard deviation as the IOU threshold; (6e4) Filter the k anchor boxes corresponding to the true box according to the IOU threshold: the anchor boxes larger than the IOU threshold are taken as positive samples, and the anchor boxes smaller than the IOU threshold are taken as negative samples.
7. The method according to claim 1, characterized in that: The generalized focal loss function GFL in (6f) is composed of the classification loss function QFL, the bounding box loss function DFL, and the bounding box distribution loss function L GIOU The combination is as follows: Among them, N pos represents the sum of the number of positive samples corresponding to all predicted boxes, q is the IOU value of the predicted box and the true box, σ is the predicted category score, the hyperparameter β is 2, y and z represent the true box and the predicted box respectively, r represents the minimum rectangular box surrounding the true box and the predicted box, z i and z i+1 is the left and right coordinate value closest to y in the prediction box, and the hyperparameters λ0 and λ1 are set to 2. Indicates the positive or negative sample corresponding to the prediction box, If 1 if yes, 0 otherwise.
8. The method according to claim 1, characterized in that: In (7b), the non-maximum suppression method is used to filter the overlapping prediction boxes, which is implemented as follows: (7b1) Setting the screening threshold N; (7b2) Using all prediction boxes to form an initial prediction box set B; (7b3) Create the final prediction box set D, initialized to an empty set; (7b4) Multiply the IOU value of the predicted box and the true box and the predicted category score as the confidence, and sort the predicted boxes in set B in descending order according to the confidence; (7b5) Select the first prediction box, add it to set D, and delete it from set B; (7b6) Traverse all the prediction boxes in set B and calculate their IOU values with the final prediction boxes in set D. If the IOU value is greater than the threshold N, delete it from set B; (7b7) Repeat steps (7b5) to (7b6) until set B is empty; (7b8) The elements in the output set D are used as the final prediction box.
