Target tracking method of two-stage fusion multi-scale template under judgment mechanism guidance
By introducing a core template image into the TransT model and performing self-cross attention learning, combined with an IoU prediction head for template updating, the problem of insufficient adaptability of TransT when the target appearance is deformed is solved, and higher tracking accuracy and stability are achieved.
Patent Information
- Application Number
- CN202410582084.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-11
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2044-05-11
AI Technical Summary
The existing Transformer-based target tracking algorithm TransT is not adaptable enough to the deformation of the target's appearance and cannot effectively utilize background information, resulting in poor tracking performance.
A two-stage fusion multi-scale template method guided by a judgment mechanism is adopted. By introducing core template images into the TransT model and performing self-attention and cross-attention learning, and combining the IoU prediction head for template updating, the continuity and accuracy of tracking are ensured.
It effectively addresses target appearance deformation, reduces erroneous tracking, and improves the accuracy and stability of target tracking, especially during long-term tracking.
Smart Images

Figure CN118429386B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the technical field of single-target tracking methods, and relates to a target tracking method with a two-stage fusion multi-scale template guided by a judgment mechanism. Background Technology
[0002] Object tracking technology is a core research area in computer vision, widely used in video surveillance, sports image capture, and autonomous driving. Object tracking technology has matured to a point where it is suitable for most types of scenarios. However, its performance often suffers when the target undergoes frequent changes in appearance. Object tracking tasks require models with high adaptability and accurate recognition capabilities, primarily to accommodate changes in the target's appearance, posture, and spatial position during long-term tracking.
[0003] Fully convolutional Siamese networks typically use a fixed sliding window for training and inference when processing these transformations. This data processing method is limited to a certain extent by the fixed-size local window, making it difficult to fully capture the long-distance relationship between the target and the background.
[0004] Transformer-based target tracking algorithms employ a self-attention mechanism, enabling the establishment of global dependencies within the input sequence, unaffected by input size limitations. Furthermore, through global feature exchange and fusion, they promptly acquire motion cues about the target, thereby improving tracking accuracy and robustness. The Transformer-based target tracking algorithm TransT, by effectively combining convolutional neural networks and attention mechanisms, overcomes the limitations of fully convolutional networks, achieving effective feature exchange and fusion. However, TransT utilizes limited useful features during inference, relying solely on the initial frame template. Therefore, it cannot effectively adapt to subsequent appearance deformations of the target. Moreover, the model only considers the target itself during tracking, failing to adequately utilize background information. Consequently, the model cannot promptly acquire motion cues about the target, and the initial and subsequent states of the target do not correspond well. Summary of the Invention
[0005] The purpose of this invention is to provide a target tracking method with a two-stage fusion multi-scale template guided by a judgment mechanism. TransT is applied to adapt to the problem of target appearance deformation in target tracking scenarios.
[0006] The technical solution adopted in this invention is a target tracking method based on a two-stage fusion multi-scale template guided by a judgment mechanism, which is implemented according to the following steps:
[0007] Step 1: Obtain training data, including search images, template images, and core template images;
[0008] Step 2: Improve the TransT model to obtain the TransT-C tracking model, and train the TransT-C tracking model using the training data obtained in Step 1;
[0009] Step 3: Improve the TransT-C tracking model trained in Step 2 to obtain the TransT-T tracking model;
[0010] Step 4: Obtain training data for the TransT-T tracking model;
[0011] Step 5: Train the TransT-T tracking model to obtain the trained TransT-T tracking model;
[0012] Step 6: Use the trained TransT-T tracking model to track the target.
[0013] The invention is further characterized in that:
[0014] Step 1 is as follows:
[0015] Step 1.1: Select the video sequence corresponding to the training sample in the public training dataset, and then randomly select a base frame in the selected video sequence. Based on the position of the base frame and the set maximum gap, sample the template frame and the search frame from the video sequence respectively. The template frame is sampled before or within the range of the base frame, and the search frame is sampled after the base frame.
[0016] Step 1.2: Set the search area size coefficient, template area size coefficient, core template area size coefficient, size of the search area, template area and core template area, as well as the perturbation coefficients of the center and scale;
[0017] Step 1.3: For the search image, template image, and core template image, based on the size coefficients of the search region, template region, and core template region, and the sizes of the search region, template region, and core template region, crop out the regions centered on the perturbed target box from the corresponding images and adjust these regions to the sizes of the corresponding search region, template region, and core template region.
[0018] Step 1.4: Convert the resized search area, template area, and core template area into grayscale images, then perform translation, scaling, or rotation transformations and color standardization, and finally encapsulate the processed data, including the search image, template image, core template image, and the bounding box of the template image.
[0019] Step 2 involves improving the TransT model to obtain the TransT-C tracking model, specifically as follows:
[0020] Based on the TransT model, a core template image is added as an input to the input layer in addition to the search image and template image. After the core template image, template image, and search image are input, feature extraction is performed in the feature extraction layer. The extracted features are encoded and positionally encoded in the encoding layer. The encoded features are then fed into the feature fusion layer. Each feature fusion layer includes a self-attention mechanism layer and a cross-attention mechanism layer connected in sequence. The encoded features of the core template image, search image, and template image are fed into the self-attention mechanism layer in their respective feature fusion layers for self-attention learning. Then, the features of the core template image and search image after self-attention learning are fed into the corresponding cross-attention mechanism layer to achieve cross-attention learning and obtain the features of the search image. The features of the search image after cross-attention learning and the features of the template image after self-attention learning are input into the cross-attention mechanism layer corresponding to the template image for cross-attention learning to obtain the features of the search image.
[0021] Step 2 involves training the TransT-C tracking model using the training data obtained in Step 1, specifically as follows:
[0022] Step 2.1, set the training parameters;
[0023] Step 2.2: Input the search image, template image, and core template image from the training data into the TransT-C tracking model. In the feature extraction layer, use a ResNet pre-trained on ImageNet as the backbone network for feature extraction. Use the features output from the third layer of ResNet as the extracted features to obtain the search image features X. x Template image features X z Core template image features X c ;
[0024] Step 2.3: Input the feature maps corresponding to the search image, template image, and core template image obtained in Step 2.2 into the corresponding encoding layers. In the encoding layer, use a 1*1 convolutional layer to adjust the number of channels of the feature map output by the third layer of ResNet to a fixed number of 256 channels, and use sinusoidal position coding to add a specific position code to each input feature map to obtain the encoded feature map.
[0025] Step 2.4: The feature maps corresponding to the search image, template image, and core template image, after the position encoding added in Step 2.3, are respectively fed into the corresponding feature fusion layer. Self-attention learning is performed in the feature fusion layer to obtain the search image feature X' after self-attention learning. x The core template image features X' after self-attention learning c and the template image features x' after self-attention learning zThen, the search image features X' are learned through self-attention. x and core template image features X' c Then, the features are fused through the corresponding cross-attention mechanism layer to obtain the search image features X” after cross-attention. x and the core template image features X” after cross-attention c Then, the search image features X” after cross-attention are performed. x and the template image features X' after self-attention learning z The cross-attention mechanism layer in the feature fusion layer corresponding to the template image performs cross-attention fusion to obtain the search image features X”'. x ;
[0026] Step 2.5, use the search image features X”' obtained in step 2.4 x The processed features are obtained by processing through a feedforward network layer;
[0027] Step 2.6: Use the features processed in step 2.5 to perform classification prediction and regression prediction in sequence to obtain the center position and bounding box of the predicted target;
[0028] Step 2.7: Based on the training parameters set in Step 2.1, use AdamW to train the model to obtain the trained TransT-C tracking model.
[0029] The sine wave position code in step 2.3 is dynamically generated according to the formula:
[0030] For position p and dimension i, the position encoding can be represented as:
[0031] If i is even, then the position encoding is:
[0032]
[0033] If i is odd, then the position encoding is:
[0034]
[0035] Where d is the dimension of the entire positional encoding vector, representing the total number of feature vector points in the positional encoding; p represents the position of the pixel in the row or column, including two dimensions (x, y), representing the row position and column position of the pixel respectively, that is, p indicates encoding in the x-direction or encoding in the y-direction; i represents the index of half the dimension in the positional encoding vector.
[0036] The process of performing self-attention mechanism operation on the search image features in step 2.4 is as follows:
[0037] X' x =Xx +MultiHead(X x +P x ,X x +P x ,X x (3)
[0038] The process of self-attention learning for the core template image features is as follows:
[0039] X' c =X c +MultiHead(X c +P c ,X c +P c ,X c (4)
[0040] Among them, P x and P c These are the positional codes corresponding to the search image and the core template image obtained according to formula (1) or (2), respectively, and MultiHead is multi-head attention;
[0041] Search image features X' after self-attention learning x and core template image features X' c Then, the fusion is performed through the corresponding cross-attention mechanism layer, specifically as follows:
[0042] The process of learning cross-attention for search image features is as follows:
[0043] X” x =X' x +MultiHead(X' x +P x ,X' c +P c ,X' c (5)
[0044] The process of cross-attention learning for core template image features is as follows:
[0045] X” c =X' c +MultiHead(X' c +P c ,X' x +P x ,X' x (6)
[0046] The self-attention mechanism for learning template image features is specifically as follows:
[0047] X' z =Xz +MultiHead(X z +P z ,X z +P z ,X z (7)
[0048] Then X' z and X” x Perform cross-attention fusion to obtain the search image features X”' x :
[0049] X”' x =X” x +MultiHead(X) x +P x ,X' z +P z ,X' z (8)
[0050] Among them, P z The position code is the one corresponding to the template image obtained according to formula (1) or (2).
[0051] Step 3 specifically involves:
[0052] Based on the TransT-C tracking model, an IoU prediction head is added after the regression prediction layer to obtain the TransT-T tracking model.
[0053] Step 4 is as follows:
[0054] Step 4.1: Upsample 1 search image and 2 template images for each training sample in the public training dataset. When selecting 2 template images, randomly select one frame as the base frame in the entire video sequence of each training sample. Then, randomly select any frame before and after the base frame as the template frame according to the maximum interval setting range. That is, the base frame and the template frame are used as 2 template images.
[0055] Step 4.2: Process the 1-frame search image and 2-frame template images corresponding to each training sample in the manner of steps 1.2-1.4. Finally, when encapsulating the data, stitch the 2 template images corresponding to the same training sample together to obtain the stitched template image, and stitch the 2 core template images corresponding to the same training sample together to obtain the stitched core template image.
[0056] Step 4.4: Adjust the shapes of the encapsulated template image and core template image. Change the shapes of the template image and core template image from (batchsize,n,c,h,w) to (batchsize*n,c,h,w), where batchsize,n,c,h,w represent the number of training batches, the number of templates, the number of channels, the height, and the width, respectively. Use the adjusted template image, core template image, and search image as training data.
[0057] Step 5 specifically involves:
[0058] Step 5.1, set the training parameters;
[0059] Step 5.2: Train the TransT-C tracking model based on the model trained in Step 2. During the training process, freeze the BN layer data of the TransT-C tracking model and train it according to Steps 2.1-2.6.
[0060] Step 5.3: Combine the predicted bounding box obtained from the regression prediction with the search image features X”' output by the feature fusion layer. x The input is fed into the IoU prediction head, which is generated by a multilayer perceptron (MLP). The IoU prediction head first combines the predicted bounding box obtained from regression prediction with the search image features X”' output by the feature fusion layer. x The features are concatenated and then processed using MLP to output a 1-dimensional IoU prediction value. The output value is then normalized using the sigmoid function to ensure that the IoU prediction value is between [0,1].
[0061] Step 5.4, Calculation of the IoU prediction head loss. The loss of the IoU prediction head is calculated based on the difference between the predicted IoU value and the actual IoU value in Step 5.3, specifically as follows:
[0062] Loss = mean(((1-IoU)) 2 )*((IoU pred -IoU 2 (9)
[0063] Among them, IoU pred It is the IoU prediction value obtained in step 5.3. IoU is the actual intersection-union ratio, which represents the intersection-union ratio between the model's predicted bounding box and GroundTruth. GroundTruth is the bounding box of the template image encapsulated when encapsulating data in step 4.2.
[0064] Step 5.5: Based on the training parameters set in Step 5.1, use AdamW to train the model according to the process in Steps 5.2-5.4 to obtain the trained TransT-T tracking model.
[0065] Step 6 specifically involves:
[0066] Step 6.1: Initialize the template image based on the bounding box of the first frame of the video to be tracked. Starting from the second frame, the search image is cropped and processed in the manner of steps 1.2-1.4 to obtain the final template image, core template image, and search image.
[0067] Step 6.2: Input the template image, core template image, and search image from Step 6.1 into the trained TransT-T tracking model and extract the search image features, template image features, and core template image features respectively according to the method in Step 2.2. Then, copy the template image features and core template image features respectively to obtain two template image features and two core template image features. Concatenate the two template image features to obtain the final template image features. Concatenate the two core template image features to obtain the final core template image features.
[0068] Step 6.3: Process the search image features, final template image features, and core template image features obtained in Step 6.2 sequentially according to Steps 2.3-2.6. During tracking in the current frame, store the predicted bounding boxes output by regression prediction in the two preceding frames. Using the prediction head trained in Step 5, extract the search image features X”' from the final output of the feature fusion layer in the current frame. x The predicted bounding boxes from the regression prediction outputs of the two adjacent previous frames are concatenated to obtain two concatenated features. Then, the concatenated features are processed by MLP to output a 1-dimensional IoU prediction value. The output value is then normalized by the sigmoid function to obtain the IoU prediction value, thus obtaining two IoU prediction values.
[0069] Step 6.4: If the sum of the two IoU predicted values is greater than the set threshold, then the template is updated and step 6.5 is executed; if the sum of the two IoU predicted values is less than or equal to the threshold, then the template is not updated and the current predicted bounding box is output.
[0070] Step 6.5: If template updates are performed, calculate the new center position and bounding box of the target based on the predicted bounding box output by regression prediction during current tracking. Then, crop the template image and core template image according to the target size, and use the cropped template image and core template image as a new template combination. Standardize the new template combination using a preset mean and standard deviation, scaling the pixel values to between 0 and 1. Then, feed the scaled template image and core template image back to step 6.2, extract the image features of the template image and core template image, and then use the extracted features to replace the template image features and core template image features copied in step 6.2 to obtain the stitched template image features and core template image features again. Then, continue to execute steps 6.3-6.4 until the sum of the two IoU predicted values is less than or equal to the threshold, and output the predicted bounding box.
[0071] The beneficial effects of this invention are:
[0072] This invention employs a two-stage attention operation. In the first stage, the feature vectors of the template image, core template image, and search image undergo self-attention learning. Then, the learned core template features and search features undergo a first-stage cross-attention learning. Finally, the output search features and template features undergo a second-stage cross-attention learning. The first stage focuses on identifying the core features of the target, while the second stage associates a small amount of background information, allowing the model to learn the relationship between the target and its surrounding environment. Simultaneously, the model's prediction results are evaluated. In the IoU prediction head, the current tracking result is compared with the results of the two adjacent previous frames. If the prediction result can effectively maintain the continuity of tracking, the template is updated. In this way, during long-term tracking, it can effectively cope with target appearance deformation, reduce erroneous tracking, and ensure the accuracy and stability of tracking. Attached Figure Description
[0073] Figure 1 This is a flowchart of the target tracking method with dual-stage fusion and multi-scale templates guided by the judgment mechanism of this invention;
[0074] Figure 2 This is a schematic diagram of the TransT-C tracking model in the target tracking method of dual-stage fusion multi-scale template guided by the judgment mechanism of this invention;
[0075] Figure 3 This is a flowchart of the target tracking method using the TransT-T model in the dual-stage fusion multi-scale template guided by the judgment mechanism of this invention;
[0076] Figure 4 This is a comparison curve of the success rate values obtained from testing the appearance deformation scenarios of OTB-100 in Embodiment 5, Comparative Example 1, and Comparative Example 2 of the present invention.
[0077] Figure 5 Comparison curves of success rate values obtained from testing LaSOT appearance deformation scenarios in Embodiment 5, Comparative Example 1, and Comparative Example 2 of the present invention. Detailed Implementation
[0078] The present invention will now be described in detail with reference to the accompanying drawings and specific embodiments.
[0079] Example 1
[0080] The target tracking method based on a judgment mechanism, involving a two-stage fusion of multi-scale templates, has the following process: Figure 1 As shown, the specific steps are as follows:
[0081] Step 1: Obtain training data, including search images, template images, and core template images; specifically:
[0082] Step 1.1: Select the video sequence corresponding to the training sample in the public training dataset, and then randomly select a base frame in the selected video sequence. Based on the position of the base frame and the set maximum gap (max_gap = 100), sample the template frame and the search frame from the video sequence respectively. The template frame is sampled before or within the range of the base frame, and the search frame is sampled after the base frame.
[0083] Step 1.2: Set the search area size coefficient, template area size coefficient, core template area size coefficient, size of the search area, template area and core template area, as well as the perturbation coefficients of the center and scale;
[0084] Step 1.3: For the search image, template image, and core template image, based on the size coefficients of the search region, template region, and core template region, and the sizes of the search region, template region, and core template region, crop out the regions centered on the perturbed target box from the corresponding images and adjust these regions to the sizes of the corresponding search region, template region, and core template region.
[0085] Step 1.4: Convert the resized search area, template area, and core template area into grayscale images, then perform translation, scaling, or rotation transformations and color standardization, and finally encapsulate the processed data, including the search image, template image, core template image, and the bounding box of the template image.
[0086] Step 2, improve the TransT model to obtain the TransT-C tracking model, specifically as follows:
[0087] like Figure 2As shown, based on the TransT model, a core template image is added as an input to the input layer in addition to the search image and template image. After the core template image, template image, and search image are input, feature extraction is performed in the feature extraction layer. The extracted features are encoded and positionally encoded in the encoding layer. The encoded features are then fed into the feature fusion layer. Each feature fusion layer includes a self-attention mechanism layer and a cross-attention mechanism layer connected in sequence. The encoded features of the core template image, search image, and template image are fed into the self-attention mechanism layer in their respective feature fusion layers for self-attention learning. Then, the features of the core template image and search image after self-attention learning are fed into the corresponding cross-attention mechanism layer for cross-attention learning to achieve data association. The features of the search image after cross-attention learning and the features of the template image after self-attention learning are input into the cross-attention mechanism layer corresponding to the template image for cross-attention learning to obtain the features of the search image.
[0088] The TransT-C tracking model is then trained using the training data obtained in step 1, specifically as follows:
[0089] Step 2.1, set the training parameters;
[0090] Step 2.2: Input the search image, template image, and core template image from the training data into the TransT-C tracking model. In the feature extraction layer, use a ResNet pre-trained on ImageNet as the backbone network for feature extraction. Use the features output from the third layer of ResNet as the extracted features, with 1024 channels, to obtain the search image features X. x Template image features X z Core template image features X c ;
[0091] Step 2.3: Input the feature maps corresponding to the search image, template image, and core template image obtained in Step 2.2 into the corresponding encoding layers. In the encoding layer, use a 1*1 convolutional layer to adjust the number of channels of the feature map output by the third layer of ResNet to a fixed number of 256 channels, and use sinusoidal position coding to add a specific position code to each input feature map to obtain the encoded feature map.
[0092] The sine wave position code is dynamically generated according to the formula:
[0093] For position p and dimension i, the position encoding can be represented as:
[0094] If i is even, then the position encoding is:
[0095]
[0096] If i is odd, then the position encoding is:
[0097]
[0098] Where d is the dimension of the entire positional encoding vector, representing the total number of feature vector points in the positional encoding; p represents the position of the pixel in the row or column, including two dimensions (x, y), representing the row position and column position of the pixel respectively, that is, p indicates encoding in the x-direction or encoding in the y-direction; i represents the index of half the dimension in the positional encoding vector.
[0099] Step 2.4: The feature maps corresponding to the search image, template image, and core template image, after the position encoding added in Step 2.3, are respectively fed into the corresponding feature fusion layer. Self-attention learning is performed in the feature fusion layer to obtain the search image feature X' after self-attention learning. x The core template image features X' after self-attention learning c and the template image features X' after self-attention learning z Then, the search image features X' are learned through self-attention. x and core template image features X' c Then, the features are fused through the corresponding cross-attention mechanism layer to obtain the search image features X” after cross-attention. x and the core template image features X” after cross-attention c Then, the search image features X” after cross-attention are performed. x and the template image features X' after self-attention learning z The cross-attention mechanism layer in the feature fusion layer corresponding to the template image performs cross-attention fusion to obtain the search image features X”'. x ;
[0100] The process of performing self-attention mechanism operations on the search image features is as follows:
[0101] X' x =X x +MultiHead(X x +P x ,X x +P x ,X x (3)
[0102] The process of self-attention learning for the core template image features is as follows:
[0103] X' c =X c +MultiHead(X c +Pc ,X c +P c ,X c (4)
[0104] Among them, P x and P c The location codes corresponding to the search image and the core template image obtained according to formula (1) or (2) are respectively. MultiHead is multi-head attention. In this embodiment, 8-head attention is used. Multi-head attention divides the 256-dimensional features into 8 heads. The feature dimension corresponding to each head is 256 / 8. Then attention operations are performed in parallel.
[0105] Search image features X' after self-attention learning x and core template image features X' c Then, the fusion is performed through the corresponding cross-attention mechanism layer, specifically as follows:
[0106] The process of learning cross-attention for search image features is as follows:
[0107] X” x =X' x +MultiHead(X' x +P x ,X' c +P c ,X' c (5)
[0108] The process of cross-attention learning for core template image features is as follows:
[0109] X” c =X' c +MultiHead(X' c +P c ,X' x +P x ,X' x (6)
[0110] The self-attention mechanism for learning template image features is specifically as follows:
[0111] X' z =X z +MultiHead(X z +P z ,X z +P z ,X z (7)
[0112] Then X' z and X” xPerform cross-attention fusion to obtain the search image features X”' x :
[0113] X”' x =X” x +MultiHead(X) x +P x ,X' z +P z ,X' z (8)
[0114] Among them, P z The position code corresponding to the template image obtained according to formula (1) or (2);
[0115] Step 2.5, use the search image features X”' obtained in step 2.4 x The processing is performed through a feedforward network layer, which contains two linear layers and a non-linear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and a non-linear activation function ReLU is applied between the two linear transformations; the second linear layer maps the output of the intermediate layer from 2048 dimensions back to 256 dimensions to ensure compatibility with subsequent output layers, thus obtaining the processed features.
[0116] Step 2.6: Use the features processed in step 2.5 to perform classification prediction and regression prediction in sequence to obtain the center position and bounding box of the predicted target;
[0117] Step 2.7: Based on the training parameters set in Step 2.1, use AdamW to train the model to obtain the trained TransT-C tracking model;
[0118] Step 3: Improve the TransT-C tracking model trained in Step 2 to obtain the TransT-T tracking model. Specifically, add an IoU prediction head after the regression prediction layer to the TransT-C tracking model to obtain the TransT-T tracking model.
[0119] Step 4, obtain the training data for the TransT-T tracking model, specifically:
[0120] Step 4.1: Upsample 1 search image and 2 template images for each training sample in the public training dataset. When selecting 2 template images, randomly select one frame as the base frame in the entire video sequence of each training sample. Then, randomly select any frame as the template frame within a range of 100 before and after the base frame, based on the maximum interval setting. The maximum interval max_gap = 100, which is within 100 before and after the base frame. Thus, the base frame and the template frame are used as 2 template images.
[0121] Step 4.2: Process the 1-frame search image and 2-frame template images corresponding to each training sample in the manner of steps 1.2-1.4. Finally, when encapsulating the data, stitch the 2 template images corresponding to the same training sample together to obtain the stitched template image, and stitch the 2 core template images corresponding to the same training sample together to obtain the stitched core template image.
[0122] Step 4.4: Adjust the shapes of the encapsulated template image and core template image. Change the shapes of the template image and core template image from (batchsize,n,c,h,w) to (batchsize*n,c,h,w), where batchsize,n,c,h,w represent the number of training batches, the number of templates, the number of channels, the height, and the width, respectively. Use the adjusted template image, core template image, and search image as training data.
[0123] Step 5: Train the TransT-T tracking model to obtain the trained TransT-T tracking model; specifically:
[0124] Step 5.1, set the training parameters;
[0125] Step 5.2: Train the TransT-C tracking model based on the model trained in Step 2. During the training process, freeze the BN layer data of the TransT-C tracking model and train it according to Steps 2.1-2.6.
[0126] Step 5.3: Combine the predicted bounding box obtained from the regression prediction with the search image features X”' output by the feature fusion layer. x The input is fed into the IoU prediction head, which is generated by a multilayer perceptron (MLP). The IoU prediction head first combines the predicted bounding box obtained from regression prediction with the search image features X”' output by the feature fusion layer. x The features are concatenated and then processed using MLP to output a 1-dimensional IoU prediction value. The output value is then normalized using the sigmoid function to ensure that the IoU prediction value is between [0,1].
[0127] Step 5.4, Calculation of the IoU prediction head loss. The loss of the IoU prediction head is calculated based on the difference between the predicted IoU value and the actual IoU value in Step 5.3, specifically as follows:
[0128] Loss = mean(((1-IoU)) 2 )*((IoU pred -IoU) 2 (9)
[0129] Among them, IoU predIt is the IoU prediction value obtained in step 5.3. IoU is the actual intersection-union ratio, which represents the intersection-union ratio between the model's predicted bounding box and GroundTruth. GroundTruth is the bounding box of the template image encapsulated when encapsulating data in step 4.2.
[0130] Step 5.5: Based on the training parameters set in Step 5.1, use AdamW to train the model according to the process in Steps 5.2-5.4 to obtain the trained TransT-T tracking model.
[0131] Step 6: Use the trained TransT-T tracking model to track the target, specifically as follows:
[0132] Step 6.1: Initialize the template image based on the bounding box of the first frame of the video to be tracked. Starting from the second frame, the search image is cropped and processed in the manner of steps 1.2-1.4 to obtain the final template image, core template image, and search image.
[0133] Step 6.2: Input the template image, core template image, and search image from Step 6.1 into the trained TransT-T tracking model and extract the search image features, template image features, and core template image features respectively according to the method in Step 2.2. Then, copy the template image features and core template image features respectively to obtain two template image features and two core template image features. Concatenate the two template image features to obtain the final template image features. Concatenate the two core template image features to obtain the final core template image features.
[0134] Step 6.3, as follows Figure 3 As shown, the search image features obtained in step 6.2, the final template image features, and the core template image features are processed sequentially according to steps 2.3-2.6. During tracking in the current frame, the predicted bounding boxes from the regression prediction output of the two preceding frames are stored. Using the prediction head trained in step 5, the search image features X' finally output at the feature fusion layer in the current frame are... x "The predicted bounding boxes from the regression prediction outputs of the two adjacent previous frames are concatenated to obtain two concatenated features. Then, the concatenated features are processed using MLP to output a 1-dimensional IoU prediction value. The output value is then normalized using the sigmoid function to obtain the IoU prediction value, resulting in two IoU prediction values."
[0135] Step 6.4: If the sum of the two IoU predicted values is greater than the set threshold (1.7), then the template is updated and step 6.5 is executed; if the sum of the two IoU predicted values is less than or equal to the threshold, then the template is not updated and the current predicted bounding box is output.
[0136] Step 6.5: If template updates are performed, calculate the new center position and bounding box of the target based on the predicted bounding box output by regression prediction during current tracking. Then, crop the template image and core template image according to the target size, and use the cropped template image and core template image as a new template combination. Standardize the new template combination using a preset mean and standard deviation, scaling the pixel values to between 0 and 1. Then, feed the scaled template image and core template image back to step 6.2, extract the image features of the template image and core template image, and then use the extracted features to replace the template image features and core template image features copied in step 6.2 to obtain the stitched template image features and core template image features again. Then, continue to execute steps 6.3-6.4 until the sum of the two IoU predicted values is less than or equal to the threshold, and output the predicted bounding box.
[0137] Assuming the template image feature in step 6.2 is X, and it is copied twice to become (X,X), then the next update mainly involves replacing the features of the copied second image. The updated image is then used to extract features to obtain Y, which replaces the features at the second position. The features of the first image remain unchanged, meaning that the final result is (X,Y). Both the template image and the core template image are updated in this way.
[0138] Example 2
[0139] Based on Example 1, the common training datasets used are LaSOT and GOT-10K datasets;
[0140] Building upon Example 1, the classification prediction utilizes a multilayer perceptron (MLP) as the classification head, which receives the final search image features X”'. x The algorithm uses three stacked fully connected layers and a ReLU activation function (only used in layers 1 and 2) to output the classification probability at each position, with a dimension of 2 (including "target class" and "background class").
[0141] Regression prediction also processes the data using a 3-layer MLP model. The final linear layer outputs four parameters of the bounding box (center point coordinates x, y, width, and height), and the output values are normalized to the range [0,1] using the sigmoid function.
[0142] Cross-entropy loss is used for classification loss. The difference between the classification probability output by the model and the ground truth is measured by cross-entropy loss.
[0143]
[0144] Where y j Let y represent the Ground Truth of the j-th sample. j=1 indicates the foreground, p j This represents the probability that the model predicts it as the foreground.
[0145] The regression loss consists of two parts: the L1 norm loss and the generalized IOU loss.
[0146]
[0147] Among them, y j =1 indicates a positive sample, b j This represents the predicted bounding box of the j-th sample. λ represents the normalized Ground Truth. G =2 and λ1=5 are regularization parameters used to balance the weights of the two loss functions.
[0148] Finally, the two losses are weighted according to preset weights (classification weight: 8.333, regression weight: 5) to obtain the total loss, which is used for gradient calculation and model parameter update during the training process.
[0149] Example 3
[0150] Based on Example 2, step 2.1 sets the training parameters as follows: a total of 800 epochs are trained, AdamW is used to train the model, the learning rate of the backbone is set to 1e-5, the learning rate of other parameters is set to 1e-4, the weight decay is 1e-4, the batch size is 6, each epoch undergoes 1000 iterations, and after 500 epochs, the learning rate decreases by 10 times.
[0151] Step 5.1 sets the training parameters as follows: A total of 150 epochs are trained using AdamW. The learning rate for the backbone is set to 1e-5, the learning rate for other parameters to 1e-3, the weight decay to 1e-4, the batch size to 24, and each epoch undergoes 200 iterations. After 50 epochs, the learning rate decreases by a factor of 10.
[0152] Example 4
[0153] Based on Example 3, the size of the cropped search image in step 1.3 is 256*256*3, the size of the template image is 128*128*3, and the size of the core template is 64*64*3.
[0154] In step 4.2, the shape of the stitched template image is [2,3,128,128], and the shape of the stitched core template image is [2,3,64,64].
[0155] Example 5
[0156] The method of the present invention was verified and compared on the OTB-100 dataset and the LaSOT dataset according to the process of Example 4.
[0157] Comparative Example 1
[0158] The TransT-C tracking model trained in step 2 was used on the OTB-100 and LaSOT datasets for tracking. Specifically, the first frame image was initialized, including calculating the initial target position and size. The image was cropped based on the position center to obtain a template image Z of fixed size 128*128*3 and a core template image C of size 64*64*3. The search image was extracted from the current frame, with the center of the search image being the target position in the previous frame. The search image was cropped to obtain a search image X of fixed size 256*256*3. The image was color-normalized. The processed template image Z, core template image C, and search image X were input into the trained TransT-C tracking model, and the predicted target center position and bounding box were output according to steps 2.1-2.6.
[0159] Comparative Example 2
[0160] In the OTB-100 and LaSOT datasets, tracking was performed using the TransT model. Specifically, based on Comparative Example 1, the search image X and template image Z were input into the TransT model to predict the center position and bounding box of the target.
[0161] The test results of Example 5, Comparative Example 1, and Comparative Example 2 are shown in Table 1:
[0162] Table 1
[0163]
[0164] As shown in the table, comparing TransT-C and TransT algorithms, which incorporate a core template into the input data and use a two-stage approach to fuse the two templates, the accuracy of TransT-C improved by 0.6% and the success rate by 1.3% on the OTB-100 dataset, while the accuracy improved by 0.9% and the success rate by 1% on the LaSOT dataset. Introducing a template update module into TransT-C yields TransT-T, which, when tested on the OTB-100 dataset, shows a 2.4% improvement in accuracy and a 3.8% improvement in success rate compared to TransT. On the LaSOT dataset, TransT-T shows a 1.7% improvement in accuracy and a 1.5% improvement in success rate compared to TransT.
[0165] like Figure 4-5As shown, on the Deformation (appearance deformation sequences in the OTB-100 dataset), TransT-C improved by 1% compared to TransT, and TransT-T improved by 3% compared to TransT. On the Deformation (appearance deformation sequences in the LaSOT dataset), TransT-T and TransT-C improved the success rate by 2.1% and 1.7% respectively compared to TransT. This indicates that the two-stage association module and template update module can effectively improve the tracking model's ability to adapt to appearance deformation. Table 2 shows a comparison of the test results in appearance deformation scenarios on the two datasets.
[0166] Table 2
[0167]
[0168] To compare the performance of adapting to appearance deformation, this invention was tested in appearance deformation sequence scenes on the OTB-100 and LaSOT datasets. The results show that TransT-T and TransT-C improved the success rate of TransT by 3% and 1% compared to TransT on the OTB-100 and LaSOT datasets, respectively, and by 2.1% and 1.7%. This indicates that by associating scene content at different scales, the algorithm can effectively match targets that differ significantly in different frames due to scale scaling or appearance deformation. Moreover, the introduced temporal information can effectively help the model track changes in the target and comprehensively grasp its position and shape.
[0169] This invention presents a two-stage fusion multi-scale template target tracking algorithm guided by a judgment mechanism. In the initial tracking stage, the input data is processed, including template images, core template images, and search images. These three images are input into a ResNet50 for feature extraction, outputting a feature vector for the third layer. Subsequently, a sinusoidal positional encoding is added to the extracted feature vector, and the positionally encoded feature vector is then fed into the two-stage fusion module.
[0170] In the two-stage attention module, the feature vectors of the template, core template, and search image are first subjected to self-attention learning. Then, the learned core template features and search features are subjected to the first stage of cross-attention learning, which includes four feature fusion layers. The output search features are then subjected to the second stage of cross-attention learning, which includes one feature fusion layer. Finally, the search feature vector is fed into the prediction head for classification, regression, and IoU prediction.
[0171] IoU prediction is performed based on the feature vector of the current frame and the stored regression values of the two preceding frames. The two prediction results are added together. When the sum is greater than or equal to a threshold of 1.7, the image is cropped according to the current prediction result, the template image and core template image are updated, and the prediction result is output. When the threshold is less than 1.7, the template is not updated, and the prediction result is output directly. This invention uses a refined two-stage association model to fuse features of different ranges, enabling the model to identify and locate the target. When the tracking results are good, temporal information is introduced by updating the template, and the information from multiple frames is integrated to gain a more comprehensive understanding of the target's state and motion, allowing the model to adapt well to frequent appearance deformations of the target.
Claims
1. A target tracking method with a two-stage fusion multi-scale template guided by a judgment mechanism, characterized in that, The specific steps are as follows: Step 1: Obtain training data, including search images, template images, and core template images; Step 2: Improve the TransT model to obtain the TransT-C tracking model, and train the TransT-C tracking model using the training data obtained in Step 1; The TransT-C tracking model is obtained by improving the TransT model as follows: Based on the TransT model, a core template image is added as an input to the input layer in addition to the search image and template image. After the core template image, template image, and search image are input, feature extraction is performed in the feature extraction layer. The extracted features are encoded and positionally encoded in the encoding layer. The encoded features are then fed into the feature fusion layer. Each feature fusion layer includes a self-attention mechanism layer and a cross-attention mechanism layer connected in sequence. The encoded features of the core template image, search image, and template image are fed into the self-attention mechanism layer in their respective feature fusion layers for self-attention learning. Then, the features of the core template image and search image after self-attention learning are fed into the corresponding cross-attention mechanism layer to achieve cross-attention learning and obtain the search image features. The features of the search image after cross-attention learning and the features of the template image after self-attention learning are fed into the cross-attention mechanism layer corresponding to the template image for cross-attention learning to obtain the search image features. Step 3: Improve the TransT-C tracking model trained in Step 2 to obtain the TransT-T tracking model; Step 4: Obtain training data for the TransT-T tracking model; Step 5: Train the TransT-T tracking model to obtain the trained TransT-T tracking model; Step 6: Use the trained TransT-T tracking model to track the target.
2. The target tracking method with a two-stage fusion multi-scale template guided by the judgment mechanism according to claim 1, characterized in that, Step 1 specifically involves: Step 1.1: Select the video sequence corresponding to the training sample in the public training dataset, and then randomly select a base frame in the selected video sequence. Based on the position of the base frame and the set maximum gap, sample the template frame and the search frame from the video sequence respectively. The template frame is sampled before or within the range of the base frame, and the search frame is sampled after the base frame. Step 1.2: Set the search area size coefficient, template area size coefficient, core template area size coefficient, size of the search area, template area and core template area, as well as the perturbation coefficients of the center and scale; Step 1.3: For the search image, template image, and core template image, based on the size coefficients of the search region, template region, and core template region, and the sizes of the search region, template region, and core template region, crop out the regions centered on the perturbed target box from the corresponding images and adjust these regions to the sizes of the corresponding search region, template region, and core template region. Step 1.4: Convert the resized search area, template area, and core template area into grayscale images, then perform translation, scaling, or rotation transformations and color standardization, and finally encapsulate the processed data, including the search image, template image, core template image, and the bounding box of the template image.
3. The target tracking method with a two-stage fusion multi-scale template guided by the judgment mechanism according to claim 2, characterized in that, Step 2, which uses the training data obtained in step 1 to train the TransT-C tracking model, specifically involves: Step 2.1, set the training parameters; Step 2.2: Input the search image, template image, and core template image from the training data into the TransT-C tracking model. In the feature extraction layer, use a ResNet pre-trained on ImageNet as the backbone network for feature extraction. Use the features output from the third layer of ResNet as the extracted features to obtain the search image features. Template image features Core template image features ; Step 2.3: Input the feature maps corresponding to the search image, template image, and core template image obtained in Step 2.2 into the corresponding encoding layers, and use 1 in the encoding layer. The convolutional layer 1 adjusts the number of channels of the feature map output by the third layer of ResNet to a fixed number of 256 channels, and uses sinusoidal position coding to add a specific position code to each input feature map to obtain the encoded feature map; Step 2.4: The feature maps corresponding to the search image, template image, and core template image, after the position encoding added in Step 2.3, are respectively fed into the corresponding feature fusion layer. Self-attention learning is performed in the feature fusion layer to obtain the search image features after self-attention learning. Core template image features after self-attention learning and template image features after self-attention learning Then, the search image features are learned through self-attention. and core template image features Then, the images are fused through the corresponding cross-attention mechanism layers to obtain the search image features after cross-attention. and core template image features after cross-attention Then, search for image features after cross-attention. and template image features after self-attention learning The cross-attention mechanism layer in the feature fusion layer corresponding to the template image performs cross-attention fusion to obtain the search image features. ; Step 2.5, use the search image features obtained in Step 2.
4. The processed features are obtained by processing through a feedforward network layer; Step 2.6: Use the features processed in step 2.5 to perform classification prediction and regression prediction in sequence to obtain the center position and bounding box of the predicted target; Step 2.7: Based on the training parameters set in Step 2.1, use AdamW to train the model to obtain the trained TransT-C tracking model.
4. The target tracking method with dual-stage fusion multi-scale templates guided by the judgment mechanism according to claim 3, characterized in that, The sine wave position code in step 2.3 is dynamically generated according to the formula: For position p and dimension i, the position encoding can be represented as: If i is even, then the position encoding is: If i is odd, then the position encoding is: Where d is the dimension of the entire positional encoding vector, representing the total number of feature vector points in the positional encoding; p represents the position of the pixel in the row or column, including two dimensions (x, y), representing the row position and column position of the pixel respectively, that is, p refers to encoding in the x-direction or encoding in the y-direction; i represents the index of half the dimension in the positional encoding vector.
5. The target tracking method with a two-stage fusion multi-scale template guided by the judgment mechanism according to claim 4, characterized in that, The process of performing self-attention mechanism operation on the search image features in step 2.4 is as follows: The process of self-attention learning for the core template image features is as follows: in, and The location codes corresponding to the search image and the core template image obtained according to formula (1) or (2) are respectively. For the attention of multiple parties; Search image features after self-attention learning and core template image features Then, the fusion is performed through the corresponding cross-attention mechanism layer, specifically as follows: The process of learning cross-attention for search image features is as follows: The process of cross-attention learning for core template image features is as follows: The self-attention mechanism for learning template image features is specifically as follows: Then and Cross-attention fusion is performed to obtain the search image features. : in, The position code corresponding to the template image obtained according to formula (1) or (2).
6. The target tracking method with a two-stage fusion multi-scale template guided by the judgment mechanism according to claim 5, characterized in that, Step 3 specifically involves: Based on the TransT-C tracking model, an IoU prediction head is added after the regression prediction layer to obtain the TransT-T tracking model.
7. The target tracking method with dual-stage fusion multi-scale templates guided by the judgment mechanism according to claim 6, characterized in that, Step 4 specifically involves: Step 4.1: Upsample 1 search image and 2 template images for each training sample in the public training dataset. When selecting 2 template images, randomly select one frame as the base frame in the entire video sequence of each training sample. Then, randomly select any frame before and after the base frame as the template frame according to the maximum interval setting range. That is, the base frame and the template frame are used as 2 template images. Step 4.2: Process the 1-frame search image and 2-frame template images corresponding to each training sample in the manner of steps 1.2-1.
4. Finally, when encapsulating the data, stitch the 2 template images corresponding to the same training sample together to obtain the stitched template image, and stitch the 2 core template images corresponding to the same training sample together to obtain the stitched core template image. Step 4.4: Adjust the shapes of the encapsulated template image and core template image. The shapes of the template image and core template image are adjusted from (batchsize, n, c, h, w) to (batchsize...). The training data consists of n, c, h, and w, where batchsize, n, c, h, and w represent the number of training batches, the number of templates, the number of channels, the height, and the width, respectively. The adjusted template image, the core template image, and the search image are used as training data.
8. The target tracking method with dual-stage fusion multi-scale templates guided by the judgment mechanism according to claim 7, characterized in that, Step 5 specifically involves: Step 5.1, set the training parameters; Step 5.2: Train the TransT-C tracking model based on the model trained in Step 2. During the training process, freeze the BN layer data of the TransT-C tracking model and train it according to Steps 2.1-2.
6. Step 5.3: Combine the predicted bounding boxes obtained from regression prediction with the search image features output by the final feature fusion layer. The input is fed into the IoU prediction head, which is generated by a multilayer perceptron (MLP). The IoU prediction head first combines the predicted bounding boxes obtained from regression prediction with the search image features output by the feature fusion layer. The features are concatenated and then processed using MLP to output a 1-dimensional IoU prediction value. The output value is then normalized using the sigmoid function to ensure that the IoU prediction value is between [0,1]. Step 5.4, Calculation of the loss of the IoU prediction head, the loss of the IoU prediction head. The calculation is based on the difference between the predicted IoU value and the actual IoU value in step 5.3, specifically as follows: in, It is the IoU prediction value obtained in step 5.
3. The actual intersection-union ratio (IU) represents the IU between the model-predicted bounding box and GroundTruth, where GroundTruth is the bounding box of the template image encapsulated during step 4.2 when encapsulating the data. Step 5.5: Based on the training parameters set in Step 5.1, use AdamW to train the model according to the process in Steps 5.2-5.4 to obtain the trained TransT-T tracking model.
9. The target tracking method with dual-stage fusion multi-scale templates guided by the judgment mechanism according to claim 8, characterized in that, Step 6 specifically involves: Step 6.1: Initialize the template image based on the bounding box of the first frame of the video to be tracked. Starting from the second frame, the search image is cropped and processed in the manner of steps 1.2-1.4 to obtain the final template image, core template image, and search image. Step 6.2: Input the template image, core template image, and search image from Step 6.1 into the trained TransT-T tracking model and extract the search image features, template image features, and core template image features respectively according to the method in Step 2.
2. Then, copy the template image features and core template image features respectively to obtain two template image features and two core template image features. Concatenate the two template image features to obtain the final template image features. Concatenate the two core template image features to obtain the final core template image features. Step 6.3: Process the search image features, final template image features, and core template image features obtained in Step 6.2 sequentially according to Steps 2.3-2.
6. During tracking in the current frame, store the predicted bounding boxes output by regression prediction in the two preceding frames. Using the prediction head trained in Step 5, apply the search image features finally output by the feature fusion layer in the current frame. The predicted bounding boxes from the regression prediction outputs of the two adjacent previous frames are concatenated to obtain two concatenated features. Then, the concatenated features are processed by MLP to output a 1-dimensional IoU prediction value. The output value is then normalized by the sigmoid function to obtain the IoU prediction value, thus obtaining two IoU prediction values. Step 6.4: If the sum of the two IoU predicted values is greater than the set threshold, then the template is updated and step 6.5 is executed; if the sum of the two IoU predicted values is less than or equal to the threshold, then the template is not updated and the current predicted bounding box is output. Step 6.5: If template updates are performed, calculate the new center position and bounding box of the target based on the predicted bounding box output by regression prediction during current tracking. Then, crop the template image and core template image according to the target size, and use the cropped template image and core template image as a new template combination. Standardize the new template combination using a preset mean and standard deviation, scaling the pixel values to between 0 and 1. Then, feed the scaled template image and core template image back to step 6.2, extract the image features of the template image and core template image, and then use the extracted features to replace the template image features and core template image features copied in step 6.2 to obtain the stitched template image features and core template image features again. Then, continue to execute steps 6.3-6.4 until the sum of the two IoU predicted values is less than or equal to the threshold, and output the predicted bounding box.
Citation Information
Patent Citations
End-to-end single target tracking method based on pyramid pooling attention mechanism
CN116823885A
RGBT target tracking method based on target perception enhancement fusion structure
CN117474957A
