Target tracking method based on multilayer feature fusion and semantic enhancement
Through the method of multi-layer feature fusion and semantic enhancement, combined with ResNet50 and multi-cross attention mechanism, the problem of insufficient feature utilization and redundant features in the Transformer method is solved, the accuracy and stability of target tracking are improved, and it can adapt to complex scenes. target changes.
Patent Information
- Application Number
- CN202410687849.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-30
- Publication Date
- 2024-09-06
AI Technical Summary
Existing Transformer-based target tracking methods are difficult to fully utilize the multi-layer output of the backbone network in complex scenes, and there are redundant feature problems when using the cross-attention mechanism, resulting in unstable tracking results.
Using multi-layer feature fusion and semantic enhancement methods, image features are extracted through ResNet50, and feature association and optimization are performed in the target semantic enhancement model with a multi-cross attention mechanism. A judgment mechanism is designed to determine the accuracy of the tracking results, and masking is introduced. Code features and timing information to enhance model attention.
It improves the accuracy of target recognition and the stability of tracking results, enhances the model's ability to understand targets, and adapts to target changes in complex environments.
Smart Images

Figure CN118608764A
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of computer vision, and in particular relates to a target tracking method based on multi-layer feature fusion and semantic enhancement. Background Art
[0002] Target tracking technology is a key research area in the field of computer vision. When tracking targets, the algorithm must be able to accurately identify targets in complex and changing scenes, and maintain stable tracking of the original target in the presence of multiple similar objects. Compared with the Transformer-based target tracking method, the self-attention mechanism can capture the subtle gap between the target and the background, and use the spatial and texture information of global features to track the target, which significantly improves the tracking accuracy and robustness. TransT can break through the local receptive field limitation of the fully convolutional twin network, but TransT fails to make full use of the multi-layer output of the backbone network to comprehensively analyze the scene content during the reasoning process, and uses too many redundant features while using the cross-attention mechanism to associate information. It does not determine whether the current features are all useful features, and does not introduce temporal information to adapt to the appearance and position changes of the target, resulting in unstable tracking results, which affects the overall performance and applicability. Summary of the invention
[0003] The purpose of the present invention is to provide a target tracking method based on multi-layer feature fusion and semantic enhancement, which improves the accuracy of target recognition by introducing a cross-attention mechanism and a judgment mechanism, judges the accuracy of the tracking results, and accurately outputs the tracking results.
[0004] The technical solution adopted by the present invention is a target tracking method based on multi-layer feature fusion and semantic enhancement, which specifically includes the following steps:
[0005] Step 1: Obtain the target image, input the target image into the TransT feature extraction network ResNet50, and obtain the output features;
[0006] Step 2: Input the features extracted in step 1 into a target semantic enhancement model with a multi-cross attention mechanism, extract the features most relevant to the emphasis and target through the model, and optimize the cross attention mechanism of the model to perform target recognition and tracking;
[0007] Step 3: Design a judgment mechanism to judge the tracking results in step 2 to determine whether the single tracking bounding box drifts. If no drift occurs, output the tracking result to complete the target tracking.
[0008] The present invention is also characterized in that
[0009] Step 1 is implemented as follows:
[0010] Step 1.1, when the tracker receives the image and annotation box for the first time, it initializes the template features of the tracker, calculates the center position and size of the target, calculates the cropping size according to the set template size, and obtains the initial template image z of the target;
[0011] Step 1.2, update the position of the target, obtain and process the target image area of the current frame, calculate the crop size according to the set search image size, obtain the new position and size of the target, obtain the search image x, and use the processed image area to update the network;
[0012] Step 1.3: Input the obtained template image and search image into the backbone feature extraction network of TransT. The backbone of TransT is a pre-trained ResNet50 network, which outputs the feature maps of the second layer Layer2 and the third layer Layer3, with the number of channels being 512 and 1024 respectively.
[0013] Step 2 is implemented as follows:
[0014] Step 2.1: Improve the training of Transtfpn based on TransT;
[0015] Step 2.2, improve the tracking of Transtfpn based on TransT;
[0016] Step 2.3: Introduce the Transtfpn-Mask algorithm to optimize the cross-attention mechanism of the model for target recognition and tracking.
[0017] Step 2.1 is implemented as follows:
[0018] Step 2.1.1, sample frames from the training sequence to form batch data, randomly select a dataset from the predefined dataset list, the dataset list is [LaSOT, GOT-10K], randomly select a base frame in the selected video sequence, randomly select a base frame from the selected video sequence, the base frame is used to subsequently determine the sampling range of the template frame and the search frame, 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 including the base frame, and the search frame is sampled after the base frame,
[0019] Step 2.1.2, process the sample frame. During the initialization process, multiple parameters are set, including the search area size coefficient, the template area size coefficient, the size of the search area and the template area, the center and scale perturbation coefficients, and random noise is added to the center position and size of the bounding box. Then, for the search image and the template image, according to their respective area size coefficients and target sizes, the area centered on the perturbed target box is cropped from the image, and these areas are adjusted to a fixed size;
[0020] Apply predefined transformations to the cropped and resized search and template regions, first converting them to grayscale, then performing jitter transformations such as translation, scaling or rotation and color normalization, and finally encapsulating the processed data, including the search image and template image and the bounding box of the template image;
[0021] Step 2.1.3, extract image features. When training Transtfpn, use ResNet50 pre-trained on ImageNet as the backbone network for feature extraction. Use the output of Layer2 and Layer3 templates, with 512 and 1024 channels respectively.
[0022] Step 2.1.4: Positionally encode the extracted features. Use a 1*1 fully connected layer to adjust the number of channels of the Layer2 feature map and Layer3 feature map output by ResNet50 to the fixed number of channels 256 required by the model. Use sinusoidal position encoding to add a unique code to each input feature so that the model can utilize the position information.
[0023] The sine wave position encoding is dynamically generated according to the formula, where each dimension of the position encoding corresponds to a different frequency of the sine or cosine function; for position p and dimension i, the position encoding can be expressed as:
[0024] If i is even, use:
[0025]
[0026] If i is odd, use:
[0027]
[0028] Where d is the dimension of the entire position encoding vector, indicating the total number of all feature vector points in the position 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 half-dimensional index in the position encoding vector;
[0029] Step 2.1.5, the input features with position encoding are then input into the feature fusion network of Transtfpn. The feature fusion network is mainly composed of a hierarchical feature association module and a hierarchical feature fusion module. The hierarchical feature association module is stacked by 4 basic layers, and each basic layer is composed of a cross-attention mechanism. The encoder inputs the Layer2 features and Layer3 features of the template image and the search image. First, the cross-attention operation is performed on the two parts of the Layer2 level features. The cross-attention mechanism is a multi-head attention. The learning of the single-head attention mechanism can be expressed as:
[0030]
[0031] Where Q, K, and V are the input feature vectors. When calculating attention, position encoding is added to Q and K. i represents the number of multi-head attentions, which is set to 8. Multi-head attention divides the 256-dimensional features into 8 heads, and the feature dimension corresponding to each head is 256 / 8. Then the attention operation is performed in parallel.
[0032] The process of cross-attention learning for the template features of Layer2 is:
[0033] X′ z2 =X z2 +MultiHead(X z2 +P z2 , X x2 +P x2 , X x2 ) (4)
[0034] In the formula, P is the position code, X z2 is the template feature of Layer2, X′ z2 i Template features after cross-attention learning;
[0035] The process of cross-attention learning for the search features of Layer2 is:
[0036] X′ x2 =X x2 +MultiHead(X x2 +P x2 , X z2 +P z2 , X z2 ) (5)
[0037] Where P is the position code, X x2 is the search feature at Layer 2, and X′ x2 is the search feature after cross-attention learning;
[0038] Step 2.1.6, the feedforward network further processes the output of Layer2 cross attention. The feedforward network contains two linear layers and a nonlinear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and a nonlinear 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;
[0039] Step 2.1.7: Associate the template features and search features at Layer 3 with each other through cross attention. The process of cross attention learning for the template features at Layer 3 is as follows:
[0040] X′ z3 =X z3 +MultiHead(X z3 +P z3 , X x3 +P x3 , X x3 ) (6)
[0041] In the formula, p is the position code, X z3 is the template feature of Layer3, X′ z3 is the template feature after cross-attention learning,
[0042] The process of cross-attention learning for the search features of Layer3 is:
[0043] X′ x3 =X x3 +MultiHead(X x3 +P x3 , X z3 +P z3 , X z3 ) (7)
[0044] In the formula, p is the position code, X x3 is the search feature at Layer 3, X′ x3 is the search feature after cross-attention learning;
[0045] Step 2.1.8, the feedforward network further processes the output of Layer3 cross attention. The feedforward network contains two linear layers and a nonlinear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and a nonlinear 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;
[0046] Step 2.1.9: The search features output by the two hierarchical feature association modules are fused through the hierarchical fusion module. First, X′ x2 The features of are processed by the dropout layer and then combined with X′ x3 Add,
[0047] S1(X′ x3 ) = norm(X′ x3 +dropout(X′ x2 )) (8)
[0048] The output value S1(X′ x3 ) is processed through the activation layer,
[0049] S2(X′ x3 )=relu(linear1(S1(X′ x3 ))) (9)
[0050] The output value S2(X′ x3 ) is processed by linear layers and dropout layers,
[0051] S3(X′ x3 )=linear2(dropout(S2(X′ x3 ))) (10)
[0052] The output value S3(X′ x3 ) is processed by the dropout layer and the normalization layer,
[0053] X″ x3 =X′ x3 =norm(S3(X′ x3 )+dropout(S3(X′ x3 )) (11)
[0054] Step 2.1.10: The search feature X″ output by the hierarchical fusion module x3 and the template feature X′ obtained in step 2.1.7 z3 Through the cross-attention mechanism, we can associate and obtain the final search features:
[0055] X″′ x =X″ x3 +MultiHead(X″ x3 +P x3 , X′ z3 +P z3 , X′ z3 ) (12)
[0056] Step 2.1.11, the final search features are processed through the feed-forward network layer, and the final output is used to predict the position of the target in the search image;
[0057] The classification prediction uses a multi-layer perceptron as the classification head. The MLP receives the output of the decoder with a dimension of 1024, and passes through 3 stacked fully connected layers and relu activation functions to finally output the classification probability of each position with a dimension of 2, including "target class" and "background class";
[0058] Regression prediction also processes data through a 3-layer MLP model. The final linear layer outputs the four parameters of the bounding box, the center point coordinates x, y, width and height, and normalizes the output value to the range of [0, 1] through the sigmoid function.
[0059] Step 2.1.12, cross entropy loss is used for classification loss. The difference between the classification probability output by the model and the true label is measured by cross entropy loss.
[0060]
[0061] where y j Represents the GroundTruth of the jth sample, y j =1 indicates foreground, p j represents the probability of the model predicting the foreground;
[0062] The regression loss consists of two parts, l1 norm loss and generalized IOU loss.
[0063]
[0064] Among them, y j =1 indicates a positive sample, b j represents the predicted bounding box of the jth sample, represents the normalized GroundTruth, λ G =2 and λ1=5 are regularization parameters used to balance the weights of the two loss functions;
[0065] Finally, the two parts of the loss are weighted according to the preset weights, the classification weight is 8.333, and the regression weight is 5, and the total loss is obtained. This total loss is used for gradient calculation and model parameter update during training;
[0066] Step 2.1.13, train a total of 665 epochs, use AdamW to train the model, set the learning rate of the backbone to 1e-5, the learning rate of other parameters to 1e-4, the weight decay to 1e-4, the batch size value to 6, each epoch undergoes 1000 iterations, and after 500 epochs, the learning rate drops 10 times.
[0067] Step 2.2 is implemented according to the following steps:
[0068] Step 2.2.1, initialize the first frame image, including calculating the initial target position and size, cropping the image according to the position center, obtaining a template image Z with a fixed size of 128*128*3, and performing color standardization on the image;
[0069] Step 2.2.2, extract the search image from the current frame, the center of the search image is the position of the target in the previous frame, the image is cropped to obtain a search image X with a fixed size of 256*256*3, and the image is color normalized;
[0070] Step 2.2.3, input the processed template image and search image into the ResNet50 network for feature extraction to obtain the features of Layer 2 and Layer 3;
[0071] Step 2.2.4, position-encode the extracted feature vector, input the position-encoded Layer2 template features and search features into the feature association module of step 2.1.5 for learning in the same way, and input the position-encoded Layer3 template features and search features into the feature association module of step 2.1.7 for learning in the same way;
[0072] Step 2.2.5: The Layer2 and Layer3 hierarchical search features learned and output in step 2.2.4 are fused through the same fusion module as in step 2.1.9, and the fused search features and the Layer3 template features obtained in step 2.2.4 are finally associated through the cross attention mechanism;
[0073] Step 2.2.6: Use the search features finally outputted in step 2.2.5 for classification and regression prediction. Process the output feature vector through MLP and apply the Softmax function to normalize the category score at each position into a probability value, which indicates the relative probability that the position belongs to each category.
[0074] In regression prediction, the sigmoid function is first applied to the output of the MLP to obtain the normalized coordinates of the entire image size, expressed as the center point coordinates, width, and height;
[0075] In order to balance the historical position and current predicted position of the target, a window penalty is introduced to adjust the score. According to the adjusted score, the bounding box with the highest score is selected, combining the classification score and position information;
[0076] According to the selected optimal bounding box, the size and position are adjusted, including converting the normalized coordinates to the original image size and ensuring that the bounding box does not exceed the image boundary. The current prediction result is input into step 3, and the current result is evaluated using the judgment mechanism. If the update threshold is reached, the template input is updated; if the threshold is not reached, the current result is directly output without updating the template.
[0077] Step 2.3 is implemented as follows:
[0078] Step 2.3.1, the shape of the search feature is H*W, first flatten the feature into a sequence of length H*W, and generate a mask sequence of the same shape according to the long sequence of the search feature;
[0079] Step 2.3.2, sorting from high to low according to the influence value distribution of the search feature, the present invention sets a feature retention ratio of 60%, adds indexes to the feature points, sets the index values of 60% of the feature points before sorting to 1, sets the index values of the removed feature points to 0, and adds index values to the corresponding mask positions;
[0080] Step 2.3.3, attach the mask to the search feature sequence, the influence value of the position feature point with index value 1 remains unchanged, and the position feature point with index value 0 is assigned 0. At this time, the internal influence value of the search feature is updated, and the next round of cross-attention learning will be carried out. In step 2.2.4, the hierarchical feature association module in Transtfpn will carry out 4 rounds of cross-attention learning. After learning, the search features will dynamically generate masks according to the current influence value distribution, and update the current search feature influence value distribution;
[0081]
[0082] Where index(X i ) represents the feature point X i The index in the feature map X, S[:h%×N] is the index set of feature points to be retained after sorting, where h=60 and N is the total number of feature points.
[0083] Step 3 is implemented as follows:
[0084] Step 3.1: Improve the training of Transtfpn-T based on Transtfpn;
[0085] Step 3.2: Improve the tracking of Transtfpn-T based on Transtfpn.
[0086] Step 3.1 is implemented as follows:
[0087] Training is performed on the basis of the weight file Transtfpn trained in step 2.1. The BN layer data of Transtfpn is frozen during the training process. The IoU prediction head is mainly trained. LaSOT and GOT-10K are used as training data sets. During the training process, training data are sampled from these two data sets with the same probability. For each training sample, 1 frame of search image and 2 frames of template image are sampled. A frame is randomly selected from the visible frames in the entire video sequence as the base frame. Then, within the range before and after the base frame, the maximum interval max_gap=100 is considered to find additional template frames, which together constitute a template set.
[0088] Step 3.1.2: Perform the same processing on the sampled template set and search image as in step 2.1.2. Finally, when encapsulating the data, concatenate the template image from the first dimension. The output template shape is [2,3,128,128].
[0089] Step 3.1.3, adjust the shape of the packaged template. 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. Adjust the shape of the template and extract network features for the input. This is the same feature extraction process as step 2.1.3.
[0090] Step 3.1.4, adjust the extracted template feature shape, adjust the generated position coding shape, adjust the extracted template feature shape, and perform position coding on the extracted features. The coding generation method here is the same as step 2.1.4.
[0091] Step 3.1.5: The input features with position encoding are then input into the feature fusion network of Transtfpn-T. The structure of the fusion network is consistent with that of 2.1.5, and the way of combining hierarchical features is the same as that of steps 2.1.6 to 2.1.10.
[0092] Step 3.1.6: Use the final output fusion vector for classification, regression and IoU prediction. The training method for classification and regression is the same as step 2.1.11. The IoU prediction is generated by a multi-layer perceptron MLP. First, the predicted regression value is concatenated with the output of the feature fusion network in step 3.1.5 in the last dimension. The concatenated features are processed by MLP and output as a 1-dimensional prediction value. The output value is normalized by the sigmoid function to ensure that the IoU prediction value is between [0,1].
[0093] Step 3.1.7, the loss calculation of the IoU prediction head is achieved by comparing the difference between the IoU value predicted by the model and the actual IoU. First, the predicted IoU value corresponding to the target bounding box is obtained by matching the index, and the corresponding predicted bounding box is selected according to the regression prediction. Get GroundTruth from the data encapsulated in step 3.1.2.
[0094] Calculate the generalized intersection-over-union ratio between the predicted bounding box and GroundTruth, and return two values GIoU and IoU, where IoU is the actual intersection-over-union ratio calculated, and the IoU value obtained by MLP processing is the IoU value predicted by the model. The loss calculation method of the IoU prediction head is:
[0095] Loss = mean(((1-IoU) 2 )*((IoU pred -IoU) 2 )) (16)
[0096] Among them, IoU is the actual intersection-over-union ratio, which represents the intersection-over-union ratio between the model prediction bounding box and GroundTruth, IoU pred is the IoU value predicted by the model,
[0097] Step 3.1.8, train a total of 150 epochs, use AdamW to train the model, set the learning rate of the backbone to 1e-5, the learning rate of other parameters to 1e-3, the weight decay to 1e-4, the batch size value to 24, each epoch undergoes 200 iterations, and after the 50th epoch, the learning rate drops by 10 times.
[0098] Step 3.2 is implemented as follows:
[0099] Step 3.2.1, initialize the template image, set the number of templates to 2, initialize the template image according to the annotation information of the first frame of the video to be tracked, and the second frame is the search image. The cropping and processing of the template image and the search image are the same as steps 2.2.1 and 2.2.2;
[0100] Step 3.2.2, extract the features of the template image and the search image. The feature extraction method is the same as step 3.1.3. When tracking the first frame, the number of copies of the initial template features is 2. In the later tracking, the features of the second template image are updated, and then the feature list of the template image is established, and the features are spliced from the second dimension.
[0101] Step 3.2.3, add position coding to the extracted features, the coding method is the same as step 3.1.4;
[0102] Step 3.2.4: Input the features with position encoding into the feature fusion network. The fusion network structure and the hierarchical feature association method are the same as step 3.1.5.
[0103] Step 3.2.5: Classify, regress and predict IoU for the features output by the decoder. The classification and regression predictions are the same as those in step 2.2.6. When tracking the current frame, store the regression value information of the two adjacent frames. Use the IoU prediction head trained in step 3.1.6 to calculate the IoU prediction value by concatenating the fusion vector output by the current frame and the regression values of the two adjacent frames. If the sum of these two values is greater than the threshold, proceed to step 3.2.6; if it is not greater than the threshold, do not update the template, and output the current prediction bounding box to complete target tracking.
[0104] Step 3.2.6, update the template, calculate the new center position and size of the target based on the bounding box obtained by the current tracking, and crop it according to the size of the target. The size of the template image is 128*128, and the image is standardized using the preset mean and standard deviation, and the pixel values are scaled to between 0 and 1. The normalized image is passed to the extraction network in step 3.2.2 to extract features, the second image feature in the template list is removed, and then the newly extracted template feature is added to the list to complete target tracking.
[0105] The beneficial effects of the present invention are:
[0106] (1) The present invention is a target tracking method based on multi-layer feature fusion and semantic enhancement. The template image and the search image are initialized, and the Layer2 and Layer3 features of each image are extracted by using ResNet50. The template features and search features at each level are associated with each other using a cross-attention mechanism, and then the learned Layer2 and Layer3 search features are fused through a dropout layer, a linear layer, an activation layer, and a normalization layer. This integration strategy provides a rich and comprehensive representation information for the model, so that the model can better understand the essential attributes of the target, including shape, size, texture, etc., thereby improving the accuracy of target recognition.
[0107] (2) The target tracking method of the present invention introduces mask features in the process of learning Layer 2 and Layer 3 features through cross-attention. The influence values of the features are sorted and ranked from high to low according to the influence values. The retention ratio of high influence values is set to 60%. The original values of the feature values ranked in the top 60% according to the influence values are kept unchanged, and the influence values of the last 40% of the features are assigned to 0. In this way, the model can selectively retain the features that are most helpful for the model to maintain a high degree of attention to the target in a complex environment, further optimizing the tracking performance of the model.
[0108] (3) The target tracking method of the present invention has a judgment mechanism that helps to evaluate whether the current tracking bounding box has drifted. The fusion vector of the current frame is spliced with the regression vectors stored in the two adjacent previous frames, and then input into the IoU prediction head to obtain two IoU prediction values. If the sum of the IoU prediction values of the two parts is greater than or equal to the threshold value of 1.6, the image is cropped and processed according to the current tracking data, and the template data is updated. If the sum of the IoU prediction values of the two parts is less than the threshold, it is determined that the bounding box drift has occurred in a short period of time. In order to prevent error accumulation, the template data is not updated, and the tracking result of the current frame is directly output. In this way, the accuracy of the tracking result is judged, and the temporal information of the target is fully utilized in the updating process to strengthen the attention association of the context and adapt to the changes in the target and background in the scene. BRIEF DESCRIPTION OF THE DRAWINGS
[0109] Figure 1 It is a flow chart of the target tracking method of the present invention;
[0110] Figure 2 This is a network framework diagram of the attention mechanism provided by the present invention that integrates multiple layers of deep features;
[0111] Figure 3 It is a framework diagram of the feature mask generation process and the impact results provided by the present invention;
[0112] Figure 4 It is a structural diagram of the judgment mechanism evaluation and tracking result module provided by the present invention;
[0113] Figure 5 , Figure 6 It is a comparison chart of the tracking results of the method provided by the present invention;
[0114] Figure 7 , Figure 8 This is a comparison chart of the success rates of Transtfpn, Transtfpn-Mask, and Transtfpn-T in the OTB-100 and LaSOT datasets for similar background interference video sequences. DETAILED DESCRIPTION
[0115] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.
[0116] Example 1
[0117] This embodiment provides a target tracking method based on multi-layer feature fusion and semantic enhancement, such as Figure 1As shown, the method specifically includes the following steps: Step 1, obtaining a target image, inputting the target image into the TransT feature extraction network ResNet50, and obtaining output features; Step 2, inputting the features extracted in Step 1 into a target semantic enhancement model with a multi-cross attention mechanism, extracting features most relevant to the emphasis and the target through the model, and introducing a dynamic mask to perform target recognition and tracking; Step 3, designing a judgment mechanism to judge the tracking results in Step 2, judging whether the single tracking bounding box drifts, and outputting the tracking results when no drift occurs, thereby completing target tracking.
[0118] Example 2
[0119] On the basis of Example 1, the present invention is based on a target tracking method for multi-layer feature fusion and semantic enhancement, and step 1 is specifically implemented according to the following steps: Step 1.1, when the tracker receives the image and annotation box for the first time, initialize the template features of the tracker, calculate the center position and size of the target, calculate the cropping size according to the set template size, and obtain the initial template image z of the target; Step 1.2, update the position of the target, obtain and process the target image area of the current frame, calculate the cropping size according to the set search image size, obtain the new position and size of the target, obtain the search image x, and use the processed image area to update the network; Step 1.3, input the obtained template image and search image into the backbone feature extraction network of TransT, the backbone of TransT is a pre-trained ResNet50 network, and outputs the feature maps of the second layer (Layer2 level) and the third layer (Layer3 level), with the number of channels being 512 and 1024, respectively.
[0120] Example 3
[0121] On the basis of Example 2, the present invention is based on a target tracking method of multi-layer feature fusion and semantic enhancement, and step 2 is specifically implemented according to the following steps: step 2.1, training of the tracking module based on TransT improvement; step 2.2, tracking of the tracking module based on TransT improvement; step 2.3, introducing a dynamic mask to perform target recognition and tracking. Step 2.1 is specifically: step 2.1.1, sampling frames from the training sequence to form batch data, randomly selecting a data set from a predefined data set list, the data set list is [LaSOT, GOT-10K]. Randomly select a base frame from the selected video sequence, and randomly select a base frame from the selected video sequence. The base frame is used to subsequently determine the sampling range of the template frame and the search frame. 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 including the base frame, and the search frame is sampled after the base frame; step 2.1.2, process the sampled frame. During the initialization process, multiple parameters are set, including the search area size factor (search_area_factor), the template area size factor (template_area_factor), the size of the search area and template area (search_sz, temp_sz), and the perturbation coefficients of the center and scale. Random noise is added to the center position and size of the bounding box. Then, for the search image and template image, according to their respective area size coefficients and target sizes, the area centered on the perturbed target box is cropped from the image and adjusted to a fixed size (search_sz, temp_sz). The size of the cropped search image is 256*256*3, and the size of the template image is 128*128*3. Predefined transformations are applied to the cropped and resized search area and template area, first converted to grayscale, followed by jitter transformations such as translation, scaling or rotation, and color normalization. Finally, encapsulate the processed data, including the search image, template image, and the bounding box of the template image; Step 2.1.3, extract image features, use the ResNet50 pre-trained on ImageNet as the backbone network for feature extraction when training Transtfpn. The network has a total of 4 main sections. Here, the output of the second (Layer2) and third (Layer3) templates are used, with the number of channels being 512 and 1024 respectively; Step 2.1.4, positionally encode the extracted features, and use a 1*1 fully connected layer to adjust the number of channels of the Layer2 feature map and Layer3 feature map output by ResNet50 to the fixed number of channels of 256 required by the model.Sine wave position encoding enables the model to utilize position information by adding a unique code to each input feature. Sine wave position encoding is dynamically generated according to the formula, where each dimension of the position encoding corresponds to a different frequency of the sine or cosine function. For position p and dimension i, the position encoding can be expressed as:
[0122] If i is even, use:
[0123]
[0124] If i is odd, use:
[0125]
[0126] Where d is the dimension of the entire position encoding vector, indicating the total number of all feature vector points in the position 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 half-dimensional index in the position encoding vector.
[0127] Step 2.1.5, the input features with position encoding are then input into the feature fusion network of Transtfpn. The feature fusion network is mainly composed of a hierarchical feature association module and a hierarchical feature fusion module. The hierarchical feature association module is composed of 4 stacked base layers, each of which is composed of a cross-attention mechanism. The encoder inputs the Layer2 features and Layer3 features of the template image and the search image, and first performs a cross-attention operation on the two parts of the Layer2 feature level. The cross-attention mechanism is a multi-head attention. The learning of the single-head attention mechanism can be expressed as:
[0128]
[0129] In the formula, Q, K, V are the input feature vectors. When calculating attention, position encoding is added to Q and K. i represents the number of multi-head attention, which is set to 8 here. Multi-head attention (MultiHead) divides the 256-dimensional feature into 8 heads, each head corresponds to a feature dimension of 256 / 8, and then performs attention operations in parallel.
[0130] The process of cross-attention learning for the template features of Layer2 is:
[0131] X′ z2 =X z2 +MultiHead(X z2 +P z2 , X x2 +P x2 , X x2 ) (4)
[0132] The process of cross-attention learning for the search features of Layer2 is:
[0133] X′ x2 =X x2 +MultiHead(X x2 +P x2 , X z2 +P z2 , X z2 ) (5)
[0134] In the formula, P is the position code, X z2 and X x2 They are the template features and search features at Layer 2, respectively, and X′ z2 and X′ x2 Template features and search features after cross-attention learning.
[0135] Step 2.1.6, the feedforward network (FFN) further processes the output of Layer2 cross attention. The feedforward network contains two linear layers and a nonlinear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and a nonlinear 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 be compatible with the subsequent output layer;
[0136] Step 2.1.7: Associate the template features and search features at Layer 3 with each other through cross attention. The process of cross attention learning for the template features at Layer 3 is as follows:
[0137] X′ z3 =X z3 +MultiHead(X z3 +P z3 , X x3 +P x3 , X x3 ) (6)
[0138] The process of cross-attention learning for the search features of Layer3 is:
[0139] X′ x3 =X x3 +MultiHead(X x3 +P x3 , X z3 +P z3 , X z3 ) (7)
[0140] Where P is the position code, Xz3 and X x3 They are the template features and search features at Layer 3, respectively, and X′ z3 and X′ x3 are the template features and search features after cross-attention learning; in step 2.1.8, the feedforward network (FFN) further processes the output of Layer3 cross-attention. The feedforward network contains two linear layers and a nonlinear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and applies a nonlinear activation function relu between the two linear transformations. The second linear layer maps the output of the intermediate layer from 2048 dimensions back to 256 dimensions to be compatible with the subsequent output layer.
[0141] Step 2.1.9: The search features output by the two hierarchical feature association modules are fused through the hierarchical fusion module. First, X′ x2 The features of are processed by the dropout layer and then combined with X′ x3 Add.
[0142] S1(X′ x3 ) = norm(X′ x3 +dropout(X′ x2 )) (8)
[0143] The output value S1(X′ x3 ) is processed through the activation layer,
[0144] S2(X′ x3 )=relu(linear1(S1(X′ x3 ))) (9)
[0145] The output value S2(X′ x3 ) is processed by linear layers and dropout layers,
[0146] S3(X′ x3 )=linear2(dropout(s2(X′ x3 ))) (10)
[0147] The output value S3(X′ x3 ) is processed by the dropout layer and the normalization layer,
[0148] X″ x3 =norm(S3(X′ x3 )+dropout(S3(X′ x3 )) (11)
[0149] Step 2.1.10: The search feature X″ output by the hierarchical fusion modulex3 and the template feature X′ obtained in step 2.1.7 z3 Through the cross-attention mechanism, we can associate and obtain the final search features:
[0150] X″′ x =X″ x3 +MultiHead(X″ x3 +P x3 , X′ z3 +P z3 , X′ z3 ) (12)
[0151] Step 2.1.11, process the final search features through the feedforward network layer, and the final output is used to predict the position of the target in the search image. The classification prediction uses a multi-layer perceptron (MLP) as the classification head. The MLP receives the output of the decoder (dimension is 1024) and passes through 3 stacked fully connected layers and relu activation functions (only for the 1st and 2nd layers). Finally, the classification probability of each position is output, with a dimension of 2 (including "target class" and "background class"); regression prediction also processes the data through a 3-layer MLP model. The final linear layer outputs the 4 parameters of the bounding box (center point coordinates x, y, width and height), and the output value is normalized to the range of [0, 1] through the sigmoid function.
[0152] Step 2.1.12, cross entropy loss is used for classification loss. The difference between the classification probability output by the model and the true label (GroundTruth) is measured by cross entropy loss.
[0153]
[0154] where y j Represents the GroundTruth of the jth sample, y j =1 indicates foreground, p j Represents the probability that the model predicts it to be the foreground.
[0155] The regression loss consists of two parts, l1 norm loss and generalized IOU loss.
[0156]
[0157] Among them, y j =1 indicates a positive sample, b j represents the predicted bounding box of the jth sample, Represents the normalized GroundTruth. G=2 and λ1=5 are regularization parameters used to balance the weights of the two loss functions. Finally, the two losses are weighted according to the 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 training; Step 2.1.13, a total of 665 epochs were trained, and the model was trained using AdamW. The learning rate of the backbone was set to 1e-5, the learning rate of other parameters was set to 1e-4, and the weight decay was set to 1e-4. The batch size value was 6, and each epoch went through 1000 iterations. After 500 epochs, the learning rate dropped by 10 times.
[0158] Step 2.2 is as follows:
[0159] Step 2.2.1, initialize the first frame image, including calculating the initial target position and size. Crop the image according to the position center to obtain a template image Z with a fixed size of 128*128*3, and perform color standardization on the image; Step 2.2.2, extract the search image from the current frame, the center of the search image is the position of the target in the previous frame, crop the image, and obtain a search image X with a fixed size of 256*256*3. Perform color standardization on the image; Step 2.2.3, input the processed template image and search image into the ResNet50 network for feature extraction, and obtain the features of the second layer (Layer2) and the third layer (Layer3); Step 2.2.4, position encode the extracted feature vector, and input the template features and search features of the Layer2 layer after position encoding into the feature association module of step 2.1.5 for learning in the same way. The Layer3 template features and search features after position encoding are input into the feature association module of step 2.1.7 for learning in the same way; step 2.2.5, the Layer2 and Layer3 search features output by learning in step 2.2.4 are fused through the same fusion module of step 2.1.9. The fused search features and the Layer3 template features obtained in step 2.2.4 are finally associated through the cross attention mechanism; step 2.2.6, the search features finally output in step 2.2.5 are used for classification and regression prediction. The output feature vector is processed by MLP, and the Softmax function is applied to normalize the category score at each position to a probability value, indicating the relative probability that the position belongs to each category; in regression prediction, the sigmoid function is first applied to the output of MLP to obtain normalized coordinates equivalent to the size of the entire image, expressed as the center point coordinates, width and height; in order to balance the historical position and current predicted position of the target, the window penalty is introduced to adjust the score. According to the adjusted score, select the bounding box with the highest score. This step combines the classification score and location information; according to the selected best bounding box (bbox), adjust the size and position. This step includes converting the normalized coordinates to the original image size and ensuring that the bounding box does not exceed the image boundary. Input the current prediction result into step 3, and use the judgment mechanism to evaluate the current result. If the update threshold is reached, update the template input; if the threshold is not reached, directly output the current result without updating the template. The specific steps of step 2.3 are: optimize the cross attention mechanism in the model Transtfpn of step 2.2, such as Figure 3As shown, the specific steps are: Step 2.3.1, the shape of the search feature is H*W, first flatten the feature into a sequence of length H*W, and generate a mask sequence of the same shape according to the long sequence of the search feature; Step 2.3.2, sort from high to low according to the influence value distribution of the search feature, and the present invention sets a 60% feature retention ratio. Add indexes to the feature points, set the index values of 60% of the feature points before sorting to 1, and set the index values of the removed feature points to 0. Add index values to the corresponding mask positions; Step 2.3.3, attach the mask to the search feature sequence, the influence value of the position feature point with index value 1 remains unchanged, and the position feature point with index value 0 is assigned to 0. At this time, the internal influence value of the search feature is updated, and the next round of cross-attention learning will be carried out. In step 2.2.4, the hierarchical feature association module in Transtfpn will perform 4 rounds of cross-attention learning. After learning, the search features will dynamically generate masks according to the current influence value distribution, and update the current search feature influence value distribution.
[0160]
[0161] Where index(X i ) represents the feature point X i The index in the feature map X, S[:h%×N] is the index set of feature points to be retained after sorting, where h=60 and N is the total number of feature points.
[0162] Step 3: Figure 4As shown, the current fusion result is input into the judgment mechanism and the stored regression value information of the previous two frames for IoU prediction calculation. The judgment mechanism is mainly based on an IoU prediction head, and the input is the output result of the current frame and the stored regression information of the previous two adjacent frames. It is implemented in the following steps: Step 3.1, training based on the Transtfpn improved tracking module (Transtfpn-T); Step 3.2, tracking based on the Transtfpn improved tracking module (Transtfpn-T); Step 3.1.1, training based on the weight file Transtfpn trained in step 2.1, freezing the BN layer data of Transtfpn during the training process, mainly training the IoU prediction head. LaSOT and GOT-10K are used as training data sets, and training data are sampled from these two data sets with the same probability during the training process. For each training sample, 1 frame of search image and 2 frames of template image will be sampled. Randomly select a frame from the visible frames in the entire video sequence as the base frame, and then look for additional template frames in the range before and after the base frame (considering the maximum interval max_gap=100), which together constitute the template set; step 3.1.2, perform the same processing on the sampled template set and the search image in the same way as step 2.1.2, and finally, when encapsulating the data, splice the template image from the first dimension, and the output template shape is [2,3,128,128]; step 3.1.3, adjust the encapsulated template shape, batchsize, n, c, h, w represent the number of training batches, the number of templates, the number of channels, the height and width respectively. The template shape is adjusted from (batchsize, n, c, h, w) to (batchsize*n, c, h, w), and the input network features are extracted. This is the same feature extraction process as step 2.1.3. Step 3.1.4: Adjust the shape of the extracted template features, adjust the generated position encoding shape to (batchsize, n, c, h, w), and adjust the extracted template feature shape to (batchsize, n, c, h, w). Position encoding is performed on the extracted features, which is the same as the encoding generation method in step 2.1.4. Step 3.1.5: The input features with position encoding are then input into the feature fusion network of Transtfpn-T. The structure of the fusion network is consistent with that of 2.1.5, and the way of combining hierarchical features is the same as that of steps 2.1.6 to 2.1.10. Step 3.1.6: The final output fusion vector is used for classification, regression and IoU prediction. The training method for classification and regression is the same as step 2.1.11.The IoU prediction is generated by a multi-layer perceptron (MLP). First, the predicted regression value is concatenated with the output of the feature fusion network in step 3.1.5 in the last dimension. The concatenated features are processed by MLP and output as a 1-dimensional prediction value. The output value is normalized by the sigmoid function to ensure that the IoU prediction value is between [0, 1]. Step 3.1.7, the loss calculation of the IoU prediction head is achieved by comparing the difference between the IoU value predicted by the model and the actual IoU. First, obtain the predicted IoU value corresponding to the target bounding box selected by matching the index, and select the corresponding predicted bounding box according to the regression prediction. Get GroundTruth from the data encapsulated in step 3.1.2, calculate the generalized intersection-over-union ratio between the predicted bounding box and GroundTruth, and return two values GIoU and IoU, where IoU is the actual intersection-over-union ratio calculated. The IoU value obtained by MLP processing is the IoU value predicted by the model. The loss calculation method of the IoU prediction head is:.
[0163] Loss = mean(((1-IoU) 2 )*((IoU pred -IoU) 2 )) (16)
[0164] Among them, IoU is the actual intersection-over-union ratio, which represents the intersection-over-union ratio between the model prediction bounding box and GroundTruth, IoU pred is the IoU value predicted by the model.
[0165] Step 3.1.8, train a total of 150 epochs, use AdamW to train the model, set the learning rate of the backbone to 1e-5, the learning rate of other parameters to 1e-3, and the weight decay to 1e-4. The batch size value is 24, and each epoch undergoes 200 iterations. After the 50th epoch, the learning rate drops by 10 times. Step 3.2 is specifically as follows: Step 3.2.1, initialize the template image, set the number of templates to 2, initialize the template image according to the annotation information of the first frame of the video to be tracked, and the second frame starts as the search image. Regarding the template image, the cropping and processing of the search image are the same as Step 2.2.1 and Step 2.2.2; Step 3.2.2, extract the features of the template image and the search image, and the feature extraction method is the same as Step 3.1.3. When tracking the first frame, the number of copies of the initial template features is 2. In the later tracking, the features of the second template image are updated, and then a feature list of the template image is established, and the features are spliced from the second dimension; Step 3.2.3, add position coding to the extracted features, and the coding method is the same as Step 3.1.4; Step 3.2.4, input the features after adding the position coding into the feature fusion network, and the fusion network structure and the hierarchical feature association method are the same as Step 3.1.5; Step 3.2.5, classify, regress and predict IoU for the features output by the decoder, and the classification and regression predictions are the same as the prediction methods in Step 2.2.6. When tracking the current frame, store the regression value information of the two adjacent frames. Use the IoU prediction head trained in step 3.1.6 to calculate the fusion vector output by the current frame and the regression value of the two adjacent frames to obtain the IoU prediction value. If the sum of these two values is greater than the threshold (set to 1.6), the template is updated. If it is not greater than the threshold, the template is not updated, and the current prediction bounding box is output; step 3.2.6, if the template is updated, the new center position and size of the target are calculated based on the bounding box obtained by the current tracking. Crop according to the size of the target, where the size of the template image is 128*128, and the image is standardized using the preset mean and standard deviation, and the pixel values are scaled to between 0 and 1. Pass the normalized image to the extraction network in step 3.2.2 to extract features. Remove the second image in the template list, and then add the newly calculated template features to the list.
[0166] Example 4
[0167] To verify the effectiveness of the present invention, the existing method is used to study the drift phenomenon caused by similar background interference in the target tracking scene and even the phenomenon of tracking failure. The Transtfpn, Transtfpn-Mask and Transtfpn-T proposed in the present invention are compared on the OTB-100 dataset and the LaSOT dataset.
[0168] Table 1 Example 1 Test results
[0169]
[0170] As can be seen from the table, the Transtfpn algorithm is compared with the TransT algorithm. On the OTB-100 dataset, the success rate value is increased by 0.9%, and on the LaSOT dataset, the accuracy is increased by 1.1%, and the success rate value is increased by 0.4%. The algorithm that introduces dynamic mask based on Transtfpn is Transtfpn-Mask. Compared with the TransT algorithm, the accuracy is increased by 3.7% and the success rate is increased by 5% on the OTB-100 dataset; the average accuracy is increased by 9.4% and the success rate is increased by 7.9% on the LaSOT dataset. The algorithm that introduces temporal information in Transtfpn-Mask is Transtfpn-T. Compared with the TransT algorithm, the accuracy is increased by 4.3% and the success rate is increased by 4.5% on the OTB-100 dataset; the average accuracy is increased by 11.4% and the success rate is increased by 10.8% on the LaSOT dataset.
[0171] like Figure 7 As shown, on Background_clutter (similar background interference sequence in the OTB-100 dataset), the success rates of Transtfpn, Transtfpn-Mask, and Transtfpn-T were improved by 2.3%, 6%, and 9%, respectively, compared with TransT.
[0172] like Figure 8 As shown, on Background_clutter (similar background interference sequence in the LaSOT dataset), the success rates of Transtfpn, Transtfpn-Mask, and Transtfpn-T were improved by 0.2%, 9.6%, and 10.7% respectively compared with TransT.
[0173] The present invention is a target tracking algorithm based on multi-layer feature fusion and semantic enhancement. In the initial stage of tracking, the input data is processed, and the input data includes a template image and a search image. The two images are input into ResNet50 for feature extraction, and the feature vectors of the second layer (Layer2) and the third layer (Layer3) are output. Then, the extracted feature vector is added with sine wave position coding, and the feature vector with added position coding is transmitted to the hierarchical feature fusion module.
[0174] In the hierarchical feature fusion module, the template features and search features of the Layer2 level are learned through 4 rounds of cross-attention mechanism, and the template features and search features of the Layer3 level are learned through 4 rounds of cross-attention mechanism. In this fusion process, the feature values output by each round of cross-attention are analyzed, and masks are added to irrelevant or weakly relevant features. The search features output by the two learning stages are associated and fused through the dropout layer, linear layer, activation layer and normalization layer, and the fused search features are then associated with the learned Layer3 template features through the cross-attention mechanism, and then the search features are sent to the prediction head for classification, regression and IoU prediction.
[0175] IoU prediction is performed based on the feature vector of the current frame and the regression values of the two adjacent frames stored, and the prediction results of the two parts are added. When it is greater than or equal to the threshold value of 1.6, the image is cropped according to the current prediction result, the template image is updated, and the prediction result is output; when the threshold value is less than 1.6, the template is not updated and the prediction result is directly output. The present invention can capture rich semantic information and finer spatial details at the same time. This fusion of hierarchical features can better distinguish the target from the background, thereby improving the tracking accuracy. By adding a mask, the interference of the background can be reduced and the focus on the target can be strengthened. The method of using temporal information fusion is more robust for processing situations such as rapid movement, occlusion, and illumination changes of the target, thereby improving the overall tracking performance to a certain extent.
Claims
1. A target tracking method based on multi-layer feature fusion and semantic enhancement, characterized in that: The specific steps include: Step 1: Obtain the target image, input the target image into the TransT feature extraction network ResNet50, and obtain the output features; Step 2: Input the features extracted in step 1 into a target semantic enhancement model with a multi-cross attention mechanism, extract the features most relevant to the emphasis and target through the model, and optimize the cross attention mechanism of the model to perform target recognition and tracking; Step 3: Design a judgment mechanism to judge the tracking results in step 2 to determine whether the single tracking bounding box drifts. If no drift occurs, output the tracking results to complete target tracking.
2. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 1, characterized in that: The step 1 is specifically implemented according to the following steps: Step 1.1, when the tracker receives the image and annotation box for the first time, it initializes the template features of the tracker, calculates the center position and size of the target, calculates the cropping size according to the set template size, and obtains the initial template image z of the target; Step 1.2, update the position of the target, obtain and process the target image area of the current frame, calculate the crop size according to the set search image size, obtain the new position and size of the target, obtain the search image x, and use the processed image area to update the network; Step 1.3: Input the obtained template image and search image into the backbone feature extraction network of TransT. The backbone of TransT is a pre-trained ResNet50 network, which outputs the feature maps of the second layer Layer2 and the third layer Layer3, with the number of channels being 512 and 1024 respectively.
3. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 1 is characterized in that: The step 2 is specifically implemented according to the following steps: Step 2.1: Improve the training of Transtfpn based on TransT; Step 2.2, improve the tracking of Transtfpn based on TransT; Step 2.3: Introduce the Transtfpn-Mask algorithm to optimize the cross-attention mechanism of the model for target recognition and tracking.
4. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 3 is characterized in that: The step 2.1 is specifically implemented according to the following steps: Step 2.1.1, sample frames from the training sequence to form batch data, randomly select a dataset from the predefined dataset list, the dataset list is [LaSOT, GOT-10K], randomly select a base frame in the selected video sequence, randomly select a base frame from the selected video sequence, the base frame is used to subsequently determine the sampling range of the template frame and the search frame, 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 including the base frame, and the search frame is sampled after the base frame, Step 2.1.2, process the sample frame. During the initialization process, multiple parameters are set, including the search area size coefficient, the template area size coefficient, the size of the search area and the template area, the center and scale perturbation coefficients, and random noise is added to the center position and size of the bounding box. Then, for the search image and the template image, according to their respective area size coefficients and target sizes, the area centered on the perturbed target box is cropped from the image, and these areas are adjusted to a fixed size; Apply predefined transformations to the cropped and resized search and template regions, first converting them to grayscale, then performing jitter transformations such as translation, scaling or rotation and color normalization, and finally encapsulating the processed data, including the search image and template image and the bounding box of the template image; Step 2.1.3, extract image features. When training Transtfpn, use ResNet50 pre-trained on ImageNet as the backbone network for feature extraction. Use the output of Layer2 and Layer3 templates, with 512 and 1024 channels respectively. Step 2.1.4: Positionally encode the extracted features. Use a 1*1 fully connected layer to adjust the number of channels of the Layer2 feature map and Layer3 feature map output by ResNet50 to the fixed number of channels 256 required by the model. Use sinusoidal position encoding to add a unique code to each input feature so that the model can utilize the position information. The sine wave position encoding is dynamically generated according to the formula, where each dimension of the position encoding corresponds to a different frequency of the sine or cosine function; for position p and dimension i, the position encoding can be expressed as: If i is even, use: If i is odd, use: Where d is the dimension of the entire position encoding vector, indicating the total number of all feature vector points in the position 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 half-dimensional index in the position encoding vector; Step 2.1.5, the input features with position encoding are then input into the feature fusion network of Transtfpn. The feature fusion network is mainly composed of a hierarchical feature association module and a hierarchical feature fusion module. The hierarchical feature association module is stacked by 4 basic layers, and each basic layer is composed of a cross-attention mechanism. The encoder inputs the Layer2 features and Layer3 features of the template image and the search image. First, the cross-attention operation is performed on the two parts of the Layer2 level features. The cross-attention mechanism is a multi-head attention. The learning of the single-head attention mechanism can be expressed as: Where Q, K, and V are the input feature vectors. When calculating attention, position encoding is added to Q and K. i represents the number of multi-head attentions, which is set to 8. Multi-head attention divides the 256-dimensional features into 8 heads, and the feature dimension corresponding to each head is 256 / 8. Then the attention operation is performed in parallel. The process of cross-attention learning for the template features of Layer2 is: X z ′2=X z2 +MultiHead(X z2 +P z2 ,X x2 +P x2 ,X x2 ) (4) In the formula, P is the position code, X z2 is the template feature of Layer2, X′ z2 i Template features after cross-attention learning; The process of cross-attention learning for the search features of Layer2 is: X′ x2 =X x2 +MultiHead(X x2 +P x2 ,X z2 +P z2 ,X z2 ) (5) Where P is the position code, X x2 is the search feature at Layer 2, and X′ x2 is the search feature after cross-attention learning; Step 2.1.6, the feedforward network further processes the output of Layer2 cross attention. The feedforward network contains two linear layers and a nonlinear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and a nonlinear 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; Step 2.1.7: Associate the template features and search features at Layer 3 with each other through cross attention. The process of cross attention learning for the template features at Layer 3 is as follows: X′ z3 =X z3 +MultiHead(X z3 +P z3 ,X x3 +P x3 ,X x3 ) (6) In the formula, p is the position code, X z3 is the template feature of Layer3, X′ z3 is the template feature after cross-attention learning, The process of cross-attention learning for the search features of Layer3 is: X′ x3 =X x3 +MultiHead(x x3 +P x3 ,x z3 +P z3 ,x z3 ) (7) In the formula, p is the position code, X x3 is the search feature at Layer 3, X′ x3 is the search feature after cross-attention learning; Step 2.1.8, the feedforward network further processes the output of Layer3 cross attention. The feedforward network contains two linear layers and a nonlinear activation function: the first linear layer maps the input feature vector from 256 dimensions to 2048 dimensions, and a nonlinear 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; Step 2.1.9: The search features output by the two hierarchical feature association modules are fused through the hierarchical fusion module. First, X′ x2 The features of are processed by the dropout layer and then combined with X′ x3 Add, S1(X′ x3 )=norm(X′ x3 +dropout(X′ x2 )) (8) The output value S1(X′ x3 ) is processed through the activation layer, S2(X′ x3 )=relu(linear1(S1(X′ x3 ))) (9) The output value S2(X′ x3 ) is processed by linear layers and dropout layers, S3(X′ x3 )=linear2(dropout(S2(X′ x3 ))) (10) The output value S3(X′ x3 ) is processed by the dropout layer and the normalization layer. X″ x3 =X″ x3 =norm(S3(X′ x3 )+dropout(S3(X′ x3 )) (11) Step 2.1.10: The search feature X″ output by the hierarchical fusion module x3 and the template feature X′ obtained in step 2.1.7 z3 Through the cross-attention mechanism, we can associate and obtain the final search features: X″′ x =X″ x3 +MultiHead(X″ x3 +P x3 ,X′ z3 +P z3 ,X′ z3 ) (12) Step 2.1.11, the final search features are processed through the feed-forward network layer, and the final output is used to predict the position of the target in the search image; The classification prediction uses a multi-layer perceptron as the classification head. The MLP receives the output of the decoder with a dimension of 1024, and passes through 3 stacked fully connected layers and relu activation functions to finally output the classification probability of each position with a dimension of 2, including "target class" and "background class"; Regression prediction also processes data through a 3-layer MLP model. The final linear layer outputs the four parameters of the bounding box, the center point coordinates x, y, width and height, and normalizes the output value to the range of [0, 1] through the sigmoid function. Step 2.1.12, cross entropy loss is used for classification loss. The difference between the classification probability output by the model and the true label is measured by cross entropy loss. where y j Represents the GroundTruth of the jth sample, y j =1 indicates foreground, p j represents the probability of the model predicting the foreground; The regression loss consists of two parts, l1 norm loss and generalized IOU loss. Among them, y j =1 indicates a positive sample, b j represents the predicted bounding box of the jth sample, represents the normalized GroundTruth, λ G =2 and λ1=5 are regularization parameters used to balance the weights of the two loss functions; Finally, the two parts of the loss are weighted according to the preset weights, the classification weight is 8.333, and the regression weight is 5, and the total loss is obtained. This total loss is used for gradient calculation and model parameter update during training; Step 2.1.13, train a total of 665 epochs, use AdamW to train the model, set the learning rate of the backbone to 1e-5, the learning rate of other parameters to 1e-4, the weight decay to 1e-4, the batch size value to 6, each epoch undergoes 1000 iterations, and after 500 epochs, the learning rate drops 10 times.
5. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 4 is characterized in that: The step 2.2 is specifically implemented according to the following steps: Step 2.2.1, initialize the first frame image, including calculating the initial target position and size, cropping the image according to the position center, obtaining a template image Z with a fixed size of 128*128*3, and performing color standardization on the image; Step 2.2.2, extract the search image from the current frame, the center of the search image is the position of the target in the previous frame, the image is cropped to obtain a search image X with a fixed size of 256*256*3, and the image is color normalized; Step 2.2.3, input the processed template image and search image into the ResNet50 network for feature extraction to obtain the features of Layer 2 and Layer 3; Step 2.2.4, position-encode the extracted feature vector, input the position-encoded Layer2 template features and search features into the feature association module of step 2.1.5 for learning in the same way, and input the position-encoded Layer3 template features and search features into the feature association module of step 2.1.7 for learning in the same way; Step 2.2.5: The Layer2 and Layer3 hierarchical search features learned and output in step 2.2.4 are fused through the same fusion module as in step 2.1.9, and the fused search features and the Layer3 template features obtained in step 2.2.4 are finally associated through the cross attention mechanism; Step 2.2.6: Use the search features finally outputted in step 2.2.5 for classification and regression prediction. Process the output feature vector through MLP and apply the Softmax function to normalize the category score at each position into a probability value, which indicates the relative probability that the position belongs to each category. In regression prediction, the sigmoid function is first applied to the output of the MLP to obtain the normalized coordinates of the entire image size, expressed as the center point coordinates, width, and height; In order to balance the historical position and current predicted position of the target, a window penalty is introduced to adjust the score. According to the adjusted score, the bounding box with the highest score is selected, combining the classification score and position information; According to the selected optimal bounding box, the size and position are adjusted, including converting the normalized coordinates to the original image size and ensuring that the bounding box does not exceed the image boundary. The current prediction result is input into step 3, and the current result is evaluated using the judgment mechanism. If the update threshold is reached, the template input is updated; if the threshold is not reached, the current result is directly output without updating the template.
6. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 5, characterized in that: The step 2.3 is specifically implemented according to the following steps: Step 2.3.1, the shape of the search feature is H*W, first flatten the feature into a sequence of length H*W, and generate a mask sequence of the same shape according to the long sequence of the search feature; Step 2.3.2, sorting from high to low according to the influence value distribution of the search feature, the present invention sets a feature retention ratio of 60%, adds indexes to the feature points, sets the index values of 60% of the feature points before sorting to 1, sets the index values of the removed feature points to 0, and adds index values to the corresponding mask positions; Step 2.3.3, attach the mask to the search feature sequence, the influence value of the position feature point with index value 1 remains unchanged, and the position feature point with index value 0 is assigned 0. At this time, the internal influence value of the search feature is updated, and the next round of cross-attention learning will be carried out. In step 2.2.4, the hierarchical feature association module in Transtfpn will carry out 4 rounds of cross-attention learning. After learning, the search features will dynamically generate masks according to the current influence value distribution, and update the current search feature influence value distribution; Where index(X i ) represents the feature point X i The index in the feature map X, S[:h%×N] is the index set of feature points to be retained after sorting, where h=60 and N is the total number of feature points.
7. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 6, characterized in that: The step 3 is specifically implemented according to the following steps: Step 3.1: Improve the training of Transtfpn-T based on Transtfpn; Step 3.2: Improve the tracking of Transtfpn-T based on Transtfpn.
8. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 7, characterized in that: The step 3.1 is specifically implemented according to the following steps: Step 3.1.1, training is performed on the basis of the weight file Transtfpn trained in step 2.
1. During the training process, the BN layer data of Transtfpn is frozen. The IoU prediction head is mainly trained. LaSOT and GOT-10K are used as training data sets. During the training process, training data are sampled from these two data sets with the same probability. For each training sample, 1 frame of search image and 2 frames of template image are sampled. A frame is randomly selected from the visible frames in the entire video sequence as the base frame. Then, within the range before and after the base frame, the maximum interval max_gap=100 is considered to find additional template frames, which together constitute a template set. Step 3.1.2: Perform the same processing on the sampled template set and search image as in step 2.1.
2. Finally, when encapsulating the data, concatenate the template image from the first dimension. The output template shape is [2,3,128,128]. Step 3.1.3, adjust the shape of the packaged template. 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. Adjust the shape of the template and extract network features for the input. This is the same feature extraction process as step 2.1.
3. Step 3.1.4, adjust the extracted template feature shape, adjust the generated position coding shape, adjust the extracted template feature shape, and perform position coding on the extracted features. The coding generation method here is the same as step 2.1.
4. Step 3.1.5: The input features with position encoding are then input into the feature fusion network of Transtfpn-T. The structure of the fusion network is consistent with that of 2.1.5, and the way of combining hierarchical features is the same as that of steps 2.1.6 to 2.1.
10. Step 3.1.6: Use the final output fusion vector for classification, regression and IoU prediction. The training method for classification and regression is the same as step 2.1.
11. The IoU prediction is generated by a multi-layer perceptron MLP. First, the predicted regression value is concatenated with the output of the feature fusion network in step 3.1.5 in the last dimension. The concatenated features are processed by MLP and output as a 1-dimensional prediction value. The output value is normalized by the sigmoid function to ensure that the IoU prediction value is between [0,1]. Step 3.1.7, the loss calculation of the IoU prediction head is achieved by comparing the difference between the IoU value predicted by the model and the actual IoU. First, the predicted IoU value corresponding to the target bounding box is obtained by matching the index, and the corresponding predicted bounding box is selected according to the regression prediction. Get GroundTruth from the data encapsulated in step 3.1.
2. Calculate the generalized intersection-over-union ratio between the predicted bounding box and GroundTruth, and return two values GIoU and IoU, where IoU is the actual intersection-over-union ratio calculated, and the IoU value obtained by MLP processing is the IoU value predicted by the model. The loss calculation method of the IoU prediction head is: Loss=mean(((1-IoU) 2 )*((IoU pred -IoU) 2 )) (16) among them, IoU is the actual intersection-over-union ratio, which represents the intersection-over-union ratio between the model predicted bounding box and GroundTruth. pred is the IoU value predicted by the model, Step 3.1.8, train a total of 150 epochs, use AdamW to train the model, set the learning rate of the backbone to 1e-5, the learning rate of other parameters to 1e-3, the weight decay to 1e-4, the batch size value to 24, each epoch undergoes 200 iterations, and after the 50th epoch, the learning rate drops by 10 times.
9. The target tracking method based on multi-layer feature fusion and semantic enhancement according to claim 8, characterized in that: The step 3.2 is specifically implemented according to the following steps: Step 3.2.1, initialize the template image, set the number of templates to 2, initialize the template image according to the annotation information of the first frame of the video to be tracked, and the second frame is the search image. The cropping and processing of the template image and the search image are the same as steps 2.2.1 and 2.2.2; Step 3.2.2, extract the features of the template image and the search image. The feature extraction method is the same as step 3.1.
3. When tracking the first frame, the number of copies of the initial template features is 2. In the later tracking, the features of the second template image are updated, and then the feature list of the template image is established, and the features are spliced from the second dimension. Step 3.2.3, add position coding to the extracted features, the coding method is the same as step 3.1.4; Step 3.2.4: Input the features with position encoding into the feature fusion network. The fusion network structure and the hierarchical feature association method are the same as step 3.1.
5. Step 3.2.5: Classify, regress and predict IoU for the features output by the decoder. The classification and regression predictions are the same as those in step 2.2.
6. When tracking the current frame, store the regression value information of the two adjacent frames. Use the IoU prediction head trained in step 3.1.6 to calculate the IoU prediction value by concatenating the fusion vector output by the current frame and the regression values of the two adjacent frames. If the sum of these two values is greater than the threshold, proceed to step 3.2.6; if it is not greater than the threshold, do not update the template, and output the current prediction bounding box to complete target tracking. Step 3.2.6, update the template, calculate the new center position and size of the target based on the bounding box obtained by the current tracking, and crop it according to the size of the target. The size of the template image is 128*128, and the image is standardized using the preset mean and standard deviation, and the pixel values are scaled to between 0 and 1. The normalized image is passed to the extraction network in step 3.2.2 to extract features, the second image feature in the template list is removed, and then the newly extracted template feature is added to the list to complete target tracking.
Citation Information
Cited By
Multi-picture input and historical trajectory enhancement single-target tracking method and device integrated with existence judgment
CN122289324A
