A target detection method that takes into account both detection speed and detection accuracy
By introducing lightweight network MobileNet v2 and coordinated attention mechanism in YOLO v4, the problem of speed and accuracy of deep learning object detection algorithm in mobile devices is solved, and efficient object detection is achieved.
Patent Information
- Application Number
- CN202310152180.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-02-22
- Publication Date
- 2025-08-22
- Estimated Expiration
- 2043-02-22
AI Technical Summary
The existing deep learning object detection algorithm models are large in size, have a large number of parameters, and are slow in computing speed, making them difficult to effectively apply in mobile devices or embedded devices, and lightweight models are difficult to take into account both detection accuracy and real-time.
The lightweight network MobileNet v2 is used to replace the backbone network of YOLO v4, and combined with coordinated attention (CA) and hollow pyramid pooling (CAASPP), an improved YOLO v4 target detection network is built to improve detection speed and accuracy through feature fusion and attention mechanisms.
While ensuring the accuracy of detection, it greatly improves the detection speed. It is suitable for mobile devices and embedded devices and has important application value.
Smart Images

Figure CN116343081B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the fields of computer vision technology and target detection, and in particular to a target detection method that takes both detection speed and detection accuracy into consideration. Background Art
[0002] Object detection algorithms are the core foundation of computer vision and hold significant research and application value. With the development of deep learning, computer vision is playing a vital role in various fields. Traditional object detection algorithms typically use hand-crafted features for classification, which are not well-suited to the diversity of targets. Classic deep learning object detection algorithms, such as the Region Convolutional Neural Network (RCNN), often employ large, parameter-heavy, and computationally slow models, making them difficult to integrate into mobile or embedded devices. Existing lightweight models, such as GoogleNet (Google Inception Net), struggle to balance detection accuracy and real-time performance. Therefore, designing highly accurate and fast object detection networks has become a pressing issue in both academic research and practical applications. Summary of the Invention
[0003] The present invention aims to address the shortcomings of target detection methods based on deep convolutional neural networks and proposes a target detection method that takes into account both detection speed and detection accuracy. This method can significantly improve the detection speed while ensuring detection accuracy, and effectively exert the performance of the network in practical applications.
[0004] The purpose of the present invention is achieved through the following technical solutions:
[0005] A target detection method that takes into account both detection speed and detection accuracy includes the following steps:
[0006] S1, collect data and build dataset;
[0007] Based on the task requirements, collect data and build the data set required for the detection task;
[0008] S2, labeled dataset:
[0009] Label the dataset and divide it into training set, validation set and test set;
[0010] S3, build the target detection network:
[0011] The YOLO v4 target detection network consists of a backbone network, a feature fusion network, and a detection head, including the following steps:
[0012] In S3-1, in the backbone network, the lightweight network MobileNet v2 is used to replace the backbone network in YOLO v4 for feature extraction, thereby obtaining three preliminary effective feature layers of different sizes;
[0013] S3-2, combined with Coordinate Attention (CA), adds a Coordinate Attention Atrous spatial pyramid pooling (CAASPP) after the minimum effective feature layer;
[0014] S4, training network:
[0015] Use the training set and validation set described in S2 to train the network in S3 to obtain a trained network detection model;
[0016] S5, target detection test:
[0017] Use the trained network in S4 to test the test set in S2 to verify the training results and detect the target.
[0018] Furthermore, in S2, the training set accounts for 78-84%, the validation set accounts for 6-12%, and the test set accounts for 7-13%.
[0019] Furthermore, S4 includes the following steps:
[0020] S4-1, normalize the image used for training to 416×416 pixels;
[0021] S4-2, set model parameters:
[0022] The number of training iterations is 100 to 300, the initial learning rate lr is 3e-5 to 5e-5, and the batch_size of the number of images put into the network training each time is 4 to 32;
[0023] S4-3, the Backbone part of the target detection network performs a convolution operation on the image to obtain three valid feature maps, and then extracts and fuses feature information from these three valid feature maps. During the fusion process, the feature maps undergo multiple upsampling operations to extract high-dimensional features, and then are fused with features of different scales respectively. Finally, the prediction head of the target detection network outputs the detection results to obtain the detection model.
[0024] Advantages or beneficial effects of the present invention:
[0025] 1. This paper addresses the issues of classic deep learning object detection algorithms, such as large model size, numerous parameters, and slow computational speed, which hinder their integration into mobile or embedded devices. This paper proposes an object detection method that balances detection accuracy and speed. This method replaces the original deep network with a lightweight network, significantly reducing the network's computational complexity and parameter requirements. This method can significantly improve the speed of object detection, thereby meeting the requirements of real-time detection.
[0026] 2. This paper introduces an attention mechanism into the network to better obtain rich contextual information. By combining the attention mechanism, it compensates for some of the precision loss caused by model lightweighting and improves the accuracy of the network model.
[0027] 3. The present invention has broad application prospects and has important practical value in the fields of biological resource exploration, species protection, etc. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a flow chart of a target detection method that takes both detection speed and detection accuracy into consideration in an embodiment of the present invention;
[0029] Figure 2 This is the schematic diagram of the improved YOLO v4 algorithm;
[0030] Figure 3 This is the CAASPP schematic diagram;
[0031] Figure 4 This is the CA schematic diagram. DETAILED DESCRIPTION
[0032] The present invention will be described in detail below with reference to the accompanying drawings and embodiments, examples of which are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain the present invention, but should not be construed as limiting the present invention.
[0033] Example:
[0034] like Figure 1 As shown, a target detection method that takes into account both detection speed and detection accuracy includes the following steps:
[0035] Step 1), collect data and build a data set;
[0036] Use a camera or other device to obtain photos of underwater creatures, including the underwater creatures to be detected, and use a relevant data set. The simulation experiment in this invention is mainly for underwater fish detection. The data set uses the Labeled Fishes in the Wild fish data set and ornamental fish pictures collected from the Internet, with a total of 2100 fish images.
[0037] Step 2), label the dataset:
[0038] The images in step 1) are manually annotated into a VOC format dataset, so that the training set accounts for 81%, the validation set accounts for 9%, and the test set accounts for 10%. The training set accounts for 1701 images, the validation set accounts for 189 images, and the test set accounts for 210 images;
[0039] Step 3), build the target detection network:
[0040] The target detection network is composed of an improved YOLO v4 network, such as Figure 2 As shown in the figure, MobileNet v2 represents the backbone network of the improved YOLO v4 network, Linear Bottleneck represents the linear bottleneck structure, ASPP represents the atrous pyramid pooling part, Concat represents the connection operation, Conv represents the convolution operation, UpSampling represents the upsampling operation, DownSampling represents the downsampling operation, CA represents the coordinated attention module, and Head represents the detection head;
[0041] The improved object detection network differs from the original YOLO v4 network in the following two aspects:
[0042] 1) The backbone network is replaced by MobileNet v2 instead of the original CSPDarkNet53 for feature extraction. The three initial effective feature layers of the same size are fused to replace MobileNet v2 with YOLOv4. The sizes of the three initial effective feature layers are 13×13×1024, 26×26×512, and 52×52×256 respectively.
[0043] 2) Add a CAASPP after the smallest valid feature layer 13×13×1024.
[0044] During detection, it is only necessary to input the image to be detected into the backbone network, and finally the detection head can detect whether the target to be detected exists.
[0045] like Figure 3 As shown in CAASPP, Input represents input, Conv represents convolution operation, rate represents expansion factor, Image Pooling represents global average pooling, CA represents coordinated attention module, Concat represents connection operation, Output represents
[0046] Represents output.
[0047] The specific implementation process of CAASPP can be expressed as follows:
[0048] The input feature map is mapped into six parts, which are respectively passed through four convolutions, one pooling and a CA module to obtain six feature maps. These six feature maps are spliced and then the number of channels and input features are adjusted by connecting 1×1 convolution. Figure 1 The output feature map can be obtained.
[0049] For the convolution part, a 1×1 convolution module and three 3×3 dilation factors with rate = {1, 3, 5} are used; for the pooling part, global average pooling is used; for the CA part, the CA attention mechanism is used.
[0050] like Figure 4 As shown in the figure, in the CA module, X Avg Pool represents global average pooling in the horizontal direction, Y AvgPool represents global average pooling in the vertical direction, Concat represents a connection operation, Conv2d represents a two-dimensional convolution operation, BatchNorm represents a batch normalization operation, Non-Linear represents a nonlinear processing operation, split represents a segmentation operation, and Sigmoid represents an activation function.
[0051] The specific implementation process of CA can be expressed as follows:
[0052] The initial input feature map is defined as F = (h, w, c), where h is the height of the feature map, w is the width of the feature map, and c is the number of channels of the feature map, that is, the spatial dimension.
[0053] In order to obtain attention on the width and height of the image and encode the precise position information, CA first performs global average pooling on the input feature map in the width (X direction) and height (Y direction) directions respectively, and obtains feature maps in the width and height directions respectively, as shown in formula (1) and formula (2):
[0054]
[0055]
[0056] in, Represents the perceptual feature map in the height direction, Represents the perceptual feature map in the width direction; where i represents each position in the width direction, and j represents each position in the height direction;
[0057] Then, the feature maps of the width and height of the global receptive field are spliced together, and then the spliced feature maps are sent to the convolution module with a shared convolution kernel of 1×1, and their dimensions are reduced to the original c / r, where r represents the scaling factor; then the batch normalized feature map F1 is sent to the nonlinear activation function to obtain a feature map f of the shape of 1×(w+h)×c / r, as shown in formula (3):
[0058] f=δ(F1([z w ,z h ])) (3)
[0059] Among them, δ(·) represents the nonlinear activation function; z w Represents the perceptual feature map in the width direction; z h Represents the perceptual feature map in the height direction;
[0060] Then, the feature map f is convolved with a kernel of 1×1 according to the height and width of the original F to obtain the feature map F with the same number of channels as the original h and F w , after the Sigmoid activation function, the attention weight g of the feature map in the height direction is obtained h and the attention weight g in the width direction w , as shown in the following formula (4) and formula (5):
[0061] g h =σ(F h (f h )) (4)
[0062] g w =σ(F w (f w )) (5)
[0063] Among them, σ(·) represents the Sigmoid activation function, f h Represents the perceptual feature map in the height direction after the nonlinear activation function, f w Represents the perceptual feature map in the width direction after the nonlinear activation function;
[0064] After the above calculation, the attention weight g of the input feature map in the height direction is obtained h and the attention weight g in the width direction w Finally, a weighted multiplication calculation is performed on the initial input feature map to obtain a feature map with attention weights in the width and height directions, as shown in formula (6):
[0065]
[0066] Among them, yc (i, j) represents the coordinate attention output of the i-th row and j-th column on the feature map of the c-th channel, x c (i,j) represents the element in row i and column j of the feature map on channel c. Represents the weight value of the i-th row on the feature map of the c-th channel, Represents the weight value of the jth column on the feature map on the cth channel;
[0067] In step 4), the improved YOLOv4 network model is trained using the image dataset with category and location labels described in step 2. The specific operations are as follows:
[0068] a. Normalize the images used for training to 416×416 pixels;
[0069] b. Set model parameters:
[0070] The training iteration period is set to epoch = 200, the initial learning rate is set to lr = 5e-5, and the batch_size of the images put into the network training each time is set to 8;
[0071] c. The backbone of the object detection network performs a convolution operation on the image to obtain three valid feature maps. Feature information is extracted and fused from these three valid feature maps. During the fusion process, the feature maps undergo multiple upsampling operations to extract high-dimensional features, which are then fused with features of different scales. Finally, the prediction head of the object detection network outputs the detection results to obtain the detection model.
[0072] d. After 200 iterations, the loss function stabilizes, proving that the model is credible.
[0073] In step 5), the trained improved YOLO v4 model is used to test the test set in step 2) to verify the training results; and the non-maximum suppression method is used to detect the underwater fish in step 1), where the suppression value is set to 0.5. After the above steps, the real-time performance of target monitoring can be greatly improved while ensuring the accuracy of target detection.
[0074] The preferred embodiments of the present invention disclosed above are merely illustrative of the present invention and are not intended to limit the present invention to the specific embodiments described. Obviously, numerous modifications and variations are possible based on the contents of this specification. These embodiments are selected and described in detail herein to better explain the principles and practical applications of the present invention, thereby enabling those skilled in the art to better understand and utilize the present invention.
Claims
1. A target detection method that takes into account both detection speed and detection accuracy, characterized in that: The steps include: S1, collect data and build dataset; Based on the task requirements, collect data and build the data set required for the detection task; S2, labeled dataset: Label the dataset and divide it into training set, validation set and test set; S3, build the target detection network: The YOLO v4 target detection network consists of a backbone network, a feature fusion network, and a detection head, including the following steps: In S3-1, in the backbone network, the lightweight network MobileNet v2 is used to replace the backbone network in YOLO v4 for feature extraction, thereby obtaining three preliminary effective feature layers of different sizes; S3-2, combined with Coordinate Attention (CA), adds a Coordinate Attention Atrous spatial pyramid pooling (CAASPP) after the minimum effective feature layer; The input feature map is mapped into six parts, which are respectively passed through four convolutions, one pooling and a CA module to obtain six feature maps. These six feature maps are spliced together, and then the number of channels is adjusted to be consistent with the input feature map by connecting 1×1 convolution to obtain the output feature map; For the convolution module, a 1×1 convolution module and three 3×3 dilation factors with rate={1, 3, 5} are used; for the pooling module, global average pooling is used; for the CA module, the CA attention mechanism is used. S4, training network: Use the training set and validation set described in S2 to train the network in S3 to obtain a trained network detection model; S5, target detection test: Use the trained network in S4 to test the test set in S2 to verify the training results and detect the target.
2. The target detection method according to claim 1, wherein: In S2, the training set accounts for 78-84%, the validation set accounts for 6-12%, and the test set accounts for 7-13%.
3. The target detection method according to claim 1, wherein: S4 includes the following steps: S4-1, normalize the image used for training to 416×416 pixels; S4-2, set model parameters: The number of training iterations is 100 to 300, the initial learning rate lr is 3e-5 to 5e-5, and the batch_size of the number of images put into the network training each time is 4 to 32; S4-3, the Backbone part of the target detection network performs a convolution operation on the image to obtain three valid feature maps, and then extracts and fuses feature information from these three valid feature maps. During the fusion process, the feature maps undergo multiple upsampling operations to extract high-dimensional features, and then are fused with features of different scales respectively. Finally, the prediction head of the target detection network outputs the detection results to obtain the detection model.
Citation Information
Patent Citations
Lightweight model-based insulator defect detection method and system
CN114782410A
Power operation site safety protection equipment wearing state detection method based on YOLO-MobileNet
CN115424063A