Lightweight Parking Detection Method Based on Multi-Scale Attention Mechanism
By introducing a lightweight YOLOv8 network with a multi-scale attention mechanism, combined with MobileNetV3 and EMA attention mechanisms, and optimizing feature extraction and loss function, the problem of insufficient accuracy in parking space detection under extreme environments is solved, and efficient and accurate parking space status detection is achieved.
Patent Information
- Application Number
- CN202411277361.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-12
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2044-09-12
Smart Images

Figure CN119314141B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of image processing and target detection technology, and relates to a lightweight parking detection method based on a multi-scale attention mechanism. Background Technology
[0002] In today's fast-paced lifestyle, people's demands for time and efficiency are constantly increasing, and vehicle utilization is on the rise, making the role and significance of parking space status detection in parking lots particularly prominent. During peak hours and in emergencies, providing real-time parking space occupancy information can significantly reduce the time vehicles spend searching for parking spaces. Therefore, the invention of efficient and accurate parking space status detection is of great significance for improving the efficiency of parking lots and vehicle users, and for meeting modern society's demands for speed, convenience, and safety.
[0003] Currently, many image processing algorithms can perform detection tasks, such as image segmentation and object detection. In recent years, object detection technology has made significant progress, especially object detection based on convolutional neural networks (CNNs), which has surpassed traditional methods and become the mainstream technology. Currently, mainstream object detection algorithms based on CNNs are mainly divided into two categories: two-stage object detection algorithms, which first generate candidate regions and then use CNNs to classify these regions while simultaneously correcting their positions, such as R-CNN and Fast R-CNN. Although this method achieves high detection accuracy through multiple detection and classification steps, it is relatively slow. One-stage object detection algorithms, unlike two-stage algorithms, do not require a separate candidate region generation step and directly output the object's class probability and position coordinates, such as the YOLO series, SSD, OverFeat, and RetinaNet. Their advantage lies in the end-to-end detection process, which significantly accelerates the detection speed.
[0004] With the continuous development of the YOLO series algorithms, the Ultralytics team released YOLOv8 in 2023. YOLOv8 incorporates numerous improvements and optimizations based on the YOLO series, including the introduction of the C2f (CSPNet to Fusion) module, an improved Feature Pyramid Network (FPN) and Path Aggregation Network (PANet), as well as state-of-the-art activation functions and model compression techniques. These innovations enable YOLOv8 to excel in object detection tasks, providing high detection speed and superior accuracy. Despite its excellent performance in many aspects, YOLOv8's detection accuracy may still be affected by extreme weather conditions and low-light environments. Summary of the Invention
[0005] In view of this, the purpose of this invention is to provide a lightweight parking detection method based on a multi-scale attention mechanism, which aims to further enhance the model's feature extraction capability for images, improve the accuracy and robustness of target detection while reducing the computational cost and time of model training and detection, and achieve lightweight and accurate parking space status detection.
[0006] To achieve the above objectives, the present invention provides the following technical solution:
[0007] A lightweight parking detection method based on a multi-scale attention mechanism includes the following steps:
[0008] S1. Obtain the parking space dataset and preprocess the dataset;
[0009] S2. Construct a lightweight YOLOv8 network structure, in which the Backbone layer includes at least several MobileNetV3 modules and several C2f_ScConv modules; introduce an EMA attention mechanism between the C2f modules and the Detect module in the Neck layer;
[0010] S3. Establish the loss function WIoU v3 for the lightweight YOLOv8 network structure;
[0011] S4. Train the lightweight YOLOv8 network structure based on the preprocessed dataset to obtain a lightweight parking detection model, and use the lightweight parking detection model to detect the parking space status in real time.
[0012] Furthermore, in step S1, the process of obtaining the dataset includes: autonomously collecting parking space images, collecting open-source parking space detection datasets, and integrating the autonomously collected parking space images with the open-source parking space detection datasets to obtain the final dataset.
[0013] The preprocessing of the dataset includes: labeling the images in the dataset as either "parking space vacant" or "parking space occupied"; and dividing the labeled dataset into training and testing sets.
[0014] Furthermore, in step S2, the constructed lightweight YOLOv8 network structure mainly includes a backbone network, a neck network, and a head network.
[0015] The backbone network includes at least one regular convolutional layer (Conv), several lightweight convolutional 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 sets of MobileNetV3 convolutional layers and C2f_ScConv modules to progressively extract feature maps of different scales. Each set of MobileNetV3 convolutional layers and C2f_ScConv modules inputs the extracted features into the next layer for higher-level feature extraction until the output reaches the SPPF module located at the end of the backbone network.
[0016] The neck network includes at least one upsampling module (Upsample), several concatenation modules (Concat), several convolutional 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 then processed by the convolutional modules (C2f) and EMA for feature extraction and information enhancement.
[0017] The head network receives multi-scale feature maps from the neck network and performs the final object detection task through the detection module Detect, including bounding box regression and class prediction.
[0018] Furthermore, the lightweight convolutional neural network MobileNetV3 includes at least an inverse residual bottleneck structure. The inverse residual bottleneck structure first uses a 1×1 regular convolution to increase the number of channels in the feature map, expanding the low-dimensional input to a high-dimensional space. In the expanded high-dimensional space, depthwise separable convolution is used to extract features in the spatial dimension. Then, a 1×1 regular convolution and the sigmoid function are used to process the channels, 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.
[0019] When the size and number of channels of the input feature map are the same as those of the output, the input is directly connected to the output via a skip connection.
[0020] The activation function is the h-SigMoid activation function, which approximates the curve of the standard Sigmoid function using a piecewise linear function. The calculation formula is as follows:
[0021]
[0022] ReLU is an activation function, as shown in the following equation:
[0023] ReLU(x) = min(max(0,x),b)
[0024] Where 'a' is used to shift 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; and 'b' is used to normalize the output, so that the output of the ReLU activation function is normalized from [0, b] to [0, 1].
[0025] Furthermore, in the C2f_ScConv module, the input feature map is first divided into two parts by a regular convolution Conv and a splitting layer Split. One part skips several Bottleneck_ScConv layers in 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-calibrating convolution operation through SCConv. The features extracted by each Bottleneck_ScConv layer are passed to the concatenation layer Concat and the next Bottleneck_ScConv layer. The concatenation layer Concat fuses all the received features along the channel dimension. The fused features include the features extracted by depthwise 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 spatially refined features X. W The generated spatial refined feature X W The input is then processed by the Channel Reconstruction Unit (CRU) to reduce channel redundancy, resulting in 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 input feature map has dimensions 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 a grouping operation, with each group having C / G channels.
[0029] Each set of feature maps is processed by average pooling in the X and Y directions to generate two 1-dimensional feature vectors. The two 1-dimensional feature vectors are then processed by pointwise convolution and activation functions to generate two attention weight vectors. The two attention weight vectors are then processed by matrix multiplication to generate an H×W attention matrix.
[0030] Each feature map is further processed by global average pooling to generate a 1-dimensional feature vector; the 1-dimensional feature vector is processed by pointwise 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 to generate an H×W×C / G attention matrix; the attention matrix is processed through pointwise convolution and activation functions to generate the final attention weight matrix; the final attention weight matrix is multiplied elementwise with the input feature map to generate a feature map with redistributed weights; the feature map with redistributed weights is processed through pointwise convolution and activation functions to generate the final output feature map.
[0032] Let the input feature map X∈R N×C×H×W Where N is the batch size, different convolutional kernels or pooling operations are used to capture features at different scales:
[0033]
[0034] Where, k s This represents the size of the s-th type of convolution kernel;
[0035] In the cross-spatial learning part, the module calculates attention weights by interacting with features of spatial location; it then uses the softmax function to normalize the attention score.
[0036]
[0037] Among them, e i,j For attention scores at a specific location, a i,j This refers to the normalized attention weights.
[0038] Furthermore, in step S3, WIoU v3 is a novel bounding box regression loss function that 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 formula for calculating IoU is:
[0040]
[0041] in, Area(B) represents the intersection of the ground truth bounding box and the predicted bounding box. These represent the areas of the actual and predicted bounding boxes, respectively.
[0042] The value of WIoU v3 is adjusted based on the IoU value and an introduced focusing factor α, as follows:
[0043]
[0044] Here, α is a dynamic focusing parameter that changes with the IoU value.
[0045] The beneficial effects of this invention are as follows:
[0046] This invention achieves lightweight and accurate parking space status detection. Compared with existing technologies, it firstly introduces the MobileNetV3 module, improves the C2f_SCConv module, and integrates the EMA attention mechanism. While reducing computational resources and memory consumption, it optimizes the feature extraction process, enabling the model to obtain more detailed and richer feature representations at different scales. Secondly, it optimizes the loss function by replacing it with WIoU v3. This reduces the competitiveness of high-quality anchor boxes while also reducing harmful gradients generated by low-quality examples, resulting in better robustness and accuracy.
[0047] Other advantages, objectives, and features of the invention will be set forth in part in the description which follows, and in part will be apparent to those skilled in the art from the following examination, or may be learned from practice of the invention. The objectives and other advantages of the invention can be realized and obtained through the following description. Attached Figure Description
[0048] To make the objectives, technical solutions, and advantages of the present invention clearer, the preferred embodiments of the present invention will be described in detail below with reference to the accompanying drawings, wherein:
[0049] Figure 1 Here is the network structure diagram of the Parking_YOLO model;
[0050] Figure 2 This is a network structure diagram of the MobileNetV3 module;
[0051] Figure 3 Here is the network structure diagram of the SCConv module;
[0052] Figure 4 Here is the network structure diagram of the C2f_ScConv module;
[0053] Figure 5 A flowchart illustrating the EMA attention mechanism.
[0054] Figure 6 This is a schematic diagram of the training results of the Parking_YOLO model;
[0055] Figure 7 This is a schematic diagram of a test example. Detailed Implementation
[0056] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can be modified or changed 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 are only schematic representations of the basic concept of the present invention. Unless otherwise specified, the following embodiments and features can be combined with each other.
[0057] The accompanying drawings are for illustrative purposes only and are schematic diagrams, not actual pictures. They should not be construed as limiting the invention. To better illustrate the embodiments of the invention, some parts in the drawings may be omitted, enlarged, or reduced, and do not represent the actual product dimensions. It is understandable to those skilled in the art that some well-known structures and their descriptions may be omitted in the drawings.
[0058] In the accompanying drawings of the embodiments of the present invention, the same or similar reference numerals correspond to the same or similar components. In the description of the present invention, it should be understood that if terms such as "upper," "lower," "left," "right," "front," and "rear" indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, they are only for the convenience of describing the present invention and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, the terms used to describe positional relationships in the drawings are only for illustrative purposes and should not be construed as limiting the present invention. For those skilled in the art, the specific meaning of the above terms can be understood according to the specific circumstances.
[0059] Please see Figures 1 to 7 This is a lightweight parking detection method based on a 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 the parking space dataset and preprocess the dataset;
[0063] S2. Construct a lightweight YOLOv8 network structure, in which the Backbone layer includes at least several MobileNetV3 modules and several C2f_ScConv modules; introduce an EMA attention mechanism between the C2f modules and the Detect module in the Neck layer;
[0064] S3. Establish the loss function WIoU v3 for the lightweight YOLOv8 network structure;
[0065] S4. Train the lightweight YOLOv8 network structure based on the preprocessed dataset to obtain a lightweight parking detection model, and use the lightweight parking detection model to detect the parking space status in real time.
[0066] In this embodiment, step S1 includes acquiring a large number of parking space images, covering as many parking space scenarios as possible. Furthermore, the acquired large number of parking space images are integrated with open-source parking space image datasets to form the dataset for this embodiment. The open-source datasets include PKLot and CNRPark-EXT, two parking space detection datasets. The PKLot dataset, created by the Federal Technical University of Brazil, contains parking lot images from three different locations (São Paulo and Curitiba, Brazil), covering three weather conditions: sunny, cloudy, and rainy. The CNRPark-EXT dataset, created by the University of Rome Tor Vergata in Italy, contains images acquired from different camera perspectives in the university parking lot, divided into daytime and nighttime sections.
[0067] The integrated data is labeled with two states: parking space vacancy and parking space occupation, and then 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 shown below. Figure 1As shown, the lightweight YOLOv8 network structure mainly consists of a backbone network, a neck network, and a head network. The backbone network includes at least one regular convolutional layer (Conv), several lightweight convolutional neural networks (MobileNetV3), several C2f_ScConv modules, and at least one spatial pyramid pooling module (SPPF). The input image first passes through a series of convolutional layers and C2f_ScConv modules to progressively extract feature maps at different scales. The SPPF module at the end of the backbone network receives feature maps from the previous layer and performs multi-scale pooling operations to generate more semantically informative feature maps, providing rich features for the neck network. The neck network includes at least one upsampling module (Upsample), several concatenation modules (Concat), several convolutional modules (C2f), and several efficient multi-scale attention modules (EMA). Starting from the high-level feature maps of the backbone network, the Upsample module is first applied, and then the feature maps from the lower-level feature maps of the backbone network are fused using the Concat module. The fused feature maps then pass through the C2f and EMA modules for further feature extraction and emphasis on important information. The head network receives multi-scale feature maps from the neck network and performs the final object detection task through the detection module Detect, including bounding box regression and class prediction.
[0069] like Figure 2The MobileNetV3 network architecture shown is a lightweight convolutional neural network architecture that incorporates several optimization techniques, including inverted residuals with linear bottlenecks and the h-SigMoid activation function, to provide high-precision model performance while maintaining low computational complexity. The inverted residual bottlenecks use 1x1 convolutions (Conv) to increase the number of channels in the feature map, expanding the low-dimensional input to a high-dimensional one, increasing the number of channels to 128. This allows for capturing more information in subsequent depthwise convolution operations. In the expanded high-dimensional space, depthwise separable convolutions are used for feature extraction, processing a 49×49 feature map. Subsequently, 1×1 convolutions and the Sigmoid function are used to process the channels, and finally, bilinear upsampling further enlarges the feature map. In the segmentation task, after upsampling to the target size, a 1×1 convolution is used to adjust the final output. When the input feature map size and number of channels are the same as the output, directly adding the input to the output through residual connections (skip connections) can help the network better propagate gradients and avoid information loss in multi-layer networks. The h-SigMoid activation function reduces computational complexity by approximating the curve of the standard Sigmoid function with a piecewise linear function. Its formula is:
[0070]
[0071] ReLU is an activation function, as shown in the following equation:
[0072] ReLU(x) = min(max(0,x),b)
[0073] Where 'a' is used to shift 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; and 'b' is used to normalize the output, so that the output of the ReLU activation function is normalized from [0, b] to [0, 1].
[0074] In this embodiment, if a = 3 and b = 6, then specifically:
[0075]
[0076] ReLU6 is an activation function, as shown in the following equation:
[0077] ReLU6(x) = min(max(0,x),6)
[0078] Here, "3" is used to shift 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 normalize the output, normalizing the output of ReLU6 from [0,6] to [0,1].
[0079] A C2f module incorporating SCConv is introduced. The SCConv module not only reduces the number of model parameters and FLOPs but also enhances the feature representation capabilities. For example... Figure 3 The diagram shows the structure of the SCConv module. The SCConv module utilizes two components: a Spatial Reconstruction Unit (SRU) and a Channel Reconstruction Unit (CRU). The SRU suppresses spatial redundancy through a separation-reconstruction method, while the CRU employs a segmentation-transformation-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, generating a spatially refined feature X. W The generated spatial refined feature X W The input is then processed by the Channel Reconstruction Unit (CRU) to reduce channel redundancy, resulting in the channel refined feature Y.
[0080] The structural diagram of the C2f_ScConv module that integrates SCConv is shown below. Figure 4 As shown, its structure involves dividing the input feature map into two parts using a regular convolutional (Conv) and a splitting layer (Split). One part skips the intermediate layers of the backbone network, while the other part enters multiple Bottleneck_ScConv layers within the network. The cv2 function in Bottleneck_ScConv calls SCConv to process the features, and the SCConv module integrates the core components SRU and CRU. Therefore, in C2f_ScConv, each Bottleneck undergoes a self-calibrating convolution operation via SCConv, forming the Bottleneck_ScConv module, which enhances the feature extraction capabilities in both channel and spatial dimensions. After feature extraction by Bottleneck_ScConv, the feature map and the skipped input feature map are fused along the channel dimension. The fused features include those extracted through depthwise convolution and retained shallow information.
[0081] An EMA attention mechanism is added at the connection between C2f and Detect in the Neck layer. This module can efficiently capture multi-scale information and enhance spatial feature learning, improving the representation of features at different scales and in different spatial regions, and providing a richer and more robust understanding of the input data. Figure 5As shown, the input feature map has dimensions 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 a grouping operation, with each group having C / G channels. Each group of feature maps is processed by X-axis average pooling (X Avg Pool) and Y-axis average pooling (Y Avg Pool) to generate two 1D feature vectors. These two 1D feature vectors are processed by pointwise convolution (Conv(1×1)) and an activation function (Sigmoid) to generate two attention weight vectors. These two attention weight vectors are then processed by matrix multiplication (Matmul) to generate an H×W attention matrix. Each group of feature maps is processed by global average pooling (Avg Pool) to generate a 1D feature vector. This 1D feature vector is then processed by pointwise convolution (Conv(1×1)) and an activation function (Softmax) to generate an attention weight vector. This attention weight vector is then processed by matrix multiplication (Matmul) to generate a C / G×1 attention matrix. The spatial attention matrix and channel attention matrix are fused using matrix multiplication (Matmul) to generate an attention matrix of size H×W×C / G. This attention matrix is then processed using pointwise convolution (Conv(1×1)) and an activation function (Sigmoid) to generate the final attention weight matrix. The final attention weight matrix is then element-wise multiplied with the input feature map to generate a reweighted feature map. This reweighted feature map is then processed using pointwise convolution (Conv(1×1)) and an activation function (Sigmoid) to generate the final output feature map.
[0082] Assume the input feature map X∈R N×C×H×W Where N is the batch size, C is the number of channels, and H and W are the height and width of the spatial dimensions, using different convolutional kernels or pooling operations to capture features at different scales:
[0083]
[0084] Where, k s This represents the size of the s-th type of convolutional kernel, used to capture features at different scales.
[0085] In the cross-spatial learning part, the module calculates attention weights by interacting with features at spatial locations. These weights determine which features are focused on at different locations. The softmax function can be used to normalize the attention scores, ensuring that the weights sum to 1, thereby highlighting important features and suppressing unimportant features.
[0086]
[0087] Among them, e i,jIt is the attention score for a specific location, a i,j It is the normalized attention weight.
[0088] In this embodiment, step S3 establishes a new loss function. WIoU v3 is a novel bounding box regression loss function that introduces a dynamic focusing mechanism to improve upon traditional IoU loss. It better addresses some issues in bounding box prediction, such as insensitivity to loss when approaching a perfect match, and dynamic adjustment of prediction errors. Let the true bounding box be B = (x1, y1, x2, y2), and the predicted bounding box be... The formula for calculating IoU is:
[0089]
[0090] in, Area(B) represents the intersection of the ground truth bounding box and the predicted bounding box. These are the areas of the actual and predicted bounding boxes, respectively.
[0091] A focusing factor alpha is introduced, which is usually adjusted based on the IoU value. The specific formula may vary, but the general form is as follows:
[0092]
[0093] Here, alpha is a dynamic focusing parameter that can change with the IoU value. For example, when the IoU is high, a larger alpha can be chosen to enhance the loss, and vice versa.
[0094] In step S4, this embodiment provides a training example, training the aforementioned lightweight YOLOv8 neural network to obtain the lightweight parking detection model Parking_YOLO. This embodiment provides a training environment of Python-3.9.19, torch-2.3.1+cu121, CUDA:0 (NVIDIA GeForce RTX 2080 with Max-Q Design, 8192MiB), with 300 training epochs, a batch size of 8, imgsz of 640, and 2 workers. The final trained model result is shown below. Figure 6 As shown, the accuracy is 99.622%, the recall is 99.292%, the mean precision (mAP) for 0.5 is 99.4%, and the mean precision (mAP) for 0.5-0.95 is 94.975%. The localization loss, classification loss, and distributed focusing loss are 0.37187, 0.22235, and 0.80947, respectively. Additionally, Parking_YOLO has 470 layers and a model size of 3.008735 * 10^6. 6The number of parameters is 3.008719*10. 6 With a GFLOPs of 7.6, it has better lightweight performance than the YOLOv8 model under the same training environment.
[0095] Then, during the actual detection process, the real-time acquired parking space images are imported into the Parking_YOLO model to detect the parking space status in the test image. Figure 7 The images shown on the left and right are 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 solutions of the present invention and are not intended to limit it. Although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art should understand that modifications or equivalent substitutions can be made to the technical solutions of the present invention without departing from the spirit and scope of the present invention, and all such modifications or substitutions should be covered within the scope of the claims of the present invention.
Claims
1. A lightweight parking detection method based on a multi-scale attention mechanism, characterized in that: It includes the following steps: S1. Obtain the parking space dataset and preprocess the dataset; S2. Construct a lightweight YOLOv8 network structure, in which the Backbone layer includes at least several MobileNetV3 modules and several C2f_ScConv modules; introduce an EMA attention mechanism between the C2f modules and the Detect module in the Neck layer; S3. Establish the loss function WIoU v3 for the lightweight YOLOv8 network structure; S4. Train the lightweight YOLOv8 network structure based on the preprocessed dataset to obtain a lightweight parking detection model, and use the lightweight parking detection model to detect the parking space status in real time. The lightweight convolutional neural network MobileNetV3 includes at least an inverse residual bottleneck structure. This structure first uses a 1×1 regular convolution to increase the number of channels in the feature map, expanding the low-dimensional input to a high-dimensional space. In this expanded high-dimensional space, depthwise separable convolutions are used to extract features in the spatial dimension. Subsequently, a 1×1 regular convolution and a sigmoid function are used to process the channels, and finally, bilinear upsampling is applied. In segmentation tasks, after upsampling to the target size, a 1×1 regular convolution is used to adjust the final output. When the size and number of channels of the input feature map are the same as those of the output, the input is directly connected to the output via a skip connection. The activation function is the h-SigMoid activation function, which approximates the curve of the standard Sigmoid function using a piecewise linear function. The calculation formula is as follows: ReLU is an activation function, as shown in the following equation: ReLU(x) = min(max(0,x),b) Where 'a' is used to shift 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; and 'b' is used to normalize the output, normalizing the output of the ReLU activation function from [0, b] to [0, 1]. In the C2f_ScConv module, the input feature map is first divided into two parts by a regular convolution Conv and a splitting layer Split. One part skips several Bottleneck_ScConv layers in 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-calibrating convolution operation through SCConv. The features extracted by each Bottleneck_ScConv layer are passed to the concatenation layer Concat and the next Bottleneck_ScConv layer. The concatenation layer Concat fuses all the received features along the channel dimension. The fused features include the features extracted by depthwise 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 spatially refined features X. W The generated spatial refined feature X W The channel is then input into the channel reconstruction unit (CRU) for processing to reduce channel redundancy, resulting in the channel refined feature Y. In step S3, WIoU v3 is a novel bounding box regression loss function that introduces a dynamic focusing 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 formula for calculating IoU is: in, Area(B) represents the intersection of the ground truth bounding box and the predicted bounding box. These represent the areas of the actual and predicted bounding boxes, respectively. The value of WIoU v3 is adjusted based on the IoU value and an introduced focusing factor α, as follows: Here, α is a dynamic focusing parameter that changes with the IoU value.
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 dataset includes: autonomously collecting parking space images, collecting open-source parking space detection datasets, and integrating the autonomously collected parking space images with the open-source parking space detection datasets to obtain the final dataset. The preprocessing of the dataset includes: labeling the images in the dataset as either "parking space vacant" or "parking space occupied"; and dividing the labeled dataset into training and testing sets.
3. The lightweight parking detection method based on a multi-scale attention mechanism according to claim 1, characterized in that: In step S2, the constructed lightweight YOLOv8 network structure mainly includes a backbone network, a neck network, and a head network. The backbone network includes at least one regular convolutional layer (Conv), several lightweight convolutional 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 sets of MobileNetV3 convolutional layers and C2f_ScConv modules to progressively extract feature maps of different scales. Each set of MobileNetV3 convolutional layers and C2f_ScConv modules inputs the extracted features into the next layer for higher-level feature extraction until the output reaches the SPPF module located at the end of the backbone network. The neck network includes at least one upsampling module (Upsample), several concatenation modules (Concat), several convolutional 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 then processed by the convolutional modules (C2f) and EMA for feature extraction and information enhancement. The head network receives multi-scale feature maps from the neck network and performs the final object detection task through the detection module Detect, including bounding box regression and class prediction.
4. A lightweight parking detection method based on a multi-scale attention mechanism according to claim 3, characterized in that: The processing flow of the EMA attention mechanism between the C2f module and the Detect module is as follows: The input feature map has dimensions 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 a grouping operation, with each group having C / G channels. Each set of feature maps is processed by average pooling in the X and Y directions to generate two 1-dimensional feature vectors. The two 1-dimensional feature vectors are then processed by pointwise convolution and activation functions to generate two attention weight vectors. The two attention weight vectors are then processed by matrix multiplication to generate an H×W attention matrix. Each feature map is further processed by global average pooling to generate a 1-dimensional feature vector; the 1-dimensional feature vector is processed by pointwise convolution and activation function to generate an attention weight vector; the attention weight vector is then 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 to generate an H×W×C / G attention matrix; The attention matrix is processed through pointwise convolution and activation functions to generate the final attention weight matrix; the final attention weight matrix is then multiplied element-wise with the input feature map to generate a feature map with redistributed weights. The feature maps with reassigned weights are processed by pointwise convolution and activation functions to generate the final output feature map; Let the input feature map X∈R N×C×H×W Where N is the batch size, different convolutional kernels or pooling operations are used to capture features at different scales: Among them, k s This represents the size of the s-th type of convolution kernel; In the cross-spatial learning part, the module calculates attention weights by interacting with features of spatial location; it then uses the softmax function to normalize the attention score. Among them, e i,j For attention scores at a specific location, a i,j This refers to the normalized attention weights.
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