Lightweight parking detection method based on multi-scale attention mechanism
By introducing a multi-scale attention mechanism and optimized loss function in the YOLOv8 network, the problems of low detection accuracy and high computing cost in extreme environments in the prior art are solved, and the lightweight and accurate parking space status detection is achieved.
Patent Information
- Application Number
- CN202411277361.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-12
AI Technical Summary
The existing object detection algorithm has low detection accuracy in extreme weather and low-light environments, and the cost and time of model training and detection operations are high, making it difficult to achieve lightweight and accurate parking space status detection.
The lightweight YOLOv8 network structure based on multi-scale attention mechanism is adopted, and the feature extraction process is optimized by introducing the MobileNetV3 module, C2f_SCConv module and EMA attention mechanism, and a new loss function WIoU v3 is introduced to improve robustness and accuracy.
In the case of reducing computing resources and memory usage, the feature representation ability of the model at different scales is improved, the harmful gradient of low-quality examples is reduced, the detection accuracy and robustness is improved, and the parking space status detection is achieved lightweight and precision.
Smart Images

Figure CN119314141A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of image processing and target detection, and relates to a lightweight parking detection method based on a multi-scale attention mechanism. Background Art
[0002] In the context of modern fast-paced life, people's demand for time and efficiency is constantly increasing, and the utilization rate of vehicles is on the rise, making the role and significance of parking space status detection in parking lots particularly prominent. During peak hours and emergency situations, if real-time parking space occupancy information is provided, the time it takes for vehicles to find parking spaces can be significantly reduced. Therefore, the invention of parking space status detection in parking lots with high efficiency and accuracy is of great significance to improving the efficiency of parking lots and vehicle users and meeting the needs of modern society for speed, convenience and safety.
[0003] At present, there are many image processing algorithms that can complete detection tasks, such as image segmentation, target detection, etc. In recent years, target detection technology has made significant progress, especially the invention of target detection based on convolutional neural network has surpassed the traditional invention and become the current mainstream technology. At present, the mainstream target detection algorithms based on convolutional neural network are mainly divided into two categories: two-stage target detection algorithm, first generate candidate regions, then use convolutional neural network to classify these candidate regions, and perform position correction at the same time, such as R-CNN and Fast R-CNN, etc. Although this invention achieves high detection accuracy through multiple detection and classification steps, the speed is relatively slow; single-stage target detection algorithm, unlike the two-stage invention, this type of algorithm does not require a separate candidate region generation step, and directly outputs the category probability and position coordinates of the object, such as YOLO series, SSD, OverFeat and RetinaNet, etc. Its advantage lies in the end-to-end detection process, which significantly speeds up the detection speed.
[0004] With the continuous development of the YOLO series of algorithms, the Ultralytics team released YOLOv8 in 2023. YOLOv8 has made many improvements and optimizations based on the YOLO series, including the introduction of the C2f (CSPNet to Fusion) module, the improved feature pyramid network (FPN) and the path aggregation network (PANet), as well as the latest activation functions and model compression technology. These innovations make YOLOv8 perform well in target detection tasks, providing efficient detection speed and excellent detection accuracy. Although YOLOv8 performs well in many aspects, its detection accuracy may still be affected in extreme weather, low light and other environments. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide a lightweight parking detection method based on a multi-scale attention mechanism, aiming to further enhance the model's ability to extract features from images, while improving target detection accuracy and robustness, reducing the computational cost and time of model training and detection, and achieving lightweight and accurate parking space status detection.
[0006] In order to achieve the above object, the present invention provides the following technical solutions:
[0007] A lightweight parking detection method based on a multi-scale attention mechanism comprises the following steps:
[0008] S1. Obtain a parking space dataset and preprocess the dataset;
[0009] S2. Construct a lightweight YOLOv8 network structure, which includes at least several MobileNetV3 modules and several C2f_ScConv modules in the Backbone layer; introduce the EMA attention mechanism between the C2f module and the Detect module in the Neck layer;
[0010] S3, establish the loss function WIoU v3 for the lightweight YOLOv8 network structure;
[0011] S4. Based on the preprocessed data set, the lightweight YOLOv8 network structure is trained to obtain a lightweight parking detection model, and the parking space status is detected in real time through the lightweight parking detection model.
[0012] Further, in step S1, the process of obtaining the data set includes: autonomously collecting parking space images, collecting an open source parking space detection data set, and integrating the autonomously collected parking space images with the open source parking space detection data set to obtain a final data set;
[0013] The preprocessing process of the data set includes: annotating the images in the data set, that is, annotating them into two states: parking space vacant and parking space occupied; dividing the annotated data set into a training set and a test set.
[0014] Furthermore, in step S2, the constructed lightweight YOLOv8 network structure mainly includes the backbone network Backbone, the neck network Neck, and the head network Head.
[0015] The backbone network Backbone includes at least one conventional convolution layer Conv, several lightweight convolution neural networks MobileNetV3, several C2f_ScConv modules and at least one spatial pyramid pooling module SPPF. In the backbone network, the input image first passes through several groups of MobileNetV3 convolution layers and C2f_ScConv modules to gradually extract feature maps of different scales. Each group of MobileNetV3 convolution layers and C2f_ScConv modules inputs the extracted features into the next layer for higher-level feature extraction until they are output to the SPPF module at the end of the backbone network.
[0016] In the neck network Neck, there is at least one upsampling module Upsample, several concatenation modules Concat, several convolution modules C2f and several efficient multi-scale attention modules EMA. In the neck network, the high-level feature map output by the SPPF module of the backbone network is first upsampled, and then fused with the low-level feature map of the backbone network through the concatenation module Concat. The fused feature map is subjected to feature extraction and information emphasis by the convolution module C2f and the EMA module.
[0017] The head network Head receives the multi-scale feature maps from the neck network and performs the final target detection task through the detection module Detect, including bounding box regression and category prediction.
[0018] Furthermore, the lightweight convolutional neural network MobileNetV3 includes at least an inverted residual bottleneck structure, which first uses a 1×1 conventional convolution to increase the number of channels of the feature map, expanding the low-dimensional input to a high dimension; in the expanded high-dimensional space, a depth-wise separable convolution is used to extract features in the spatial dimension; then the channel is processed using a 1×1 conventional convolution and a Sigmoid function, and finally bilinear upsampling; in the segmentation task, after upsampling to the target size, the final output is adjusted by a 1×1 conventional convolution;
[0019] When the input feature map size and number of channels are consistent with the output, the input is directly output through the skip connection;
[0020] The activation function is the h-SigMoid activation function, which approximates the curve of the standard Sigmoid function with a piecewise linear function. The calculation formula is:
[0021]
[0022] Where ReLU is an activation function, which is shown as follows:
[0023] ReLU(x)=min(max(0,x),b)
[0024] Among them, a is used to translate the input so that the input of the h-SigMoid activation function in the interval [-a, a] is mapped to the effective range of the ReLU activation function; b is used to standardize the output, normalizing the output of the ReLU activation function from [0, b] to [0, 1].
[0025] Furthermore, in the C2f_ScConv module, the input feature map is first split into two parts through a conventional convolution Conv and a segmentation layer Split. One part skips several Bottleneck_ScConv layers of the backbone network and is directly input into the subsequent concatenation layer Concat; the other part enters multiple Bottleneck_ScConv layers in the backbone network for feature processing, wherein each Bottleneck in the Bottleneck_ScConv module performs a self-calibrated convolution operation through SCConv, and the features extracted and output by each Bottleneck_ScConv layer are respectively passed to the concatenation layer Concat and the next Bottleneck_ScConv layer, and the concatenation layer Concat fuses all the received features through the channel dimension, and the fused features include the features extracted by the deep convolution and the retained shallow information;
[0026] In the SCConv module, the input feature map X is first processed by the spatial reconstruction unit SRU to suppress spatial redundancy and generate a spatial refined feature X W , the generated space refined feature X W Then it is input into the channel reconstruction unit CRU for processing to reduce channel redundancy and obtain the channel refined feature Y.
[0027] Furthermore, the processing flow of the EMA attention mechanism between the C2f module and the Detect module is as follows:
[0028] The size of the input feature map is C×H×W, where C represents the number of channels, H represents the height, and W represents the width; the input feature map is divided into G groups through the grouping operation, and the number of channels in each group is C / G;
[0029] Each set of feature maps generates two 1-dimensional feature vectors through average pooling in the X direction and average pooling in the Y direction. The two 1-dimensional feature vectors are processed through point-by-point convolution and activation function to generate two attention weight vectors. The two attention weight vectors are multiplied by matrix to generate an H×W attention matrix.
[0030] Each set of feature maps is also processed by global average pooling to generate a 1-dimensional feature vector; the 1-dimensional feature vector is processed by point-by-point convolution and activation function to generate an attention weight vector; the attention weight vector is processed by matrix multiplication to generate a C / G×1 attention matrix;
[0031] The spatial attention matrix and the channel attention matrix are fused through matrix multiplication operations to generate an H×W×C / G attention matrix; the attention matrix is processed through point-by-point convolution and activation function to generate the final attention weight matrix; the final attention weight matrix is element-wise multiplied with the input feature map to generate the feature map after reallocation of weights; the feature map after reallocation of weights is processed through point-by-point convolution and activation function to generate the final output feature map;
[0032] Assume that the input feature map X∈R N×C×H×W , where N is the batch size, using different convolution kernels or pooling operations to capture features at different scales:
[0033]
[0034] Among them, k s Represents the size of the sth convolution kernel;
[0035] In the cross-space learning part, the module calculates the attention weight by interacting with the features of the spatial position; the softmax function is used to normalize the attention score:
[0036]
[0037] Among them, e i,j is the attention score of a specific position, a i,j is the normalized attention weight.
[0038] Further, in step S3, WIoU v3 is a new bounding box regression loss function, which introduces a dynamic focusing mechanism to improve the traditional IoU loss:
[0039] Let the true bounding box be B = (x1, y1, x2, y2) and the predicted bounding box be The calculation formula of IoU is:
[0040]
[0041] in, represents the intersection of the true bounding box and the predicted bounding box, area(B) and are the areas of the true and predicted bounding boxes, respectively;
[0042] The value of WIoU v3 is adjusted according to the IoU value and an introduced focusing factor α, and its formula is:
[0043]
[0044] Among them, α is a dynamic focusing parameter, which changes with the change of IoU value.
[0045] The beneficial effects of the present invention are:
[0046] The present invention realizes the lightweight and precise parking space status detection. Compared with the existing technology, firstly, the MobileNetV3 module is introduced, the C2f_SCConv module is improved, and the EMA attention mechanism is integrated. By optimizing the feature extraction process, the model can obtain more detailed and rich feature representation at different scales while reducing computing resources and memory usage; secondly, the loss function is optimized by replacing the loss function with WIoU v3. While reducing the competitiveness of high-quality anchor frames, the harmful gradients generated by low-quality examples are also reduced, showing better robustness and accuracy.
[0047] Other advantages, objectives and features of the present invention will be described in the following description to some extent, and to some extent, will be obvious to those skilled in the art based on the following examination and study, or can be taught from the practice of the present invention. The objectives and other advantages of the present invention can be realized and obtained through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] In order to make the purpose, technical solutions and advantages of the present invention more clear, the present invention will be described in detail below in conjunction with the accompanying drawings, wherein:
[0049] Figure 1 This is the network structure diagram of the Parking_YOLO model;
[0050] Figure 2 This is the network structure diagram of the MobileNetV3 module;
[0051] Figure 3 This is the network structure diagram of the SCConv module;
[0052] Figure 4 This is the network structure diagram of the C2f_ScConv module;
[0053] Figure 5 This is the processing flow chart of the EMA attention mechanism;
[0054] Figure 6 This is a diagram of the training results of the Parking_YOLO model;
[0055] Figure 7 A schematic diagram of a test example. DETAILED DESCRIPTION
[0056] The following describes the embodiments of the present invention by specific examples, and those skilled in the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and the details in this specification can also be modified or changed in various ways based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that the illustrations provided in the following embodiments only illustrate the basic concept of the present invention in a schematic manner, and the following embodiments and features in the embodiments can be combined with each other without conflict.
[0057] Among them, the drawings are only used for illustrative explanations, and they only represent schematic diagrams rather than actual pictures, and should not be understood as limitations on the present invention. In order to better illustrate the embodiments of the present invention, some parts of the drawings may be omitted, enlarged or reduced, and do not represent the size of actual products. For those skilled in the art, it is understandable that some well-known structures and their descriptions in the drawings may be omitted.
[0058] The same or similar numbers in the drawings of the embodiments of the present invention correspond to the same or similar parts; in the description of the present invention, it should be understood that if the terms "upper", "lower", "left", "right", "front", "rear", etc. indicate the orientation or position relationship, they are based on the orientation or position relationship shown in the drawings, which is only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation. Therefore, the terms describing the position relationship in the drawings are only used for illustrative purposes and cannot be understood as limiting the present invention. For ordinary technicians in this field, the specific meanings of the above terms can be understood according to specific circumstances.
[0059] See also Figure 1 to Figure 7 , which is a lightweight parking detection method based on multi-scale attention mechanism.
[0060] Example
[0061] This embodiment proposes a lightweight parking detection method based on a multi-scale attention mechanism, which includes the following steps:
[0062] S1. Obtain a parking space dataset and preprocess the dataset;
[0063] S2. Construct a lightweight YOLOv8 network structure, which includes at least several MobileNetV3 modules and several C2f_ScConv modules in the Backbone layer; introduce the EMA attention mechanism between the C2f module and the Detect module in the Neck layer;
[0064] S3, establish the loss function WIoU v3 for the lightweight YOLOv8 network structure;
[0065] S4. Based on the preprocessed data set, the lightweight YOLOv8 network structure is trained to obtain a lightweight parking detection model, and the parking space status is detected in real time through the lightweight parking detection model.
[0066] In this embodiment, step S1 includes collecting a large number of parking space images, and the collected parking space images cover as many parking space scenes as possible. In addition, the large number of collected parking space images are integrated with the open source parking space image dataset as the dataset of this embodiment. The open source datasets include PKLot and CNRPark-EXT, which are two parking space detection datasets. The KLot dataset was created by the Federal University of Technology of Brazil and contains parking lot images in three different locations (Sao Paulo and Curitiba, Brazil), covering three weather conditions of sunny, cloudy and rainy days. The CNRPark-EXT dataset was created by the University of Rome Tor Vergata in Italy and contains images collected from different camera perspectives in the university parking lot, divided into daytime and nighttime parts.
[0067] The integrated data are labeled with two states: parking space vacancy and parking space occupation, and divided into training set and test set.
[0068] In this embodiment, the structural diagram of the lightweight YOLOv8 network structure constructed in step S2 is as follows: Figure 1As shown in the figure, the lightweight YOLOv8 network structure mainly includes the backbone network Backbone, the neck network Neck, and the head network Head. In the backbone network Backbone, it includes at least one conventional convolution layer Conv, several lightweight convolution neural networks MobileNetV3, several C2f_ScConv, and at least one spatial pyramid pooling module SPPF. The input image first passes through a series of convolution layers and C2f_ScConv modules to gradually extract feature maps of different scales. The SPPF module at the end of the backbone network is used to receive feature maps from the previous layer. After multi-scale pooling operations, feature maps with more semantic information are generated to provide rich features for the neck network. In the neck network Neck, it includes at least one upsampling module Upsample, several concatenation modules Concat, several convolution modules C2f, and several efficient multi-scale attention modules EMA. Starting from the high-level feature map of the backbone network, the upsampling module Upsample is first performed, and then it is fused with the lower-level feature map from the backbone network through the concatenation module Concat. The fused feature map passes through the convolution module C2f and the EMA module to further extract features and emphasize important information. The head network receives the multi-scale feature maps from the neck network and performs the final target detection task through the detection module Detect, including bounding box regression and category prediction.
[0069] like Figure 2The network structure of MobileNetV3 shown in the figure is a lightweight convolutional neural network architecture. It introduces multiple optimization methods such as the inverted residual bottleneck structure (Inverted Residuals with Linear Bottlenecks) and the h-SigMoid activation function, so that it can provide high-precision model performance while maintaining low computational complexity. The inverted residual bottleneck structure uses 1x1 convolution Conv to increase the number of channels of the feature map, expands the low-dimensional input to a high dimension, and expands the number of channels to 128, so that more information can be captured in the subsequent deep convolution operation. In the expanded high-dimensional space, the deep separable convolution is used to extract features in the spatial dimension, processing a 49×49 feature map, and then using 1×1 convolution and Sigmoid function to process the channel. Finally, after bilinear upsampling (BilinearUpsample), the feature map is further enlarged. In the segmentation task, after upsampling to the target size, the final output is adjusted by 1×1 convolution. When the input feature map size and number of channels are consistent with the output, directly adding the input to the output through a residual connection (skip connection) can help the network better transfer gradients and prevent information from disappearing in multi-layer networks. The h-SigMoid activation function reduces the computational complexity by approximating the curve of the standard Sigmoid function with a piecewise linear function. Its formula is:
[0070]
[0071] Where ReLU is an activation function, which is shown as follows:
[0072] ReLU(x)=min(max(0,x),b)
[0073] Among them, a is used to translate the input so that the input of the h-SigMoid activation function in the interval [-a, a] is mapped to the effective range of the ReLU activation function; b is used to standardize the output, normalizing the output of the ReLU activation function from [0, b] to [0, 1].
[0074] In this embodiment, a=3, b=6, then specifically, we have:
[0075]
[0076] Among them, ReLU6 is an activation function, which is shown as follows:
[0077] ReLU6(x)=min(max(0,x),6)
[0078] Among them, "3" is used to translate the input so that the input of the activation function in the interval [-3,3] is mapped to the effective range of ReLU6 (i.e. [0,6]), and "6" is used to standardize the output, normalizing the output of ReLU6 from [0,6] to [0,1].
[0079] The C2f module that integrates SCConv is introduced. The SCConv module not only reduces the number of model parameters and FLOPs, but also enhances the ability of feature representation. Figure 3 The schematic diagram of the SCConv module shown in Figure 1 shows the structure of the SCConv module. The SCConv module uses two components: the spatial reconstruction unit (SRU) and the channel reconstruction unit (CRU). The SRU suppresses spatial redundancy through a separation-reconstruction method, while the CRU uses a segmentation-conversion-fusion strategy to reduce channel redundancy. In the SCConv module, the input feature map X is first processed by the spatial reconstruction unit SRU to suppress spatial redundancy and generate a spatial refined feature X. W , the generated space refined feature X W Then it is input into the channel reconstruction unit CRU for processing to reduce channel redundancy and obtain the channel refined feature Y.
[0080] The structural diagram of the C2f_ScConv module that integrates SCConv is as follows Figure 4 As shown in the figure, its structure is to divide the input feature map into two parts through conventional convolution Conv and segmentation layer Split. One part directly skips the middle layer of the backbone network, and the other part enters multiple Bottleneck_ScConv layers in the network. The cv2 in Bottleneck_ScConv calls SCConv to process features, and the SCConv module integrates the two core components SRU and CRU. Therefore, in C2f_ScConv, each Bottleneck will undergo a self-calibrated convolution operation through SCConv, forming a Bottleneck_ScConv module, which enhances the feature extraction capabilities of the channel and spatial dimensions. After completing the feature extraction of Bottleneck_ScConv, the feature map and the skipped part of the input feature map are fused through the channel dimension. The fused features include the features extracted by deep convolution and the retained shallow information.
[0081] The EMA attention mechanism is added to the connection between C2f and Detect in the Neck layer. This module can efficiently capture multi-scale information and enhance spatial feature learning, improve the representation of features at different scales and in different spatial regions, and provide a richer and more robust understanding of the input data. Figure 5As shown in the figure, the size of the input feature map (Input) is C×H×W, where C represents the number of channels, H represents the height, and W represents the width. The input feature map is divided into G groups through the grouping operation (Groups), and the number of channels in each group is C / G. Each group of feature maps is subjected to the average pooling (X Avg Pool) in the X direction and the average pooling (YAvg Pool) in the Y direction to generate two 1-dimensional feature vectors. The two 1-dimensional feature vectors are processed by point-by-point convolution (Conv(1×1)) and activation function (Sigmoid) to generate two attention weight vectors. The two attention weight vectors are subjected to matrix multiplication (Matmul) to generate an H×W attention matrix. Each group of feature maps is subjected to the global average pooling (Avg Pool) operation to generate a 1-dimensional feature vector. This 1-dimensional feature vector is processed by point-by-point convolution (Conv(1×1)) and activation function (Softmax) to generate an attention weight vector. This attention weight vector is subjected to matrix multiplication (Matmul) to generate a C / G×1 attention matrix. The spatial attention matrix and the channel attention matrix are fused through a matrix multiplication (Matmul) operation to generate an H×W×C / G attention matrix. The attention matrix is processed through point-by-point convolution (Conv(1×1)) and an activation function (Sigmoid) to generate the final attention weight matrix. The final attention weight matrix is element-wise multiplied with the input feature map to generate a weighted feature map. The weighted feature map is processed through point-by-point convolution (Conv(1×1)) and an activation function (Sigmoid) to generate the final output feature map.
[0082] Assume that the input feature map X∈R N×C×H×W , where N is the batch size, C is the number of channels, H and W are the height and width of the spatial dimension, using different convolution kernels or pooling operations to capture features at different scales:
[0083]
[0084] Among them, k s Represents the size of the s-th convolution kernel, which is used to capture features of different scales.
[0085] In the cross-space learning part, the module calculates attention weights by interacting with the features of the spatial positions, which determine which features to focus on at different positions. The softmax function can be used to normalize the attention scores to ensure that the weights sum to 1, thereby highlighting important features and suppressing unimportant features.
[0086]
[0087] Among them, e i,jis the attention score of a specific position, a i,j is the normalized attention weight.
[0088] In this embodiment, step S3 establishes a new loss function. WIoU v3 is a new bounding box regression loss function that introduces a dynamic focusing mechanism to improve the traditional IoU loss and can better handle some problems in bounding box prediction, such as insensitivity to loss when approaching perfect matching and dynamic adjustment of prediction error. Assume that the true bounding box is B = (x1, y1, x2, y2) and the predicted bounding box is The calculation formula of IoU is:
[0089]
[0090] in, represents the intersection of the true bounding box and the predicted bounding box, area(B) and are the areas of the true and predicted bounding boxes, respectively.
[0091] A focus factor alpha is introduced, which is usually adjusted according to the IoU value. The specific formula may vary, but the general form is:
[0092]
[0093] Among them, alpha is a dynamic focusing parameter, which can change with the change of IoU value. For example, when IoU is high, a larger alpha can be selected to strengthen the loss, and vice versa.
[0094] In step S4, this embodiment provides a training example to train the aforementioned lightweight YOLOv8 neural network to obtain a lightweight parking detection model Parking_YOLO. This embodiment provides a training environment of Python-3.9.19torch-2.3.1+cu121 CUDA:0 (NVIDIAGeForce RTX 2080with Max-Q Design, 8192MiB), the number of training rounds is set to 300, batch_size is set to 8, imgsz is set to 640, and workers is set to 2. Finally, the trained model result is as follows Figure 6 As shown, the accuracy is 99.622%, the recall rate is 99.292%, the average detection accuracy mAP_0.5 is 99.4%, the average detection accuracy mAP_0.5-0.95 is 94.975%, the positioning loss, classification loss, and distributed focus loss are 0.37187, 0.22235, and 0.80947 respectively. In addition, the number of layers of Parking_YOLO is 470, and the model size is 3.008735*10 6, the parameter amount is 3.008719*10 6 , GFLOPs is 7.6, which has better lightweight performance than the YOLOv8 model under the same training environment.
[0095] Then, in the actual detection process, the real-time parking space image is imported into the Parking_YOLO model to detect the parking space status of the image to be tested. Figure 7 The left and right sides show the original image to be detected and the detection status image respectively.
[0096] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention rather than to limit it. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solution of the present invention can be modified or replaced by equivalents without departing from the purpose and scope of the technical solution, which should be included in the scope of the claims of the present invention.
Claims
1. A lightweight parking detection method based on a multi-scale attention mechanism, characterized by: It includes the following steps: S1. Obtain a parking space dataset and preprocess the dataset; S2. Construct a lightweight YOLOv8 network structure, which includes at least several MobileNetV3 modules and several C2f_ScConv modules in the Backbone layer; introduce the EMA attention mechanism between the C2f module and the Detect module in the Neck layer; S3, establish the loss function WIoU v3 for the lightweight YOLOv8 network structure; S4. Based on the preprocessed data set, the lightweight YOLOv8 network structure is trained to obtain a lightweight parking detection model, and the parking space status is detected in real time through the lightweight parking detection model.
2. The lightweight parking detection method based on a multi-scale attention mechanism according to claim 1, characterized in that: In step S1, the process of obtaining the data set includes: autonomously collecting parking space images, collecting open source parking space detection data sets, integrating the autonomously collected parking space images with the open source parking space detection data sets to obtain a final data set; The preprocessing process of the data set includes: annotating the images in the data set, that is, annotating them into two states: parking space vacant and parking space occupied; dividing the annotated data set into a training set and a test set.
3. The lightweight parking detection method based on multi-scale attention mechanism according to claim 1, characterized in that: In step S2, the constructed lightweight YOLOv8 network structure mainly includes the backbone network Backbone, the neck network Neck, and the head network Head. The backbone network Backbone includes at least one conventional convolution layer Conv, several lightweight convolution neural networks MobileNetV3, several C2f_ScConv modules and at least one spatial pyramid pooling module SPPF. In the backbone network, the input image first passes through several groups of MobileNetV3 convolution layers and C2f_ScConv modules to gradually extract feature maps of different scales. Each group of MobileNetV3 convolution layers and C2f_ScConv modules inputs the extracted features into the next layer for higher-level feature extraction until they are output to the SPPF module at the end of the backbone network. In the neck network Neck, there is at least one upsampling module Upsample, several concatenation modules Concat, several convolution modules C2f and several efficient multi-scale attention modules EMA. In the neck network, the high-level feature map output by the SPPF module of the backbone network is first upsampled, and then fused with the low-level feature map of the backbone network through the concatenation module Concat. The fused feature map is subjected to feature extraction and information emphasis by the convolution module C2f and the EMA module. The head network Head receives the multi-scale feature maps from the neck network and performs the final target detection task through the detection module Detect, including bounding box regression and category prediction.
4. The lightweight parking detection method based on a multi-scale attention mechanism according to claim 3, characterized in that: The lightweight convolutional neural network MobileNetV3 includes at least an inverted residual bottleneck structure. The inverted residual bottleneck structure first uses a 1×1 regular convolution to increase the number of channels of the feature map, expanding the low-dimensional input to a high dimension. In the expanded high-dimensional space, a depth-separable convolution is used to extract features in the spatial dimension. Then, a 1×1 regular convolution and a Sigmoid function are used to process the channel, and finally bilinear upsampling is performed. In the segmentation task, after upsampling to the target size, the final output is adjusted by a 1×1 regular convolution; When the input feature map size and number of channels are consistent with the output, the input is directly output through the skip connection; The activation function is the h-SigMoid activation function, which approximates the curve of the standard Sigmoid function with a piecewise linear function. The calculation formula is: Where ReLU is an activation function, which is shown as follows: ReLU(x)=min(max(0,x),b) Among them, a is used to translate the input so that the input of the h-SigMoid activation function in the interval [-a, a] is mapped to the effective range of the ReLU activation function; b is used to standardize the output, normalizing the output of the ReLU activation function from [0, b] to [0, 1].
5. The lightweight parking detection method based on multi-scale attention mechanism according to claim 3 is characterized in that: In the C2f_ScConv module, the input feature map is first split into two parts by a conventional convolution Conv and a segmentation layer Split. One part skips several Bottleneck_ScConv layers of the backbone network and is directly input into the subsequent concatenation layer Concat; the other part enters multiple Bottleneck_ScConv layers in the backbone network for feature processing. Each Bottleneck in the Bottleneck_ScConv module performs a self-calibrated convolution operation through SCConv. The features extracted and output by each Bottleneck_ScConv layer are respectively passed to the concatenation layer Concat and the next Bottleneck_ScConv layer. The concatenation layer Concat fuses all the received features through the channel dimension. The fused features include the features extracted by the deep convolution and the retained shallow information. In the SCConv module, the input feature map X is first processed by the spatial reconstruction unit SRU to suppress spatial redundancy and generate a spatial refined feature X W , the generated space refined feature X W Then it is input into the channel reconstruction unit CRU for processing to reduce channel redundancy and obtain the channel refined feature Y.
6. The lightweight parking detection method based on multi-scale attention mechanism according to claim 3 is characterized by: The processing flow of the EMA attention mechanism between the C2f module and the Detect module is as follows: The size of the input feature map is C×H×W, where C represents the number of channels, H represents the height, and W represents the width; the input feature map is divided into G groups through the grouping operation, and the number of channels in each group is C / G; Each set of feature maps generates two 1-dimensional feature vectors through average pooling in the X direction and average pooling in the Y direction. The two 1-dimensional feature vectors are processed through point-by-point convolution and activation function to generate two attention weight vectors. The two attention weight vectors are multiplied by matrix to generate an H×W attention matrix. Each set of feature maps is also processed by global average pooling to generate a 1-dimensional feature vector; the 1-dimensional feature vector is processed by point-by-point convolution and activation function to generate an attention weight vector; the attention weight vector is processed by matrix multiplication to generate a C / G×1 attention matrix; The spatial attention matrix and the channel attention matrix are fused through matrix multiplication operations to generate an H×W×C / G attention matrix; The attention matrix is processed through point-by-point convolution and activation function to generate the final attention weight matrix; the final attention weight matrix is element-by-element multiplied with the input feature map to generate the feature map after redistribution of weights; The feature map after redistribution of weights is processed by point-by-point convolution and activation function to generate the final output feature map; Assume that the input feature map X∈R N×C×H×W , where N is the batch size, using different convolution kernels or pooling operations to capture features at different scales: Among them, k s Represents the size of the sth convolution kernel; In the cross-space learning part, the module calculates the attention weight by interacting with the features of the spatial position; the softmax function is used to normalize the attention score: Among them, e i,j is the attention score of a specific position, a i,j is the normalized attention weight.
7. The lightweight parking detection method based on multi-scale attention mechanism according to claim 1, characterized in that: In step S3, WIoU v3 is a new bounding box regression loss function that introduces a dynamic focus mechanism to improve the traditional IoU loss: Let the true bounding box be B = (x1, y1, x2, y2) and the predicted bounding box be The calculation formula of IoU is: in, represents the intersection of the true bounding box and the predicted bounding box, area(B) and are the areas of the true and predicted bounding boxes, respectively; The value of WIoU v3 is adjusted according to the IoU value and an introduced focusing factor α, and its formula is: Among them, α is a dynamic focusing parameter, which changes with the change of IoU value.
Citation Information
Patent Citations
Lightweight parking space state detection method based on visual attention
CN116824551A
Road target detection method and system based on improved YOLOv8
CN117037119A
Improved YOLOv8 unmanned aerial vehicle aerial target detection method
CN117557922A
Hot rolled steel strip defect detection algorithm based on YOLO algorithm
CN117593258A
Real-time cherry tomato maturity detection method based on multi-scale attention mechanism
CN117690124A
Cited By
Image recognition and positioning method of component embedded part based on target detection
CN119672717A
Improved Yolov10-oriented target detection fusion method
CN119723272A
An Object Detection Fusion Method for Improving Yolov10
CN119723272B
Real-time plasmodium detection method based on lightweight neural network model
CN119919936A
Light-weight-based tire flaw detection method
CN120182785A