A target tracking method based on a cyclic shift window, a terminal device, and a medium
Patent Information
- Application Number
- CN202411017977.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2026-11-03
- Estimated Expiration
- 2044-07-26
AI Technical Summary
现有的视觉目标跟踪技术在面对复杂场景中的干扰因素时,容易产生累积误差导致跟踪漂移,难以在多变的场景中保持准确性。
A target tracking method based on cyclic shift windows is adopted, which combines a Transformer matching module, a bounding box estimation module, and a dynamic template image update module. Through feature extraction, multi-head attention feature map calculation, and sparse dropout attention mechanism, the computational efficiency and accuracy of the target tracking model are optimized.
It improves the accuracy and speed of target tracking, can adapt to different scenarios and complex dynamics, and achieves real-time tracking.
Smart Images

Figure CN119048553B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of target tracking, and more particularly to a target tracking method, terminal device, and medium based on a cyclic shift window. Background Technology
[0002] Computer vision, as an interdisciplinary field, has developed rapidly in recent decades. Among them, visual object tracking (VOT), as an important branch of computer vision, has attracted widespread research interest and demonstrated great potential in practical applications.
[0003] Visual target tracking aims to locate and track dynamic targets of interest in a continuous video sequence. Its core task is to estimate the target's position, shape, and other state information in each frame. Research on visual target tracking technology not only has theoretical value but also has wide-ranging practical applications, including video surveillance, human-computer interaction, autonomous driving, military applications, and robot vision. Although target tracking has made significant progress in the past decade, the variability of the scene during tracking and the various interference factors encountered in specific scenarios, such as partial occlusion, changes in illumination intensity, scale variations, and interference from similar objects, can cause cumulative errors in the tracking model, leading to tracking drift and ultimately tracking failure. Summary of the Invention
[0004] To address the aforementioned problems, this invention proposes a target tracking method, terminal device, and medium based on a cyclic shift window.
[0005] The specific plan is as follows:
[0006] A target tracking method based on a cyclic shift window includes the following steps:
[0007] S1: Extract the target image corresponding to the target to be tracked from the first frame image in the video stream as a static template image, extract the target image corresponding to the target to be tracked from the images before the frame image to be analyzed as a dynamic template image, and use the frame image to be analyzed as the search area image.
[0008] S2: Construct a target tracking model. The model's network structure includes a feature extraction module, a Transformer matching module, and a bounding box estimation module; where:
[0009] The feature extraction module receives the input search region image, static template image and dynamic template image and performs feature extraction to obtain the corresponding search region feature map, static template feature map and dynamic template feature map. Then, it flattens the feature maps of the three images respectively, and stitches the flattening results into an intermediate feature map. Then, it adds spatial location coding to the intermediate feature map to obtain the intermediate feature map with added spatial location coding.
[0010] The Transformer matching module consists of 6 Transformer layers. After each Transformer layer performs steps S01-S102, it outputs the corresponding multi-head attention feature map. The input of the first Transformer layer is the intermediate feature map with added spatial location encoding, and the input of the Transformers layers 2-6 is the multi-head attention feature map output by the previous layer. The Transformer matching module inputs the multi-head attention feature map output by the 6th layer into the bounding box estimation module for bounding box estimation.
[0011] S101: Slice the input feature map into N heads, and perform steps S201-S206 for each head to obtain the single-head attention matrix corresponding to each head;
[0012] S102: Concatenate the single-head attention matrices corresponding to all heads, and then reshape the concatenation result to the size of the intermediate feature map to obtain the multi-head attention feature map corresponding to this layer.
[0013] S201: Perform three different linear transformations on each head to obtain the first feature map corresponding to that head. Second feature map and the third feature map
[0014] S202: Transfer the first feature map Reshape into query matrix Q, and use the second feature map Perform a circular shift to obtain the bond tensor The third feature map Perform a circular shift to obtain a value tensor
[0015] S203: Key Tensor The bond matrix K is obtained by reshaping. C Then, the key matrix K C Transpose the matrix to obtain the transposed key matrix. logarithmic tensor Reshaping yields the value matrix V C ;
[0016] S204: For the query matrix Q and the transposed key matrix Perform matrix multiplication to obtain the feature attention matrix A;
[0017] S205: Activate the feature attention matrix A, and redistribute the activated feature attention matrix onto a zero matrix of the same size as the original matrix to obtain the attention matrix A. s ;
[0018] S206: Transfer the attention matrix A s The sum-value matrix V C Perform matrix multiplication and resize the result to obtain the single-head attention matrix corresponding to that head.
[0019] S3: After training the model using a training set constructed from historical video streams, target tracking is performed using the trained model.
[0020] Furthermore, in step S101, for the heads with larger window sizes among the N heads obtained from slicing, the operations of steps S301-S307 are performed to obtain the single-head attention matrix corresponding to these heads. For the other heads, the operations of steps S201-S206 are still performed to obtain the single-head attention matrix corresponding to each head.
[0021] S301: Perform three different linear transformations on each head to obtain the first feature map corresponding to that head. Second feature map and the third feature map
[0022] S302: For the first feature map Perform Fourier transform to obtain For the second feature map Perform Fourier transform to obtain
[0023] S303: Yes Each of the L blocks is subjected to the same operation L times, resulting in... in, Indicates will The result of repeating the l-th block L times, where l∈[1,L];
[0024] S304: Will and conjugate Perform dot product operation, sum the different channels in the dot product operation result, perform inverse Fourier transform on the summation result, extract the real part after inverse Fourier transform, and stack the extracted real parts as the l-th row in the feature attention matrix A.
[0025] S305: Activate the feature attention matrix A, and redistribute the activated feature attention matrix onto a zero matrix of the same size as the original matrix to obtain the attention matrix A. s ;
[0026] S306: Transfer the third feature map Perform a circular shift to obtain a value tensor logarithmic tensor Reshaping yields the value matrix V C ;
[0027] S307: Transfer attention matrix A s The sum-value matrix V C Perform matrix multiplication and resize the result to obtain the single-head attention matrix corresponding to that head.
[0028] Furthermore, when activating the feature attention matrix A, the largest K elements in each row of the feature attention matrix A are first selected, and then the selected K elements are activated, while all unselected elements are replaced with zero.
[0029] Furthermore, the bounding box estimation module adopts the corner estimation framework of the Stark algorithm.
[0030] Furthermore, the model also includes a dynamic template image update module. The dynamic template image is extracted from frame images at fixed intervals. When the latest dynamic template image is obtained, the dynamic template image update module calculates its corresponding prediction score based on the latest dynamic template image and determines whether the prediction score is greater than the score threshold. If so, the latest dynamic template image is used as the dynamic template image to be used.
[0031] Furthermore, the dynamic template image update module calculates the predicted score based on a multilayer perceptron.
[0032] Furthermore, the model's loss function combines L1 loss and IOU loss.
[0033] A target tracking terminal device based on a cyclic shift window includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of the method described above in the embodiments of the present invention.
[0034] A computer-readable storage medium storing a computer program that, when executed by a processor, implements the steps of the method described above in the embodiments of the present invention.
[0035] The present invention adopts the above technical solution, which has superior performance in both tracking effect and tracking speed. It can adapt to different scenarios and complex dynamic conditions for tracking target objects, and can track in real time. Attached Figure Description
[0036] Figure 1 The figure shown is a schematic diagram of the overall structure of the model in Embodiment 1 of the present invention.
[0037] Figure 2 The diagram shown is a schematic of the Transformer's structure when solving in the frequency domain in this embodiment.
[0038] Figure 3 The diagram shown is a schematic of the spatial domain calculation to frequency domain analysis process in this embodiment.
[0039] Figure 4 The diagram shown is a schematic of the sparse discard attention activation process in this embodiment. Detailed Implementation
[0040] To further illustrate the various embodiments, the present invention provides accompanying drawings. These drawings are part of the disclosure of the present invention, primarily used to illustrate the embodiments, and can be used in conjunction with the relevant descriptions in the specification to explain the operating principles of the embodiments. With reference to these drawings, those skilled in the art should be able to understand other possible implementations and the advantages of the present invention.
[0041] The present invention will now be further described in conjunction with the accompanying drawings and specific embodiments.
[0042] Example 1:
[0043] This embodiment provides a target tracking method based on a multi-scale cyclic shift window Transformer tracking model with sparsification (i.e., sparse CSWinTT). The Transformer is used as a matching module, making full use of the Transformer's powerful cross-attention capability to calculate the correlation between the template and the search region.
[0044] The network structure of the target tracking model used in the method is as follows: Figure 1 As shown, it consists of four main components: feature extraction module, Transformer matching module, bounding box estimation module, and dynamic template image update module.
[0045] In this embodiment, ResNet-50 is selected as the feature extraction module, which accepts a pair of image inputs and a dynamic template image input, namely, the template image, the search region image, and the dynamic template image. These output features are then divided into window sequences and fed into the Transformer matching module. The matching module concatenates the two window sequences and sends them to a multi-head 6-layer Transformer. The multi-head Transformer performs scale adaptation for each head using a specific window size. Then, the outputs of each Transformer head are concatenated, and the resulting bounding boxes are obtained by estimating the bounding boxes based on corner points using the STARK algorithm. Finally, the dynamic template is updated in real-time using the scores.
[0046] (1) Attention Spatial Calculation
[0047] First, given the search region image in the initial frame. Static template image and dynamic template images Then, the search area image Static template image and dynamic template images The input is fed into the feature extraction module (BackBone) to obtain the corresponding search region feature map. Static template feature map and dynamic template feature map As shown in the following formula:
[0048]
[0049] in,
[0050] Then, the obtained search region feature map Static template feature map and dynamic template feature map The three feature maps are stretched to achieve flattening, and then stitched together to form a larger intermediate feature map. As shown in the following formula:
[0051]
[0052] Where Flatten represents the feature map of the search region. Static template feature map and dynamic template feature map The flattening operator is specifically divided into L windows of size r×r; Concat represents the concatenation operator that combines the flattening results of the three components. This represents the intermediate feature map obtained by splicing, with a size of [size missing]. The window size is r×r, and the number of windows is
[0053] Next, in the intermediate feature map Add spatial location coding Forming an intermediate feature map with added spatial location encoding The specific formula is as follows:
[0054]
[0055] Among them, feature map The size is
[0056] Then, the intermediate feature maps with added spatial location encoding are processed. Slice the material into eight sections, as shown in the following formula:
[0057]
[0058] Here, Split represents the slicing operator, which incorporates intermediate feature maps encoded with spatial location. It was cut into eight heads, each head being [size missing]. It should be noted that, in other embodiments, the number of heads to be split can be set by those skilled in the art as needed, and no restrictions are imposed here.
[0059] Perform a linear transformation on each head to transform the intermediate feature map. Divided into first feature map Second feature map and the third feature map The specific formula is as follows:
[0060]
[0061] Where LL represents a linear transformation, and LL1, LL2, and LL3 represent three different linear transformations; for Feature maps are obtained by performing three different linear transformations: LL1, LL2, and LL3. Feature map Feature map Feature map The size is Feature map The size is and feature maps The size is
[0062] The first feature map Reshape it into a query matrix Q, with the following formula:
[0063]
[0064] Wherein, the size of the query matrix Q is The Reshape function in MATLAB transforms a specified matrix into a matrix of a specific dimension without changing the number of elements in the matrix. The function can readjust the number of rows, columns, and dimensions of the matrix.
[0065] The second feature map and the third feature map Perform cyclic shifts separately to transform the second feature map. The result of the cyclic shift is used as a bond tensor The third feature map The result of the circular shift is used as a value tensor The specific formula is as follows:
[0066]
[0067] in, Represents a mask tensor. CS indicates the processing of tensors (i.e. The second and third dimensions of the result are cyclically shifted by operators. The size is The size is
[0068] Then the key tensor Sum tensor Reshape to obtain keys and value V C The specific formula is as follows:
[0069]
[0070] Wherein, the bond matrix K C Size is Then transpose the key matrix to obtain Size is Value matrix V C Size is
[0071] For the obtained query matrix Q and the transposed key matrix The feature attention matrix A is obtained by performing matrix multiplication, as shown in the following formula:
[0072]
[0073] Wherein, the size of the feature attention matrix A is
[0074] Subsequently, in this embodiment, the feature attention matrix A is fed into the selection elimination module (SE) for selective deletion. The deleted feature attention matrix is then activated, and the points of the activated attention matrix are redistributed to a zero matrix of the same size as the original matrix. The final matrix A is obtained. s As shown in the following formula:
[0075] A s =SE(A)(10)
[0076] Here, SE represents the selective elimination module, which mainly performs selective deletion on the feature attention matrix A. The feature attention matrix A after selective deletion is... s Size is
[0077] Feature attention matrix A after the elimination module s Then the value matrix V C Perform matrix multiplication to obtain the single-head attention matrix M i The specific formula is as follows:
[0078] M i =A s ×V c (11)
[0079] Among them, M i The size is
[0080] The single-head attention matrix M i The size is reshaped to obtain the reshaped single-head attention matrix O. i This is so that it can be connected next, as shown in the following formula:
[0081] O i =Reshape(M i (12)
[0082] Among them, O i Size is also
[0083] Then, the attention matrices obtained from each head are concatenated and reshaped into the original attention features. The size of is given by the following formula:
[0084]
[0085] Here, LP stands for linear transformation layer, and LP1, ..., LP8 represent different linear transformations. Size is This represents the multi-head attention feature map output by the j-th layer.
[0086] The Transformer matching module consists of 6 Transformer layers. After each Transformer layer performs the above operations, it outputs the corresponding multi-head attention feature map. The input to the first layer of the Transformer is an intermediate feature map with added spatial location encoding. The input to the second through sixth layers of the Transformer is the multi-head attention feature map output from the previous layer. The Transformer matching module inputs the multi-head attention feature map output from the sixth layer into the bounding box estimation module for bounding box estimation. By repeating this process six times, and processing the attention through six channels, a more accurate attention result is obtained. The specific formula is shown below:
[0087]
[0088] in, Size and Same as
[0089] (2) Attention frequency domain calculation
[0090] Because circular matrices contain redundant data, spatial operations on them incur significant computational overhead, leading to high computational complexity if performed directly in the spatial domain. Therefore, this embodiment transforms the complex spatial domain calculations in the larger sliced head into point-to-point multiplication in the frequency domain. For example, it transforms the 4th and 8th layers into point-to-point multiplication in the frequency domain. Figure 2 As shown.
[0091] The first feature map obtained in the spatial domain Second feature map Performing a Fourier transform converts it from the spatial domain to the frequency domain, simplifying complex calculations in the spatial domain into dot product operations in the frequency domain, as shown in the following equation:
[0092]
[0093] Among them, the first feature map The size is Second feature map The size is fft [2,3] In the first feature map Second feature map Perform a Fourier transform on the second and third dimensions (r). The result after the Fourier transform is... The sizes are respectively
[0094] right To extend, specifically to The operation is repeated for each block (token), and each block is repeated L times to obtain... arrive The specific formula is as follows:
[0095]
[0096] in, The size is Size is Repeat represents the repeat operator, which repeats each input tensor L times in the first dimension.
[0097] Then, find the tensor. conjugate The specific formula is as follows:
[0098]
[0099] Here, Conjugate represents the conjugate operator, that is, Invert the imaginary part. The size is
[0100] Will and Performing a dot product and then summing the results across different channels simplifies the complex spatial domain calculations. After obtaining the results, the frequency domain results need to be converted to the spatial domain. This requires performing an inverse Fourier transform on the results, taking the real parts of the inverse Fourier transform, and stacking them into the l-th row of an attention weight matrix A, i.e.:
[0101]
[0102] Where ⊙ is the dot product operator, and A is of size .
[0103] To facilitate understanding, formula (18) will be analyzed in detail here. Figure 3 The diagram shows the specific steps for converting from the spatial domain to the frequency domain, which will be analyzed in detail below.
[0104] like Figure 3 As shown, query tensor For L items of size r 2 The token is ×d, and the key tensor is also L of size r. 2 The token of ×d, first on the key tensor The cyclically shifted bond tensor is obtained by performing a cyclic shift using formula (7). To more clearly demonstrate how to convert spatial domain computation to frequency domain computation, this embodiment focuses on the cyclically shifted key tensor. Expanding on this, the specific formula is as follows:
[0105]
[0106] in The size is
[0107] As shown in equation (8), the bond tensor after cyclic shift and query tensors Remodeling into bond matrix K C With the query matrix Q, and then with the key matrix K C Obtain by transposing Query matrix Q and transpose key matrix The matrix multiplication operation is performed between them as shown in formula (9). Here, we expand and analyze it as shown in the following formula:
[0108]
[0109] Where Q(l,:) is the l-th row of Q, and its size is for Any column in the array, each column being of size 1 Where n = (a-1)r 2 +b, where A(l,n) is the l-th and n-th element. To query tensors The l-th token, Key tensor Group a r 2 The b-th token among a tokens, where a = 1, 2, 3, ..., L and b = 1, 2, 3, ..., r 2 .
[0110] Matrix multiplication can be converted into tensor-related operations, as shown in the following equation:
[0111]
[0112] Where * represents the related operation, and vec is the Lagrange operator.
[0113] The related operations can be viewed as convolution operations, as shown in the following equation:
[0114]
[0115] Where * represents the relevant operation. Represents the query tensor The l-th token,
[0116] Key tensor The b-th token in group a, where b = 1, 2, ..., r 2 ,
[0117] Indicates to The reverse folds.
[0118] According to the convolution theorem, the convolution operation in the spatial domain can be transformed into a dot product operation in the frequency domain. First, the feature map... and feature map Perform a Fourier transform, then apply the tensor Perform the conjugate operation, referring to equations (15) to (17), and finally... The convolution operation is converted to Fourier transform. and The frequency domain dot product operation is shown in the following equation:
[0119]
[0120] Where ⊙ represents the dot product, as shown in formula (15), for Fourier transform, for After performing a Fourier transform and then conjugating the result, both have a magnitude of 1.
[0121] In summary, as shown in formula (18), all blocks after cyclic shift are calculated according to the above formulas (22) and (23), then summed, and then the result is subjected to inverse Fourier transform. The real part is taken and stretched into a column vector, and finally transposed.
[0122] As described above, this embodiment simplifies complex matrix multiplication operations in the spatial domain into simple tensor dot product operations in the frequency domain, which greatly reduces computational complexity, the need for large amounts of intermediate variable storage, and the use of computer resources.
[0123] (3) Selecting attention mechanisms
[0124] In the Transformer architecture, self-attention is a core component. It allows the model to dynamically focus on different parts of the sequence while processing sequential data, without specifically focusing on the main target. Furthermore, as the sequence length increases, the computational complexity and memory requirements of the original self-attention mechanism increase exponentially. In this embodiment, no modifications were made to the original Transformer's self-attention mechanism, causing its focus on global attention to mask its focus on key information. This embodiment introduces sparse dropout into the Transformer's self-attention mechanism. Instead of performing attention calculations at every position in the sequence, it selects a subset of positions. This module gradually discards search region markers belonging to the background, thereby improving the distinction between foreground and background, reducing the ambiguity of foreground edge regions, and improving some tracking and inference speed.
[0125] In this embodiment, the similarity between all pixel pairs between the query and the key is first calculated, and unnecessary markers are masked in the similarity matrix. Then, as... Figure 4 As shown, the original attention activation process directly feeds all acquired labels into the softmax activation function without any processing, resulting in indiscriminate activation of each label. This simultaneous activation of background and foreground labels leads to their mixing and difficulty in differentiation. To address this, this embodiment first uses top-K selection to identify the K largest elements in each row of the feature attention matrix A. Then, it activates the K largest elements in each row, discarding the remaining unselected elements. Finally, these calculated values are returned to their original matrix positions, with all unselected elements replaced with zero, as shown in the following formula:
[0126]
[0127] Where TopK represents the selection operator that selects the K largest elements in each row of the similarity matrix, Softmax represents the activation function, Scatter represents the scattering operator, and A s The size is
[0128] By introducing sparsity, the problem of the original attention feature being more susceptible to noise and distracting backgrounds due to the amplification of relatively small similarity weights is solved. The pixel value of each attention feature is determined only by the K most similar pixels, making the foreground more focused and the edge regions of the foreground more discriminative.
[0129] (4) Bounding box estimation module
[0130] To improve the quality of bounding box estimation and provide more accurate and robust predictions for target tracking, this embodiment introduces the corner prediction head proposed by the Stark algorithm into the bounding box estimation module. Specifically, by outputting two probability maps of the upper left and lower right corners of the target bounding box, the expected value of the probability distribution of the two probability maps is calculated to obtain the coordinates of the upper left and lower right points. Finally, the coordinates of the predicted box are determined based on the two points of the upper left and lower right, as described in detail below.
[0131] Multi-head attention feature map after six channels The input is fed into a simple fully convolutional neural network (FCN). An FCN consists of L stacked Conv-BN-ReLU layers, and the input... After being processed by FCN, it outputs two probability maps P for the top left and bottom right corners of the target bounding box. t1(x,y) P br(x,y) The specific formula is as follows:
[0132]
[0133] Among them, P t1(x,y) This represents the probability plot in the upper left corner of the prediction box, P. br(x,y) This represents the probability graph in the lower right corner of the prediction box.
[0134] Then, the two probability graphs P obtained are... t1(x,y) P br(x,y) The following formula is used to calculate the coordinates of the bottom left and bottom right corners, thereby determining the position of the target prediction box:
[0135]
[0136] in, The top left corner point, The bottom right corner point.
[0137] (5) Dynamic template image update module
[0138] During target tracking, the tracked target may change significantly over time; therefore, capturing the target's latest state is crucial for tracking. To address this, this embodiment introduces a spatiotemporal scheme for the Stark algorithm, as detailed below.
[0139] Unlike the baseline method, which only uses the first and current frames as input, this embodiment also introduces dynamic template updates sampled from intermediate frames as additional input. For example... Figure 1As shown, dynamic templates can capture changes in the target's appearance over time, thus providing additional temporal information. However, during tracking, there are situations where dynamic templates should not be updated, such as when the target is completely occluded or removed from the field of view. In such cases, updating the dynamic template image is unreliable. Therefore, for simplicity, this embodiment assumes that the dynamic template image can be updated as long as the search area contains the target object. To automatically determine whether the current situation is reliable, this embodiment adds a simple score prediction head, Score, which is a multilayer perceptron. If the score obtained by Score is higher than a threshold τ, it is considered that it can be updated; otherwise, it is not updated, as shown in the following formula:
[0140]
[0141] Where MLP represents a three-layer perceptron with one sigmoid activation layer, and τ represents the threshold. Represents a dynamic template image. (Through...) if Score≥τ.
[0142] (6) Loss Function
[0143] The baseline tracking model used in this embodiment is trained in an end-to-end manner, combining the l1 and generalized IoU losses from the DERT architecture. The loss function is shown in the following equation:
[0144]
[0145] Among them, b i For the true frame, For the predicted bounding box, λ iou and λ L1 This is a hyperparameter, with a size of
[0146] This embodiment does not employ the classification loss and Hungarian algorithm found in the DETR architecture, thus further simplifying the training process. During inference, the template image and its features derived from the backbone are initialized in the first frame and fixed in subsequent frames. During tracking, in each frame, the network obtains a search region from the current frame as input and returns a predicted bounding box as the final result, without using any post-processing.
[0147] Existing research indicates that joint learning of localization and classification tasks may result in suboptimal solutions for both tasks, rather than optimal ones. Therefore, decoupling the localization and classification tasks is necessary. Based on this, this embodiment divides the training process into two stages, with localization as the primary task and classification as the secondary task.
[0148] In the first stage, the entire network, excluding the score head, is trained end-to-end using only the localization-related loss function in Equation (28). The task of this stage is to ensure that all search regions contain the target object and to train the model's localization capability.
[0149] In the second stage, this embodiment only optimizes the scoring head, as shown in formula (29):
[0150]
[0151] Among them, y i P represents the true label. i This represents the confidence level of the prediction. To avoid impacting the localization task, all other parameters are frozen at this stage in this embodiment. In this way, after two stages of training, the final model possesses both localization and classification capabilities.
[0152] During model training, a training set constructed from historical video streams is used to train the model. During inference, the initial dynamic template image is extracted from the first frame. Based on the template size, a search region is cropped and input into the network to generate a bounding box and a confidence score. The dynamic template image is updated only at the update interval and when the confidence score is higher than a threshold τ. In this embodiment, the update interval is set to Tu frames. The dynamic template is cropped from the original image and then input into the feature extraction module for feature extraction.
[0153] This invention introduces a transformer tracking model with multi-scale cyclic shift window attention. By introducing multi-scale cross-window attention, the model maintains object integrity and designs a selection elimination module to address the insufficient attention to key information in the original Transformer architecture's self-attention. Finally, spatiotemporal joint information and corner prediction are used to improve the accuracy of the predicted bounding box. This tracking model has the following characteristics:
[0154] (1) It can maintain the integrity of the object and retain more positional information when calculating cross-window attention between the tracking target and the search area. In view of the large amount of computation caused by the cyclic shift in this model, this paper designs a strategy to transform the attention calculation from the spatial domain to the frequency domain. This strategy can effectively reduce the computational cost and storage cost and improve the tracking speed of the model.
[0155] (2) In addition, this embodiment addresses the problem of insufficient attention to key information in the original Transformer architecture by designing a selection elimination module. This module can effectively focus attention on key information and eliminate noise information, thereby obtaining better attention information and improving the overall tracking speed of the model.
[0156] (3) Finally, this embodiment introduces spatiotemporal joint information and corner prediction. The information of the time channel is obtained through dynamic template input, so as to effectively deal with the changes of the target object. The corner prediction is calculated by the upper left corner and the lower right corner. The two points determine the position of the tracking target, so that the model of this embodiment can obtain a better tracking box.
[0157] Extensive experiments have demonstrated that this embodiment exhibits superior performance in both tracking effect and tracking speed. It can adapt to different scenarios and complex dynamic conditions for tracking target objects and can perform tracking at real-time speed.
[0158] Example 2:
[0159] The present invention also provides a target tracking terminal device based on a cyclic shift window, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps in the method embodiment described above in Embodiment 1 of the present invention.
[0160] Furthermore, as an executable solution, the target tracking terminal device based on a cyclic shift window can be a computing device such as a desktop computer, laptop, handheld computer, or cloud server. The target tracking terminal device based on a cyclic shift window may include, but is not limited to, a processor and memory. Those skilled in the art will understand that the above-described structure of the target tracking terminal device based on a cyclic shift window is merely an example and does not constitute a limitation on the target tracking terminal device based on a cyclic shift window. It may include more or fewer components than described above, or combine certain components, or different components. For example, the target tracking terminal device based on a cyclic shift window may also include input / output devices, network access devices, buses, etc., and this embodiment of the invention does not limit this.
[0161] Furthermore, as an executable solution, the processor can be a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices. The general-purpose processor can be a microprocessor or any conventional processor. This processor is the control center of the cyclic shift window-based target tracking terminal device, connecting all parts of the device via various interfaces and lines.
[0162] The memory can be used to store the computer programs and / or modules. The processor implements various functions of the target tracking terminal device based on the cyclic shift window by running or executing the computer programs and / or modules stored in the memory and calling the data stored in the memory. The memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system and at least one application program required for a function; the data storage area may store data created based on the use of the mobile phone, etc. In addition, the memory may include high-speed random access memory and may also include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0163] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the method described in the embodiments of the present invention.
[0164] If the modules / units integrated in the target tracking terminal device based on the cyclic shift window are implemented as software functional units and sold or used as independent products, they 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 of the present invention 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, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), and software distribution media, etc.
[0165] Although the invention has been specifically shown and described in conjunction with preferred embodiments, those skilled in the art should understand that various changes in form and detail may be made to the invention without departing from the spirit and scope of the invention as defined in the appended claims, all of which shall be within the scope of protection of the invention.
Claims
1. A target tracking method based on a cyclic shift window, characterized in that, Includes the following steps: S1: Extract the target image corresponding to the target to be tracked from the first frame image in the video stream as a static template image, extract the target image corresponding to the target to be tracked from the images before the frame image to be analyzed as a dynamic template image, and use the frame image to be analyzed as the search area image. S2: Construct a target tracking model. The model's network structure includes a feature extraction module, a Transformer matching module, and a bounding box estimation module; where: The feature extraction module receives the input search region image, static template image and dynamic template image and performs feature extraction to obtain the corresponding search region feature map, static template feature map and dynamic template feature map. Then, it flattens the feature maps of the three images respectively, and stitches the flattening results into an intermediate feature map. Then, it adds spatial location coding to the intermediate feature map to obtain the intermediate feature map with added spatial location coding. The Transformer matching module consists of 6 Transformer layers. After each Transformer layer performs steps S01-S102, it outputs the corresponding multi-head attention feature map. The input of the first Transformer layer is the intermediate feature map with added spatial location encoding, and the input of the Transformers layers 2-6 is the multi-head attention feature map output by the previous layer. The Transformer matching module inputs the multi-head attention feature map output by the 6th layer into the bounding box estimation module for bounding box estimation. S101: Slice the input feature map into N heads, and perform steps S201-S206 for each head to obtain the single-head attention matrix corresponding to each head; S102: Concatenate the single-head attention matrices corresponding to all heads, and then reshape the concatenation result to the size of the intermediate feature map to obtain the multi-head attention feature map corresponding to this layer. S201: Perform three different linear transformations on each head to obtain the first feature map corresponding to that head. Second feature map and the third feature map S202: Transfer the first feature map Reshape into query matrix Q, and use the second feature map Perform a circular shift to obtain the bond tensor The third feature map Perform a circular shift to obtain a value tensor S203: Key Tensor The bond matrix K is obtained by reshaping. C Then, the key matrix K C Transpose the matrix to obtain the transposed key matrix. logarithmic tensor Reshaping yields the value matrix V C ; S204: For the query matrix Q and the transposed key matrix Perform matrix multiplication to obtain the feature attention matrix A; S205: Activate the feature attention matrix A, and redistribute the activated feature attention matrix onto a zero matrix of the same size as the original matrix to obtain the attention matrix A. s ; S206: Transfer the attention matrix A s The sum-value matrix V C Perform matrix multiplication and resize the result to obtain the single-head attention matrix corresponding to that head. S3: After training the model using a training set constructed from historical video streams, target tracking is performed using the trained model.
2. The target tracking method based on a cyclic shift window according to claim 1, characterized in that: In step S101, for the heads with larger window sizes among the N heads obtained from slicing, the operations of steps S301-S307 are performed to obtain the single-head attention matrix corresponding to these heads. For the other heads, the operations of steps S201-S206 are still performed to obtain the single-head attention matrix corresponding to each head. S301: Perform three different linear transformations on each head to obtain the first feature map corresponding to that head. Second feature map and the third feature map S302: For the first feature map Perform Fourier transform to obtain For the second feature map Perform Fourier transform to obtain S303: Yes Each of the L blocks is subjected to the same operation L times, resulting in... in, Indicates will The result of repeating the l-th block L times, where l∈[1,L]; S304: Will and conjugate Perform dot product operation, sum the different channels in the dot product operation result, perform inverse Fourier transform on the summation result, extract the real part after inverse Fourier transform, and stack the extracted real parts as the l-th row in the feature attention matrix A. S305: Activate the feature attention matrix A, and redistribute the activated feature attention matrix onto a zero matrix of the same size as the original matrix to obtain the attention matrix A. s ; S306: Transfer the third feature map Perform a circular shift to obtain a value tensor logarithmic tensor Reshaping yields the value matrix V C ; S307: Transfer attention matrix A s The sum-value matrix V C Perform matrix multiplication and resize the result to obtain the single-head attention matrix corresponding to that head.
3. The target tracking method based on a cyclic shift window according to claim 1, characterized in that: When activating the feature attention matrix A, first select the K largest elements in each row of the feature attention matrix A, then activate the selected K elements, and replace all unselected elements with zero.
4. The target tracking method based on a cyclic shift window according to claim 1, characterized in that: The bounding box estimation module adopts the corner estimation framework in the Stark algorithm.
5. The target tracking method based on a cyclic shift window according to claim 1, characterized in that: The model also includes a dynamic template image update module. The dynamic template image is extracted from frame images at fixed intervals. When the latest dynamic template image is obtained, the dynamic template image update module calculates its corresponding prediction score based on the latest dynamic template image and determines whether the prediction score is greater than the score threshold. If so, the latest dynamic template image is used as the dynamic template image to be used.
6. The target tracking method based on a cyclic shift window according to claim 5, characterized in that: The dynamic template image update module calculates the predicted score based on a multilayer perceptron.
7. The target tracking method based on a cyclic shift window according to claim 1, characterized in that: The model's loss function combines L1 loss and IOU loss.
8. A target tracking terminal device based on a cyclic shift window, characterized in that: It includes a processor, a memory, and a computer program stored in the memory and running on the processor, wherein the processor executes the computer program to implement the steps of the method as described in any one of claims 1 to 7.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Multi-target tracking method based on multi-scale deformable attention mechanism
CN116309725A
Cross-video target tracking method and system, and electronic device and storage medium
WO2023216572A1
