Vehicle re-identification method and system based on hierarchical hybrid attention mechanism

The vehicle re-identification method using a hierarchical hybrid attention mechanism employs a three-level hierarchical processing structure and feature fusion strategy to solve the problems of intra-class differences and inter-class similarities in complex traffic scenarios, thereby improving the accuracy and robustness of vehicle re-identification and adapting to multi-scale feature extraction and illumination changes.

CN122116087APending Publication Date: 2026-05-29XI AN JIAOTONG UNIV +2

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
XI AN JIAOTONG UNIV
Filing Date
2026-03-31
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

Existing vehicle re-identification technologies face challenges in complex traffic scenarios, including large intra-class differences, high inter-class similarities, and insufficient multi-scale feature fusion, leading to high mismatch rates. Furthermore, traditional methods struggle to effectively handle changes in viewpoint and occlusion.

Method used

The vehicle re-identification method employs a hierarchical hybrid attention mechanism. Through a three-level hierarchical processing structure, it utilizes progressively increasing window size and positional encoding, combined with feature fusion from bottom-up and top-down paths, to generate multi-scale features, including low-level detail features, mid-level component features, and high-level global features, which are then matched using an MLP classification module.

Benefits of technology

It significantly improves the robustness and generalization ability of the model in cross-camera tracking, enhances the accuracy and robustness of re-identification, effectively handles occlusion and viewpoint changes in complex scenes, reduces computational complexity, and improves the comprehensiveness and accuracy of feature extraction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122116087A_ABST
    Figure CN122116087A_ABST
Patent Text Reader

Abstract

The application discloses a vehicle re-identification method and system based on a hierarchical mixed attention mechanism and belongs to the technical field of computer vision re-identification. The method comprises the following steps: constructing a network architecture comprising a hierarchical mixed attention encoder, a feature fusion layer and an MLP classification module; obtaining an input vehicle image; using the encoder to adopt a three-level hierarchical processing structure, generating low-level details, middle-level components and high-level global features through 4*4, 8*8 and 16*16 window divisions in a step-by-step increasing manner, and embedding corresponding absolute, relative and normalized global position encodings; performing cross-level interaction fusion through a bottom-up and top-down bidirectional path to generate a fusion feature vector; and finally outputting a vehicle ID probability or a feature vector for matching through an MLP module. The application effectively solves the problems of large intra-class difference, high inter-class similarity and insufficient multi-scale feature fusion of vehicle re-identification in a complex traffic scene, and improves the recognition accuracy and generalization ability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of computer vision re-identification technology, specifically relating to a vehicle re-identification method and system based on a hierarchical hybrid attention mechanism. Background Technology

[0002] With the rapid development of Intelligent Transportation Systems (ITS) and Vehicle-to-Everything (V2X) technologies, Vehicle Re-Identification (VeReID), as a core technology for cross-camera tracking and vehicle identity matching, plays a crucial role in smart city management, public safety monitoring, and autonomous driving collaboration. Statistics show that the global intelligent transportation market is projected to exceed $65 billion by 2025, and vehicle re-identification technology, due to its key role in scenarios such as violation tracking, traffic optimization, and electronic toll collection, has become a research hotspot in both academia and industry.

[0003] However, vehicle re-identification in complex traffic scenarios still faces significant challenges: the same vehicle exhibits significant differences in appearance due to changes in viewpoint, lighting conditions, and partial occlusion, resulting in large intra-class variations; different vehicles are highly similar in global features such as model and color, leading to high inter-class similarity. Relying solely on traditional methods easily leads to mismatches. In recent years, vehicle re-identification methods based on deep learning CNNs for extracting visual features have made significant progress, but the local receptive field of CNNs limits their ability to model global contextual information. With the success of Transformers in natural language processing, ViT has demonstrated powerful feature representation capabilities in vehicle re-identification, but its fixed-size image patch partitioning is difficult to adapt to the multi-scale characteristics of vehicle components, and its ability to model local details is weak. Existing variants of Transformers mainly improve model capabilities through multi-scale methods, such as Swin-Transformer, which constructs a multi-scale feature pyramid through hierarchical window partitioning and cross-window shifting operations. However, its window partitioning strategy does not fully consider the relationship between scale and position, resulting in limited generalization ability in occluded and cross-viewpoint scenarios. Summary of the Invention

[0004] The technical problem to be solved by this invention is to address the shortcomings of the prior art by providing a vehicle re-identification method and system based on a hierarchical hybrid attention mechanism. This involves constructing a hierarchical multi-scale attention encoder Vehicle Re-Identification Network, which draws on the hierarchical window partitioning concept of Swin-Transformer and the structure of VIT, to solve the technical problems of large intra-class variation, high inter-class similarity, and insufficient multi-scale feature fusion in existing vehicle re-identification (VeRI) methods in complex traffic scenarios.

[0005] The present invention adopts the following technical solution: A vehicle re-identification method based on a hierarchical hybrid attention mechanism includes the following steps: S1. Construct a vehicle re-identification network architecture, which includes a hierarchical hybrid attention encoder, a feature fusion layer, and an MLP classification module connected in sequence. S2. Obtain the input vehicle image, and use the hierarchical hybrid attention encoder to perform hierarchical encoding processing on the input vehicle image to generate multi-scale features. The multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical hybrid attention encoder adopts a three-level hierarchical processing structure, including a bottom-level processing unit, a middle-level processing unit, and a high-level processing unit. The bottom-level processing unit, the middle-level processing unit, and the high-level processing unit each divide the input vehicle image using progressively larger window sizes, and each embeds positional codes of the corresponding level and performs feature calculations using corresponding attention modules. S3. Input the low-level detailed features, mid-level component features and high-level global features into the feature fusion layer, and perform cross-level interactive fusion through a bidirectional path from bottom to top and from top to bottom to generate a fused feature vector. S4. Input the fused feature vector into the MLP classification module. After global pooling and normalization, output the vehicle ID probability distribution or vehicle feature vector for re-identification and matching.

[0006] Preferably, in step S2, the progressively increasing window size is specifically defined as follows: The underlying processing unit divides the input vehicle image into 4×4 pixel windows to extract local detail features. The intermediate processing unit divides the input vehicle image into 8×8 pixel windows to extract component-level correlation features. The high-level processing unit divides the input vehicle image into 16×16 pixel windows to extract global semantic features.

[0007] Preferably, the embedding of position codes corresponding to the respective levels specifically includes: An absolute position code is embedded in the features generated by the underlying processing unit, and the unique position index code is directly added to the underlying detail features; Relative position encoding is embedded in the features generated by the middle layer processing unit to construct a learnable bias matrix and incorporate the relative position information into the attention score calculation. Normalized global position codes are embedded in the features generated by the high-level processing unit, and sine and cosine codes are performed based on the normalized coordinates of the block center point and concatenated with the high-level global features.

[0008] Preferably, it further includes an edge processing step: When the size of the input vehicle image cannot be divided by the window size, the image edge area is filled using a zero-fill mechanism; In the subsequent attention calculation process, a mask matrix is ​​generated for the filled region, and the contribution of the filled region to the attention score is ignored.

[0009] Preferably, in step S2, the feature calculation using the corresponding attention module specifically includes: In the lower-level processing unit and the middle-level processing unit, the attention score is calculated using a local window self-attention mechanism or a shifted window self-attention mechanism. In the high-level processing unit, a large window attention mechanism is used to calculate the attention score; The attention score is calculated based on the query matrix, key matrix, and value matrix, combined with the position encoding or bias term of the corresponding level.

[0010] Preferably, in step S3, the cross-level interactive fusion via a bidirectional path of bottom-up and top-down paths specifically includes: In the bottom-up path, the low-level detailed features are upsampled to the mid-level scale, and the upsampled features are concatenated with the mid-level component features; the concatenated mid-level features are upsampled to the high-level scale and concatenated with the high-level global features; In the top-down path, the high-level global features are downsampled to the mid-level scale and fused with the mid-level features; A lightweight gating network is used to generate fusion weights for each layer. The features after bidirectional path fusion are weighted and summed, and the final fusion feature vector is generated through linear projection.

[0011] Preferably, in the top-down path, the specific method for downsampling high-level global features to the mid-level scale is as follows: Perform max pooling or convolution with a stride greater than 1 on the high-level global features to make their spatial resolution consistent with that of the mid-level component features; In the bottom-up path of step S3, the upsampling operation specifically uses a bilinear interpolation algorithm or a transposed convolution algorithm to enlarge the feature map size.

[0012] Preferably, in step S4, the output vehicle ID probability distribution or vehicle feature vector is used for re-identification and matching, specifically including: During the training phase, the normalized fused feature vector is input into the fully connected layer, and the difference between the predicted vehicle ID probability distribution and the true label is calculated using the cross-entropy loss function in order to optimize the network parameters. During the inference phase, the normalized fused feature vector is directly output, the similarity between the feature vector of the query image and the feature vector of the database image is calculated, and the consistency of vehicle identity is determined based on the similarity threshold.

[0013] Preferably, before step S2, image preprocessing is performed, specifically as follows: Acquire the original vehicle image and adjust it to the preset H×W resolution; The adjusted image is standardized by subtracting the mean and dividing by the standard deviation to obtain a standardized input vehicle image.

[0014] Secondly, embodiments of the present invention provide a vehicle re-identification system based on a hierarchical hybrid attention mechanism, comprising: The image acquisition module is used to acquire the input vehicle image; The hierarchical encoding module is used to construct a hierarchical hybrid attention encoder, which uses a three-level hierarchical processing structure to perform hierarchical encoding processing on the input vehicle image to generate multi-scale features; the multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical encoding module includes a bottom-level processing unit, a middle-level processing unit, and a high-level processing unit, which are respectively configured to divide the input vehicle image using progressively larger window sizes, embed positional codes of the corresponding level, and perform feature calculations using corresponding attention modules. The feature fusion module is used to construct a feature fusion layer. It receives the low-level detailed features, mid-level component features and high-level global features, and performs cross-level interactive fusion through bidirectional paths from bottom to top and from top to bottom to generate a fused feature vector. The identification output module is used to construct the MLP classification module. It receives the fused feature vector, and after global pooling and normalization, outputs the vehicle ID probability distribution or vehicle feature vector for re-identification and matching.

[0015] Thirdly, a computer device includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the vehicle re-identification method based on the hierarchical hybrid attention mechanism described above.

[0016] Fourthly, embodiments of the present invention provide a computer-readable storage medium including a computer program, which, when executed by a processor, implements the steps of the vehicle re-identification method based on a hierarchical hybrid attention mechanism described above.

[0017] Fifthly, a chip includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor, when executing the computer program, implements the steps of the vehicle re-identification method based on the hierarchical hybrid attention mechanism described above.

[0018] In a sixth aspect, embodiments of the present invention provide an electronic device, including a computer program, which, when executed by the electronic device, implements the steps of the vehicle re-identification method based on a hierarchical hybrid attention mechanism described above.

[0019] Compared with the prior art, the present invention has at least the following beneficial effects: A vehicle re-identification method based on a hierarchical hybrid attention mechanism employs a three-level hierarchical processing structure. It segments the image using progressively larger window sizes and embeds corresponding location codes. Through a small-medium-large window hierarchy, it simultaneously captures highly recognizable local details of the vehicle, mid-level component relationships, and high-level global semantics. This multi-scale parallel processing mechanism effectively addresses the challenges of large intra-class differences and high inter-class similarities in complex traffic scenarios. Combined with bidirectional path feature fusion, it achieves comprehensive feature representation from microscopic details to macroscopic semantics, significantly improving the model's robustness and generalization ability in cross-camera tracking, laying a solid feature foundation for subsequent high-precision matching.

[0020] Furthermore, the 4×4 small window can precisely focus on pixel-level texture details, effectively extracting fine-grained features such as headlight shapes and logo text, preventing key identification points from being blurred due to an excessively large receptive field; the 8×8 medium window precisely covers the typical scale of vehicle components, enabling the modeling of spatial topological relationships between components such as wheels and rearview mirrors; and the 16×16 large window provides sufficient global context for understanding the overall shape of the vehicle. This specific combination of sizes achieves the best balance between computational complexity and feature extraction capability, avoiding computational redundancy caused by overly fine segmentation while preventing the loss of details caused by overly coarse segmentation.

[0021] Furthermore, low-level detail features are highly sensitive to absolute position; absolute encoding can accurately locate the specific coordinates of subtle features such as car logos and scratches, preventing spatial information confusion. Mid-level component features focus more on the relative relationships between components; relative position encoding enhances the model's understanding of the spatial structure of components through a learnable bias matrix, improving its resistance to deformation. High-level global features need to adapt to different resolution inputs; normalized global encoding ensures the consistency of global semantics across images at different scales. Maximizing the utility of positional information allows the model to maintain accurate spatial perception even when dealing with complex situations such as viewpoint changes and partial occlusion, significantly outperforming single encoding methods.

[0022] Furthermore, at the lower and middle layers, local and shifted window mechanisms restrict attention computation to the neighborhood, significantly reducing computational complexity. Simultaneously, shifting operations enable cross-window information interaction, effectively capturing local textures and component details. At the higher layer, the large window attention mechanism breaks down local limitations, allowing for global information aggregation, thereby extracting highly discriminative global semantic features. This hybrid attention strategy, combining fine-grained local computation with macroscopic global control, not only ensures the model's processing speed on high-resolution vehicle images but also guarantees the comprehensiveness of feature extraction, effectively solving the problems of excessive memory consumption and difficulty in capturing local details in traditional ViT models when processing high-resolution images.

[0023] Furthermore, by employing a zero-padding mechanism, the system adapts to fixed window segmentation requirements without compromising the original image content, preserving complete vehicle edge information. More importantly, the introduction of a mask matrix during attention calculation masks interference from padded regions, preventing spurious features from participating in the computation and avoiding the model learning incorrect background noise. This significantly improves the model's adaptability to non-standard sized images and enhances the system's stability and feature extraction purity in real-world complex environments.

[0024] Furthermore, the bidirectional path design employs a bottom-up approach to progressively pass rich texture details from lower layers to higher layers, compensating for the lack of detail in deeper networks. The top-down approach feeds back strong semantic context from higher layers to middle layers, helping the model infer occluded components under occlusion conditions. Combined with adaptive weighting using a lightweight gating network, the model can dynamically adjust the contribution weights of features at each level, suppressing noise interference and highlighting key discriminative features. The generated fused feature vectors possess extremely strong discriminative power, significantly improving the re-identification accuracy of vehicles under challenging conditions such as extreme lighting and severe occlusion.

[0025] Furthermore, during the training phase, the cross-entropy loss function forces the model to learn feature representations with class discriminative power, causing features of the same vehicle to cluster in space and features of different vehicles to separate, leading to rapid convergence and optimization of network parameters. During the inference phase, the classification head is removed, and cosine similarity is directly calculated using the high-dimensional feature vectors normalized by L2. This not only meets the essential requirement of "retrieval and matching" in vehicle re-identification tasks but also significantly reduces computational latency during inference. This ensures the model's training efficiency on large-scale datasets while guaranteeing response speed and matching accuracy in practical deployments, demonstrating high engineering application value.

[0026] Furthermore, by uniformly adjusting the resolution, the impact of inconsistent input sizes on the network structure is eliminated. Standardization by subtracting the mean and dividing by the standard deviation transforms the image pixel distribution into a standard normal distribution, accelerating the convergence speed of the neural network and improving the stability of gradient descent. This effectively eliminates the domain shift problem caused by changes in illumination and device differences, enhancing the model's generalization ability to different acquisition environments. This is a prerequisite for ensuring that the subsequent hierarchical attention mechanism can stably extract high-quality features.

[0027] Furthermore, max pooling effectively preserves the most salient feature responses during downsampling, suppresses background noise, and prevents irrelevant information from interfering with high-level semantics; bilinear interpolation smoothly restores spatial resolution during upsampling, avoids checkerboard effects, and maintains the continuity of detailed features. This not only ensures strict matching of feature dimensions during fusion but also minimizes information loss during scaling, resulting in an optimal fused feature vector in both spatial structure and semantic content. This further solidifies the model's performance advantage in fine-grained vehicle re-identification tasks.

[0028] It is understood that the beneficial effects of the second to sixth aspects mentioned above can be found in the relevant descriptions in the first aspect mentioned above, and will not be repeated here.

[0029] In summary, the method of this invention innovatively combines multi-scale window partitioning, differentiated position encoding, and bidirectional feature fusion strategy through a hierarchical hybrid attention mechanism. It can simultaneously and accurately capture both local details and global semantics of vehicles, effectively overcoming the challenges of large intra-class differences, high inter-class similarity, and occlusion in complex scenes. It significantly improves the accuracy and robustness of re-identification, and has both high computational performance and excellent engineering application value.

[0030] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description

[0031] Figure 1 A diagram illustrating the network structure of a hierarchical hybrid attention mechanism for vehicle re-identification. Figure 2 This is a diagram of the feature extraction process; Figure 3 For the dataset samples; Figure 4 This is a diagram illustrating the local feature calculation process. Figure 5 A schematic diagram of a computer device provided in an embodiment of the present invention; Figure 6 This is a block diagram of a chip according to an embodiment of the present invention; Figure 7 This is a flowchart of the method of the present invention.

[0032] Among them, 60. Computer equipment; 61. Processor; 62. Memory; 63. Computer program; 600. Electronic device; 610. Processing unit; 620. Storage unit; 6201. Random access memory unit; 6202. Cache memory unit; 6203. Read-only memory unit; 6204. Program / utility; 6205. Program module; 630. Bus; 640. Display unit; 650. Input / output interface; 660. Network adapter; 700. External device. Detailed Implementation

[0033] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0034] In the description of this invention, it should be understood that the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0035] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0036] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Additionally, the character " / " in this invention generally indicates that the preceding and following objects have an "or" relationship.

[0037] It should be understood that although terms such as first, second, third, etc., may be used in the embodiments of the present invention to describe the preset range, these preset ranges should not be limited to these terms. These terms are only used to distinguish the preset ranges from one another. For example, without departing from the scope of the embodiments of the present invention, the first preset range may also be referred to as the second preset range, and similarly, the second preset range may also be referred to as the first preset range.

[0038] Depending on the context, the word "if" as used here can be interpreted as "when," "when," "in response to determination," or "in response to detection." Similarly, depending on the context, the phrase "if determination" or "if detection (of the stated condition or event)" can be interpreted as "when determination," "in response to determination," "when detection (of the stated condition or event)," or "in response to detection (of the stated condition or event)."

[0039] The accompanying drawings illustrate various structural schematic diagrams according to embodiments disclosed in this invention. These drawings are not to scale, and some details have been enlarged for clarity, and some details may have been omitted. The shapes of the various regions and layers shown in the drawings, as well as their relative sizes and positional relationships, are merely exemplary and may deviate from reality due to manufacturing tolerances or technical limitations. Furthermore, those skilled in the art can design regions / layers with different shapes, sizes, and relative positions as needed.

[0040] This invention provides a vehicle re-identification method based on a hierarchical hybrid attention mechanism. A hierarchical hybrid attention encoder is designed, using a bottom-level small window (4×4) to focus on high-recognition details such as headlights and logos, a middle-level medium window (8×8) to model component-level correlations, and a top-level large window (16×16) to extract global features. Position encoding is combined to achieve optimized fusion of local and global features. To further enhance model robustness, a hybrid fusion strategy combining bottom-up and top-down approaches is proposed. By combining hierarchical windowing, hybrid position encoding, and dynamic attention adjustment, this invention achieves improvements in mAP and Rank-1 metrics on public datasets compared to baseline models such as ViT and Swin-Transformer.

[0041] Please see Figure 7 This invention discloses a vehicle re-identification method based on a hierarchical hybrid attention mechanism, comprising the following steps: S1. Design a vehicle re-identification network architecture based on a hierarchical hybrid attention mechanism, which includes a hierarchical hybrid attention encoder, a feature fusion layer, and an MLP classification module; S101. Design a hierarchical hybrid attention encoder as the core feature extraction module. The encoder adopts a three-level hierarchical processing structure. The input image passes through the bottom processing unit (4×4 pixel window), the middle processing unit (8×8 pixel window), and the high processing unit (16×16 pixel window). The encoder achieves multi-scale information fusion through hierarchical feature transfer. S102. The design feature fusion layer serves as a bridge between the encoder and the classification module. Its input receives the three-level features (low-level detailed features, middle-level component features, and high-level global features) output by the encoder, and achieves cross-level interaction through bidirectional paths from bottom to top and from top to bottom. S103. Construct an MLP classification module as the network output layer. Its input receives the feature vector generated by the feature fusion layer. After global pooling and normalization, it is input into FFN to obtain the vehicle ID probability distribution. S104. Connect the hierarchical hybrid attention encoder, feature fusion layer and MLP classification module in sequence to form a complete forward propagation path.

[0042] S2. A layered coding mechanism is adopted, consisting of a bottom-level small window, a middle-level medium window, and a top-level large window. S201. Standardize the input vehicle image to (H*W) resolution, and generate three image blocks of different scales by dividing it into layers through a window. S202. Define the underlying processing unit using a 4×4 pixel window partitioning strategy to generate (H / 4)×(W / 4) non-overlapping local blocks, where H and W are the height and width of the input image. Each block C represents the number of channels. Projection matrix. Will 3D pixel block mapping to 3D feature space, the formula is , This segmentation mechanism addresses the problem of losing fine-grained information caused by large intra-class differences by focusing on highly recognizable details such as headlights and logos through a small receptive field. S203. Define the middle-layer processing unit using an 8×8 pixel window partitioning strategy to generate (H / 8)×(W / 8) non-overlapping component-level blocks. Each block C represents the number of channels. Projection matrix. ,Will 3D pixel block mapping to 3D feature space, the formula is , This mechanism solves the problem of component-level semantic fragmentation by modeling the spatial relationships between components such as car windows and doors, and tires and rims using mesoscale receptive fields. S204. Define the high-level processing unit using a 16×16 pixel window partitioning strategy to generate (H / 16)×(W / 16) non-overlapping global blocks. Each block C represents the number of channels. Projection matrix. ,Will 3D pixel block mapping to 3D feature space, the formula is , This mechanism extracts overall semantic features such as vehicle outline and color distribution through a large receptive field, thus addressing the problem of insufficient global context modeling.

[0043] S205. When the input image size (H×W) cannot be strictly divided by the window size, a zero-padding mechanism is used to adapt to the block division requirements: S2051. Input image H×W, current window size is P×P (P applies to bottom, middle or high layer sizes), ), calculate horizontal and vertical fill volume , That is, the right edge of the image is padded Zero elements of column pixels, padding at the bottom of the image. Zero elements per pixel; S2052. After padding the image with zero elements, update the size to... , The filled region is ignored by the mask during attention calculation.

[0044] S3. Embed different positional codes at the bottom, middle, and top levels; S301. Absolute position encoding is applied to the local blocks generated by the bottom-level 4×4 small window partitioning. The bottom-level small window uses refined absolute position encoding, assigning a unique position code to each 4×4 block. Two-dimensional sine coding is used, covering (H / 4)×(W / 4) positions. The absolute position index pos of each 4×4 block is 0≤pos<(H / 4×W / 4). and the underlying features after adding features as follows:

[0045]

[0046] ; in, When hyperparameters When taking 512, In most cases, inputting an image Absolute position encoding is directly added to and concatenated with the underlying features to ensure the location of details. Depend on Linear projection yields, , when, There are a total of 3136 underlying blocks.

[0047] S302. Apply relative position encoding to the blocks generated by the 8×8 window partitioning in the middle layer to enhance component-level association, and calculate the relative positional relationship between the query and the key to construct a learnable bias matrix. The original image is divided into... Each patch has a block location defined by row and column coordinates. , For each query block key block, calculate their relative position offset. Relative position encoding in, , Calculating the relative position requires constructing a row and column offset matrix, which needs to be calculated based on the offset between the two position blocks. k represents the row and column offsets of the original block and the shifted block. , Middle-layer relative position encoding Instead of directly concatenating with mid-level features, attention scores are obtained by incorporating attention bias terms.

[0048] S303. Apply normalized global position encoding to the global block generated by the high-level 16×16 large window. The position encoding is as follows: The image is divided into (H / 16) × (W / 16) 16 × 16 global blocks. The normalized coordinates of the center point of each block are calculated. Attention is applied to the center coordinates of the 16 × 16 blocks. Normalization ,get This ensures coordinate consistency across images of different resolutions. Then, for... and Using sine and cosine encoding respectively, the global positional encoding is: : ,

[0049]

[0050]

[0051] in, , The location codes at each level are embedded into the features in different ways, and the global location codes are concatenated to enhance the understanding of the overall layout.

[0052] S4. Add different attention modules for different levels; S401, The calculation method for local window self-attention is as follows: , , Weight matrix , Here, h is the dimension of the attention head, and h is the number of attention heads. The attention score is:

[0053] S402, The attention score for the shifted window's self-attention is calculated as follows, where, is the dimension of the attention head, and h is the number of attention heads (in this paper, we set h=8).

[0054]

[0055] S403. The attention calculation method for large windows in high-rise buildings is as follows: , , Weight matrix , Here, h is the dimension of the attention head, and h is the number of attention heads. The attention score is:

[0056] S5. By adopting a two-way feature fusion strategy of bottom-up and top-down, linear projection is performed on the fused feature pyramid to form the feature representation of the vehicle.

[0057] S501. In the bottom-up path, low-level features are upsampled to the mid-level dimensions using bilinear interpolation, and mid-level features are upsampled to the high-level dimensions. A 1×1 convolution is used to align the channel count with the mid-level feature dimensions, and the two are concatenated to obtain the feature. ; S502. In the top-down path, high-level features are downsampled to the mid-level size using max pooling, and the downsampled high-level features are concatenated with the mid-level features. ; S503. Generate the fusion weights of each level through a lightweight gating network, calculated as follows;

[0058]

[0059] S504. Concatenate the global codes to obtain the initial global features. Where N is the number of blocks, It is a dimension; a linear projection is performed on the fused feature pyramid to form the feature representation of the image patch.

[0060] S6. Input the final fused feature vector into the MLP. After input, hiding and activation functions, the recognition result is output.

[0061] S601 and MLP unit inputs are globally normalized features. The input image for HMA-VeReID is cropped for vehicle regions after object detection and normalized to a resolution of 224×224. A hierarchical hybrid attention encoder generates multi-scale features, which are dynamically fused to output global features, which are then L2 normalized to obtain...

[0062] S602. The cross-entropy loss function is used during the training phase. ; S603 and MLP output dimensions are the number of vehicle categories. Softmax maps the raw scores (Logits) output from the last layer of the MLP to a probability distribution. After converting Logits into probabilities, Softmax can directly calculate the difference between the predicted probability and the true label. During the inference stage, there's no need to calculate cross-entropy loss; normalized global features are used directly for similarity matching. The normalized feature vector is input into the classification MLP unit, and the output is a vehicle ID probability distribution, where... , .

[0063] In another embodiment of the present invention, a vehicle re-identification system based on a hierarchical hybrid attention mechanism is provided. This system can be used to implement the above-mentioned vehicle re-identification method based on a hierarchical hybrid attention mechanism. Specifically, the vehicle re-identification system based on a hierarchical hybrid attention mechanism includes an image acquisition module, a hierarchical encoding module, a feature fusion module, and a recognition output module.

[0064] The image acquisition module is used to acquire the input vehicle image; The hierarchical encoding module is used to construct a hierarchical hybrid attention encoder, which uses a three-level hierarchical processing structure to perform hierarchical encoding processing on the input vehicle image to generate multi-scale features; the multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical encoding module includes a bottom-level processing unit, a middle-level processing unit, and a high-level processing unit, which are respectively configured to divide the input vehicle image using progressively larger window sizes, embed positional codes of the corresponding level, and perform feature calculations using corresponding attention modules. The feature fusion module is used to construct a feature fusion layer. It receives the low-level detailed features, mid-level component features and high-level global features, and performs cross-level interactive fusion through bidirectional paths from bottom to top and from top to bottom to generate a fused feature vector. The identification output module is used to construct the MLP classification module. It receives the fused feature vector, and after global pooling and normalization, outputs the vehicle ID probability distribution or vehicle feature vector for re-identification and matching.

[0065] This invention provides a terminal device comprising a processor and a memory. The memory stores a computer program, which includes program instructions. The processor executes the program instructions stored in the computer storage medium. The processor may be a Central Processing Unit (CPU), or other general-purpose processors, graphics processing units (GPUs), tensor processing units (TPUs), digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. It is the computing and control core of the terminal, suitable for implementing one or more instructions, specifically suitable for loading and executing one or more instructions to achieve a corresponding method flow or function. The processor described in this embodiment can be used for the operation of a vehicle re-identification method based on a hierarchical hybrid attention mechanism, including: A vehicle re-identification network architecture is constructed, comprising a hierarchical hybrid attention encoder, a feature fusion layer, and an MLP classification module connected sequentially. An input vehicle image is acquired, and the hierarchical hybrid attention encoder performs hierarchical encoding processing on the input vehicle image to generate multi-scale features. These multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical hybrid attention encoder adopts a three-level hierarchical processing structure, including a low-level processing unit, a mid-level processing unit, and a high-level processing unit. Each of the low-level, mid-level, and high-level processing units divides the input vehicle image using progressively larger window sizes, embeds corresponding level positional encodings, and performs feature calculations using corresponding attention modules. The low-level detail features, mid-level component features, and high-level global features are input to the feature fusion layer, where cross-level interactive fusion is performed through bidirectional paths (bottom-up and top-down) to generate a fused feature vector. The fused feature vector is input to the MLP classification module, and after global pooling and normalization, outputs a vehicle ID probability distribution or a vehicle feature vector for re-identification matching.

[0066] Please see Figure 5The terminal device is a computer device. In this embodiment, the computer device 60 includes a processor 61, a memory 62, and a computer program 63 stored in the memory 62 and executable on the processor 61. When executed by the processor 61, the computer program 63 implements the vehicle re-identification method based on a hierarchical hybrid attention mechanism as described in this embodiment. To avoid repetition, details are omitted here. Alternatively, when executed by the processor 61, the computer program 63 implements the functions of each model / unit in the vehicle re-identification system based on a hierarchical hybrid attention mechanism as described in this embodiment. To avoid repetition, details are omitted here.

[0067] Computer device 60 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. Computer device 60 may include, but is not limited to, a processor 61 and a memory 62. Those skilled in the art will understand that... Figure 5 This is merely an example of computer device 60 and does not constitute a limitation on computer device 60. It may include more or fewer components than shown, or combine certain components, or different components. For example, computer device may also include input / output devices, network access devices, buses, etc.

[0068] The processor 61 may be a Central Processing Unit (CPU), or other general-purpose processors, graphics processing units (GPUs), tensor processing units (TPUs), digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0069] The memory 62 can be an internal storage unit of the computer device 60, such as a hard disk or memory of the computer device 60. The memory 62 can also be an external storage device of the computer device 60, such as a plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, etc. equipped on the computer device 60.

[0070] Furthermore, the memory 62 may include both internal storage units of the computer device 60 and external storage devices. The memory 62 is used to store computer programs and other programs and data required by the computer device. The memory 62 can also be used to temporarily store data that has been output or will be output.

[0071] Please see Figure 6 The terminal device is an electronic device 600, which is manifested in the form of a general-purpose computing device. The components of the electronic device may include, but are not limited to: at least one processing unit 610, at least one storage unit 620, a bus 630 connecting different platform components (including storage unit 620 and processing unit 610), a display unit 640, etc.

[0072] The storage unit stores program code, which can be executed by the processing unit 610 to perform the steps described in the method section of this specification according to various exemplary embodiments of the present invention. For example, the processing unit 610 can perform actions such as... Figure 7 The steps are shown in the figure.

[0073] Storage unit 620 may include a readable medium in the form of a volatile storage unit, such as random access memory (RAM) 6201 and / or cache memory 6202, and may further include a read-only memory (ROM) 6203.

[0074] Storage unit 620 may also include a program / utility 6204 having a set (at least one) program module 6205, such program module 6205 including but not limited to: operating system, one or more application programs, other program modules and program data, each or some combination of these examples may include an implementation of a network environment.

[0075] Bus 630 can represent one or more of several types of bus structures, including a memory cell bus or memory cell controller, a peripheral bus, a graphics acceleration port, a processing unit, or a local bus using any of the multiple bus structures.

[0076] Electronic device 600 can also communicate with one or more external devices 700 (e.g., keyboard, pointing device, Bluetooth device, etc.), and with one or more devices that enable a user to interact with electronic device 600, and / or with any device that enables electronic device 600 to communicate with one or more other computing devices (e.g., router, modem). This communication can be performed via input / output interface 650. Furthermore, electronic device 600 can also communicate with one or more networks (e.g., local area network, wide area network, and / or public network, such as the Internet) via network adapter 660. Network adapter 660 can communicate with other modules of electronic device 600 via bus 630. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms.

[0077] Example 4 This invention also provides a storage medium, specifically a computer-readable storage medium, which is a memory device in a terminal device for storing programs and data. It is understood that the computer-readable storage medium here can include both built-in storage media in the terminal device and extended storage media supported by the terminal device; it can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. The computer-readable storage medium provides storage space that stores the terminal's operating system. Furthermore, the storage space also stores one or more instructions suitable for loading and execution by a processor, which can be one or more computer programs (including program code). More specific examples of the computer-readable storage medium include: an electrical connection with one or more wires, a portable disk, a hard disk, random access memory, read-only memory, erasable programmable read-only memory, optical fiber, portable compact disk read-only memory, optical storage device, magnetic storage device, or any suitable combination thereof.

[0078] Computer-readable storage media also include data signals propagated in baseband or as part of a carrier wave, carrying readable program code. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. A readable storage medium can also be any readable medium other than a readable storage medium that can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The program code contained on the readable storage medium can be transmitted using any suitable medium, including but not limited to wireless, wired, optical fiber, radio frequency, etc., or any suitable combination thereof.

[0079] Program code for performing the operations of this invention can be written in any combination of one or more programming languages, including object-oriented programming languages ​​such as Java and C++, and conventional procedural programming languages ​​such as C or similar languages. The program code can execute entirely on the user's computing device, partially on the user's computing device, as a standalone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).

[0080] One or more instructions stored in the computer-readable storage medium can be loaded and executed by the processor to implement the corresponding steps of the vehicle re-identification method based on the hierarchical hybrid attention mechanism in the above embodiments; one or more instructions in the computer-readable storage medium are loaded and executed by the processor to perform the following steps: A vehicle re-identification network architecture is constructed, comprising a hierarchical hybrid attention encoder, a feature fusion layer, and an MLP classification module connected sequentially. An input vehicle image is acquired, and the hierarchical hybrid attention encoder performs hierarchical encoding processing on the input vehicle image to generate multi-scale features. These multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical hybrid attention encoder adopts a three-level hierarchical processing structure, including a low-level processing unit, a mid-level processing unit, and a high-level processing unit. Each of the low-level, mid-level, and high-level processing units divides the input vehicle image using progressively larger window sizes, embeds corresponding level positional encodings, and performs feature calculations using corresponding attention modules. The low-level detail features, mid-level component features, and high-level global features are input to the feature fusion layer, where cross-level interactive fusion is performed through bidirectional paths (bottom-up and top-down) to generate a fused feature vector. The fused feature vector is input to the MLP classification module, and after global pooling and normalization, outputs a vehicle ID probability distribution or a vehicle feature vector for re-identification matching.

[0081] The databases involved in the embodiments provided in this application may include at least one type of relational database and non-relational database. Non-relational databases may include, but are not limited to, blockchain-based distributed databases. The processors involved in the embodiments provided in this application may be general-purpose processors, central processing units, graphics processing units, digital signal processors, programmable logic devices, quantum computing-based data processing logic devices, etc., and are not limited to these.

[0082] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. The components of the embodiments of the present invention described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the claimed invention, but merely to illustrate selected embodiments of the invention. All other embodiments obtained by those skilled in the art based on the embodiments of the present invention without inventive effort are within the scope of protection of the present invention.

[0083] Please see Figure 1 The first step is to perform patch segmentation and feature encoding on the image. For The image uses the underlying layer. The small window has a number of blocks. =3136, Each block feature The length of the feature vector of each block =48, projection matrix ,make The formula for mapping a 48-dimensional pixel block to a 512-dimensional feature space is as follows: , The location encoding uses absolute location encoding. The absolute location encoding of each block is extracted as follows: Number of components. frequency coefficient Therefore, in the 512-dimensional positional components, the 0th dimension is... The first dimension is The 511th dimension is The feature after adding position encoding is . It is 512-dimensional, and its calculation process is as follows: Figure 4 As shown.

[0084]

[0085] Spatially concatenate the 3136 blocks, where pos is the position index, and obtain the bottom-level total feature according to the raster scan order. .

[0086] Self-attention calculation is performed on the bottom-level small window, with the number of attention heads set to 8. , It is the dimension of attention head. Attention score for each head The calculation is as follows: global attention requires concatenating the attention scores of 8 heads, while keeping the number of output dimensions unchanged.

[0087]

[0088]

[0089] in, , , , It is the underlying general characteristic. Length of feature vector per block =192, projection matrix ,make The formula for mapping a 192-dimensional pixel block to a 512-dimensional feature space is as follows: , .

[0090] Please see Figure 4 The calculation process of local features, obtaining and Finally, the input features of the MLP are obtained through bidirectional fusion, and the final output result is obtained. The specific process needs to be explained with experiments.

[0091] To verify the performance of the proposed model, the experimental platform was configured with an Intel Xeon Max processor, 64GB of RAM, and an NVIDIA 4090 graphics card with 24GB of VRAM. The deep learning framework used was PyTorch-2.0. Three commonly used large-scale benchmark datasets in the field of vehicle re-identification are VeRi-776, VehicleID, and VeRi-Wild. The VeRi-776 and VehicleID datasets include front and rear views and views from different angles for each vehicle, with each image labeled with the vehicle ID, camera information, and vehicle model. These datasets do not include vehicle-to-everything (V2X) communication, road background, or vehicle interaction information; therefore, this paper uses the VeRi-776 and VeRi-Wild datasets, with images covering different time periods. This dataset consists of 174 cameras covering a 200 square kilometer urban area. Each camera recorded continuously for 30 days, 24 hours a day, taking into account various real-world weather and lighting conditions. The dataset contains 416,314 images with 40,671 samples, including a training set of 277,797 images with 30,671 samples and a test subset of 128,517 images with 10,000 samples. The dataset provides camera IDs, timestamps, and tracking relationships between cameras. The dataset content is as follows: Figure 3 As shown The evaluation metrics used in this invention are as follows: mean average precision (mAP) and cumulative matching characteristics (CMC@1, CMC@5) are used for evaluation. The mAP metric is used to calculate the average area under the Precision-Recall curve for all query images. Rank- k Before the check-up k The matching results are used to determine whether the query image is in the database. k The performance of the retrieval system is evaluated by analyzing the matching results. k This reflects the system's prior k The accuracy of each matching result is considered; a higher value indicates better system performance. The average accuracy (AP) is calculated for each category, and then the AP of all categories is averaged to obtain the mAP.

[0092]

[0093]

[0094]

[0095] Where Q represents the total number of query images in the query set, AP represents the average precision retrieval result for each query image, n represents the total number of images in the dataset, and N represents the total number of target vehicle images. PK represents the precision of the top k retrieval result sequences, and gt(q,K) represents whether the target vehicle ranks among the top k retrieval results. Several publicly available classic Ve-RI models were selected for comparison, including ResNet, ViT, and Swin-transformer. ViT is an image processing benchmark model based on the Transformer architecture, capable of handling complex image features and possessing strong generalization ability. Swin-transformer uses a hierarchical construction method similar to that in convolutional neural networks, but introduces the concepts of Windows and Swift Windows, and does not involve positional encoding.

[0096] 1) Comparative Experiment ResNet50, ViT, and SWIN-T were selected as baseline models for comparison with this algorithm. Considering time consumption and model performance, none of the four algorithms were pre-trained on ImageNet, so their mAP index was lower than the official data of the baseline models, but they still showed good actual performance. All models were trained on the training set using the cross-entropy loss function, and the accuracy was used as the evaluation index for validating the model performance after each training round. The model with the highest accuracy on the validation set was selected for testing. During training, the learning rate was selected from {0.001, 0.002, 0.005, 0.01}, the weight decay coefficient was selected from {0.01, 0.05, 0.1, 0.2}, and the Dropout rate was determined from {0.1, 0.2, 0.3, 0.5}. Grid search was used for hyperparameter selection, and the AdamW

[14] optimizer was used for model optimization. Each training lasted for 60 epochs. The specific experimental results are shown in Table 1 below: Table 1: Results of the comparative experiment

[0097] Experimental results show that our proposed HMAE-VeReID method achieves the best Rank-1 performance on the VeRi-Wild dataset and ranks second in Rank-5. On the VeRi-776 dataset, it achieves the highest scores in all three evaluation metrics, fully validating the effectiveness of our method. Transformer-based models (ViT, Swin-Transformer, and our proposed method) utilize attention mechanisms to extract more discriminative features, thus outperforming the convolutional network ResNet-50 across the board on the large-scale VeRi-Wild dataset. However, on the smaller VeRi-776 dataset, ResNet-50 surpasses ViT, indicating that larger datasets are more conducive to the advantages of Transformer vision models. Notably, the hierarchical design of Swin-Transformer and our proposed method, compared to the flat structure of ViT, allows them to outperform ResNet-50 overall, even on smaller datasets.

[0098] 2) Ablation experiment To investigate the contributions of each component of this method and the impact of learned characteristics at different stages, ablation experiment variants include: HMAE-VeReIDatt: Replaces the default visual token feature fusion strategy with an attention-based fusion mechanism.

[0099] HMAE-VeReIDavg: Uses average pooling instead of the original method for visual token feature fusion.

[0100] HMAE-VeReIDw / o-glob: Removes global features, retaining only local and mid-level features.

[0101] HMAE-VeReIDw / o-loc: Removes local features, retaining only global and mid-level features. The experimental results are shown in Table 2.

[0102] Table 2: Results of the ablation experiment

[0103] Experimental results show that, by comparing these variants, HMAE-VeReIDavg significantly outperforms HMAE-VeReIDatt, indicating that the attention-based fusion mechanism can effectively filter out the more important parts from the combined global, mid-level, and local features, thereby obtaining more discriminative features and improving vehicle re-identification performance. In contrast, the average pooling method may weaken key discriminative features during the pooling process. The performance decrease of HMAE-VeReID w / o-glob and HMAE-VeReID w / o-loc compared to HMAE-VeReID demonstrates that fusing global and local features with different patch sizes and window settings can effectively enhance model performance. Furthermore, the performance gap between HMAE-VeReID w / o-glob and HMAE-VeReID w / o-loc indicates that while local and mid-level features can provide some overall information, they cannot completely replace true global features; the feature fusion strategy employed by HMAE-VeReID effectively integrates these three types of features.

[0104] In summary, this invention presents a vehicle re-identification method and system based on a hierarchical hybrid attention mechanism, which can achieve accurate cross-camera vehicle tracking in real-world scenarios such as traffic violation monitoring and electronic toll collection. Through the synergy of multi-scale feature learning and dynamic adaptation, it provides both theoretical and practical value for next-generation intelligent transportation systems. Experimental results show that the network designed in this invention outperforms baseline models (ViT, SwinTransformer, ResNet-50) on both the VeRi-Wild and VeRi-776 datasets. Specifically, without pre-training on any external image datasets, the method achieves a Rank-1 accuracy of 85.1% on VeRi-Wild and 76.4% on VeRi-776, demonstrating particularly strong performance under occlusion and low-light conditions. Ablation experiments further confirm the necessity of hierarchical attention, positional encoding, and bidirectional fusion strategies.

[0105] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.

[0106] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0107] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed in this invention can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0108] In the embodiments provided by this invention, it should be understood that the disclosed devices / terminals and methods can be implemented in other ways. For example, the device / terminal embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0109] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0110] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0111] If the integrated module / unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, a read-only memory (ROM), a random-access memory (RAM), an electrical carrier signal, a telecommunication signal, and a software distribution medium, etc.

[0112] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus, and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0113] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0114] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0115] The above content is only for illustrating the technical concept of the present invention and should not be construed as limiting the scope of protection of the present invention. Any modifications made to the technical solution based on the technical concept proposed in this invention shall fall within the scope of protection of the claims of this invention.

Claims

1. A vehicle re-identification method based on a hierarchical hybrid attention mechanism, characterized in that, Includes the following steps: S1. Construct a vehicle re-identification network architecture, which includes a hierarchical hybrid attention encoder, a feature fusion layer, and an MLP classification module connected in sequence. S2. Obtain the input vehicle image, and use the hierarchical hybrid attention encoder to perform hierarchical encoding processing on the input vehicle image to generate multi-scale features. The multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical hybrid attention encoder adopts a three-level hierarchical processing structure, including a bottom-level processing unit, a middle-level processing unit, and a high-level processing unit. The bottom-level processing unit, the middle-level processing unit, and the high-level processing unit each divide the input vehicle image using progressively larger window sizes, and each embeds positional codes of the corresponding level and performs feature calculations using corresponding attention modules. S3. Input the low-level detailed features, mid-level component features and high-level global features into the feature fusion layer, and perform cross-level interactive fusion through a bidirectional path from bottom to top and from top to bottom to generate a fused feature vector. S4. Input the fused feature vector into the MLP classification module. After global pooling and normalization, output the vehicle ID probability distribution or vehicle feature vector for re-identification and matching.

2. The vehicle re-identification method based on hierarchical hybrid attention mechanism according to claim 1, characterized in that, In step S2, the progressively increasing window size is specifically defined as follows: The underlying processing unit divides the input vehicle image into 4×4 pixel windows to extract local detail features; The intermediate processing unit divides the input vehicle image into 8×8 pixel windows to extract component-level correlation features. The high-level processing unit divides the input vehicle image into 16×16 pixel windows to extract global semantic features.

3. The vehicle re-identification method based on a hierarchical hybrid attention mechanism according to claim 2, characterized in that, The embedding of position codes corresponding to the respective levels specifically includes: An absolute position code is embedded in the features generated by the underlying processing unit, and the unique position index code is directly added to the underlying detail features; Relative position encoding is embedded in the features generated by the middle layer processing unit to construct a learnable bias matrix and incorporate the relative position information into the attention score calculation. Normalized global position codes are embedded in the features generated by the high-level processing unit, and sine and cosine codes are performed based on the normalized coordinates of the block center point and concatenated with the high-level global features.

4. The vehicle re-identification method based on hierarchical hybrid attention mechanism according to claim 2, characterized in that, It also includes edge processing steps: When the size of the input vehicle image cannot be divided by the window size, the image edge area is filled using a zero-fill mechanism; In the subsequent attention calculation process, a mask matrix is ​​generated for the filled region, and the contribution of the filled region to the attention score is ignored.

5. The vehicle re-identification method based on a hierarchical hybrid attention mechanism according to claim 1, characterized in that, In step S2, the feature calculation using the corresponding attention module specifically includes: In the lower-level processing unit and the middle-level processing unit, the attention score is calculated using a local window self-attention mechanism or a shifted window self-attention mechanism. In the high-level processing unit, a large window attention mechanism is used to calculate the attention score; The attention score is calculated based on the query matrix, key matrix, and value matrix, combined with the position encoding or bias term of the corresponding level.

6. The vehicle re-identification method based on hierarchical hybrid attention mechanism according to claim 1, characterized in that, In step S3, the cross-level interactive fusion via a bidirectional path of bottom-up and top-down approaches specifically includes: In the bottom-up path, the low-level detailed features are upsampled to the mid-level scale, and the upsampled features are concatenated with the mid-level component features; the concatenated mid-level features are upsampled to the high-level scale and concatenated with the high-level global features; In the top-down path, the high-level global features are downsampled to the mid-level scale and fused with the mid-level features; A lightweight gating network is used to generate fusion weights for each layer. The features after bidirectional path fusion are weighted and summed, and the final fusion feature vector is generated through linear projection.

7. The vehicle re-identification method based on a hierarchical hybrid attention mechanism according to claim 6, characterized in that, In the top-down path, the specific method for downsampling high-level global features to the mid-level scale is as follows: Perform max pooling or convolution with a stride greater than 1 on the high-level global features to make their spatial resolution consistent with that of the mid-level component features; In the bottom-up path of step S3, the upsampling operation specifically uses a bilinear interpolation algorithm or a transposed convolution algorithm to enlarge the feature map size.

8. The vehicle re-identification method based on a hierarchical hybrid attention mechanism according to claim 1, characterized in that, In step S4, the output vehicle ID probability distribution or vehicle feature vector is used for re-identification and matching, specifically including: During the training phase, the normalized fused feature vector is input into the fully connected layer, and the difference between the predicted vehicle ID probability distribution and the true label is calculated using the cross-entropy loss function in order to optimize the network parameters. During the inference phase, the normalized fused feature vector is directly output, the similarity between the feature vector of the query image and the feature vector of the database image is calculated, and the consistency of vehicle identity is determined based on the similarity threshold.

9. The vehicle re-identification method based on hierarchical hybrid attention mechanism according to claim 1, characterized in that, Before step S2, image preprocessing is performed, specifically as follows: Acquire the original vehicle image and adjust it to the preset H×W resolution; The adjusted image is standardized by subtracting the mean and dividing by the standard deviation to obtain a standardized input vehicle image.

10. A vehicle re-identification system based on a hierarchical hybrid attention mechanism, characterized in that, include: The image acquisition module is used to acquire the input vehicle image; The hierarchical encoding module is used to construct a hierarchical hybrid attention encoder, which uses a three-level hierarchical processing structure to perform hierarchical encoding processing on the input vehicle image to generate multi-scale features; the multi-scale features include at least low-level detail features, mid-level component features, and high-level global features. The hierarchical encoding module includes a bottom-level processing unit, a middle-level processing unit, and a high-level processing unit, which are respectively configured to divide the input vehicle image using progressively larger window sizes, embed positional codes of the corresponding level, and perform feature calculations using corresponding attention modules. The feature fusion module is used to construct a feature fusion layer. It receives the low-level detailed features, mid-level component features and high-level global features, and performs cross-level interactive fusion through bidirectional paths from bottom to top and from top to bottom to generate a fused feature vector. The identification output module is used to construct the MLP classification module. It receives the fused feature vector, and after global pooling and normalization, outputs the vehicle ID probability distribution or vehicle feature vector for re-identification and matching.