An unsupervised optical flow estimation method based on Transformer feature pyramid network
By introducing the Transformer feature pyramid network and occlusion compensation processing in optical flow estimation, the problem of difficulty in occlusion and global feature capture by convolutional neural networks in optical flow estimation is solved, and more efficient and accurate optical flow prediction is achieved.
Patent Information
- Application Number
- CN202111506127.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-10
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-12-10
AI Technical Summary
Existing convolutional neural networks have occlusion problems and difficulty in detecting small targets in optical flow estimation, and it is difficult to capture global feature information, affecting accuracy.
The Transformer-based feature pyramid network is used to enhance feature extraction capabilities through the image segmentation module and convolution mapping re-attention mechanism module, and the occlusion compensation processing and overall network training loss function are designed, combined with the multi-head re-attention mechanism and multi-head linear processing, to improve the optical quality Accuracy of flow estimation.
It improves the accuracy and speed of optical flow estimation, enhances the feature extraction capability of images by the feature pyramid layer, effectively handles occlusion areas, and improves the accuracy of optical flow prediction.
Smart Images

Figure CN114187331B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer vision technology, and in particular relates to an unsupervised optical flow estimation method based on a Transformer feature pyramid network. Background Art
[0002] Optical flow estimation is an important research direction in computer vision applications, and has broad application prospects in the fields of autonomous driving, intelligent robots, motion and expression recognition, and target tracking. With the development of deep learning, many researchers choose to use deep learning technology to deal with the problem of optical flow estimation. This method has the advantages of fast running speed and high accuracy, and has achieved leading results on multiple public datasets. However, so far, there are some urgent problems to be solved by using only convolutional neural networks to deal with the problem of optical flow estimation, such as occlusion problems, small target detection, and the inability of convolutional neural networks to capture global feature information. The above problems can be effectively solved by fusing the Transformer model with the feature pyramid network.
[0003] Transformer is a special self-attention mechanism model. In recent years, the computational efficiency and scalability of the Transformer model have made it widely used in computer vision. At present, the computer vision fields to which the Transformer model is extended mainly include image classification, image recognition, object detection, semantic segmentation and image generation. This paper proposes for the first time to apply the Transformer model to the field of optical flow estimation to improve the accuracy of optical flow prediction. Summary of the invention
[0004] The purpose of the present invention is to provide an unsupervised optical flow estimation method based on a Transformer feature pyramid network, which enhances the feature extraction capability of the feature pyramid layer for an image and performs occlusion compensation processing on occluded pixels in the image to improve the accuracy of optical flow estimation.
[0005] An unsupervised optical flow estimation method based on a Transformer feature pyramid network comprises the following steps:
[0006] Step 1: Build a Transformer-based feature pyramid network;
[0007] Based on the Transformer feature pyramid network, there are two completely identical network branches with a total of 12 layers, which can extract 6 types of image features, and the network of each branch shares weights; the Transformer model is integrated in the second, fourth, sixth, eighth, tenth and last layers of the Transformer feature pyramid network to enhance the feature extraction ability of the network. The model consists of an image segmentation module and a convolutional mapping re-attention mechanism module; the image segmentation module first performs a deformable convolution operation on the input image to extract local features such as edges, and then divides the image into sequences and inputs them into the convolutional mapping re-attention mechanism module; the convolutional mapping re-attention mechanism module performs a re-attention mechanism operation on the image sequence to extract global features;
[0008] Step 2: Build an optical flow estimation network; input the image features extracted from each layer of the Transformer feature pyramid network into the optical flow estimation network for prediction;
[0009] The optical flow estimation network is composed of a 5-layer convolutional neural network. First, the input second frame image is feature deformed, and then the feature matching relationship between the second frame image after feature deformation and the first frame image, that is, the feature matching cost volume, is calculated. Then, the calculated feature matching cost volume is input into the optical flow estimation network to predict the optical flow, and the output optical flow result is post-processed using the context network to obtain an accurate predicted optical flow;
[0010] Step 3: Perform occlusion compensation processing on the pixels in the occluded area;
[0011] The specific operation of occlusion compensation processing in the optical flow estimation network is to first compare the difference between the second frame reconstructed image and the first frame image, and then extract the pixels in the occluded area and perform occlusion compensation processing on them;
[0012] The difference contrast processing is to use the predicted forward optical flow to distort the second frame image to reconstruct the first frame image, and add the difference between the reconstructed first frame image and the original first frame image to the occlusion map; extracting the occlusion area pixels is to extract the occlusion area pixels in the original first frame image to fill the reconstructed image, and the occlusion compensation is performed by calculating the difference between the reconstructed image and the original first frame image;
[0013] Step 4: Design the loss function for the overall network training; combine the loss function with similarity information processing into the optical flow estimation network, and construct the loss function for the overall network training; define a function that describes the feature similarity between different image blocks of the input Transformer model to promote the diversity between different image blocks, and define a contrast loss function and an error loss function, so that the attention features of the deep layer of the network come from the corresponding input of the shallow layer and are independent of the remaining shallow layer inputs; weighted sum the loss items corresponding to the Transformer model of each layer of the pyramid, and combine the occlusion compensation loss function as the overall loss function of the network training, so as to constrain the network training process;
[0014] Step 5: Input two consecutive frames of images at the network input end, and use the overall network loss function to perform unsupervised training on the network;
[0015] Step 6: Input two consecutive frames of images into the trained model for testing, and output the corresponding estimated optical flow.
[0016] Furthermore, in step 1, the Transformer feature pyramid network has 12 convolutional layers, including 6 stages of Transformer models, each stage of the Transformer model has the same architecture, and can gradually extract 6 feature maps of different sizes; the number of channel features from the first level to the sixth level are 16, 32, 64, 96, 128, and 196 respectively;
[0017] The first convolutional layer inputs a 3×512×512 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 16×512×512 feature map; the second convolutional layer inputs a 16×512×512 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 16×256×256 feature map that is input into the first stage Transformer model;
[0018] The third convolution layer inputs a 16×256×256 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 16×256×256 feature map; the fourth convolution layer inputs a 16×256×256 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 32×128×128 feature map that is input into the second stage Transformer model;
[0019] The fifth convolutional layer inputs a 32×128×128 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 32×128×128 feature map; the sixth convolutional layer inputs a 32×128×128 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 64×64×64 feature map that is input into the third stage Transformer model;
[0020] The seventh convolution layer inputs a 64×64×64 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 64×64×64 feature map; the eighth convolution layer inputs a 64×64×64 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 96×32×32 feature map that is input into the fourth stage Transformer model;
[0021] The ninth convolutional layer inputs a 96×32×32 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 96×32×32 feature map; the tenth convolutional layer inputs a 96×32×32 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 128×16×16 feature map that is input into the fifth stage Transformer model;
[0022] The eleventh convolution layer inputs a 128×16×16 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 128×16×16 feature map; the twelfth convolution layer inputs a 128×16×16 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 196×8×8 feature map that is input into the sixth stage Transformer model;
[0023] The feature map output by the convolutional layer enters the Transformer model and is then output to the next convolutional layer of the feature pyramid to enhance the network's ability to extract features from the image.
[0024] Furthermore, in the step 1, the image segmentation module based on the Transformer feature pyramid network first performs a deformable convolution operation on the input image, so that the number of image sequences in the input convolution mapping and attention mechanism module is gradually reduced, thereby reducing the feature resolution, and at the same time expanding the width of the input sequence, so that the feature size is increased, so as to achieve the purpose of gradually reducing the feature resolution and increasing the feature size as the number of convolution layers increases. The specific steps are:
[0025] Step 1.1.1: Output image x of the i-th pyramid layer i Input to the image segmentation module, first extract edge features through deformable convolution operation to obtain the output image x′ i , the image after the deformable convolution operation is batch normalized and max pooled to obtain the output image x″i ;
[0026] x″ i =MaxPool(BN(Deconv(x i )))
[0027] Among them, x i is the output image of the i-th layer pyramid based on the Transformer feature pyramid network, and the feature size of the output image is H i ×W i represents the resolution of the i-th layer image, C i represents the number of channels of the i-th layer image; Deconv(·) represents the deformable convolution operation; BN(·) represents batch normalization; MaxPool(·) represents maximum pooling; x″ i Represents the output image after the maximum pooling operation;
[0028] Step 1.1.2: After the maximum pooling, the image x″ is obtained i Cut into 2D image blocks x″′ i , each image block x″′ i The dimension is N represents the output image x″ i The number of image sequences after segmentation is also the effective length of the input convolutional map and attention mechanism module, and (P,P) represents the resolution of each image block after segmentation;
[0029] Step 1.1.3: Flatten the segmented image blocks into N image sequences Each image sequence is a two-dimensional matrix (N, D), D = P 2 C;
[0030] Step 1.1.4: Mark the converted image sequence through a binary mask, where the 1 position represents the image sequence with important information, and the 0 position represents the image sequence with similar information. According to the different information contained in the image sequence, the image sequence is adaptively selected for marking, and the marked image sequence is input into the convolutional mapping and attention mechanism module, where the image sequences marked as 1 are interactively calculated with each other, and the image sequences marked as 0 are only calculated with themselves.
[0031] Furthermore, the convolutional mapping re-attention mechanism module based on the Transformer feature pyramid network in step 1 includes two parts: multi-head re-attention mechanism operation and multi-head linear processing. The specific steps are:
[0032] Step 1.2.1: Input the i-th layer image sequence After linear mapping to high-dimensional space, it is reorganized into a 2D image, and then three depth-separable convolution operations are performed to obtain the features of the three projections. The features after the three projections are flattened to obtain three different two-dimensional vectors in the i-th layer. Each vector is defined as follows:
[0033]
[0034] Among them, Reshape2d(·) means spatial reorganization of the image sequence; s means the size of the convolution kernel; conv2d(·) means depthwise separable convolution operation; Flatten(·) means flattening after mapping to obtain a two-dimensional vector; represents the i-th layer flattened image sequence; Represents the two-dimensional vector obtained by flattening the i-th layer after the depth-wise separable convolution operation;
[0035] Step 1.2.2: The obtained two-dimensional vector Input into the multi-head re-attention mechanism, the two-dimensional vector mapped from each input image sequence can be represented by a matrix q = [q1, q2, ..., q N ],k=[k1,k2,...,k N ],v=[v1,v2,...,v N ]; As the model depth increases, the attention similarity of the same image sequence in different layers is large, but the similarity between multiple heads from the same layer is small. A transfer matrix is used to combine the information between different heads and use them to perform attention operations again. The transfer matrices trained in different layers are different, so as to avoid attention collapse; The operation definition of the multi-head re-attention mechanism is as follows:
[0036]
[0037] Among them, q, k, v represent the matrices obtained by convolution mapping of each input image sequence; T represents the transpose operation of the matrix; q·k T represents the correlation between two positions; softmax(·) represents the correlation between q·k T Perform normalization operation; d represents the dimension of q and k; θ represents the dimension acting on multi-head attention; represents a sequence of image slices flattened by convolution mapping after spatial reorganization; Indicates that a multi-head re-attention mechanism is performed on the image slice sequence;
[0038] Step 1.2.3: Add the input and output of the multi-head attention mechanism operation and then perform batch normalization to normalize the activation values of each layer. The specific definition is as follows:
[0039]
[0040] Among them, MSA(·) represents the multi-head attention mechanism operation; BN(·) represents batch normalization processing; represents a sequence of image slices flattened by convolution mapping after spatial reorganization; Represents the image sequence output after batch normalization;
[0041] Step 1.2.4: The multi-head linear processing operation includes a feedforward network and batch normalization. The feedforward network expands the dimension of each image sequence. The activation function of batch normalization is GELU nonlinear activation. After each operation, a residual connection is performed to prevent network degradation. The specific definitions are as follows:
[0042]
[0043] Among them, FFN(·) represents the feedforward network; BN(·) represents batch normalization processing; GELU(·) represents the Gaussian error linear unit activation function; Represents the image sequence output after batch normalization processing of multi-head re-attention operation; Indicates multi-head linear processing of the output image after the multi-head re-attention operation;
[0044] Step 1.2.5: Linearly map the image sequence output by the multi-head linear processing operation and reduce its dimension, then spatially reorganize it into a 2D image and output it to the next feature pyramid layer.
[0045] Furthermore, the input of the optical flow estimation network in step 2 is two consecutive frames of images, and the output is the corresponding estimated optical flow. The specific steps are:
[0046] Step 2.1: For the two consecutive input frames of images I1 and I2, the second image I2 is feature deformed. The output estimated optical flow from the i-1th layer based on the Transformer feature pyramid network is upsampled by 2 times and then the features of the second image are bilinearly interpolated to the first image. The feature deformation operation is defined as follows:
[0047]
[0048] Where x represents the pixel value; Indicates that the optical flow result obtained by the i-1 layer optical flow estimation network is upsampled by 2 times; Represents the image features of the i-th layer of the second image of the pyramid; Represents the image features after feature deformation;
[0049] Step 2.2: Calculate the correlation between the features of the second image after feature deformation and the features of the first image, that is, calculate the feature matching cost volume of each layer. The calculation definition of the feature matching cost volume is as follows:
[0050]
[0051] Among them, x1 and x2 represent the pixel values of the first and second images respectively; Represents the feature map of the first image on the i-th layer based on the Transformer feature pyramid network; represents the image features after feature deformation of the second image on the i-th layer based on the Transformer feature pyramid network; M represents the length of the feature map; T represents the transposition operation of the matrix; CV i (x1,x2) represents the cost volume result of the feature map matching cost based on the i-th layer of the Transformer feature pyramid network;
[0052] Step 2.3: Input the feature matching cost volume result, the features of the first image, and the high-resolution optical flow obtained by upsampling into the i-th optical flow estimation layer of the optical flow estimation network to obtain the optical flow estimation result of this layer.
[0053] Furthermore, the optical flow estimation layer of the optical flow estimation network in step 2.3 uses a five-layer convolutional network, and the number of channels of each convolutional layer is 128, 128, 96, 64, and 32 respectively, and the output optical flow result is post-processed by the context network; the context network is a feedforward convolutional neural network, based on the dilated convolution design, and consists of 7 layers of convolutional networks. The convolution kernel of each convolutional layer is 3×3, and these layers have different expansion coefficients. The convolution expansion coefficient k indicates that the input unit of the filter in the layer is k units away from other input units of the filter in the layer in the vertical and horizontal directions; from top to bottom, the expansion coefficients of the convolutional layers are 1, 2, 4, 8, 16, 1 and 1 respectively. The convolutional layers with large expansion coefficients can effectively expand the size of the receptive field of each output unit on the pyramid to output a refined optical flow.
[0054] Furthermore, in step 3, the method of performing occlusion compensation processing on pixels in the occluded area is specifically as follows:
[0055] The predicted optical flow image is compared with the original image, and then the pixels in the occluded area are extracted to perform occlusion compensation processing; the difference comparison processing uses the predicted forward optical flow to distort the second frame image I2 to synthesize the first frame reconstructed image I1′, and the difference between the reconstructed image I1′ and the original image I1 is added to the occlusion map, which is defined as follows:
[0056]
[0057] Among them, x represents the pixel value; o fw represents the occlusion map; I1(x) and I′1(x) represent the original image of the first frame and the reconstructed image of the second frame, respectively; σ(·) represents the pixel-level similarity metric, which is used to calculate the similarity between the original image I1(x) and the reconstructed image I′1(x); The difference contrast loss in the i-th layer optical flow estimation network;
[0058] Extracting pixels in the occluded area is to use the corresponding pixels in the occluded area in the original image I1 to fill the image I′1 to obtain the reconstructed image I″1. The loss in the occluded area is calculated by the difference between the reconstructed image I″1 and I1, which is defined as follows:
[0059]
[0060] Where x represents the pixel value; I″1(x) represents the reconstructed pixel obtained by adding the corresponding occluded pixel to the reconstructed first image I′1(x); σ(·) represents the pixel-level similarity measure; The loss in the occluded region in the i-th layer optical flow estimation network;
[0061] Finally, the occlusion compensation loss function in the i-th layer optical flow estimation network It is obtained by summing two loss functions and is defined as follows:
[0062]
[0063] in, represents the difference contrast loss in the i-th layer optical flow estimation network; represents the loss in the occluded area in the i-th layer optical flow estimation network; Represents the occlusion compensation loss function in the i-th layer optical flow estimation network.
[0064] Furthermore, the loss function of the overall network training in step 4 is: Let the features of the input image x and the N image sequences corresponding to its i-th layer be And the feature similarity function As a penalty term in the loss function to promote diversity between different image sequences, it is defined as follows:
[0065]
[0066] Where N represents the total number of image segments; ||·||2 represents the L2 norm operation; T represents the transpose operation of the vector; x n , x m Respectively represent the features of different image slice sequences of the same layer; The feature similarity loss function representing the similarity between different image sequences at the i-th layer;
[0067] Define the contrast loss function for the i-th layer The features learned in the shallow layers of the Transformer model are more diverse than those learned in the deep layers. The contrast loss function can use the features learned in the shallow layers to regularize the deep features to reduce the similarity between different image sequences and increase the feature diversity of image sequences in the deep network. It is defined as follows:
[0068]
[0069] in, Represents the nth image sequence feature of the first layer; Indicates that the i-th layer corresponds to the n-th image sequence feature; Indicates the transposition operation of the feature vector; N indicates the number of image sequences; represents the image sequence contrast loss function of the i-th layer;
[0070] Define the error loss function of the i-th layer Each deep image sequence in the Transformer model should only focus on the corresponding image sequence input from the shallow layer, and ignore the remaining irrelevant image sequence features, which are defined as follows:
[0071]
[0072] in, Represents the nth image sequence feature of the first layer; Indicates that the i-th layer corresponds to the n-th image sequence feature; N represents the number of image sequences; represents the error loss function of the image sequence of the i-th layer;
[0073] The loss function for overall network training is defined as the weighted sum of the six-stage Transformer model loss functions and the photometric loss function. The formula is as follows:
[0074]
[0075] Among them, λ1, λ2, and λ3 are constraint balance factors, which respectively represent the proportion of the loss function of the Transformer model at different pyramid scales. The statistical loss function of the higher-resolution layer plays a greater role in network training, and the weight coefficient is higher. They represent the feature similarity loss function, contrast loss function and error loss function of the i-th layer Transformer model respectively; represents the occlusion compensation loss function in the i-th layer optical flow estimation network, and finally calculates the obtained Lfinal is the loss function for the final overall network training.
[0076] The beneficial effects of the present invention are:
[0077] The present invention introduces the Transformer model into the feature pyramid network to enhance the feature extraction capability of the network, and trains the entire network by designing an occlusion compensation loss function to obtain the final predicted optical flow. The present invention can enhance the feature extraction capability of the feature pyramid layer for images, and perform occlusion compensation processing on occluded pixels in the image to improve the accuracy of optical flow estimation. BRIEF DESCRIPTION OF THE DRAWINGS
[0078] Figure 1 It is a flow chart of the present invention.
[0079] Figure 2 This is a schematic diagram of the Transformer feature pyramid in the present invention.
[0080] Figure 3 Schematic diagram of the image segmentation module in the present invention.
[0081] Figure 4 Schematic diagram of the convolutional mapping and re-attention mechanism module in the present invention.
[0082] Figure 5 This is the overall architecture diagram of the present invention.
[0083] Figure 6 This is a schematic diagram of the occlusion compensation principle in the present invention. DETAILED DESCRIPTION
[0084] The present invention is further described below in conjunction with the accompanying drawings.
[0085] The purpose of the present invention is to provide an unsupervised optical flow estimation method based on a Transformer feature pyramid network, which belongs to the field of computer vision. First, a Transformer feature pyramid network is constructed, and the Transformer model is used to enhance the feature extraction ability of the feature pyramid network for images through the re-attention mechanism operation. Secondly, an optical flow estimation network is constructed so that the network can perform optical flow prediction. Finally, occlusion compensation processing is performed on the pixels in the occluded area, and the loss function of the overall network training is designed to perform unsupervised training on the network, thereby obtaining a faster and more accurate unsupervised optical flow estimation model.
[0086] The present invention proposes an unsupervised optical flow estimation method based on Transformer feature pyramid network, which aims to enhance the feature extraction capability of the feature pyramid layer for images and perform occlusion compensation processing on occluded pixels in the image to improve the accuracy of optical flow estimation.
[0087] The object of the present invention is achieved in that:
[0088] Step 1: Build a Transformer-based feature pyramid network. The feature pyramid network has two identical network branches with a total of 12 layers, which can extract 6 types of image features. The network of each branch shares weights. The Transformer model is integrated in the second, fourth, sixth, eighth, tenth and last layers of the feature pyramid to enhance the feature extraction ability of the network. The model consists of an image segmentation module and a convolutional mapping re-attention mechanism module. The image segmentation module first performs a deformable convolution operation on the input image to extract local features such as edges, and then divides the image into sequences and inputs them into the convolutional mapping re-attention mechanism module. The convolutional mapping re-attention mechanism module performs a re-attention mechanism operation on the image sequence to extract global features.
[0089] Step 2: Construct an optical flow estimation network. The image features extracted from each layer of the Transformer feature pyramid network are input into the optical flow estimation network for prediction. The network consists of a 5-layer convolutional neural network. First, the input second frame image is feature deformed, and then the feature matching relationship between the second frame image after feature deformation and the first frame image is calculated, that is, the feature matching cost volume. The calculated feature matching cost volume is then input into the optical flow estimation network to predict the optical flow. The output optical flow result is post-processed using the context network to obtain an accurate predicted optical flow.
[0090] Step three: Perform occlusion compensation processing on the pixels in the occluded area. The specific operation of the occlusion compensation processing in the optical flow estimation network is to first compare the difference between the reconstructed image of the second frame and the first frame, and then extract the pixels in the occluded area and perform occlusion compensation processing on them. The difference comparison processing uses the predicted forward optical flow to distort the second frame image to reconstruct the first frame image, and the difference between the reconstructed first frame image and the original first frame image is added to the occlusion map. Extracting the pixels in the occluded area is to extract the pixels in the occluded area in the original first frame image to fill the reconstructed image, and perform occlusion compensation by calculating the difference between the reconstructed image and the original first frame image.
[0091] Step 4: Design the loss function for the overall network training. Combine the loss function with similarity information processing into the optical flow estimation network, and construct the loss function for the overall network training. Define a function that describes the feature similarity between different image blocks of the input Transformer model to promote diversity between different image blocks. At the same time, define a contrast loss function and an error loss function so that the features of interest in the deep layer of the network come from the corresponding inputs of the shallow layer and are independent of the remaining shallow inputs. Take the weighted sum of the loss terms corresponding to the Transformer model of each layer of the pyramid, and combine it with the occlusion compensation loss function as the overall loss function for network training to constrain the network training process.
[0092] Step 5: Input two consecutive frames of images at the network input end and use the overall network loss function to perform unsupervised training on the network.
[0093] Step 6: Input two consecutive frames of images into the trained model for testing, and output the corresponding estimated optical flow.
[0094] This invention is the first to introduce the Transformer model into the feature pyramid network to enhance the feature extraction capability of the network. At the same time, the overall network is trained by designing an occlusion compensation loss function to obtain the final predicted optical flow.
[0095] Embodiment 1:
[0096] Step 1: Build a Transformer-based feature pyramid network.
[0097] like Figure 2 As shown in the figure, the input image I is input into the feature pyramid network, which has 12 convolutional layers and contains 6 stages of Transformer models. The Transformer model in each stage has the same architecture and can gradually extract 6 feature maps of different sizes.
[0098] The number of channel features from the first to the sixth level are 16, 32, 64, 96, 128, and 196 respectively. The first convolution layer inputs a 3×512×512 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 16×512×512 feature map. The second convolution layer inputs a 16×512×512 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 16×256×256 feature map that is input into the Transformer model of the first stage.
[0099] The third convolutional layer inputs a 16×256×256 feature map, the convolution kernel size is 3×3, the stride is 1, and the output is a 16×256×256 feature map. The fourth convolutional layer inputs a 16×256×256 feature map, the convolution kernel size is 3×3, the stride is 2, and the output is a 32×128×128 feature map that is input to the second stage Transformer model.
[0100] The fifth convolutional layer inputs a 32×128×128 feature map, the convolution kernel size is 3×3, the stride is 1, and the output feature map is 32×128×128. The sixth convolutional layer inputs a 32×128×128 feature map, the convolution kernel size is 3×3, the stride is 2, and the output feature map is 64×64×64, which is input to the third stage Transformer model.
[0101] The seventh convolution layer inputs a 64×64×64 feature map, the convolution kernel size is 3×3, the stride is 1, and the output is a 64×64×64 feature map. The eighth convolution layer inputs a 64×64×64 feature map, the convolution kernel size is 3×3, the stride is 2, and the output is a 96×32×32 feature map that is input to the fourth stage Transformer model.
[0102] The ninth convolutional layer inputs a 96×32×32 feature map, the convolution kernel size is 3×3, the stride is 1, and the output feature map is 96×32×32. The tenth convolutional layer inputs a 96×32×32 feature map, the convolution kernel size is 3×3, the stride is 2, and the output feature map is 128×16×16, which is input to the fifth stage Transformer model.
[0103] The eleventh convolution layer inputs a 128×16×16 feature map, the convolution kernel size is 3×3, the stride is 1, and the output is a 128×16×16 feature map. The twelfth convolution layer inputs a 128×16×16 feature map, the convolution kernel size is 3×3, the stride is 2, and the output is a 196×8×8 feature map that is input to the sixth stage Transformer model.
[0104] The feature map output by the convolutional layer enters the Transformer model and is then output to the next convolutional layer of the feature pyramid to enhance the network's ability to extract features from the image.
[0105] The Transformer model consists of two parts, namely the image segmentation module and the convolutional map re-attention mechanism module. First, the standard Transformer module is used to process machine language translation. The input is a 1D language sequence. In order to process 2D images, the image segmentation module segments the input image, such as Figure 3As shown in the figure. This module first performs a deformable convolution operation on the input image, so that the number of image sequences in the input convolution map and the attention mechanism module gradually decreases, thereby reducing the feature resolution. At the same time, the width of the input sequence is expanded, so that the feature size increases, achieving the purpose of gradually reducing the feature resolution and increasing the feature size as the number of convolution layers increases. There are four layers of deformable convolution, each of which is composed of a standard convolution layer and a deviation layer. The first layer of the standard convolution layer has a convolution kernel size of 7×7 and a step size of 2. The convolution kernel size of the second and third layers is 3×3 and a step size of 1. The convolution kernel size of the fourth layer is 7×7 and a step size of 2. The deviation layer of each layer is used to learn the feature map output by the previous standard convolution layer to obtain the deformation offset of the deformable convolution.
[0106] Let the output image of the i-th layer of each pyramid based on the Transformer feature pyramid network branch be x i , the characteristic size of the output image is Among them, H i ×W i represents the resolution of the i-th layer image, C i Indicates the number of channels of the i-th layer image. Output image x of this layer of pyramid i Input to the image segmentation module, first extract edge features through deformable convolution operation to obtain the output image x′ i , the image after the deformable convolution operation is batch normalized and max pooled to obtain the output image x″ i , defined as follows:
[0107] x″ i =MaxPool(BN(Deconv(x i )))
[0108] Among them, Deconv(·) represents the deformable convolution operation, BN(·) represents batch normalization, MaxPool(·) represents the maximum pooling, and x i represents the output image of the i-th layer pyramid, x″ i Represents the output image after the maximum pooling operation. After the maximum pooling, the image x" i The 2D image blocks x″′ are cut into i , each image block x″′ i The dimension is N represents the output image x″ i The number of image sequences after segmentation is also the effective length of the input convolutional map and attention mechanism module, and (P,P) represents the resolution of each image block after segmentation.
[0109] Flatten the segmented image blocks into N image sequences Each image sequence is a two-dimensional matrix (N, D), D = P 2 C. The converted image sequence is marked by a binary mask, where the 1 position represents the image sequence with important information, and the 0 position represents the image sequence with similar information. According to the different information contained in the image sequence, the image sequence is adaptively selected for marking, and the marked image sequence is input into the convolutional mapping and attention mechanism module, where the image sequences marked as 1 are interactively calculated with each other, and the image sequences marked as 0 are only calculated with themselves.
[0110] The convolutional map re-attention mechanism module contains two parts: multi-head re-attention mechanism operation and multi-head linear processing. First, the input image sequence Perform multi-head re-attention mechanism operations, such as Figure 4 As shown. This module first inputs the i-th layer image sequence After linear mapping to high-dimensional space, it is reorganized into a 2D image, and then three depth-separable convolution operations are performed to obtain the features of the three projections. The features after the three projections are flattened to obtain three different two-dimensional vectors in the i-th layer. Each vector is defined as follows:
[0111]
[0112] Among them, Reshape2d(·) means spatially reorganizing the image sequence, s means the size of the convolution kernel, conv2d(·) means depthwise separable convolution operation, and Flatten(·) means flattening after mapping to obtain a two-dimensional vector. represents the i-th layer flattened image sequence, represents the two-dimensional vector obtained by flattening the i-th layer after the depthwise separable convolution operation. Input into the multi-head re-attention mechanism, the two-dimensional vector mapped from each input image sequence can be represented by a matrix q = [q1, q2, ..., q N ],k=[k1,k2,...,k N ],v=[v1,v2,...,v N ]. As the depth of the model increases, the attention similarity of the same image sequence in different layers is large, but the similarity between multiple heads from the same layer is small. A transfer matrix is used to combine the information between different heads and use them to perform attention operations again. The transfer matrices trained in different layers are different, so as to avoid attention collapse. The operation of the multi-head re-attention mechanism is defined as follows:
[0113]
[0114] Among them, q, k, v represent the matrices obtained by convolution mapping of each input image sequence, T represents the transpose operation of the matrix, q·k T represents the correlation between two positions, and softmax(·) represents the correlation between q·k T Perform normalization operation, d represents the dimension of q and k, θ represents the dimension acting on multi-head attention, represents the sequence of image slices flattened by convolution mapping after spatial reorganization, Indicates that a multi-head re-attention mechanism operation is performed on the image slice sequence. The next layer of the multi-head re-attention operation is the batch normalization layer, which adds the input and output of the multi-head re-attention mechanism operation and then performs batch normalization to normalize the activation values of each layer. The specific definition is as follows:
[0115]
[0116] Among them, MSA(·) represents the multi-head attention mechanism operation, BN(·) represents batch normalization processing, represents the sequence of image slices flattened by convolution mapping after spatial reorganization, Represents the image sequence output after batch normalization. The multi-head linear processing operation includes a feedforward network and batch normalization. The feedforward network expands the dimension of each image sequence. The activation function of batch normalization is GELU nonlinear activation. After each operation, a residual connection is performed to prevent network degradation. The specific definition is as follows:
[0117]
[0118] Among them, FFN(·) represents the feedforward network, BN(·) represents batch normalization, GELU(·) represents the Gaussian error linear unit activation function, represents the image sequence output after batch normalization of multi-head re-attention operation, It means that multi-head linear processing is performed on the output image after the multi-head re-attention operation. The image sequence after the output of this layer is linearly mapped and dimensionally reduced, and then spatially reorganized into a 2D image and output to the feature pyramid layer of the next layer. The model training is repeated N times.
[0119] Step 2: Build an optical flow estimation network.
[0120] like Figure 5 As shown in the figure, given two input images I1 and I2, the feature pyramid has two identical shared weight branches. The second image I2 is subjected to feature deformation. The specific operation is to use the output estimated optical flow from the pyramid layer i-1 to perform a 2-fold upsampling and then perform bilinear interpolation deformation on the features of the second image toward the first image. The feature deformation operation is defined as follows:
[0121]
[0122] Among them, x represents the pixel value, It means that the optical flow result obtained by the i-1 layer optical flow estimation network is upsampled by 2 times. represents the image features of the i-th layer of the second image of the pyramid, Represents the image features after feature deformation. Calculate the correlation between the features of the second image after feature deformation and the features of the first image, that is, calculate the feature matching cost volume of each layer. The calculation definition of the feature matching cost volume is as follows:
[0123]
[0124] Among them, x1 and x2 represent the pixel values of the first and second images respectively. represents the feature map of the first image on the i-th level of the pyramid, It represents the image features after feature deformation of the second image on the i-th layer of the pyramid, M represents the length of the feature map, T represents the transposition operation of the matrix, and finally the CV obtained by calculation is i (x1,x2) represents the cost volume result of the feature map matching cost of the i-th layer of the feature pyramid.
[0125] The obtained feature matching cost volume result, the features of the first image, and the high-resolution optical flow obtained by upsampling are input into the optical flow estimation network of the i-th layer to obtain the optical flow estimation result of this layer. The optical flow estimation layer uses a five-layer convolutional network, and the number of channels of each convolutional layer is 128, 128, 96, 64, and 32 respectively. The output optical flow result is post-processed by the context network, such as median filtering or bilateral filtering. The context network is a feed-forward convolutional neural network based on the dilated convolution design. It consists of 7 layers of convolutional networks. The convolution kernel of each convolutional layer is 3×3. These layers have different expansion coefficients. The convolution expansion coefficient k indicates that the input unit of the filter in this layer is k units away from other input units of the filter in this layer in the vertical and horizontal directions. From top to bottom, the expansion coefficients of the convolutional layers are 1, 2, 4, 8, 16, 1, and 1 respectively. The convolutional layer with a large expansion coefficient can effectively expand the size of the receptive field of each output unit on the pyramid to output a refined optical flow.
[0126] Step 3: Perform occlusion compensation processing on the pixels in the occluded area.
[0127] like Figure 6As shown in the figure, the specific operation of occlusion compensation processing in the optical flow estimation network is to first compare the predicted optical flow image with the original image, and then extract the pixels in the occluded area to perform occlusion compensation processing on them. The difference comparison processing uses the predicted forward optical flow to distort the second frame image I2 to synthesize the first frame reconstructed image I′1, and add the difference between the reconstructed image I′1 and the original image I1 to the occlusion map, which is defined as follows:
[0128]
[0129] Among them, x represents the pixel value, o fw represents the occlusion map, I1(x) and I1(x) represent the first frame original image and the second frame reconstructed image respectively, σ(·) represents the pixel-level similarity metric, which is used to calculate the similarity between the original image I1(x) and the reconstructed image I′1(x). Finally, the obtained is the difference contrast loss in the i-th layer optical flow estimation network. Extracting pixels in the occluded area is to use the corresponding pixels in the occluded area in the original image I1 to fill the image I′1 to obtain the reconstructed image I″1. The loss in the occluded area is calculated by the difference between the reconstructed image I″1 and I1, which is defined as follows:
[0130]
[0131] Where x represents the pixel value, I″1(x) represents the reconstructed pixel obtained by adding the corresponding occluded pixel to the reconstructed first image I′1(x), σ(·) represents the pixel-level similarity measure, and the final calculation is is the loss in the occluded area in the i-th layer optical flow estimation network. Finally, the occlusion compensation loss function in the i-th layer optical flow estimation network is It is obtained by summing two loss functions and is defined as follows:
[0132]
[0133] in, represents the difference contrast loss in the i-th layer optical flow estimation network, represents the loss in the occluded area in the i-th layer optical flow estimation network, Represents the occlusion compensation loss function in the i-th layer optical flow estimation network.
[0134] Step 4: Design the loss function for overall network training
[0135] The loss function of the Transformer model with similarity information processing is combined with the optical flow estimation network. As the Transformer model continues to deepen, the similarity between different input image sequences continues to increase, so the feature similarity loss function between different image sequences at the i-th layer is defined Suppose the features of the input image x and its N image sequence corresponding to the i-th layer are And the feature similarity function As a penalty term in the loss function to promote diversity between different image sequences, it is defined as follows:
[0136]
[0137] Where N represents the total number of image segments, ·2 represents the L2 norm operation, T represents the transpose operation of the vector, and x n , x m Respectively represent the characteristics of different image slice sequences of the same layer, The feature similarity loss function represents the similarity between different image sequences at the i-th layer.
[0138] Define the contrast loss function for the i-th layer The features learned in the shallow layers of the Transformer model are more diverse than those learned in the deep layers. The contrast loss function can use the features learned in the shallow layers to regularize the deep features to reduce the similarity between different image sequences and increase the feature diversity of image sequences in the deep network. It is defined as follows:
[0139]
[0140] in, represents the nth image sequence feature of the first layer, Indicates that the i-th layer corresponds to the n-th image sequence feature, Indicates the transposition operation of the feature vector, N represents the number of image sequences, represents the contrast loss function of the image sequence at the i-th layer.
[0141] Define the error loss function of the i-th layer Each deep image sequence in the Transformer model should only focus on the corresponding image sequence input from the shallow layer and ignore the remaining irrelevant image sequence features, which are defined as follows:
[0142]
[0143] in, represents the nth image sequence feature of the first layer, Indicates that the i-th layer corresponds to the n-th image sequence feature, N represents the number of image sequences, Represents the error loss function of the image sequence of the i-th layer.
[0144] The total network training loss function is defined as the weighted sum of the six-stage Transformer model loss functions and the photometric loss function. The formula is as follows:
[0145]
[0146] Among them, λ1, λ2, and λ3 are constraint balance factors, which respectively represent the proportion of the loss function of the Transformer model at different pyramid scales. The higher the resolution, the greater the role of the statistical loss function in network training, and the higher the weight coefficient. They represent the feature similarity loss function, contrast loss function and error loss function of the i-th layer Transformer model respectively. represents the occlusion compensation loss function in the i-th layer optical flow estimation network, and finally calculates the obtained L final is the loss function for the final network training.
[0147] Step 5: Input two consecutive frames of images at the network input end and use the overall network loss function to perform unsupervised training on the network.
[0148] Step 6: Input two consecutive frames of images into the trained model for testing, and output the corresponding estimated optical flow.
[0149] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. An unsupervised optical flow estimation method based on Transformer feature pyramid network, characterized in that: The following steps are involved: Step 1: Build a Transformer-based feature pyramid network; Based on the Transformer feature pyramid network, there are two completely identical network branches with a total of 12 layers, which can extract 6 types of image features, and the network of each branch shares weights; the Transformer model is integrated in the second, fourth, sixth, eighth, tenth and last layers of the Transformer feature pyramid network to enhance the feature extraction ability of the network. The model consists of an image segmentation module and a convolutional mapping re-attention mechanism module; the image segmentation module first performs a deformable convolution operation on the input image to extract local features such as edges, and then divides the image into sequences and inputs them into the convolutional mapping re-attention mechanism module; the convolutional mapping re-attention mechanism module performs a re-attention mechanism operation on the image sequence to extract global features; Step 2: Build an optical flow estimation network; input the image features extracted from each layer of the Transformer feature pyramid network into the optical flow estimation network for prediction; The optical flow estimation network is composed of a 5-layer convolutional neural network. First, the input second frame image is feature deformed, and then the feature matching relationship between the second frame image after feature deformation and the first frame image, that is, the feature matching cost volume, is calculated. Then, the calculated feature matching cost volume is input into the optical flow estimation network to predict the optical flow, and the output optical flow result is post-processed using the context network to obtain an accurate predicted optical flow; Step 3: Perform occlusion compensation processing on the pixels in the occluded area; The specific operation of occlusion compensation processing in the optical flow estimation network is to first compare the difference between the second frame reconstructed image and the first frame image, and then extract the pixels in the occluded area and perform occlusion compensation processing on them; The difference contrast processing is to use the predicted forward optical flow to distort the second frame image to reconstruct the first frame image, and add the difference between the reconstructed first frame image and the original first frame image to the occlusion map; extracting the occlusion area pixels is to extract the occlusion area pixels in the original first frame image to fill the reconstructed image, and the occlusion compensation is performed by calculating the difference between the reconstructed image and the original first frame image; Step 4: Design the loss function for the overall network training; combine the loss function with similarity information processing into the optical flow estimation network, and construct the loss function for the overall network training; define a function that describes the feature similarity between different image blocks of the input Transformer model to promote the diversity between different image blocks, and define a contrast loss function and an error loss function, so that the attention features of the deep layer of the network come from the corresponding input of the shallow layer and are independent of the rest of the shallow layer inputs; The weighted sum of the loss items corresponding to the Transformer model of each layer of the pyramid is combined with the occlusion compensation loss function as the overall loss function of the network training to constrain the network training process; Step 5: Input two consecutive frames of images at the network input end, and use the overall network loss function to perform unsupervised training on the network; Step 6: Input two consecutive frames of images into the trained model for testing, and output the corresponding estimated optical flow.
2. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 1, characterized in that: In step 1, the Transformer feature pyramid network has 12 convolutional layers, including 6 stages of Transformer models. The Transformer models in each stage have the same architecture and can gradually extract 6 feature maps of different sizes. The number of channel features from the first level to the sixth level are 16, 32, 64, 96, 128, and 196 respectively. The first convolutional layer inputs a 3×512×512 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 16×512×512 feature map; the second convolutional layer inputs a 16×512×512 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 16×256×256 feature map that is input into the first stage Transformer model; The third convolution layer inputs a 16×256×256 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 16×256×256 feature map; the fourth convolution layer inputs a 16×256×256 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 32×128×128 feature map that is input into the second stage Transformer model; The fifth convolutional layer inputs a 32×128×128 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 32×128×128 feature map; the sixth convolutional layer inputs a 32×128×128 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 64×64×64 feature map that is input into the third stage Transformer model; The seventh convolutional layer inputs a 64×64×64 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 64×64×64 feature map; The eighth convolution layer inputs a 64×64×64 feature map, the convolution kernel size is 3×3, the stride is 2, and the output feature map of 96×32×32 is input into the fourth stage Transformer model; The ninth convolutional layer inputs a 96×32×32 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 96×32×32 feature map; the tenth convolutional layer inputs a 96×32×32 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 128×16×16 feature map that is input into the fifth stage Transformer model; The eleventh convolution layer inputs a 128×16×16 feature map, the convolution kernel size is 3×3, the step size is 1, and the output is a 128×16×16 feature map; the twelfth convolution layer inputs a 128×16×16 feature map, the convolution kernel size is 3×3, the step size is 2, and the output is a 196×8×8 feature map that is input into the sixth stage Transformer model; The feature map output by the convolutional layer enters the Transformer model and is then output to the next convolutional layer of the feature pyramid to enhance the network's ability to extract features from the image.
3. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 1, characterized in that: In step 1, the image segmentation module based on the Transformer feature pyramid network first performs a deformable convolution operation on the input image, so that the number of image sequences in the input convolution mapping and attention mechanism module is gradually reduced, thereby reducing the feature resolution, and at the same time expanding the width of the input sequence, so that the feature size is increased, so as to achieve the purpose of gradually reducing the feature resolution and increasing the feature size as the number of convolution layers increases. The specific steps are: Step 1.1.1: Output image x of the i-th pyramid layer i Input to the image segmentation module, first extract edge features through deformable convolution operation to obtain the output image x′ i , the image after the deformable convolution operation is batch normalized and max pooled to obtain the output image x″ i ; x″ i =MaxPool(BN(Deconv(x i ))) Among them, x i is the output image of the i-th layer pyramid based on the Transformer feature pyramid network, and the feature size of the output image is H i ×W i represents the resolution of the i-th layer image, C i represents the number of channels of the i-th layer image; Deconv(·) represents the deformable convolution operation; BN(·) represents batch normalization; MaxPool(·) represents maximum pooling; x″ i Represents the output image after the maximum pooling operation; Step 1.1.2: After the maximum pooling, the image x″ is obtained i Cut into 2D image blocks x″′ i , each image block x″′ i The dimension is N represents the output image x″ i The number of image sequences after segmentation is also the effective length of the input convolutional map and attention mechanism module, and (P,P) represents the resolution of each image block after segmentation; Step 1.1.3: Flatten the segmented image blocks into N image sequences Each image sequence is a two-dimensional matrix (N, D), D = P 2 C; Step 1.1.4: Mark the converted image sequence through a binary mask, where the 1 position represents the image sequence with important information, and the 0 position represents the image sequence with similar information. According to the different information contained in the image sequence, the image sequence is adaptively selected for marking, and the marked image sequence is input into the convolutional mapping and attention mechanism module, where the image sequences marked as 1 are interactively calculated with each other, and the image sequences marked as 0 are only calculated with themselves.
4. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 3, characterized in that: The convolutional mapping re-attention mechanism module based on the Transformer feature pyramid network in step 1 includes two parts: multi-head re-attention mechanism operation and multi-head linear processing. The specific steps are: Step 1.2.1: Input the i-th layer image sequence After linear mapping to high-dimensional space, it is reorganized into a 2D image, and then three depth-separable convolution operations are performed to obtain the features of the three projections. The features after the three projections are flattened to obtain three different two-dimensional vectors in the i-th layer. Each vector is defined as follows: Among them, Reshape2d(·) means spatial reorganization of the image sequence; s means the size of the convolution kernel; conv2d(·) means depthwise separable convolution operation; Flatten(·) means flattening after mapping to obtain a two-dimensional vector; represents the i-th layer flattened image sequence; Represents the two-dimensional vector obtained by flattening the i-th layer after the depth-wise separable convolution operation; Step 1.2.2: The obtained two-dimensional vector Input into the multi-head re-attention mechanism, the two-dimensional vector mapped from each input image sequence can be represented by a matrix q = [q1, q2, ..., q N ],k=[k1,k2,...,k N ],v=[v1,v2,...,v N ]; As the model depth increases, the attention similarity of the same image sequence in different layers is large, but the similarity between multiple heads from the same layer is small. A transfer matrix is used to combine the information between different heads and use them to perform attention operations again. The transfer matrices trained in different layers are different, so as to avoid attention collapse; The operation definition of the multi-head re-attention mechanism is as follows: Among them, q, k, v represent the matrices obtained by convolution mapping of each input image sequence; T represents the transpose operation of the matrix; q·k T represents the correlation between two positions; softmax(·) represents the correlation between q·k T Perform normalization operation; d represents the dimension of q and k; θ represents the dimension acting on multi-head attention; represents a sequence of image slices flattened by convolution mapping after spatial reorganization; Indicates that a multi-head re-attention mechanism is performed on the image slice sequence; Step 1.2.3: Add the input and output of the multi-head attention mechanism operation and then perform batch normalization to normalize the activation values of each layer. The specific definition is as follows: Among them, MSA(·) represents the multi-head attention mechanism operation; BN(·) represents batch normalization processing; represents a sequence of image slices flattened by convolution mapping after spatial reorganization; Represents the image sequence output after batch normalization; Step 1.2.4: The multi-head linear processing operation includes a feedforward network and batch normalization. The feedforward network expands the dimension of each image sequence. The activation function of batch normalization is GELU nonlinear activation. After each operation, a residual connection is performed to prevent network degradation. The specific definitions are as follows: Among them, FFN(·) represents the feedforward network; BN(·) represents batch normalization processing; GELU(·) represents the Gaussian error linear unit activation function; Represents the image sequence output after batch normalization processing of multi-head re-attention operation; Indicates multi-head linear processing of the output image after the multi-head re-attention operation; Step 1.2.5: Linearly map the image sequence output by the multi-head linear processing operation and reduce its dimension, then spatially reorganize it into a 2D image and output it to the next feature pyramid layer.
5. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 1, characterized in that: The input of the optical flow estimation network in step 2 is two consecutive frames of images, and the output is the corresponding estimated optical flow. The specific steps are: Step 2.1: For the two consecutive input frames of images I1 and I2, the second image I2 is feature deformed. The output estimated optical flow from the i-1th layer based on the Transformer feature pyramid network is upsampled by 2 times and then the features of the second image are bilinearly interpolated to the first image. The feature deformation operation is defined as follows: Where x represents the pixel value; Indicates that the optical flow result obtained by the i-1 layer optical flow estimation network is upsampled by 2 times; Represents the image features of the i-th layer of the second image of the pyramid; Represents the image features after feature deformation; Step 2.2: Calculate the correlation between the features of the second image after feature deformation and the features of the first image, that is, calculate the feature matching cost volume of each layer. The calculation definition of the feature matching cost volume is as follows: Among them, x1 and x2 represent the pixel values of the first and second images respectively; Represents the feature map of the first image on the i-th layer based on the Transformer feature pyramid network; represents the image features after feature deformation of the second image on the i-th layer based on the Transformer feature pyramid network; M represents the length of the feature map; T represents the transposition operation of the matrix; CV i (x1,x2) represents the cost volume result of the feature map matching cost based on the i-th layer of the Transformer feature pyramid network; Step 2.3: Input the feature matching cost volume result, the features of the first image, and the high-resolution optical flow obtained by upsampling into the i-th optical flow estimation layer of the optical flow estimation network to obtain the optical flow estimation result of this layer.
6. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 5, characterized in that: The optical flow estimation layer of the optical flow estimation network in step 2.3 uses a five-layer convolutional network, and the number of channels of each convolutional layer is 128, 128, 96, 64, and 32 respectively. The output optical flow result is post-processed by a context network; the context network is a feedforward convolutional neural network, based on the dilated convolution design, and consists of 7 layers of convolutional networks. The convolution kernel of each convolutional layer is 3×3, and these layers have different expansion coefficients. The convolution expansion coefficient k indicates that the input unit of the filter in the layer is k units away from other input units of the filter in the layer in the vertical and horizontal directions; from top to bottom, the expansion coefficients of the convolutional layers are 1, 2, 4, 8, 16, 1, and 1 respectively. The convolutional layers with large expansion coefficients can effectively expand the size of the receptive field of each output unit on the pyramid to output a refined optical flow.
7. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 1, characterized in that: In step 3: the method for performing occlusion compensation processing on pixels in the occluded area is specifically as follows: The predicted optical flow image is compared with the original image, and then the pixels in the occluded area are extracted to perform occlusion compensation processing; the difference comparison processing uses the predicted forward optical flow to distort the second frame image I2 to synthesize the first frame reconstructed image I′1, and the difference between the reconstructed image I′1 and the original image I1 is added to the occlusion map, which is defined as follows: Among them, x represents the pixel value; o fw represents the occlusion map; I1(x) and I′1(x) represent the original image of the first frame and the reconstructed image of the second frame, respectively; σ(·) represents the pixel-level similarity metric, which is used to calculate the similarity between the original image I1(x) and the reconstructed image I′1(x); The difference contrast loss in the i-th layer optical flow estimation network; Extracting pixels in the occluded area is to use the corresponding pixels in the occluded area in the original image I1 to fill the image I′1 to obtain the reconstructed image I″1. The loss in the occluded area is calculated by the difference between the reconstructed image I″1 and I1, which is defined as follows: Where x represents the pixel value; I″1(x) represents the reconstructed pixel obtained by adding the corresponding occluded pixel to the reconstructed first image I′1(x); σ(·) represents the pixel-level similarity measure; The loss in the occluded region in the i-th layer optical flow estimation network; Finally, the occlusion compensation loss function in the i-th layer optical flow estimation network It is obtained by summing two loss functions and is defined as follows: in, represents the difference contrast loss in the i-th layer optical flow estimation network; represents the loss in the occluded area in the i-th layer optical flow estimation network; Represents the occlusion compensation loss function in the i-th layer optical flow estimation network.
8. The unsupervised optical flow estimation method based on Transformer feature pyramid network according to claim 1, characterized in that: The loss function of the overall network training in step 4 is: Let the features of the input image x and its N image sequence corresponding to the i-th layer be And the feature similarity function As a penalty term in the loss function to promote diversity between different image sequences, it is defined as follows: Where N represents the total number of image segments; ||·||2 represents the L2 norm operation; T represents the transpose operation of the vector; x n , x m Respectively represent the features of different image slice sequences of the same layer; The feature similarity loss function representing the similarity between different image sequences at the i-th layer; Define the contrast loss function for the i-th layer The features learned in the shallow layers of the Transformer model are more diverse than those learned in the deep layers. The contrast loss function can use the features learned in the shallow layers to regularize the deep features to reduce the similarity between different image sequences and increase the feature diversity of image sequences in the deep network. It is defined as follows: in, Represents the nth image sequence feature of the first layer; Indicates that the i-th layer corresponds to the n-th image sequence feature; Indicates the transposition operation of the feature vector; N indicates the number of image sequences; represents the image sequence contrast loss function of the i-th layer; Define the error loss function of the i-th layer Each deep image sequence in the Transformer model should only focus on the corresponding image sequence input from the shallow layer, and ignore the remaining irrelevant image sequence features, which are defined as follows: in, Represents the nth image sequence feature of the first layer; Indicates that the i-th layer corresponds to the n-th image sequence feature; N represents the number of image sequences; represents the error loss function of the image sequence of the i-th layer; The loss function for overall network training is defined as the weighted sum of the six-stage Transformer model loss functions and the photometric loss function. The formula is as follows: Among them, λ1, λ2, and λ3 are constraint balance factors, which respectively represent the proportion of the loss function of the Transformer model at different pyramid scales. The statistical loss function of the higher-resolution layer plays a greater role in network training, and the weight coefficient is higher. They represent the feature similarity loss function, contrast loss function and error loss function of the i-th layer Transformer model respectively; represents the occlusion compensation loss function in the i-th layer optical flow estimation network, and finally calculates the obtained L final is the loss function for the final overall network training.
Citation Information
Patent Citations
Image Semantic Segmentation Method Based on Deep Full Convolutional Network and Conditional Random Field
AU2020103901A4
Unsupervised learning optical flow estimation method based on space and channel joint attention mechanism
CN111582483A
