Target tracking method based on cyclic shift window, terminal device and medium
Through the target tracking method based on cyclic shift window, combined with Transformer and sparse discarding mechanism, the problems of cumulative error and tracking drift in visual target tracking are solved, and efficient and real-time target tracking effect in complex scenarios is achieved.
Patent Information
- Application Number
- CN202411017977.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-11-29
- Estimated Expiration
- 2044-07-26
AI Technical Summary
When existing visual target tracking technologies face factors such as scene variability, local occlusion, lighting changes and interference from similar objects, they are prone to cumulative errors and tracking drifts, resulting in tracking failures.
The target tracking method based on the cyclic shift window is adopted, and the target tracking model is constructed through the feature extraction module, the Transformer matching module and the bounding box estimation module, and combined with the multi-head attention feature map and the sparse discard mechanism to achieve accurate tracking of the target.
Efficient and real-time target tracking is achieved in different scenarios and complex dynamic conditions, with strong adaptability, which can maintain the integrity of objects and reduce the computational complexity, and improve tracking speed and accuracy.
Smart Images

Figure CN119048553A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of target tracking, and in particular to a target tracking method based on a cyclic shift window, a terminal device and a medium. Background Art
[0002] As an interdisciplinary subject, computer vision has developed rapidly in recent decades. Among them, Visual Object Tracking (VOT), as an important branch of computer vision, has attracted extensive research interests and shown great potential in practical applications.
[0003] Visual target tracking aims to locate and track dynamic targets of interest in a video sequence of continuous frames. Its core task is to estimate the position, shape and other state information of the target in each frame. The research on visual target tracking technology is not only of theoretical value, but also has a wide range of application scenarios in practice, including: video surveillance, human-computer interaction, unmanned driving, military applications, robot vision, etc. Although target tracking has made great progress in the past decade, due to the variability of scenes in the tracking process, various interference factors will be encountered in specific scenes, mainly including local occlusion, changes in light intensity, scale changes, interference from similar objects, etc. Many interference factors will cause the tracking model to produce cumulative errors, resulting in tracking drift and ultimately tracking failure. Summary of the invention
[0004] In order to solve the above problem, the present invention proposes a target tracking method based on a cyclic shift window, a terminal device and a medium.
[0005] The specific plan is as follows:
[0006] A target tracking method based on a cyclic shift window comprises the following steps:
[0007] S1: extracting the target image corresponding to the target to be tracked from the first frame image in the video stream as a static template image, extracting the target image corresponding to the target to be tracked from the image before the frame image to be analyzed as a dynamic template image, and using the frame image to be analyzed as a search area image;
[0008] S2: Build a target tracking model. The network structure of the model includes a feature extraction module, a Transformer matching module, and a bounding box estimation module.
[0009] The feature extraction module receives the input search area image, static template image and dynamic template image for feature extraction, obtains the corresponding search area feature map, static template feature map and dynamic template feature map, flattens the feature maps of the three images respectively, and splices the flattening results into an intermediate feature map, adds the spatial position code to the intermediate feature map, and obtains the intermediate feature map with the spatial position code added;
[0010] The Transformer matching module includes 6 layers of Transformers. After each layer of Transformers performs the operations of steps S01-S102, it outputs the multi-head attention feature map corresponding to each layer. The input of the first layer of Transformers is the intermediate feature map with spatial position encoding, and the input of the 2nd to 6th layers of Transformers 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 and divide it into N heads, and perform steps S201-S206 for each head to obtain a 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 the layer;
[0013] S201: Perform three different linear transformations on each head to obtain the first feature map corresponding to the head Second feature map And the third characteristic map
[0014] S202: The first feature map Reshape into the query matrix Q, and transform the second feature map Perform circular shift to get the key tensor The third feature map Perform circular shift to get the value tensor
[0015] S203: Key Tensor Reshape to get the key matrix K C Then, the key matrix K C Transpose to get the transposed key matrix Pair value tensor Reshape to get the value matrix V C ;
[0016] S204: query matrix Q and 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 to a zero matrix of the same size as the original matrix to obtain the attention matrix A s ;
[0018] S206: Attention matrix A s and value matrix V C Perform matrix multiplication and reshape the result to obtain the single-head attention matrix corresponding to the head;
[0019] S3: After the model is trained using the training set constructed using historical video streams, the trained model is used for target tracking.
[0020] Further, in step S101, the operations of steps S301-S307 are performed for the heads with larger window sizes among the N heads obtained by slicing to obtain the single-head attention matrices corresponding to these heads, and the operations of steps S201-S206 are still performed for the other heads to obtain the single-head attention matrices corresponding to each head;
[0021] S301: Perform three different linear transformations on each head to obtain the first feature map corresponding to the head Second feature map And the third characteristic map
[0022] S302: First feature map Perform Fourier transform to get For the second feature map Perform Fourier transform to get
[0023] S303: Yes Each of the L blocks contained in the above code is subjected to L repeated operations, and the result is in, Indicates that The result of repeating the lth block in L times, l∈[1,L];
[0024] S304: and Conjugation Perform a dot product operation, sum the different channels in the dot product operation result, perform an inverse Fourier transform on the sum result, extract the real part after the inverse Fourier transform, and stack the extracted real parts as the lth row in the feature attention matrix A;
[0025] S305: Activate the feature attention matrix A, and redistribute the activated feature attention matrix to a zero matrix of the same size as the original matrix to obtain the attention matrix A s ;
[0026] S306: The third feature map Perform circular shift to get the value tensor Pair value tensor Reshape to get the value matrix V C ;
[0027] S307: Attention matrix A s and value matrix V C Perform matrix multiplication and reshape the result to obtain the single-head attention matrix corresponding to the head.
[0028] Furthermore, when activating the feature attention matrix A, first the largest K elements are selected for each row in the feature attention matrix A, and then the selected K elements are activated, and the unselected elements are all replaced by zero.
[0029] Furthermore, the bounding box estimation module adopts the corner point estimation framework of the Stark algorithm.
[0030] Furthermore, the model also includes a dynamic template image updating module, which extracts the dynamic template image from the frame images at a fixed interval. When the latest dynamic template image is obtained, the dynamic template image updating 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 is implemented based on a multi-layer perceptron when calculating the prediction score.
[0032] Furthermore, the loss function of the model adopts a combination of L1 loss and IOU loss.
[0033] A target tracking terminal device based on a cyclic shift window comprises a processor, a memory and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned method in an embodiment of the present invention when executing the computer program.
[0034] A computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the method described above in an embodiment of the present invention are implemented.
[0035] The present invention adopts the above technical solution, which has excellent performance in both tracking effect and tracking speed, can adapt to tracking target objects in different scenes and complex dynamics, and can track at real-time speed. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] Figure 1 Shown is a schematic diagram of the overall structure of the model in Example 1 of the present invention.
[0037] Figure 2 The figure shows a schematic diagram of the structure of the Transformer in this embodiment when solving in the frequency domain.
[0038] Figure 3 The figure shows a schematic diagram of the spatial domain calculation conversion frequency domain analysis process in this embodiment.
[0039] Figure 4 Shown is a schematic diagram of the sparse discarding attention activation process in this embodiment. DETAILED DESCRIPTION
[0040] To further illustrate various embodiments, the present invention provides drawings. These drawings are part of the disclosure of the present invention, which are mainly 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 contents, ordinary technicians in this field should be able to understand other possible implementations and advantages of the present invention.
[0041] The present invention will now be further described with reference to the accompanying drawings and specific implementation methods.
[0042] Embodiment 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), using the Transformer as a matching module and making full use of the powerful cross-attention capability of the Transformer to calculate the correlation between the template and the search area.
[0044] The network structure of the target tracking model used in the method is as follows Figure 1 As shown in the figure, 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 and the search area image and the dynamic template image. Then, these output features are divided into window sequences and fed into the Transformer matching module. The matching module connects the two window sequences and sends them to the multi-head 6-layer Transformer. The multi-head Transformer uses a specific window size for each head for scale adaptation. Then, the output of each Transformer head is connected together and the head is estimated based on the corner point bounding box in the STARK algorithm to obtain the resulting bounding box. Finally, the dynamic template is updated in real time through the score.
[0046] (1) Attention Spatial Domain Calculation
[0047] First, given the search area image in the initial frame Static template image and dynamic template images After that, the search area image Static template image and dynamic template images Input into the feature extraction module (BackBone) to obtain the corresponding search area feature map Static template feature map and dynamic template feature map As shown below:
[0048]
[0049] in,
[0050] Then, the obtained search area feature map Static template feature map and dynamic template feature map Stretch to flatten the image, and then concatenate the three flattened feature maps into a large intermediate feature map. As shown below:
[0051]
[0052] Among them, Flatten represents the search area feature map Static template feature map and dynamic template feature map The flattening operator is specifically divided into L windows with a window size of r×r; Concat represents a concatenation operator for concatenating the flattening results of the three windows; Represents the concatenated intermediate feature map, size is The window size is r×r, and the number of windows is
[0053] Next, in the intermediate feature map Add spatial position encoding Form an intermediate feature map with spatial position encoding The specific formula is as follows:
[0054]
[0055] Among them, the feature map The size is
[0056] Afterwards, the intermediate feature map with spatial position encoding is added Slice it and divide it into eight parts, as shown below:
[0057]
[0058] Among them, Split represents the slicing operator, adding the intermediate feature map of spatial position encoding It is divided into eight heads, each of which is It should be noted that, in other embodiments, those skilled in the art can set the number of cutting heads as needed, and no limitation is made here.
[0059] Perform a linear transformation on each head and convert the intermediate feature map Divide into the first feature map Second feature map And the third characteristic map The specific formula is as follows:
[0060]
[0061] Among them, LL represents linear transformation, LL 1 LL 2 LL 3 Represents three different linear transformations; Do LL 1 LL 2 LL 3 Three different linear transformations to obtain feature maps Feature Map Feature Map Feature Map The size is Feature Map The size is And feature map The size is
[0062] The first feature map Reshape into query matrix Q, the specific formula is as follows:
[0063]
[0064] Among them, the size of the query matrix Q is The Reshape function is a function in MATLAB that transforms a specified matrix into a matrix of a specific dimension, and the number of elements in the matrix remains unchanged. The function can readjust the number of rows, columns, and dimensions of the matrix.
[0065] The second feature map And the third characteristic map Perform cyclic shift respectively, and transform the second feature map The result of the circular shift is used as the key 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 represents the processing of tensors (i.e. The second and third dimensions of the result of (are ) are cyclic shift operators, The size is The size is
[0068] Then key tensor Sum value tensor Reshape to get the key and the value V C , as shown in the following formula:
[0069]
[0070] Among them, the bond matrix K C Size Then transpose the key matrix to obtain Size Value Matrix V C Size
[0071] For the obtained query matrix Q and the transposed key matrix Perform matrix multiplication to obtain the feature attention matrix A, as shown below:
[0072]
[0073] Among them, the size of the feature attention matrix A is
[0074] Subsequently, this embodiment sends the feature attention matrix A to the selection elimination module (SE) for selective deletion, activates the deleted feature attention matrix, and redistributes the attention matrix points after activation to a zero matrix of the same size as the original matrix. The final matrix A is obtained. s As shown below:
[0075] A s =SE(A)(10)
[0076] Among them, SE represents the selective elimination module, which mainly realizes the selective deletion of the feature attention matrix A. The feature attention matrix A after selective deletion s Size
[0077] The feature attention matrix A after the selection elimination module s Then with the value matrix V C Perform matrix multiplication to obtain the single-head attention matrix M i , as shown in the following formula:
[0078] M i =A s ×V c (11)
[0079] Among them, M i The size is
[0080] The single-head attention matrix M i Reshape the size to get the reshaped single-head attention matrix O i , so that they can be connected next, as shown below:
[0081] O i =Reshape(M i )(12)
[0082] Among them, O i The size is also
[0083] Then the attention matrices obtained from each head are concatenated and reshaped into the original attention features The specific formula is as follows:
[0084]
[0085] Among them, LP is the linear transformation layer, LP 1 ,…,LP8 represents different linear transformations, Size Represents the multi-head attention feature map output by the j-th layer.
[0086] The Transformer matching module consists of 6 layers of Transformers. After each layer of Transformer performs the above operations, it outputs the multi-head attention feature map corresponding to each layer. The input of the first layer of Transformer is the intermediate feature map with spatial position encoding, and the input of the 2nd to 6th layers of Transformer 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. By repeating six times and calculating the attention of six channels, a more accurate attention result can be obtained. The specific formula is as follows:
[0087]
[0088] in, Size and Same as
[0089] (2) Attention frequency domain calculation
[0090] Due to the redundancy of the circulant matrix data, a large amount of calculation is required when operating in the spatial domain. If the circulant matrix is directly operated in the spatial domain, it will lead to high computational complexity. Therefore, in this embodiment, the complex spatial domain calculation in the larger header obtained by slicing is transferred to the point-to-point multiplication in the frequency domain, such as transferring the 4th layer and the 8th layer to the point-to-point multiplication in the frequency domain. Figure 2 shown.
[0091] For the first feature map obtained in the spatial domain And the second feature map Perform Fourier transform to convert it from the spatial domain to the frequency domain, and simplify the complex calculation in the spatial domain to the dot product operation in the frequency domain, as shown in the following formula:
[0092]
[0093] Among them, the first feature map The size is Second feature map The size is fft [2,3] Indicated in the first feature map And the second feature map Perform Fourier transform on the second dimension (r) and the third dimension (r). After Fourier transform The sizes are
[0094] right To extend (Extension), specifically Each block (token) is repeated (Repeat) and each block is repeated L times to obtain arrive The specific formula is as follows:
[0095]
[0096] in, The size is Size Repeat represents a repetition operator that repeats each input tensor L times in the first dimension.
[0097] Then, find the tensor Conjugation The specific formula is as follows:
[0098]
[0099] Among them, Conjugate represents the conjugate operator, that is, The imaginary part is negated. The size is
[0100] Will and Do the dot product, then sum the different channels after the dot product. These two simple calculations simplify the complex spatial domain calculation. After the result is obtained, the obtained frequency domain result needs to be converted to the spatial domain. Here, the result needs to be inverse Fourier transformed, and the real part after the inverse Fourier transform is taken and stacked into the lth row in the attention weight matrix A, that is:
[0101]
[0102] Among them, ⊙ is the point multiplication operator, and the size of A is
[0103] For ease of understanding, we will analyze formula (18) in detail. Figure 3 As shown in the figure, the specific steps of converting spatial domain to frequency domain are given. This article will make a specific analysis on this below.
[0104] like Figure 3 As shown, the query tensor There are L pieces of size r 2×d token, the key tensor is also L and the size is r 2 ×d token, first of all, the key tensor Use formula (7) to perform circular shift to obtain the key tensor after circular shift Here, in order to more clearly demonstrate how to convert spatial domain calculation into frequency domain calculation, this embodiment performs a circular shift on the key tensor. Expand it, as shown below:
[0105]
[0106] in The size is
[0107] As shown in formula (8), the key tensor after cyclic shift and query tensor Reshape into key matrix K C and the query matrix Q, then the key matrix K C Transpose to obtain Query matrix Q and transposed key matrix The matrix multiplication operation is shown in formula (9), which is expanded and analyzed here as shown in the following formula:
[0108]
[0109] Among them, Q(l,:) is the lth row of Q, and its size is for Any column in , each column size is Where n = (a-1)r 2 +b, A(l,n) is the lth nth element, To query the tensor The lth token, Key Tensor Group a 2 The bth token among tokens, where a=1,2,3,…,L and b=1,2,3,…,r 2 .
[0110] Matrix multiplication can be converted into related operations on tensors as shown below:
[0111]
[0112] Among them, * is the correlation operation, and vec is the pull-column operator.
[0113] The correlation operation can be viewed as a convolution operation, as shown in the following formula:
[0114]
[0115] Among them, * represents the correlation operation, Represents a query tensor The lth token,
[0116] Represents the key tensor The bth token in the ath group of tokens, b=1,2,…,r 2 ,
[0117] Express The reverse fold.
[0118] According to the convolution theorem, the convolution operation in the spatial domain can be converted to the frequency domain for point multiplication calculation. First, the feature map and feature map Perform Fourier transform and then transform the tensor Perform conjugate operation, refer to formula (15) to formula (17), and finally The convolution operation is converted into and The frequency domain dot multiplication operation is shown in the following formula:
[0119]
[0120] Where ⊙ represents the dot product, as shown in formula (15), for The Fourier transform of for After Fourier transformation and conjugation, both are
[0121] In summary, as shown in formula (18), all blocks after cyclic shift are calculated according to the above formulas (22) and (23), and then summed. Then, the result is inverse Fourier transformed, and the real part is taken to be pulled into a column vector, and finally transposed.
[0122] As described above, this embodiment simplifies the complex matrix multiplication operation in the spatial domain into a simple tensor dot product operation in the frequency domain, which greatly reduces the complexity of the operation, the huge intermediate variable storage, and the use of computer resources.
[0123] (3) Selecting the attention mechanism
[0124] In the Transformer architecture, the self-attention mechanism is its core component, which allows the model to dynamically focus on different parts of the sequence while processing sequence data, and does not focus on the main target in a targeted manner. Moreover, as the length of the sequence increases, the computational complexity and memory requirements of the original self-attention mechanism will also increase exponentially. In the model of this embodiment, no modification is made to the original Transformer's self-attention mechanism, which makes its focus on global attention obscure its focus on key information. This embodiment introduces sparse discarding in the Transformer self-attention mechanism, that is, not allowing each position in the sequence to perform attention calculations at all positions, but selecting some positions for calculation. This module will gradually discard the search area marks belonging to the background area, thereby improving the distinction between the foreground and the background, reducing the ambiguity of the foreground edge area, and improving a part of the tracking reasoning speed.
[0125] In this embodiment, the similarity between all pixel pairs between the query and the key is first calculated, and unnecessary tags are masked in the similarity matrix. Then, Figure 4 As shown, for the acquired marks, the original attention activation will send all the acquired marks directly to the softmax activation function without any processing, so that each mark will be activated indiscriminately. The background mark and the foreground mark are activated at the same time, causing the two to be mixed together and difficult to distinguish. In this regard, in this embodiment, the topK selection is first used to select the K largest elements in each row of the feature attention matrix A, and then the K largest elements selected in each row are activated. The remaining unselected elements are sparsely discarded, and finally these calculated values are returned to the original matrix position, and all unselected ones are replaced with zero, as shown in the following formula:
[0126]
[0127] Among them, TopK represents the selection operator for selecting the K largest elements in each row of the similarity matrix, Softmax represents the activation function activation operator, Scatter represents the scatter operator, and A s The size is
[0128] By introducing sparsification, the problem of the original attention 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 pixel values most similar to it, making the foreground more focused and the edge area of the foreground more discriminative.
[0129] (4) Bounding Box Estimation Module
[0130] In order to improve the quality of bounding box estimation and provide more accurate and robust prediction for target tracking, this embodiment introduces the corner prediction head proposed by the Stark algorithm in the bounding box estimation module, that is, by outputting two probability maps of the upper left corner and the lower right corner of the target bounding box, the expected value of the probability distribution is calculated for the two probability maps, so as to obtain the coordinates of the upper left point and the lower right point, and finally determine the prediction box coordinates according to the upper left point and the lower right point, as described below.
[0131] The multi-head attention feature map after six channels is fed into a simple fully convolutional neural network (FCN). FCN is composed of L Conv-BN-ReLU layers stacked together. After being processed by FCN, two probability maps P are output for the upper left and lower right corners of the target bounding box. t1(x,y) , P br(x,y) , as shown in the following formula:
[0132]
[0133] Among them, P t1(x,y) Represents the probability map of the upper left corner of the prediction box, P br(x,y) Represents the probability map of the lower right corner of the prediction box.
[0134] Then the two probability maps P t1(x,y) , P br(x,y) Use the following formula to calculate the coordinates of the lower left and lower right corners to determine the position of the target prediction box:
[0135]
[0136] in, is the upper left corner, The lower right corner.
[0137] (5) Dynamic template image update module
[0138] In the target tracking process, the tracked target may change significantly over time, so it is very important to capture the latest state of the target for tracking. In this regard, the space-time solution of the Stark algorithm is introduced in this embodiment, as follows.
[0139] Different from the baseline method that only uses the first frame and the current frame as input, this embodiment also introduces dynamic template updates sampled from the intermediate frames as additional input. Figure 1As shown, the dynamic template can capture the changes in the target appearance over time, thereby providing additional time information. However, during the tracking process, there are some situations where the dynamic template should not be updated, such as when the target is completely blocked or removed from the field of view. At this time, it is unreliable to update the dynamic template image. Therefore, for simplicity, this embodiment considers that as long as the search area contains the target object, the dynamic template image can be updated. In order to automatically determine whether the current situation is reliable, a simple score prediction head Score is added in this embodiment, which is a multi-layer perceptron. If the score obtained by Score is higher than the threshold τ, it is considered to be updateable, otherwise it is not updated, as shown in the following formula:
[0140]
[0141] Among them, MLP represents a three-layer perceptron with a Sigmoid activation layer, τ represents the threshold, Represents a dynamic template image. 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 DERT architecture with the 1 And generalized IoU loss, the loss function is as follows:
[0144]
[0145] Among them, b i is the real frame, is the prediction box, λ iou and λ L1 is a hyperparameter, and its size is
[0146] This embodiment does not use the classification loss and Hungarian algorithm in the DETR architecture, which further simplifies the training process. During the inference process, the template image and its features from the backbone are initialized by the first frame and fixed in subsequent frames. During the tracking process, in each frame the network obtains a search area from the current frame as input and returns the predicted box as the final result without any post-processing.
[0147] Existing studies point out that joint learning of positioning and classification tasks may result in suboptimal solutions for both tasks instead of optimal solutions, so it is necessary to decouple positioning and classification tasks. Based on this, this embodiment divides the training process into two stages, with positioning as the main task and classification as the secondary task.
[0148] In the first stage, the entire network except the score head (Score) is trained end-to-end using only the loss function related to positioning in formula (28). The task of this stage is to ensure that all search areas contain the target object and train the model's positioning ability.
[0149] In the second stage, this embodiment only optimizes the split heads, as shown in formula (29):
[0150]
[0151] Among them, y i represents the true label, P i Indicates the confidence of the prediction. In order to avoid affecting the positioning task, this embodiment freezes all other parameters at this stage. In this way, after two-stage training, the final model has both positioning and classification.
[0152] During the model training process, the model is trained by collecting the training set constructed by the historical video stream. During the inference process, the initial dynamic template image is extracted from the first frame image, and a search area is cropped according to the template size and input into the network to generate a bounding box and a confidence score. The dynamic template image is updated only when the update interval and the confidence score are higher than the 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] The embodiment of the present invention introduces a transformer tracking model with multi-scale cyclic shift window attention. The integrity of the object is maintained by introducing multi-scale cross-window attention, and a selection elimination module is designed to solve the problem that the original Transformer architecture self-attention does not pay enough attention to the main information. Finally, the spatiotemporal joint information and corner point prediction are used to make the prediction box more accurate. The tracking model has the following characteristics:
[0154] (1) It can maintain the integrity of the object and retain more location information when calculating the cross-window attention between the tracking target and the search area. In view of the large amount of calculations caused by the cyclic shift in the model, this paper designs a strategy to convert 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 designs a selection elimination module to address the problem that the original Transformer architecture does not pay enough attention to the main information. This module can effectively focus on key information and eliminate noise information, thereby obtaining better attention information while relatively improving the overall tracking speed of the model.
[0156] (3) Finally, this embodiment introduces joint spatiotemporal information and corner point prediction, and obtains information on the time channel through dynamic template input, so as to effectively deal with changes in the target object. The corner point prediction is calculated through the upper left corner and the lower right corner points. The two points determine the tracking target position, allowing the model of this embodiment to obtain a better tracking frame.
[0157] A large number of experiments have proved that this embodiment has superior performance in both tracking effect and tracking speed, can adapt to tracking target objects in different scenes and complex dynamics, and can track at real-time speed.
[0158] Embodiment 2:
[0159] The present invention also provides a target tracking terminal device based on a cyclic shift window, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps in the above-mentioned method embodiment of embodiment 1 of the present invention when executing the computer program.
[0160] Further, as an executable solution, the target tracking terminal device based on the cyclic shift window can be a computing device such as a desktop computer, a notebook, a PDA, and a cloud server. The target tracking terminal device based on the cyclic shift window may include, but is not limited to, a processor and a memory. Those skilled in the art can understand that the composition structure of the target tracking terminal device based on the cyclic shift window is only an example of a target tracking terminal device based on the cyclic shift window, and does not constitute a limitation on the target tracking terminal device based on the cyclic shift window. It may include more or less components than the above, or combine certain components, or different components. For example, the target tracking terminal device based on the cyclic shift window may also include input and output devices, network access devices, buses, etc., and the embodiments of the present invention do not limit this.
[0161] Further, as an executable solution, the processor may 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, etc. The general processor may be a microprocessor or any conventional processor, etc. The processor is the control center of the target tracking terminal device based on the cyclic shift window, and uses various interfaces and lines to connect the various parts of the target tracking terminal device based on the cyclic shift window.
[0162] The memory can be used to store the computer program and / or module, and the processor realizes various functions of the target tracking terminal device based on the circular shift window by running or executing the computer program and / or module stored in the memory, and calling the data stored in the memory. The memory can mainly include a program storage area and a data storage area, wherein the program storage area can store an operating system and an application required for at least one function; the data storage area can store data created according to the use of the mobile phone, etc. In addition, the memory can include a high-speed random access memory, and can also include a non-volatile memory, such as a hard disk, a memory, a plug-in hard disk, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (Flash Card), at least one disk storage device, a flash memory device, or other volatile solid-state storage devices.
[0163] The present invention also provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method in the embodiment of the present invention are implemented.
[0164] If the module / unit integrated in the target tracking terminal device based on the circular shift window is implemented in the form of 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, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory) and software distribution medium, etc.
[0165] Although the present invention has been specifically shown and described in conjunction with the preferred embodiments, it should be understood by those skilled in the art that various changes may be made to the present invention in form and details without departing from the spirit and scope of the present invention as defined by the appended claims, all of which are within the scope of protection of the present invention.
Claims
1. A target tracking method based on a cyclic shift window, characterized in that: The following steps are involved: S1: extracting the target image corresponding to the target to be tracked from the first frame image in the video stream as a static template image, extracting the target image corresponding to the target to be tracked from the image before the frame image to be analyzed as a dynamic template image, and using the frame image to be analyzed as a search area image; S2: Build a target tracking model. The network structure of the model includes a feature extraction module, a Transformer matching module, and a bounding box estimation module. The feature extraction module receives the input search area image, static template image and dynamic template image for feature extraction, obtains the corresponding search area feature map, static template feature map and dynamic template feature map, flattens the feature maps of the three images respectively, and splices the flattening results into an intermediate feature map, adds the spatial position code to the intermediate feature map, and obtains the intermediate feature map with the spatial position code added; The Transformer matching module includes 6 layers of Transformers. After each layer of Transformers performs the operations of steps S01-S102, it outputs the multi-head attention feature map corresponding to each layer. The input of the first layer of Transformers is the intermediate feature map with spatial position encoding, and the input of the 2nd to 6th layers of Transformers 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 and divide it into N heads, and perform steps S201-S206 for each head to obtain a 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 the layer; S201: Perform three different linear transformations on each head to obtain the first feature map corresponding to the head Second feature map And the third characteristic map S202: The first feature map Reshape into the query matrix Q, and transform the second feature map Perform circular shift to get the key tensor The third feature map Perform circular shift to get the value tensor S203: Key Tensor Reshape to get the key matrix K C Then, the key matrix K C Transpose to get the transposed key matrix Pair Tensor Reshape to get the value matrix V C ; S204: query matrix Q and 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 to a zero matrix of the same size as the original matrix to obtain the attention matrix A s ; S206: Attention matrix A s and value matrix V C Perform matrix multiplication and reshape the result to obtain the single-head attention matrix corresponding to the head; S3: After the model is trained using the training set constructed using historical video streams, the trained model is used for target tracking.
2. The target tracking method based on cyclic shift window according to claim 1, characterized in that: In step S101, the operations of steps S301-S307 are performed for the heads with larger window sizes among the N heads obtained by slicing to obtain the single-head attention matrices corresponding to these heads, and the operations of steps S201-S206 are still performed for the other heads to obtain the single-head attention matrices corresponding to each head; S301: Perform three different linear transformations on each head to obtain the first feature map corresponding to the head Second feature map And the third characteristic map S302: First feature map Perform Fourier transform to get For the second feature map Perform Fourier transform to get S303: Yes Each of the L blocks contained in the above code is subjected to L repeated operations, and the result is in, Indicates that The result of repeating the lth block in L times, l∈[1,L]; S304: and Conjugation Perform a dot product operation, sum the different channels in the dot product operation result, perform an inverse Fourier transform on the sum result, extract the real part after the inverse Fourier transform, and stack the extracted real parts as the lth row in the feature attention matrix A; S305: Activate the feature attention matrix A, and redistribute the activated feature attention matrix to a zero matrix of the same size as the original matrix to obtain the attention matrix A s ; S306: The third feature map Perform circular shift to get the value tensor Pair Tensor Reshape to get the value matrix V C ; S307: Attention matrix A s and value matrix V C Perform matrix multiplication and reshape the result to obtain the single-head attention matrix corresponding to the head.
3. The target tracking method based on cyclic shift window according to claim 1, characterized in that: When activating the feature attention matrix A, first select the largest K elements for each row in 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 cyclic shift window according to claim 1, characterized in that: The bounding box estimation module adopts the corner point estimation framework in the Stark algorithm.
5. The target tracking method based on cyclic shift window according to claim 1, characterized in that: The model also includes a dynamic template image updating module. The dynamic template image is extracted from frame images at a fixed interval. When the latest dynamic template image is obtained, the dynamic template image updating 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 cyclic shift window according to claim 5, characterized in that: The dynamic template image update module calculates the prediction score based on a multi-layer perceptron.
7. The target tracking method based on cyclic shift window according to claim 1, characterized in that: The loss function of the model adopts a combination of L1 loss and IOU loss.
8. A target tracking terminal device based on a cyclic shift window, characterized in that: The method comprises a processor, a memory and a computer program stored in the memory and running on the processor, wherein the processor implements the steps of the method according to any one of claims 1 to 7 when executing the computer program.
9. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Multi-target tracking method based on multi-scale deformable attention mechanism
CN116309725A
Target tracking method, system, device and storage medium
US11821986B1
Target object tracking method and apparatus, and terminal device
WO2021120866A1
Cross-video target tracking method and system, and electronic device and storage medium
WO2023216572A1
