Video shadow detection method based on double sparse long and short term Transformer

Through the dual sparse long-term Transformer architecture, global and local features in video shadow detection are captured, shadow information is propagated and long-term and short-term features are integrated, which solves the problem of small shadow areas and background confusion, and improves the accuracy and efficiency of shadow detection.

CN118658093APending Publication Date: 2024-09-17CHINA UNIV OF MINING & TECH
View PDF 0 Cites 5 Cited by

Patent Information

Application Number
CN202410759579.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-13
Publication Date
2024-09-17

AI Technical Summary

Technical Problem

Existing video shadow detection technology has difficulty in effectively identifying small shadow areas and confusing areas that separate shadows and backgrounds, resulting in complex recognition and poor performance.

Method used

A video shadow detection method based on dual sparse long and short-term Transformer is adopted to capture global frame features and local shadow features through a dual-stream architecture, use the sparse long and short-term attention module to propagate shadow information, adaptively fuse long-term and short-term features, and update through long-term storage library Modules improve efficiency.

Benefits of technology

Without losing background context, it effectively separates the foreground and background, improves the recognition accuracy and segmentation performance of shadow areas, alleviates the problem of background confusion, and enhances temporally consistent shadow appearance learning.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118658093A
    Figure CN118658093A
Patent Text Reader

Abstract

The invention discloses a video shadow detection method based on double sparse long and short term Transformer, which comprises the following steps: inputting a first frame of image into a fine tuning SAM model to generate a reference frame pseudo mask, initializing a long and short term memory bank, inputting a current frame of image into an encoder to extract query features, reading long and short term memory features from the long and short term memory bank at the same time, then, a shadow partition mechanism is introduced to obtain an attention value only paying attention to a shadow partition, query features, long and short memory features and the attention value only paying attention to the shadow partition are input into a double sparse long and short term Transform module together, global visual information and local shadow information are learned at the same time, finally, a decoder is used for generating a prediction mask of a current frame image, and the prediction mask is used for predicting the current frame image. And the query features and the prediction masks form new memory features, and the new memory features are directly stored in a short-term memory bank and are stored in a long-term memory bank through a long-term memory bank updating module. According to the method, the powerful advantages of Transform are fully utilized, and the shadow appearance learning capability is enhanced by combining the context and time consistency of the shadow region.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a video shadow detection method based on a dual sparse long-short term Transformer, belonging to the video shadow detection technology. Background Art

[0002] Shadow detection is of great significance to many downstream tasks in the field of computer vision, such as object tracking, object segmentation, virtual reality scene generation, and autonomous driving applications. Previous work has mainly focused on the image shadow detection (ISD) task, and with the rapid development of convolutional neural networks, significant progress has been made on image benchmark datasets. In recent years, with the introduction of the first large-scale annotated video shadow detection dataset (i.e., the ViSha dataset), people have begun to shift their attention to shadow detection research in dynamic scenes.

[0003] Video shadow detection (VSD) aims to generate pixel-level prediction results of shadows in each frame. To further explore video shadow detection, many deep learning-based methods currently model the correlation of inter-frame features between videos or within videos, and have achieved a series of impressive results. Some methods use the temporal information of optical flow to capture rich feature representations of shadow targets, and achieve effective segmentation of moving shadows and small shadows. However, the representation of shadow targets by optical flow is relatively limited, and it will be greatly disturbed by the information of salient targets, which inevitably leads to poor performance. Another part of the method proposes to enhance the consistency of spatiotemporal interpolation and transfer the shadow knowledge in the labeled image to the unlabeled dataset to improve the prediction of time and scale consistency. However, when the object is occluded, the shadow will also be accompanied by a large deformation. Considering only the spatiotemporal information of adjacent frames will inevitably lead to the loss of shadows.

[0004] In summary, there are still two major challenges in the VSD task: first, small shadow areas are ignored: changes in lighting conditions and object motion usually cause shadows to be scattered and complex in shape, which complicates recognition; second, shadows confuse areas, leading to suboptimal segmentation: shadows usually show similar appearance to darker background areas, resulting in poor segmentation performance. Summary of the invention

[0005] Purpose of the invention: In order to overcome the shortcomings of the prior art, the present invention provides a video shadow detection method based on dual sparse long-short term Transformer, which enhances the shadow appearance learning from the shadow area context and temporal consistency; the method adopts a dual-stream architecture to capture global frame features and local shadow features at the same time, so that it can focus on the shadow area without losing the background context; the shadow information is propagated from distant and adjacent frames to the current frame through a sparse long-short term attention module, effectively separating the foreground from the background; the adaptive fusion module effectively fuses long-term features and short-term features to improve segmentation performance; when storing prediction results, the long-term repository update module is used to store only new features with large differences to improve efficiency.

[0006] Technical solution: To achieve the above purpose, the technical solution adopted by the present invention is:

[0007] A video shadow detection method based on dual sparse long short-term transformer uses DSLSTT-Net network model for video shadow detection, including the following steps:

[0008] Step 1. Take the first frame of the video Input into the pre-trained fine-tuned SAM model to obtain the reference frame pseudo mask Using reference frame pseudo mask Initialize long-term memory bank B L and short-term memory bank B S ; Where H, W, and C represent image height, image width, and channel size, respectively;

[0009] Step 2: The current frame image of the video Input to the Swin-Tiny encoder, the extracted features are called query features At the same time, from the long-term memory bank B L and short-term memory bank B S Read all long-term memory feature pairs and short-term memory feature pairs;

[0010] Step 3: Implement the shadow partition mechanism for the long-term memory feature pairs and the short-term memory feature pairs to obtain the attention value that only focuses on the shadow partition;

[0011] Step 4: Query feature Q t , all long-term memory feature pairs and short-term memory feature pairs, and the attention value of only focusing on the shadow partition are input into the dual sparse long-short-term Transformer module, and the global visual information and local shadow information are extracted respectively through the global visual branch and the local shadow branch;

[0012] Step 5. Use the FPN decoder to generate the current frame image I tThe prediction mask M t , the query feature Q t and the prediction mask M t Form a new memory feature pair and use the new memory feature pair to update the short-term memory library B S , through the long-term memory library update module to determine whether to store the new memory feature pair into the long-term memory library B L ;

[0013] Step 6, t=t+1, repeat Step 2 to Step 5 to obtain the trained DSLSTT-Net network model; use the trained DSLSTT-Net network model to test on the test set to obtain the video shadow detection result.

[0014] Specifically, in Step 1, given the first frame image I 1 , apply the pre-trained fine-tuned SAM model to the first frame image I 1 On the reference frame, get the pseudo mask Using reference frame pseudo mask Initialize long-term memory bank B L ={(K 1 ,V 1 )} and short-term memory B S ={(K 1 ,V 1 )},in: Represents the first frame image I 1 The features extracted by Swin-Tiny encoder, V 1 Take as the reference frame pseudo mask The fine-tuned SAM model is a model obtained by fine-tuning the masker of the SAM model on the ViSha dataset. The specific operation is to use the bounding box as a sparse prompt and freeze the image encoder and the prompt encoder of the SAM model at the same time.

[0015] Specifically, in Step 2, the current frame image I is encoded using the Swin-Tiny encoder. t Perform feature extraction to obtain query feature Q t ; At the same time, from the long-term memory bank B L and short-term memory bank B S Read all long-term memory feature pairs and short-term memory feature pairs; the long-term memory library B L contains M long-term memory feature pairs, denoted as B L = {Z 1 ,Z 2 ,…,Z i ,…Z M}, Z i =(K i ,V i), K L ={K 1 ,K 2 ,…,K M},V L = {V 1 ,V 2 ,…,V M}, The short-term memory bank B S contains one short-term memory feature pair, denoted as B S ={(K t-1 ,V t-1 )},K S =K t-1 , V S =V t-1 ,

[0016] Specifically, in Step 3, the long-term memory feature V L and short-term memory characteristics V S Implement the shadow partition mechanism and calculate the attention value that only focuses on the shadow partition, including the following steps:

[0017] Step 31, V L Perform hot encoding to get X L ∈{0,1} MHW×Y , for V S Perform hot encoding to get X S ∈{0,1} HW×Y ,Y represents the total number of shadow partitions;

[0018] Step 32: Set up the area library Store U C-dimensional region vectors with different identifiers; use the region library R to obtain the long-term memory shadow partition A L and short-term memory shadow partition A S , expressed as:

[0019] A L =SA(X L ,R)=X L PR

[0020] A S =SA(X S ,R)=X S PR

[0021] Where: SA represents the shadow partitioning mechanism, P∈{0,1} Y×U represents a random permutation matrix for X from the region library R L and X S Randomly assign Y region vectors;

[0022] The obtained shadow partition and the corresponding memory feature are summed pixel by pixel to obtain the attention value of only focusing on the shadow partition:

[0023] PV L =V L +A L

[0024] PV S =V S +A S

[0025] Among them: PV L Represents the long-term memory attention value, PV S Represents the short-term memory attention value.

[0026] Specifically, in the Step 4, the dual sparse long-short term Transformer module includes two branches with the same structure, which are respectively called the global vision branch and the local shadow branch; the branches include a sparse long-short term attention module, an adaptive fusion module and a cross attention module, and the sparse long-short term attention module includes a sparse long-term attention module and a sparse short-term attention module; the execution process of the dual sparse long-short term Transformer module includes the following steps:

[0027] Step 41, the execution process of the global vision branch includes the following steps:

[0028] Step 411, Q t As query Q, K L and V L As key K and value V respectively, perform attention operation;

[0029] Calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ; Select V L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function of Q t K L and V L TopK in China and Africa 1 The elements at the position are padded with 0 and restored to the original scale to obtain the long-term attention map F.t L , expressed as:

[0030]

[0031] Among them: TopK 1 (·) means taking the largest L in the feature matrix · α elements;

[0032] Step 412, Q t As query Q, K S and V S As key K and value V respectively, perform attention operation;

[0033] Calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ; Select V S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and V S TopK in China and Africa 2 The elements at the position are padded with 0 and restored to the original scale to obtain the short-term attention map F. t S , expressed as:

[0034]

[0035] Among them: TopK 2 (·) means taking the largest S in the feature matrix · α elements;

[0036] Step 413, F t L and F t S Input to the adaptive fusion module to obtain the fusion feature F t , including the following steps:

[0037] Step4131, F t LThe long-term memory weight map W is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , F t S The short-term memory weight map W is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S , expressed as:

[0038] W L =Sigmoid(Conv(CBR(CBR(F t L ))))

[0039] W S =Sigmoid(Conv(CBR(CBR(F t S ))))

[0040] Wherein: Conv represents a convolution operation; the CBR module includes a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function for refining features;

[0041] Step 4132, W L and W S Respectively with F t L and F t S Do pixel-by-pixel multiplication and add to F t L and F t S Add pixel by pixel to get the fusion feature F t , expressed as:

[0042] F t =W L ⊙F t L +W S ⊙F t S +F t L +F t S

[0043] Step 4133, F t With Q t Perform residual connection and layer normalization operations to obtain E 1 , expressed as:

[0044] E 1 =Norm(F t +Q t )

[0045] Step 42: The execution process of the local shadow branch includes the following steps:

[0046] Step 421, Q t As query Q, K L and PV L As key K and value V respectively, perform attention operation;

[0047] Calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ;Select PV L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function of Q t K L and PV L TopK in China and Africa 1 The elements at the position are padded with 0 and restored to the original scale to obtain the long-term attention map PF. t L , expressed as:

[0048]

[0049] Among them: TopK 1 (·) means taking the largest L in the feature matrix · α elements;

[0050] Step 422, Q t As query Q, K S and PV S As key K and value V respectively, perform attention operation;

[0051] Calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α;Select PV S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and PV S TopK in China and Africa 2 The elements at the position are padded with 0 and restored to the original scale to obtain the short-term attention map PF. t S , expressed as:

[0052]

[0053] Among them: TopK 2 (·) means taking the largest S in the feature matrix · α elements;

[0054] Step 423, PF t L and PF t S Input to the adaptive fusion module to obtain the fusion feature PF t , including the following steps:

[0055] Step 4231, PF t L The long-term memory weight map PW is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , PF t S The short-term memory weight map PW is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S , expressed as:

[0056] PW L =Sigmoid(Conv(CBR(CBR(PF t L ))))

[0057] PW S =Sigmoid(Conv(CBR(CBR(PF t S ))))

[0058] The CBR module includes a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function for refining features;

[0059] Step 4232, PW L and PWS PF t L and PF t S Do pixel-by-pixel multiplication and compare with PF t L and PF t S Add pixel by pixel to get the fusion feature PF t , expressed as:

[0060] PF t =PW L ⊙PF t L +PW S ⊙PF t S +PF t L +PF t S

[0061] Step 4233, PF t With Q t Perform residual connection and layer normalization operations to obtain E 2 , expressed as:

[0062] E 2 =Norm(PF t +Q t )

[0063] Step 43: Use cross attention to interact global information and local information between the global visual branch and the local shadow branch to compensate for the information loss of the two branches and obtain global visual information. and local shadow information It is expressed as:

[0064]

[0065] Among them: Norm represents the layer normalization operation; CrossAttn represents the cross attention, which 1 As query Q, let E 2 Serves as both key K and value V.

[0066] Specifically, in Step 5, the FPN decoder is used to generate the current frame image I t The prediction mask M t , update short-term memory B S and long-term memory bank B L ; comprising the following steps:

[0067] Step 51, generate the current frame image I through the FPN decoder tThe prediction mask M t , and the query feature Q t and the prediction mask M t Form a new memory feature pair Z t =(K t ,V t )=G(Q t ,M t ), where G represents the convolution operation;

[0068] Step 52, Z t Store directly into B S , B S Update to B S = {Z t}={(K t ,V t )};

[0069] Step 53, Z t With B L Each long-term memory feature Z i Perform inner product operation and calculate the similarity between them, expressed as:

[0070]

[0071] Where: sc(Z t ,Z j ) represents Z t and Z i The similarity between them, Matmul represents the dot multiplication operation;

[0072] Step 54, set the threshold parameter D, through Get the maximum similarity value Msc(Z t ): If Msc(Z t )≤D, then Z t Stored in long-term memory B S ; If Msc(Z t )>D, then discard Z t .

[0073] Specifically, in the Step 6, the DSLSTT-Net network model is supervised and trained using a loss function to obtain a trained DSLSTT-Net network model; the trained DSLSTT-Net network model is tested on a test set to obtain a video shadow detection result.

[0074] Beneficial effects: The video shadow detection method based on dual sparse long-term and short-term Transformers provided by the present invention has the following advantages over the prior art: 1. The dual Transformer architecture in the present invention learns shadow information from global and local perspectives respectively, effectively focusing attention on each shadow area while retaining background context clues; 2. The sparse long-term and short-term attention module in the present invention effectively separates the foreground from the background, effectively alleviating the background confusion problem; 3. The adaptive fusion module in the present invention can learn different weights of long-term and short-term memory features, thereby improving the accuracy of shadow object representation in aggregated features; 4. Unlike the traditional method of updating the long-term memory library using fixed interval frames, the long-term memory library update module in the present invention calculates the similarity function to store the current frame that has significant differences from the frames in the memory library, so as to effectively supplement the memory library. BRIEF DESCRIPTION OF THE DRAWINGS

[0075] Figure 1 1 is a flow chart for implementing the method of the present invention;

[0076] Figure 2 It is a structural block diagram of the DSLSTT-Net network model of the present invention;

[0077] Figure 3 It is the structural diagram of the shadow partition mechanism;

[0078] Figure 4 Figure 2 is a structural block diagram of the dual sparse long short-term Transformer module. DETAILED DESCRIPTION

[0079] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0080] Video shadow detection aims to segment shadow areas in video sequences, which is a key task in video understanding. Although the existing technologies have made progress in this field, they still face challenges in effectively detecting small shadow areas and confusing areas due to the limited apparent ability of shadow areas. To overcome these challenges, this paper provides a video shadow detection method based on dual sparse long-term and short-term Transformers. Figure 1 As shown in FIG. , it is a flowchart for implementing the method. The method uses Figure 2The DSLSTT-Net network model shown in the figure performs video shadow detection. First, the pre-trained fine-tuned SAM model is used to generate a pseudo mask for the first frame image and initialize the long short-term memory bank. Then, the query feature of the current frame image is extracted through the Swin-Tiny encoder, and all memory feature pairs are taken out from the long short-term memory bank. The shadow partitioning mechanism is used to shadow partition the memory feature pairs to obtain the attention value that only focuses on the shadow partition. Then, the DSLSTT module (double sparse long short-term transformer module) is introduced to propagate the long short-term memory features to the current frame image from the global and local perspectives, and the prediction mask is generated through the decoder. Finally, the query feature and the prediction mask are combined into a new memory feature and stored in the long short-term memory bank, and the long-term memory bank update module is introduced to improve the model efficiency. The following is a detailed description of each step.

[0081] Step S01: Generate a reference frame pseudo mask using the pre-trained fine-tuned SAM model and initialize the long short-term memory bank.

[0082] The first frame of the video Input into the pre-trained fine-tuned SAM model to obtain the reference frame pseudo mask Using reference frame pseudo mask Initialize long-term memory bank B L ={(K 1 ,V 1 )} and short-term memory B S ={(K 1 ,V 1 )};in: Represents the first frame image I 1 The features extracted by Swin-Tiny encoder, V 1 Take as the reference frame pseudo mask H, W, and C represent image height, image width, and channel size, respectively.

[0083] The fine-tuned SAM model is a model obtained by fine-tuning the masker of the SAM model on the ViSha dataset. The specific operation is to use the bounding box as a sparse prompt and freeze the image encoder and the prompt encoder of the SAM model at the same time.

[0084] Step S02: extracting query features of the current frame image and reading memory features from the long short-term memory library.

[0085] The current frame image of the video Input to the Swin-Tiny encoder, the extracted features are called query features At the same time, from the long-term memory bank B L and short-term memory bank B S Read all long-term memory feature pairs and short-term memory feature pairs.

[0086] The long-term memory bank B L contains M long-term memory feature pairs, denoted as B L = {Z 1 ,Z 2 ,…,Z i ,…Z M}, Z i =(K i ,V i ), K L ={K 1 ,K 2 ,…,K M},V L = {V 1 ,V 2 ,…,V M}, The short-term memory bank B S contains one short-term memory feature pair, denoted as B S ={(K t-1 ,V t-1 )},K S =K t-1 , V S =V t-1 ,

[0087] Step S03: Use the shadow partitioning mechanism to perform long-term and short-term memory feature V L and V S Perform shadow zoning.

[0088] like Figure 3 As shown in the figure, it is a structural block diagram of the shadow partition mechanism; for the long-term memory feature V L and short-term memory characteristics V S Implement the shadow partitioning mechanism to obtain the attention value that only focuses on the shadow partition; specifically, the following steps are included:

[0089] Step 31, V L Perform one-hot encoding to obtain XL∈{0,1} MHW×Y , for V S Perform hot encoding to get X S ∈{0,1} HW×Y ,Y represents the total number of shadow partitions;

[0090] Step 32: Set up the area library Store U C-dimensional region vectors with different identifiers; use the region library R to obtain the long-term memory shadow partition A L and short-term memory shadow partition A S , expressed as:

[0091] A L =SA(X L ,R)=X L PR

[0092] A S =SA(X S ,R)=X S PR

[0093] Where: SA represents the shadow partitioning mechanism, P∈{0,1} Y×U represents a random permutation matrix for X from the region library R L and X S Randomly assign Y region vectors;

[0094] The obtained shadow partition and the corresponding memory feature are summed pixel by pixel to obtain the attention value of only focusing on the shadow partition:

[0095] PV L =V L +A L

[0096] PV S =V S +A S

[0097] Among them: PV L Represents the long-term memory attention value, PV S Represents the short-term memory attention value.

[0098] Step S04: Based on the query features, the LSTM feature pairs and the attention value focusing only on the shadow partition, the DSLSTT module is used to propagate rich global and local information.

[0099] The double sparse long short-term transformer module is referred to as the DSLSTT module, such as Figure 4 As shown, the DSLSTT module includes two branches with the same structure, namely the global vision branch and the local shadow branch; the branches include a sparse long-short-term attention module, an adaptive fusion module and a cross attention module, and the sparse long-short-term attention module includes a sparse long-term attention module and a sparse short-term attention module.

[0100] 4.1 Global Vision Branch

[0101] The global vision branch is used to obtain the global feature E 1 ; The specific process is as follows:

[0102] Step 411, Q t As query Q, K L and V LAs key K and value V respectively, perform attention operation;

[0103] Calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ; Select V L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function of Q t K L and V L TopK in China and Africa 1 The elements at the position are padded with 0 and restored to the original scale to obtain the long-term attention map F. t L , expressed as:

[0104]

[0105] Among them: TopK 1 (·) means taking the largest L in the feature matrix · α elements;

[0106] Step 412, Q t As query Q, K S and V S As key K and value V respectively, perform attention operation;

[0107] Calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ; Select V S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and V S TopK in China and Africa2 The elements at the position are padded with 0 and restored to the original scale to obtain the short-term attention map F. t S , expressed as:

[0108]

[0109] Among them: TopK 2 (·) means taking the largest S in the feature matrix · α elements;

[0110] Step 413, F t L and F t S Input to the adaptive fusion module to obtain the fusion feature F t , including the following steps:

[0111] Step4131, F t L The long-term memory weight map W is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , F t S The short-term memory weight map W is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S , expressed as:

[0112] W L =Sigmoid(Conv(CBR(CBR(F t L ))))

[0113] W S =Sigmoid(Conv(CBR(CBR(F t S ))))

[0114] Wherein: Conv represents a convolution operation; the CBR module includes a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function for refining features;

[0115] Step 4132, W L and W S Respectively with F t L and F t S Do pixel-by-pixel multiplication and add to F t L and F t SAdd pixel by pixel to get the fusion feature F t , expressed as:

[0116] F t =W L ⊙F t L +W S ⊙F t S +F t L +F t S

[0117] Step 4133, F t With Q t Perform residual connection and layer normalization operations to obtain E 1 , expressed as:

[0118] E 1 =Norm(F t +Q t )

[0119] 4.2 Local Shadow Branch

[0120] The local shadow branch is used to obtain the local feature E 2 ; The specific process is as follows:

[0121] Step 421, Q t As query Q, K L and PV L As key K and value V respectively, perform attention operation;

[0122] Calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ;Select PV L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function of Q t K L and PV L TopK in China and Africa 1 The elements at the position are padded with 0 and restored to the original scale to obtain the long-term attention map PF. tL , expressed as:

[0123]

[0124] Among them: TopK 1 (·) means taking the largest L in the feature matrix · α elements;

[0125] Step 422, Q t As query Q, K S and PV S As key K and value V respectively, perform attention operation;

[0126] Calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ;Select PV S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and PV S TopK in China and Africa 2 The elements at the position are padded with 0 and restored to the original scale to obtain the short-term attention map PF. t S , expressed as:

[0127]

[0128] Among them: TopK 2 (·) means taking the largest S in the feature matrix · α elements;

[0129] Step 423, PF t L and PF t S Input to the adaptive fusion module to obtain the fusion feature PF t , including the following steps:

[0130] Step 4231, PF t LThe long-term memory weight map PW is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , PF t S The short-term memory weight map PW is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S , expressed as:

[0131] PW L =Sigmoid(Conv(CBR(CBR(PF t L ))))

[0132] PW S =Sigmoid(Conv(CBR(CBR(PF t S ))))

[0133] The CBR module includes a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function for refining features;

[0134] Step 4232, PW L and PW S PF t L and PF t S Do pixel-by-pixel multiplication and compare with PF t L and PF t S Add pixel by pixel to get the fusion feature PF t , expressed as:

[0135] PF t =PW L ⊙PF t L +PW S ⊙PF t S +PF t L +PF t S

[0136] Step 4233, PF t With Q t Perform residual connection and layer normalization operations to obtain E 2 , expressed as:

[0137] E 2 =Norm(PF t +Qt )

[0138] 4.3 Cross-Attention

[0139] Cross attention is used for the global visual branch and the local shadow branch to interact with the global information and local information, making up for the information loss of the two branches and obtaining the global visual information. and local shadow information It is expressed as:

[0140]

[0141] Among them: Norm represents the layer normalization operation; CrossAttn represents the cross attention, which 1 As query Q, let E 2 Serves as both key K and value V.

[0142] Step S05: Generate a prediction mask M through the decoder t , together with the query feature Q t Update long and short-term memory together.

[0143] Use FPN decoder to generate current frame image I t The prediction mask M t , the query feature Q t and the prediction mask M t Form a new memory feature pair and use the new memory feature pair to update the short-term memory library B S , through the long-term memory library update module to determine whether to store the new memory feature pair into the long-term memory library B L ; comprising the following steps:

[0144] Step 51, generate the current frame image I through the FPN decoder t The prediction mask M t , and the query feature Q t and the prediction mask M t Form a new memory feature pair Z t =(K t ,V t )=G(Q t ,M t ), where G represents the convolution operation;

[0145] Step 52, Z t Store directly into B S , B S Update to B S = {Z t}={(K t ,V t )};

[0146] Step 53, Z t With B L Each long-term memory feature Z i Perform inner product operation and calculate the similarity between them, expressed as:

[0147]

[0148] Where: sc(Z t ,Z j ) represents Z t and Z i The similarity between them, Matmul represents the dot multiplication operation;

[0149] Step 54, set the threshold parameter D, through Get the maximum similarity value Msc(Z t ): If Msc(Z t )≤D, then Z t Stored in long-term memory B S ; If Msc(Z t )>D, then discard Z t .

[0150] Step S06: Update the current frame image to complete the supervised training of the DSLSTT-Net network model.

[0151] t=t+1, repeat steps S06-S05, use the loss function to supervise the DSLSTT-Net network model to obtain the trained DSLSTT-Net network model; use the trained DSLSTT-Net network model to test on the test set to obtain the video shadow detection result.

[0152] The DSLSTT-Net network model used to implement the above-mentioned video shadow detection method mainly includes a fine-tuned SAM model, a Swin-Tiny encoder, a shadow partitioning mechanism, a DSLSTT module, an FPN decoder and a long-term memory library update module. The DSLSTT module mainly includes a sparse long-short-term attention module, an adaptive fusion module and a cross-attention module.

[0153] The fine-tuned SAM model is a model obtained by fine-tuning the mask of the SAM model on the ViSha dataset. The specific operation is to use the bounding box as a sparse hint and freeze the image encoder and hint encoder of the SAM model at the same time. 1 Input the fine-tuned SAM model to get the reference frame pseudo mask Using reference frame pseudo mask Initialize long-term memory bank B L and short-term memory bank B S .

[0154] The Swin-Tiny encoder is used to extract the current frame image I t The query feature Q t .

[0155] The shadow partition mechanism, from the long-term memory bank B L and short-term memory bank B S Read the feature V L and V S , after hot encoding, we get feature X L and X S , and then set the region library R to store U C-dimensional region vectors with different identifiers, and use the region library R to obtain the long-term memory shadow partition A L and short-term memory shadow partition A S , and then get the long-term and short-term attention value PV that only focuses on the shadow partition L and PV S .

[0156] The DSLSTT module takes as input the query feature Q t , all long-term memory feature pairs and short-term memory feature pairs, only pay attention to the attention value of the shadow partition, and the output memory feature propagates to the features of the current frame image. The DSLSTT module includes two branches with the same structure, namely the global vision branch and the local shadow branch; the branches include a sparse long-term attention module, an adaptive fusion module and a cross attention, and the sparse long-term attention module includes a sparse long-term attention module and a sparse short-term attention module.

[0157] For the global vision branch, Q t As query Q, K L and V L As key K and value V respectively, after sparse long-term attention module, calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ; Select V L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function of Q t K L and V L TopK in China and Africa1 The elements at the position are padded with 0 and restored to the original scale to obtain the long-term attention map F. t L At the same time, Q t As query Q, K S and V S As key K and value V respectively, after sparse short-term attention module, calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ; Select V S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and V S TopK in China and Africa 2 The elements at the position are padded with 0 and restored to the original scale to obtain the short-term attention map F. t S Then, the adaptive fusion module is used to transform F t L The long-term memory weight map W is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , F t S The short-term memory weight map W is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S ; Then, for W L and W S Respectively with F t L and F t S Do pixel-by-pixel multiplication and add to F t L and F t S Add pixel by pixel to get the fusion feature F t ; Finally, F t With Q t Perform residual connection and layer normalization operations to obtain E 1 .

[0158] For a locally shadowed branch, Qt As query Q, K L and PV L As key K and value V respectively, after sparse long-term attention module, calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ;Select PV L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function of Q t K L and PV L TopK in China and Africa 1 The elements at the position are padded with 0 and restored to the original scale to obtain the long-term attention map PF. t L At the same time, Q t As query Q, K S and PV S As key K and value V respectively, after sparse short-term attention module, calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ;Select PV S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and PV S TopK in China and Africa 2 The elements at the position are padded with 0 and restored to the original scale to obtain the short-term attention map PF. t S Then, the adaptive fusion module is used to transform PF t LThe long-term memory weight map PW is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , PF t S The short-term memory weight map PW is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S ; Then, for PW L and PW S PF t L and PF t S Do pixel-by-pixel multiplication and compare with PF t L and PF t S Add pixel by pixel to get the fusion feature PF t ; Finally, PF t With Q t Perform residual connection and layer normalization operations to obtain E 2 .

[0159] Cross-attention is used to interact global information and local information between the global visual branch and the local shadow branch to compensate for the information loss of the two branches and obtain global visual information. and local shadow information

[0160] The FPN decoder takes global visual information as input. and local shadow information The output is the current frame image I t The prediction mask M t . The query feature Q t and the prediction mask M t Form a new memory feature pair Z t ; Use Z t Directly replace short-term memory bank B S The short-term memory feature pairs in Z are used; the long-term memory library is used to update the module to determine whether Z t Stored in long-term memory B L .

[0161] The long-term memory update module first updates Z t With B L Each long-term memory feature Z i Do the inner product operation to calculate the similarity between them; then determine whether the maximum similarity value is less than or equal to the set threshold parameter D: If so, set Z t Stored in long-term memory B S Otherwise, discard Zt .

[0162] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any form, and any technical solution obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present invention.

Claims

1. A video shadow detection method based on dual sparse long-term and short-term Transformer, characterized by: Using the DSLSTT-Net network model for video shadow detection includes the following steps: Step 1. Take the first frame of the video Input into the pre-trained fine-tuned SAM model to obtain the reference frame pseudo mask Using reference frame pseudo mask Initialize long-term memory bank B L and short-term memory bank B S ; Where H, W, and C represent image height, image width, and channel size, respectively; Step 2: The current frame image of the video Input to the Swin-Tiny encoder, the extracted features are called query features At the same time, from the long-term memory bank B L and short-term memory bank B S Read all long-term memory feature pairs and short-term memory feature pairs; Step 3: Implement the shadow partition mechanism for the long-term memory feature pairs and the short-term memory feature pairs to obtain the attention value that only focuses on the shadow partition; Step 4: Query feature Q t , all long-term memory feature pairs and short-term memory feature pairs, and the attention value of only focusing on the shadow partition are input into the dual sparse long-short-term Transformer module, and the global visual information and local shadow information are extracted respectively through the global visual branch and the local shadow branch; Step 5. Use the FPN decoder to generate the current frame image I t The prediction mask M t , the query feature Q t and the prediction mask M t Form a new memory feature pair and use the new memory feature pair to update the short-term memory library B S , through the long-term memory library update module to determine whether to store the new memory feature pair into the long-term memory library B L ; Step 6, t=t+1, repeat Step 2 to Step 5 to obtain the trained DSLSTT-Net network model; use the trained DSLSTT-Net network model to test on the test set to obtain the video shadow detection result.

2. The video shadow detection method based on dual sparse long-term and short-term Transformer according to claim 1 is characterized in that: In the Step 1, given the first frame image I1, the pre-trained fine-tuned SAM model is applied to the first frame image I1 to obtain the reference frame pseudo mask Using reference frame pseudo mask Initialize long-term memory bank B L ={(K1,V1)} and short-term memory bank B S ={(K1,V1)}, where: Represents the features extracted by the Swin-Tiny encoder for the first frame image I1, and V1 is taken as the reference frame pseudo mask The fine-tuned SAM model is a model obtained by fine-tuning the masker of the SAM model on the ViSha dataset. The specific operation is to use the bounding box as a sparse prompt and freeze the image encoder and the prompt encoder of the SAM model at the same time.

3. The video shadow detection method based on dual sparse long-term and short-term Transformer according to claim 1 is characterized in that: In the Step 2, the Swin-Tiny encoder is used to encode the current frame image I t Perform feature extraction to obtain query feature Q t ; At the same time, from the long-term memory bank B L and short-term memory bank B S Read all long-term memory feature pairs and short-term memory feature pairs; the long-term memory library B L contains M long-term memory feature pairs, denoted as B L ={Z1,Z2,…,Z i ,…Z M }, Z i =(K i ,V i ), K L ={K1,K2,…,K M },V L = {V1, V2, …, V M }, The short-term memory bank B S contains one short-term memory feature pair, denoted as B S ={(K t-1 ,V t-1 )},K S =K t-1 , V S =V t-1 , 4. The video shadow detection method based on dual sparse long-term and short-term Transformer according to claim 2 is characterized in that: In Step 3, the long-term memory feature V L and short-term memory characteristics V S Implement the shadow partition mechanism and calculate the attention value that only focuses on the shadow partition, including the following steps: Step 31, V L Perform hot encoding to get X L ∈{0,1} MHW×Y , for V S Perform hot encoding to get X S ∈{0,1} HW×Y ,Y represents the total number of shadow partitions; Step 32: Set up the area library Store U C-dimensional region vectors with different identifiers; use the region library R to obtain the long-term memory shadow partition A L and short-term memory shadow partition A S , expressed as: A L =SA(X L ,R)=X L PR A S =SA(X S ,R)=X S PR Where: SA represents the shadow partitioning mechanism, P∈{0,1} Y×U represents a random permutation matrix for X from the region library R L and X S Randomly assign Y region vectors; The obtained shadow partition and the corresponding memory feature are summed pixel by pixel to obtain the attention value of only focusing on the shadow partition: PV L =V L +A L PV S =V S +A S Among them: PV L Represents the long-term memory attention value, PV S Represents the short-term memory attention value.

5. The video shadow detection method based on dual sparse long-term and short-term Transformer according to claim 1 is characterized in that: In the Step 4, the dual sparse long-short term Transformer module includes two branches with the same structure, which are respectively called the global vision branch and the local shadow branch; the branches include a sparse long-short term attention module, an adaptive fusion module and a cross attention module, and the sparse long-short term attention module includes a sparse long-term attention module and a sparse short-term attention module; the execution process of the dual sparse long-short term Transformer module includes the following steps: Step 41, the execution process of the global vision branch includes the following steps: Step 411, Q t As query Q, K L and V L As key K and value V respectively, perform attention operation; Calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ; Select V L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Visualize the function Q through Scatter t K L and V L The elements in non-TopK1 positions are padded with 0 and restored to the original scale to obtain the long-term attention map F. t L , expressed as: Among them: TopK1(·) means taking the largest L in the feature matrix · α elements; Step 412, Q t As query Q, K S and V S As key K and value V respectively, perform attention operation; Calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ; Select V S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function of Q t K S and V S The elements in non-TopK2 positions are padded with 0 and restored to the original scale to obtain the short-term attention map F. t S , expressed as: Among them: TopK2(·) means taking the largest Sα elements in the feature matrix ·; Step 413, F t L and F t S Input to the adaptive fusion module to obtain the fusion feature F t , including the following steps: Step 4131, F t L The long-term memory weight map W is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , F t S The short-term memory weight map W is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S , expressed as: W L =Sigmoid(Conv(CBR(CBR(F t L )))) W S =Sigmoid(Conv(CBR(CBR(F t S )))) Wherein: Conv represents a convolution operation; the CBR module includes a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function for refining features; Step 4132, W L and W S Respectively with F t L and F t S Do pixel-by-pixel multiplication and add to F t L and F t S Add pixel by pixel to get the fusion feature F t , expressed as: F t =W L ⊙F t L +W S ⊙F t S +F t L +F t S Step 4133, F t With Q t Perform residual connection and layer normalization operations to obtain E1, which is expressed as: E1=Norm(F t +Q t ) Step 42: The execution process of the local shadow branch includes the following steps: Step 421, Q t As query Q, K L and PV L As key K and value V respectively, perform attention operation; Calculate Q t With K L The similarity matrix of all pixel pairs between Set a sparsity L for the sparse long-term attention module α ; Select Q t K L Medium α Normalize the largest elements to change the element size from HW×MHW to HW×L α ;Select PV L Medium α Normalize the largest elements to change the element size from MHW×C to MHW×L α ; Use Scatter to visualize the function Q t K L and PV L The elements in non-TopK1 positions are padded with 0 and restored to their original scale to obtain the long-term attention map PF. t L , expressed as: Among them: TopK1(·) means taking the largest Lα elements in the feature matrix ·; Step 422, Q t As query Q, K S and PV S As key K and value V respectively, perform attention operation; Calculate Q t With K S The similarity matrix of all pixel pairs between Set a sparsity S for the sparse short-term attention module α , select Q t K S Medium S α Normalize the largest elements to change the element size from HW×HW to HW×S α ;Select PV S Medium S α Normalize the largest elements to change the element size from HW×C to HW×S α ; Use Scatter to visualize the function Q t K S and PV S The elements in non-TopK2 positions are padded with 0 and restored to the original scale to obtain the short-term attention map PF. t S , expressed as: Among them: TopK2(·) means taking the largest S in the feature matrix · α elements; Step 423, PF t L and PF t S Input to the adaptive fusion module to obtain the fusion feature PF t , including the following steps: Step 4231, PF t L The long-term memory weight map PW is obtained by sequentially passing through a 1×1 convolution layer, two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. L , PF t S The short-term memory weight map PW is obtained through two CBR modules, a 1×1 convolution layer and a Sigmoid activation function. S , expressed as: PW L =Sigmoid(Conv(CBR(CBR(PF t L )))) PW S =Sigmoid(Conv(CBR(CBR(PF t S )))) The CBR module includes a 1×1 convolution layer, a batch normalization layer, and a ReLU activation function for refining features; Step 4232, PW L and PW S PF t L and PF t S Do pixel-by-pixel multiplication and compare with PF t L and PF t S Add pixel by pixel to get the fusion feature PF t , expressed as: PF t =PW L ⊙PF t L +PW S ⊙PF t S +PF t L +PF t S Step 4233, PF t With Q t Perform residual connection and layer normalization operations to obtain E2, which is expressed as: E2=Norm(PF t +Q t ) Step 43: Use cross attention to interact global information and local information between the global visual branch and the local shadow branch to compensate for the information loss of the two branches and obtain global visual information. and local shadow information It is expressed as: Among them: Norm represents the layer normalization operation; CrossAttn represents cross attention, taking E1 as the query Q and E2 as both the key K and the value V.

6. The video shadow detection method based on dual sparse long-term and short-term Transformer according to claim 1 is characterized by: In the Step 5, the FPN decoder is used to generate the current frame image I t The prediction mask M t , update short-term memory B S and long-term memory bank B L ; comprising the following steps: Step 51, generate the current frame image I through the FPN decoder t The prediction mask M t , and the query feature Q t and the prediction mask M t Form a new memory feature pair Z t =(K t ,V t )=G(Q t ,M t ), where G represents the convolution operation; Step 52, Z t Store directly into B S , B S Update to B S = {Z t }={(K t ,V t )}; Step 53, Z t With B L Each long-term memory feature Z i Perform inner product operation and calculate the similarity between them, expressed as: Where: sc(Z t ,Z j ) represents Z t and Z i The similarity between them, Matmul represents the dot multiplication operation; Step 54, set the threshold parameter D, through Get the maximum similarity value Msc(Z t ): If Msc(Z t )≤D, then Z t Stored in long-term memory B S ; If Msc(Z t )>D, then discard Z t .

7. The video shadow detection method based on dual sparse long-term and short-term Transformer according to claim 1 is characterized in that: In the Step 6, the DSLSTT-Net network model is supervised and trained using a loss function to obtain a trained DSLSTT-Net network model; the trained DSLSTT-Net network model is tested on a test set to obtain a video shadow detection result.

Citation Information

Cited By

  • Tracking method and device of target object and computer equipment

    CN119672364A

  • Video shadow detection method and device based on dynamic prompt memory network

    CN119850651A

  • Memory network enhancement method for experimental interaction behavior recognition and application

    CN120220033A

  • Multi-modal video sequence segmentation method based on text-guided hybrid expert mechanism

    CN121725393A

  • Method for multi-modal video sequence segmentation based on text-guided hybrid expert mechanism

    CN121725393B