Monocular depth prediction method and device based on two-stage jump attention and dynamic position coding
By employing a two-stage skip attention and dynamic position coding approach, the problems of insufficient adaptability of multi-scale feature fusion and static position coding in monocular depth prediction are solved, achieving high-precision and real-time depth perception in complex scenes.
Patent Information
- Application Number
- CN202510840945.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-06-22
- Publication Date
- 2025-10-31
AI Technical Summary
Existing monocular depth prediction methods have limitations in multi-scale feature fusion under complex dynamic scenes, insufficient adaptability of static position encoding, low computational efficiency, and difficulty in meeting the real-time requirements of autonomous driving systems.
A two-stage skip attention and dynamic position encoding method is adopted. Multi-scale features are fused through local windows and global context, and weighted summation is performed on non-uniform depth candidate values to generate dynamic position encoding, which is then added to the features encoded by Transformer, thereby achieving continuity of deep features and context enhancement.
It significantly improves the accuracy and robustness of depth prediction, maintains high-precision depth estimation in complex scenarios, reduces prediction errors, enhances the ability to express scene context information, and meets the real-time requirements of autonomous driving systems.
Smart Images

Figure CN120877036A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of computer vision and autonomous driving technology, specifically relating to a monocular depth prediction method based on two-stage jump attention and dynamic position coding. Background Technology
[0002] In the field of monocular depth prediction, to improve the environmental perception capabilities of autonomous driving systems, accurate depth cues are needed for 3D object detection and scene understanding. Traditional methods typically construct depth prediction models through multi-scale feature fusion, but face the following key challenges in complex dynamic scenes: Limitations of multi-scale feature fusion. Existing methods (such as FPN and PANet) use direct averaging or cascading to fuse feature maps from different levels, leading to conflicts between shallow detail information and deep semantic information. For example, MonoDETR uses three-scale feature averaging fusion. Insufficient adaptability of static position encoding. Static depth encoding based on uniform binning (such as DepthFormer) cannot adapt to the non-uniform characteristics of scene depth distribution. Computational efficiency bottleneck. Although global attention mechanisms (such as Transformer) can capture long-range dependencies, their computational complexity is O(H). 2 W 2 This makes it difficult to meet real-time requirements.
[0003] To address the above issues, researchers have attempted optimizations using the following methods: Dynamic binning strategies. Lightweight networks are used to predict non-uniform depth intervals (such as AdaBins), but this approach lacks sufficient modeling of contextual relationships for multi-scale features, resulting in significant depth errors for distant targets in urban scenes. Local attention mechanisms. Window-based attention computation (such as the Swin Transformer) reduces the complexity to O(M). 2 HW), but a fixed window size is difficult to adapt to targets of different scales.
[0004] While the aforementioned methods partially alleviate the problem, cross-scale feature semantic conflicts and the balance between dynamic scene encoding adaptability and computational efficiency remain unresolved technical challenges. Therefore, a depth prediction method that can adaptively fuse multi-scale features, dynamically model depth distributions, and ensure real-time performance is needed to meet the robust perception requirements of autonomous driving systems in complex scenarios. Summary of the Invention
[0005] To address the aforementioned technical problem of semantic conflict in multi-scale feature fusion, this invention proposes a monocular depth prediction method based on two-stage skip attention and dynamic position encoding, comprising the following steps:
[0006] S1. Multi-scale feature maps are progressively fused through a two-stage skip attention module, including the first stage of local window attention fusing 1 / 8 and 1 / 16 features, and the second stage of global context fusing intermediate features and 1 / 32 features;
[0007] S2. Generate a depth classification probability distribution based on the fusion features, and perform a weighted summation of non-uniform depth candidate values to output a weighted depth map;
[0008] S3. Using the weighted depth map, perform linear interpolation in the position encoding embedding table to generate dynamic position codes, and add them to the features encoded by Transformer to obtain the final depth features.
[0009] Optionally, step S1 further includes:
[0010] S11) Obtain a multi-scale feature map from a monocular image, wherein the multi-scale feature map includes a first, second, and third feature map obtained by downsampling at scales of 1 / 8, 1 / 16, and 1 / 32;
[0011] S12) Input the first feature map and the second feature map into the jump attention module (SAM), and perform multi-head self-attention fusion and multilayer perceptron transformation respectively within a local fixed window to generate the first stage fusion feature;
[0012] S13) Input the first-stage fused features and the third feature map into the jump attention module again, and generate the second-stage fused features through multi-head self-attention and multilayer perceptron with the same or adjustable window size.
[0013] Optionally, step S2 further includes:
[0014] S24) The second-stage fusion features are sequentially processed by the depth prediction head and classifier to obtain depth classification logits, and the probability distribution of each depth interval is obtained through Softmax operation;
[0015] S25) The weighted depth map is obtained by weighting and summing the probability distribution with the preset non-uniform depth candidate value sequence.
[0016] Optionally, step S3 further includes:
[0017] S36) Using the weighted depth map as a coordinate index, linear interpolation is performed in the depth position code embedding table to generate a dynamic position code;
[0018] S37) Flatten the second-stage fused features and input them into the Transformer encoder to obtain context-enhanced features. Add the features to the dynamic position encoding to output the final depth features.
[0019] Optionally, the jump attention module (SAM) includes:
[0020] A local windowing multi-head self-attention layer with a fixed window size of w×w; residual connections combining a normalization layer (LayerNorm) and a multilayer perceptron are used to enhance cross-window feature representation;
[0021] Its expression is:
[0022]
[0023] Where Q is the query vector, K and V are key vectors, and B is the relative position encoding matrix.
[0024] Optionally, the generation of the first stage fusion feature in step S12) further includes performing convolutional downsampling and 1×1 convolutional projection on the first feature map and the second feature map respectively, so that the two have the same spatial resolution before inputting them into the SAM module.
[0025] Optionally, the generation of the second-stage fusion feature in step S13) further includes bilinear interpolation of the third feature map to the resolution of the first-stage fusion feature before inputting it into the SAM module for fusion.
[0026] Optionally, step S25) generates the preset non-uniform depth candidate value sequence using the following formula:
[0027]
[0028] Where, d min ,d max These represent the minimum and maximum depths, respectively, and N is the number of depth bins.
[0029] Optionally, the linear interpolation in step S36) is calculated using the following formula:
[0030]
[0031] Where z represents the continuous depth value at the corresponding pixel. E is the depth location encoding embedding table.
[0032] Optionally, the Transformer encoder contains only a single-layer encoder structure for contextual enhancement of flattened features to reduce computational load and meet real-time inference requirements.
[0033] Furthermore, existing technologies suffer from semantic conflicts in multi-scale feature fusion, and depth position encoding is mostly static and discrete, making it difficult to adapt to the needs of continuous depth changes in real-world scenarios. This results in insufficient depth prediction accuracy and weak context awareness. To address these technical problems, this invention proposes a deep feature fusion method with a skip-attention dual-stage progressive fusion strategy. This invention employs a local window multi-head attention mechanism to fuse features at scales of 1 / 8 and 1 / 16 respectively, and then fuses global features at scale 1 / 32 in a subsequent stage. Simultaneously, a depth interval regression and continuous depth value-guided position encoding interpolation mechanism are introduced in the depth output stage to achieve synergistic enhancement of geometric and contextual information. The objective of this invention can be achieved through the following technical solutions:
[0034] A monocular depth prediction method based on two-stage skip attention and dynamic position encoding includes the following steps:
[0035] 1) Feature preprocessing: The ResNet-50 feature extraction backbone network is used to extract multi-scale features from the input image, generating feature maps with resolutions of 1 / 8, 1 / 16, and 1 / 32. For each scale feature, convolution downsampling, 1×1 projection or bilinear interpolation plus 1×1 convolution and GroupNorm operations are performed to unify them to a fusionable spatial resolution and number of channels.
[0036] 2) Two-Stage Skip Attention Fusion: This process involves multi-scale feature fusion in two stages. In the first stage, a multi-head self-attention mechanism with local windows is used to fuse the 1 / 8 and 1 / 16 scale feature maps. In the second stage, the fused intermediate features are combined with the global features at the 1 / 32 scale. A skip attention module is introduced to achieve flexible fusion of local and global features. The SAM module is plug-and-play, seamlessly embedding itself into different feature layers, effectively promoting information interaction among multi-scale features and mitigating semantic conflicts that occur in traditional multi-scale fusion. Through staged, progressive fusion, information from different scales is integrated layer by layer, significantly enhancing the network's adaptability to changes in near and far scales.
[0037] 3) Depth Prediction and Interpolation Location Encoding Generation: In the depth output stage, depth classification prediction is combined with interval regression to obtain continuous depth values. Specifically, the classification probability is calculated for each preset depth interval, and the depth values are weighted and summed using the corresponding non-uniform depth interval length as a weight, thus achieving continuous depth prediction. Subsequently, an interpolation mechanism is used to dynamically generate encoding information in the location encoding embedding table based on the output continuous depth values, enabling the location encoding to be updated as the depth continuously changes, thereby synergistically enhancing the network's ability to perceive geometric structure and contextual information.
[0038] Optionally, the method or steps in this application may further include the following steps:
[0039] 1) Feature preprocessing: The ResNet-50 feature extraction backbone network is used to extract multi-scale features from the input image, generating feature maps with resolutions of 1 / 8, 1 / 16, and 1 / 32. For each scale feature, convolution downsampling, 1×1 projection or bilinear interpolation plus 1×1 convolution and GroupNorm operations are performed to unify them to a fusionable spatial resolution and number of channels.
[0040] 2) Two-Stage Skip Attention Fusion: This process involves multi-scale feature fusion in two stages. In the first stage, a multi-head self-attention mechanism with local windows is used to fuse the 1 / 8 and 1 / 16 scale feature maps. In the second stage, the fused intermediate features are combined with the global features at the 1 / 32 scale. A skip attention module is introduced to achieve flexible fusion of local and global features. The SAM module is plug-and-play, seamlessly embedding itself into different feature layers, effectively promoting information interaction among multi-scale features and mitigating semantic conflicts that occur in traditional multi-scale fusion. Through staged, progressive fusion, information from different scales is integrated layer by layer, significantly enhancing the network's adaptability to changes in near and far scales.
[0041] 3) Depth Prediction and Interpolation Location Encoding Generation: In the depth output stage, depth classification prediction is combined with interval regression to obtain continuous depth values. Specifically, the classification probability is calculated for each preset depth interval, and the depth values are weighted and summed using the corresponding non-uniform depth interval length as a weight, thus achieving continuous depth prediction. Subsequently, an interpolation mechanism is used to dynamically generate encoding information in the location encoding embedding table based on the output continuous depth values, enabling the location encoding to be updated as the depth continuously changes, thereby synergistically enhancing the network's ability to perceive geometric structure and contextual information.
[0042] Step 1) may optionally further include the following steps:
[0043] 11) Multi-scale features are extracted from the monocular input image via the ResNet-50 backbone network, resulting in multi-scale feature maps with sizes of 1 / 8, 1 / 16, and 1 / 32, denoted as .
[0044] 12) Align features at each scale:
[0045] The 1 / 8 feature map dimension is aligned with the 1 / 16 feature map:
[0046]
[0047] 1 / 16 feature map dimensions remain unchanged:
[0048]
[0049] The 1 / 32 feature map dimension is aligned with the 1 / 16 feature map:
[0050]
[0051] Among them, W ds b ds W p b p For the corresponding convolution kernel parameters and biases; Interp is the bilinear interpolation operation.
[0052] Step 2) specifically includes the following steps:
[0053] 21) The overall fusion process of the two-stage multi-scale features is as follows:
[0054]
[0055] Where F1 represents the primary fusion feature, F fusion This represents the multi-scale fusion feature.
[0056] 22) For the first stage, the input multi-scale features are divided into non-overlapping 7×7 windows, and cross-attention is calculated within the windows, then:
[0057]
[0058] Where Q comes from K,V comes from Given the position bias matrix, output the initial fusion feature F1;
[0059] 23) For the second stage, F1 and 1 / 32 scale deep features are input into the SAM module, and a sparse sampling strategy with an expansion rate d=2 is used to expand the receptive field, then:
[0060]
[0061] Where Q comes from F1, and K and V come from the bilinear upsampling results. Output multi-scale fusion features F fusion ;
[0062] Step 3) specifically includes the following steps:
[0063] 31) Regarding the second-stage fusion feature F fusion Logits are obtained through a deep classifier, and the probabilities of each discrete interval are obtained through Softmax.
[0064]
[0065] in is the output for the i-th depth interval, and N is the number of bins.
[0066] 32) Combining the preset non-uniform depth candidate values {b i Calculate continuous depth:
[0067]
[0068] 33) Position-encoded interpolation. The continuous depth D is decomposed into integer and fractional parts, let...
[0069]
[0070] The interpolated position encoding is then:
[0071] E Pos (x,y)=(1-δ)E[f]+δE[c]
[0072] Where E[·] is the depth location encoding embedding table.
[0073] 34) Integrate with the Transformer encoder. Combine F... fusion The flattened feature is fed into a single-layer Transformer, and the output is... Finally, the summation yields the final depth feature F. out :
[0074]
[0075] Optionally, the execution process of the local window attention module in step 1) includes:
[0076] The input features are divided into non-overlapping windows of size 7×7. Attention weights are calculated within each window, using a relative position bias matrix, calculated as follows:
[0077]
[0078] Where Q is the query vector, K and V are key vectors, and B is the position bias matrix.
[0079] Optionally, the formula for calculating the window scaling factor β in step 2) is:
[0080] β=σ(MLP(GAP(F)))
[0081] Where σ is the Sigmoid function, F is the input feature, and GAP represents global average pooling.
[0082] Optionally, the formula for dynamically adjusting the window size is:
[0083]
[0084] Where M is the reference window size, and its value ranges from 3×3 to 9×9.
[0085] Optionally, the generation of dynamic depth location encoding in step 3) includes:
[0086] Predicted depth interval center μ i and width σ i Calculate the interval boundaries:
[0087]
[0088] Interpolation weights w are generated based on local 3×3 feature blocks. α w β The encoding calculation formula is:
[0089]
[0090] Alternatively, the orthogonal loss function is:
[0091]
[0092] Compared with the prior art, the present invention has the following advantages:
[0093] This invention integrates a skip attention module and a two-stage progressive fusion strategy, significantly improving the effect of multi-scale feature fusion and enhancing the network's ability to perceive information at different scales, thereby improving the accuracy of depth estimation. The combination of dynamic interpolation position encoding and a depth interval regression mechanism results in a more continuous and detailed final depth map, significantly reducing prediction errors and improving the ability to express scene contextual information. In scenarios with complex occlusion or drastic scale changes, this invention exhibits stronger robustness and stability, maintaining high depth prediction accuracy. Attached Figure Description
[0094] Figure 1 This is a flowchart illustrating the depth prediction method for hierarchical dynamic window attention according to the present invention.
[0095] Figure 2 The prediction accuracy of the algorithm proposed in this paper is comparable to that of the original MonoDETR algorithm in AP. 3D A comparison chart of the model training process for the evaluation results.
[0096] Figure 3 The prediction accuracy of the algorithm proposed in this paper is comparable to that of the original MonoDETR algorithm in AP. BEV A comparison chart of the model training process for the evaluation results.
[0097] Figure 4The graph used to illustrate the algorithm proposed in this paper is the overall loss curve for model training. It integrates sub-losses such as classification, bounding box regression, and GIoU to reflect the convergence of the entire detection model.
[0098] Figure 5 The cross-entropy loss curve for the proposed algorithm is used to measure the accuracy of the model's prediction of each candidate box category.
[0099] Figure 6 The L1 bounding box regression loss curve for the algorithm proposed in this paper is used to measure the positional deviation between the predicted box and the ground truth box. Detailed Implementation
[0100] Addressing the shortcomings of existing technologies and the technical bottlenecks of semantic conflicts in multi-scale feature fusion, poor adaptability of static position encoding, and low computational efficiency in monocular depth prediction, this invention proposes a monocular depth prediction method based on two-stage skip attention and dynamic position encoding. This method achieves high-precision real-time depth perception in complex scenes through multi-stage feature fusion optimization and dynamic position encoding. The network first uses 3×3 convolution operations to adjust the number of channels in the decoder query and corresponding encoder features, ensuring they have the same dimension. Then, the query matrix, key matrix, and value matrix are divided into W×W sub-window blocks; in this invention, the window size is 7×7, and multi-head self-attention operations are performed independently within each window. The number of attention heads can be set for different levels; this example uses 8 heads. The output of each head is multiplied by the value after calculating the attention weight using Softmax to obtain the fused features. The outputs of all heads are recombined within the window, further mapped by an MLP, and added to the input features through residual connections to generate fused detail features.
[0101] The depth regression module employs a depth discretization strategy to estimate continuous depth values. This module first divides the depth range into 80 discrete intervals and learns the probability distribution of each pixel belonging to each interval. Specifically, a 1×1 convolution mapping is applied to the feature map output by the SAM module or decoder to obtain a tensor with 81 channels equal to the number of depth intervals; then, a Softmax operation is applied to each pixel along the 81-dimensional plane to obtain the probability distribution. The network calculates the final depth value, i.e., the depth of each pixel, by linearly combining the center values of all intervals with their corresponding probabilities. The output depth... Figure 1 Generally, the resolution is relatively low, and it can be upsampled to the same size as the input image through methods such as bilinear interpolation, so that the output depth map is aligned with the original image.
[0102] To achieve the above objectives, the present invention adopts the following technical solution:
[0103] A monocular depth prediction method based on two-stage skip attention and dynamic position encoding includes the following steps:
[0104] Step 1: Input a monocular RGB image, perform preprocessing, multi-scale feature extraction, and feature alignment;
[0105] In step 1:
[0106] Data input and feature extraction are performed. A 1242×375 resolution monocular RGB image from the KITTI dataset is input. A ResNet-50 backbone network is used to extract multi-scale feature maps, resulting in three scales: 1 / 8 scale high-resolution shallow features, used to capture details such as road texture and vehicle edges; 1 / 16 scale mid-level semantic features, used to encode object outlines such as vehicles, pedestrians, and mid-range scene structure; and 1 / 32 scale deep global features, used to model long-distance road layout and global semantic context.
[0107] Alignment processing is performed on features at each scale:
[0108] The 1 / 8 feature map dimension is aligned with the 1 / 16 feature map:
[0109]
[0110] 1 / 16 feature map dimensions remain unchanged:
[0111]
[0112] The 1 / 32 feature map dimension is aligned with the 1 / 16 feature map:
[0113]
[0114] Among them, W ds ∈R C×C×3×3 The step size is 2; W p W up R C×C×1×1 GN stands for GroupNorm, and the output resolution is uniformly 24×78.
[0115] Step 2: Initial features are fed into a hierarchical dynamic window for feature fusion.
[0116] In step 2:
[0117] In the first stage, SAM module computation is performed. For images with a resolution of 1242×375 in the KITTI dataset, 1 / 8 of the features are divided into 22×7 non-overlapping 7×7 windows, and 1 / 16 of the features are divided into 11×4 windows, excluding areas with insufficient zero-padding boundaries. Then, cross-attention is calculated.
[0118]
[0119] The query vector Q is generated by linear projection of 1 / 8 of the features, and the key vectors K and V are projected from 1 / 16 of the features to the same dimension of 256, introducing a learnable matrix. Enhance local spatial correlation. Finally, the results from each window are processed through residual connections and LayerNorm to output the primary fusion feature F1.
[0120] In the second stage, SAM calculation is performed again. The F1 score and 1 / 32 scale deep features are input into the SAM module, and a sparse sampling strategy with an expansion rate d=2 is used to expand the receptive field.
[0121]
[0122] The query vector Q is generated by linear projection of F1 features, and the key vectors K and V are generated by F1 features. up Features are projected to the same dimension of 256, and a learnable matrix is introduced. Enhance local spatial correlation. Finally, the results from each window are processed through residual concatenation and FFN to output the final fused feature F. fusion .
[0123] Step 3: Deep classification and continuous depth regression;
[0124] In step 3:
[0125] For F fusion The logits of 81 channels are obtained by using a 1×1 convolutional classifier, and the probabilities of each discrete interval are obtained by using Softmax.
[0126]
[0127] Combined with the preset non-uniform depth candidate value {b i Calculate continuous depth:
[0128]
[0129] Then, dynamic depth position encoding and context fusion are performed, decomposing the continuous depth D into integer and fractional parts, letting...
[0130]
[0131] The interpolated position encoding is then:
[0132] E Pos (x,y)=(1-δ)E[f]+δE[c]
[0133] Where E[·] is the depth location encoding embedding table.
[0134] Finally, it is fused with the Transformer encoder. F fusion The flattened feature is fed into a single-layer Transformer, and the output is... Finally, the summation yields the final depth feature F. out :
[0135]
[0136] Step 4, Training Configuration;
[0137] In step 4:
[0138] The training configuration used an NVIDIA V100 GPU, a batch size of 16, an AdamW optimizer, an initial learning rate of 2e-4, a weight decay of 0.1, and a training period of 195 epochs, with the learning rate decaying at epochs 125 and 165. See Table 2 for details.
[0139] Table 2 Depth Prediction Algorithm Parameters
[0140]
[0141] Table 1. Accuracy comparison of different depth prediction methods on the KITTI val dataset.
[0142]
[0143] like Figure 1 As shown, optionally, in some embodiments, in step 2, the first-stage skip attention fusion, the SAM module is calculated in the first stage. For the 1242×375 resolution image in the KITTI dataset, 1 / 8 of the features are divided into 22×7 non-overlapping 7×7 windows, and 1 / 16 of the features are divided into 11×4 windows, with zero-filled boundary insufficient regions. Then, cross-attention calculation is performed:
[0144]
[0145] The query vector Q is generated by linear projection of 1 / 8 of the dimension-aligned features, while the key vectors K and V are projected from 1 / 16 of the features to the same dimension of 256, introducing a learnable matrix. Enhance local spatial correlation. Finally, the results from each window are processed through residual connections and LayerNorm to output the primary fusion feature F1.
[0146] Step 3, Second Stage: Jump Attention Fusion;
[0147] In step 3:
[0148] In the second stage, SAM calculation is performed again. The F1 score and the dimension-aligned 1 / 32-scale deep features are input into the SAM module, and a sparse sampling strategy with an expansion rate d=2 is used to expand the receptive field.
[0149]
[0150] The query vector Q is generated by linear projection of F1 features, and the key vectors K and V are generated by F1 features. up Features are projected to the same dimension of 256, and a learnable matrix is introduced. Enhance local spatial correlation. Finally, the results from each window are processed through residual concatenation and FFN to output the final fused feature F. fusion .
[0151] Step 4: Deep classification and continuous depth regression;
[0152] In step 4:
[0153] For F fusion The logits of the number of channels N+1 are obtained after a 1×1 convolutional classifier. In this case, N is 80. The probabilities of each discrete interval are obtained through Softmax.
[0154]
[0155] Combined with the preset non-uniform depth candidate value {b i Calculate continuous depth values:
[0156]
[0157] Step 5: Dynamic position encoding generation;
[0158] In step 5:
[0159] Dynamic depth position encoding and context fusion are performed, decomposing the continuous depth D into integer and fractional parts, let:
[0160]
[0161] The interpolated position encoding is then:
[0162] E Pos (x,y,δ)=(1-δ)E[f]+δE[c]
[0163] Where E[·] is the depth location encoding embedding table, generated with F fusion Same size dynamic position code
[0164] Step 6: Context-enhanced Transformer encoding, final feature fusion, and output;
[0165] In step 6:
[0166] Fusion with Transformer encoder. Incorporate F... fusion The flattened data, along with the input mask M and absolute position code P, is fed into a single-layer Transformer encoder to complete context aggregation across spatial positions, and the output is...
[0167]
[0168] Add the contextual features to the dynamic location encoding and map them back to the original scale:
[0169]
[0170] The image is then restored to the same resolution as the input image using bilinear interpolation to obtain the final depth feature map.
[0171] Step 7, Training Configuration;
[0172] In step 7:
[0173] The training configuration used an NVIDIA V100 GPU, a batch size of 16, an AdamW optimizer, an initial learning rate of 2e-4, a weight decay of 0.1, and a training period of 195 epochs, with the learning rate decaying at epochs 125 and 165. See Table 1 for details.
[0174] Table 1 Depth Prediction Algorithm Parameters
[0175]
[0176] Step 8: Multi-scale depth supervision, edge smoothing, and gradient consistency regularization;
[0177] In step 8:
[0178] During the training phase, the first-stage fused feature F1 and the second-stage fused feature F1 from step 2 are compared. fusion Auxiliary depth classification and regression heads are added separately. The F1 score is processed through a 1×1 convolution and softmax to generate an 81-channel depth probability map. The intermediate depth map D1 is obtained by weighting and summing the values according to a predefined candidate value sequence. L1 loss and SSIM loss are calculated between D1 and the ground truth, and then weighted and fused with the main loss. This allows for multi-scale supervision of shallow, mid-, and deep features, improving the model's accuracy across different depth ranges. An image and depth gradient consistency loss is introduced for the weighted depth map D.
[0179]
[0180] in This represents the difference operator, where I is the input RGB image.
[0181] At the same time, a total variation (TV) loss is applied to D:
[0182]
[0183] The two methods, along with the main loss, can be jointly optimized to smooth the edges of the depth map and maintain structural consistency.
[0184] Step 9: Dynamic DropPath, Variable Window Strategy, and Synchronous Data Enhancement Process;
[0185] In step 9:
[0186] During training, the DropPath drop rate p is dynamically adjusted based on the current epoch and validation error. It linearly increases from an initial value of 0.1 to a maximum of 0.3 to enhance model robustness. The window size w is linearly reduced from 7×7 to 5×5, and then gradually restored to 7×7. Smaller windows focus on details, while larger windows capture contextual semantic features. In each training iteration, random color dithering is performed on the input image and its depth label simultaneously: brightness ±20%, contrast ±15%, saturation ±10%. A random horizontal flip with a probability of 50% and random Gaussian noise σ∈[0,5] are also applied. The resulting enhanced image and its corresponding depth map undergo the same geometric transformation to ensure consistency.
[0187] The effectiveness of the depth prediction method for hierarchical dynamic window attention in this invention is verified.
[0188] Figure 2 and Figure 3 The figures show a comparison of the training process of the proposed algorithm under the AP3D and APBEV metrics at three difficulty levels: "Easy," "Moderate," and "Hard." The blue line represents the detection performance of the proposed algorithm, while the yellow line represents the performance of existing algorithms. It is clear from the figures that the proposed method exhibits superior performance compared to traditional methods across all difficulty levels.
[0189] from Figure 2 As can be seen, the algorithm of this invention exhibits more stable overall performance under the AP3D metric, with a significant performance improvement, especially after the 120th epoch. At Easy difficulty, AP3D ultimately stabilizes at approximately 29.5%, an improvement of about 3% compared to the comparison method; at Moderate difficulty, it stabilizes at approximately 21%, and at Hard difficulty, it stabilizes at around 17%, all higher than traditional methods. This indicates that the 3D detection network proposed in this invention can more accurately recover the 3D position and volume information of the target.
[0190] from Figure 3It can be observed that the algorithm in this paper also performs well under the BEV perspective. Under Easy difficulty, APBEV eventually stabilizes at about 38.5%, and under Moderate and Hard difficulties, it stabilizes at about 27% and 23%, respectively, all of which are higher than the comparison methods, indicating that it also achieves high spatial consistency and structural reconstruction capabilities at the bird's-eye view level.
[0191] The performance of different algorithms was compared. As can be seen from Table 2, the 3D target detection method proposed in this invention is significantly better than traditional algorithms in terms of error control.
[0192] Table 2. Accuracy comparison of different prediction depth methods on the KITTIval dataset.
[0193]
[0194] In summary, experimental results demonstrate that the network model proposed in this invention can achieve high-precision target detection in 3D space, accurately reconstructing target positions in both BEV and 3D spatial representations. The proposed method exhibits stable structure, minimal error fluctuations during training, and accuracy evaluation results show significant superiority over existing MonoDETR deep prediction models, especially maintaining excellent performance in complex (Hard) environments. Therefore, it has broad application prospects and engineering value in tasks such as autonomous driving and environmental perception.
[0195] [First Group of Alternative Embodiments]:
[0196] 1. A monocular depth prediction method based on two-stage skip attention and dynamic position encoding, characterized by comprising the following steps:
[0197] S1. Multi-scale feature maps are progressively fused through a two-stage skip attention module, including the first stage of local window attention fusing 1 / 8 and 1 / 16 features, and the second stage of global context fusing intermediate features and 1 / 32 features;
[0198] S2. Generate a depth classification probability distribution based on the fusion features, and perform a weighted summation of non-uniform depth candidate values to output a weighted depth map;
[0199] S3. Using the weighted depth map, perform linear interpolation in the position encoding embedding table to generate dynamic position codes, and add them to the features encoded by Transformer to obtain the final depth features.
[0200] Optionally, when the jump attention module in step S1 is executed, it further includes:
[0201] Dynamic receptive field adjustment: Calculate the window scaling factor based on the local feature texture complexity, and shrink high-entropy regions. Enhanced window detail capture; expanded window receptive field for low-entropy regions.
[0202] Multi-task consistency constraint: Use the boundary prediction map of the semantic segmentation task as an attention mask to suppress occlusion areas. Error feature association in the domain; gradient-aware position bias: correcting relative position using backpropagation gradients from depth prediction loss. Encoding matrix enhances the spatial correlation of high-error regions.
[0203] These three steps achieve the following coordinated process:
[0204] Dynamic adjustment lays the foundation: receptive field scaling provides the basis for scene partitioning for multi-task constraints (such as objects in high-entropy regions). (Surface), enabling semantic masks to accurately locate occlusion boundaries;
[0205] Constraint-guided optimization: The occlusion region of the semantic mask overlaps with the gradient high-error region, driving the position bias to target... Sexuality strengthens the spatial connections between these areas;
[0206] Closed-loop adaptation: The gradient-optimized position encoding is re-inputted into the dynamic adjustment module to form "structural adaptation → language". The "semantic correction → geometric repair" cycle continuously alleviates semantic conflicts.
[0207] In summary, the three-step approach uses dynamic structure as its framework, semantic constraints as its nervous system, and gradient feedback as its lifeblood. Building an adaptive fusion system:
[0208] Dynamic windows resolve scale mismatch and improve detail / semantic balance (e.g., AP of nearby license plate texture increases by 35%).
[0209] Multi-task masking suppresses occlusion interference, reducing edge depth breakage error by 60%;
[0210] Gradient bias autonomously strengthens key spatial relationships, and cross-scenario generalization fluctuations are compressed to ±0.8%.
[0211] Ultimately, semantic conflicts shift from "passive tolerance" to "active resolution," enabling seamless handling of multi-scale features in complex scenarios. Loss fusion. This solves the technical problem of semantic conflict in multi-scale feature fusion, while existing traditional methods... Due to the fixed receptive field and cross-task separation, (1) details are lost in high-texture areas (due to excessively large windows) and semantic modeling is lost in low-texture areas. (1) Blurred (window too small); (2) Incorrect feature association in occluded areas; (3) Insufficient spatial relationship modeling in high-error areas.
[0212] Furthermore, the three sub-steps of the S1 step described above are: dynamic receptive field adjustment → multi-task constraint → gradient sensing. The biased three-step closed loop achieves the corresponding technical effects through the following mechanism:
[0213] Accuracy-efficiency co-optimization
[0214] Dynamic window adjustment: Based on texture entropy (HsHs), the window is dynamically scaled (5×5 in high-entropy areas / 9×9 in low-entropy areas) to adjust the occlusion... By focusing computational resources on the blocked area, the accuracy of detail capture increased by 35.3%, while the computational load decreased by 18%.
[0215] Multi-task constraints: Reuse the semantic segmentation boundary map (MedgeMedge) as an attention mask to enforce object edges. Depth alignment reduces edge transition error by 60% with zero additional inference overhead.
[0216] Gradient-aware bias: utilizing the gradient of depth loss Online correction of location code, ground slope error ↓ 78.9%, training convergence speed increased by 40%.
[0217] Breakthrough in generalization performance: Illumination adaptation: Expanding the window to compensate for details in low-entropy regions of foggy weather, maintaining AP3D accuracy for distant targets. 24.1% (compared to 16.5%);
[0218] Cross-domain migration: The volatility of the urban to highway scenario is compressed to ±0.8% (compared to ±3.5% in traditional solutions), due to gradient bias. Dynamically adapt the road topology. In summary: three steps are involved: local perception focusing → semantic boundary constraints → geometric error iteration. The optimized closed loop achieves a triple breakthrough in accuracy (↑35.3%), efficiency (↓18% power consumption), and generalization (↓77% cross-domain variability), and also eliminates... Fusion experiments have shown that the absence of any component leads to significant performance degradation (e.g., AP decreases by 10.7% due to occlusion).
[0219] Optionally, when generating the weighted depth map in step S2, the method further includes:
[0220] Dynamic bin density adjustment: Based on the texture complexity of local regions of the input image, a lightweight convolutional network is used. Predict the depth binning density coefficient, increase the near-field binning density in high-texture areas, and decrease the far-field binning density in low-texture areas. Spend;
[0221] Adaptive probabilistic sharpening: Dynamically scales the softmax of the deep classification probability based on the confidence distribution of the fused features. Temperature coefficients compress the probability distribution in high-confidence regions to enhance depth consistency, and expand the distribution in low-confidence regions to suppress [depth congestion]. noise;
[0222] Gradient Coupling Constraint: Introducing image edge gradient constraints into the depth regression loss function to force the gradient of the depth map. The degree variation is aligned with the edge structure of the input image.
[0223] These three steps achieve a coordinated process of dynamic binning foundation laying → probabilistic sharpening stabilization → gradient constraint closure:
[0224] 1) Binning → Cascaded Optimization of Probability: Dynamic binning provides a physical range for probability calculation that adapts to the scenario (e.g., near-field). (High-density binning), and probability sharpening refines the depth value distribution within this range; the two form a "physical framework-data filling" structure. "Full cooperation";
[0225] 2) Gradient Constraint Closed-Loop Correction: The depth maps output from the first two steps are validated for edge alignment using gradient constraints, and their reverse... The feed signal can control the bin density adjustment (such as automatic upsampling in edge areas) and the probability sharpening intensity, forming a self-correcting loop;
[0226] 3) Global Adaptive Enhancement: Binning adjustment addresses spatial heterogeneity, probabilistic sharpening handles uncertainty, and gradient constraints are implemented. Ensuring geometric coherence, these three elements cover the entire "scene-data-structure" chain, enabling deep prediction to achieve both detail fidelity and edge smoothing. slip.
[0227] In summary, the three-layer closed loop, from physical modeling and probabilistic optimization to geometric constraints, completely solves the problems caused by static binning. Distortion and structural fracture issues.
[0228] This solves the technical problem of insufficient adaptability of static deep binning strategies in complex scenarios. This can lead to two types of defects:
[0229] Geometric distortion—textured areas lose detail due to coarse binning, while smooth areas introduce noise due to redundant binning. Voice;
[0230] Structural fracture—blurred depth probability distribution causes prediction jumps, and edge gradients mismatch with the real image.
[0231] Optionally, when generating the dynamic position code in step S3, the method further includes:
[0232] Scene depth distribution perception: Perform regional statistical analysis on the weighted depth map to identify the dominant regions at near, mid, and far distances. The domain, dynamically scaling the resolution intensity of the positional encoding;
[0233] Semantic-geometric gating fusion: Using the object boundary confidence score from the semantic segmentation task as the gating weight to adjust the position Encode the injection intensity in the occluded region;
[0234] Encoding Iterative Optimization: Utilize the error gradient between the final depth features and the ground truth to fine-tune the position encoding embedding table in reverse. The parameter distribution.
[0235] The above three steps achieve the following collaborative process:
[0236] Perception-driven gating: The "key regions" (such as near-field) of deep distributed perception recognition directly guide the semantic gating. The direction of source delivery enables adaptive spatial adjustment;
[0237] Gated guided optimization: Occluded regions of semantically gated tags receive higher gradient weights during the optimization phase, driving the encoding. Targeted corrections are made to eliminate the root causes of geometric distortion;
[0238] Closed-loop continuous evolution: The optimized encoding table is re-inputted into the sensing module, forming an "analysis → execution → calibration" cycle. The ring enables positional coding to continuously adapt to scene changes, breaking through the generalization bottleneck of static coding.
[0239] In summary, the three steps, as a whole, are based on depth distribution, constrained by semantic boundaries, and modified by error feedback. Positive signals upgrade the position encoding to a "dynamic geometry adapter," resolving the near-field blurring and occlusion issues caused by static encoding. The technical problem of "splitting," or rather, the difficulty of adapting static position encoding to non-uniform depth distribution and occlusion in dynamic scenes. The technical problem of "interference leading to distortion of geometric information representation".
[0240] 2. The monocular depth prediction method based on two-stage skip attention and dynamic position coding as described in Example 1, wherein:
[0241] Step S1 further includes:
[0242] S11) Obtain a multi-scale feature map from a monocular image, wherein the multi-scale feature map includes a first feature map, a second feature map, and a third feature map obtained by downsampling at scales of 1 / 8, 1 / 16, and 1 / 32;
[0243] S12) Input the first feature map and the second feature map into the jump attention module, and perform multi-head self-attention fusion and multilayer perceptron transformation respectively within a local fixed window to generate the first stage fusion feature;
[0244] S13) The first-stage fusion features and the third feature map are input again into the jump attention module, and the second-stage fusion features are generated through multi-head self-attention and multilayer perceptron with the same or adjustable window size.
[0245] 3. The monocular depth prediction method based on two-stage skip attention and dynamic position coding as described in Example 2, wherein step S2 further includes:
[0246] S24) The second-stage fusion features are sequentially processed by the depth prediction head and classifier to obtain depth classification logits, and the probability distribution of each depth interval is obtained through Softmax operation;
[0247] S25) The weighted depth map is obtained by weighting and summing the probability distribution with the preset non-uniform depth candidate value sequence.
[0248] 4. The monocular depth prediction method based on two-stage skip attention and dynamic position coding as described in Example 3, wherein step S3 further includes:
[0249] S36) Using the weighted depth map as a coordinate index, linear interpolation is performed in the depth position code embedding table to generate a dynamic position code;
[0250] S37) Flatten the second-stage fused features and input them into the Transformer encoder to obtain context-enhanced features. Add the features to the dynamic position encoding to output the final depth features.
[0251] 5. The method according to Embodiment 4, wherein the skipping attention module comprises:
[0252] 1) Within each local window of fixed size w×w, a multi-head self-attention mechanism is executed, and its calculation formula is as follows:
[0253]
[0254] Where Q, K, and V are the query, key, and value matrices, respectively, d is the dimension per head, and B is the relative position bias matrix;
[0255] 2) After the attention output, it is sequentially connected to the DropPath residual through LayerNorm, MLP, and the MLP includes two fully connected layers + GELU + Dropout;
[0256] 3) After the MLP output, LayerNorm and DropPath residual connections are applied again to form cross-window feature expression enhancement.
[0257] 6. The method according to Embodiment 4 is characterized in that the generation of the first stage fusion feature in step S12) further includes performing convolutional downsampling and 1×1 convolutional projection on the first feature map and the second feature map respectively, so that the spatial resolution of the two is consistent before inputting them into the jump attention module.
[0258] 7. The method according to Embodiment 4, wherein the generation of the second stage fusion feature in step S13) further includes bilinear interpolation of the third feature map to the resolution of the first stage fusion feature before inputting it into the jump attention module for fusion.
[0259] 8. The method according to Embodiment 4, characterized in that, in step S25), the preset non-uniform depth candidate value sequence is generated by the following formula:
[0260]
[0261] Where, d min ,d max These represent the minimum and maximum depths, respectively, and N is the number of depth bins.
[0262] The linear interpolation is calculated using the following formula:
[0263]
[0264] Where z represents the continuous depth value at the corresponding pixel. E is the depth location encoding embedding table.
[0265] 9. The method according to Embodiment 4, wherein the Transformer encoder contains only a single-layer encoder structure for context enhancement of flattened features to reduce computational load and meet real-time inference requirements.
[0266] 10. A monocular depth prediction device based on two-stage skip attention and dynamic position coding, comprising:
[0267] The processor module is operable to execute the monocular depth method based on two-stage skip attention and dynamic position encoding according to any one of embodiments 1 to 9.
[0268] 11. A monocular depth prediction method based on two-stage skip attention and dynamic position encoding, characterized by comprising the following steps:
[0269] Step S1 further includes:
[0270] 1) Extract features from the input monocular image using the ResNet50 backbone network, and generate the first feature map, second feature map, and third feature map at scales of 1 / 8, 1 / 16, and 1 / 32 respectively;
[0271] 2) The first feature map, the second feature map, and the third feature map are mapped to the hidden dimension by 1×1 convolution, and then normalized by GroupNorm;
[0272] 3) The first feature map is downsampled by 3×3 convolution and processed by GroupNorm to align with the spatial resolution of the second feature map;
[0273] Step S2 further includes:
[0274] 4) Input the downsampled first feature map and the normalized second feature map into the jump attention module, and perform multi-head self-attention and multilayer perceptron transformation within a fixed w×w window to obtain the first stage fusion feature;
[0275] 5) Perform bilinear interpolation on the third feature map, upsample it to the spatial size of the first-stage fused features, and process it with 1×1 convolution and GroupNorm;
[0276] 6) Input the first-stage fused features and the upsampled third feature map back into the skip attention module to obtain the second-stage fused features;
[0277] 7) The fused features of the second stage are sequentially passed through a depth prediction head and a 1×1 convolutional classifier to generate depth logits;
[0278] Step S3 further includes:
[0279] 8) Perform Softmax operation on depth logits to obtain the probability distribution of each depth interval, and sum the weighted values according to the preset non-uniform depth candidate value sequence to output the weighted depth map;
[0280] 9) Using the weighted depth map as an index, perform linear interpolation in the depth position encoding embedding table to generate a dynamic position encoding of the same size as the feature map;
[0281] 10) Flatten and transpose the second-stage fusion features, and input them together with the flattened preprocessed mask and position encoding into a single-layer Transformer encoder to obtain context-enhanced features;
[0282] 11) Add the context enhancement features to the dynamic position encoding, and reshape them back to the [B,C,H,W] format to output the final depth features for subsequent tasks.
[0283] 12. The method according to embodiment 11, wherein the skipping attention module comprises:
[0284] 1) Within each local window of fixed size w×w, a multi-head self-attention mechanism is executed, and its calculation formula is as follows:
[0285]
[0286] Where Q, K, and V are the query, key, and value matrices, respectively, d is the dimension per head, and B is the relative position bias matrix;
[0287] 2) After the attention output, it is sequentially connected to LayerNorm, multilayer perceptron and DropPath residual connection. The multilayer perceptron includes two fully connected layers + GELU + Dropout.
[0288] 3) After the output of the multilayer perceptron, LayerNorm and DropPath residual connections are applied again to form cross-window feature expression enhancement.
[0289] These three steps, through a chain reaction of local correlation foundation, normalized current stabilization, and residual disturbance rejection enhancement, at the technical layer... The following three technical effects are achieved:
[0290] Precision closed loop: Window attention captures details → Layer normalization preserves order → Residual connection repairs edge continuity;
[0291] Efficiency closed loop: Fixed window reduces complexity → Lightweight MLP controls computation → DropPath suppresses overfitting;
[0292] Robust closed loop: Layer normalization resists illumination perturbation → DropPath simulates occlusion → Collaborative improvement of cross-scene generalization.
[0293] Specifically, Step 1 (Local Window Attention) → Step 2 (Normalization and Residual Connection) → Step 3 (Secondary Residual Connection) Progressive relationship of difference enhancement
[0294] The core function of step 1 is to perform multi-head self-attention calculation within a fixed window, and to establish a position bias matrix. It has local spatial correlation, but may introduce boundary noise.
[0295] The core compensation in step 2: applying layer normalization (LayerNorm) and a multilayer perceptron (MLP) to the attention output. Residual connections suppress feature distribution shifts caused by noise.
[0296] The core enhancement of step 3: secondary application layer normalization and drop path dropping, which flattens the performance of step 2. Slip features are used for detail restoration and anti-overfit enhancement.
[0297] II. Technical Effects
[0298] Step 2 involves layer normalization to repair distributed fractures, and step 3 involves MLP residual recovery of details, ultimately improving the IoU to 0.79. (+27%). This overcomes the problem that pure window attention (step 1 only) leads to depth breaks in long-distance objects (such as telephone poles) and boundaries. The issue of IoU being only 0.62 led to optimization of edge depth consistency.
[0299] Additionally, a fixed window (7×7) reduces the complexity from O(H) to O(H). 2 W 2 ) decreased to O(M 2 HW), the lightweight design of steps 2 / 3 makes Additional computational load is less than 8%. Therefore, the overall inference speed is 25 FPS (1080p input), resulting in lower latency compared to global attention models. 60%。
[0300] Furthermore, the layer normalization in step 2 eliminates the feature distribution shift caused by haze, reducing depth error by 31%. (Occlusion) Robustness: In step 3, DropPath randomly masks 15% of the feature paths to simulate occlusion failure, improving AP3D performance in Hard scenes by 17%. This adaptability to extreme scenarios enhances its robustness.
[0301] Traditional Transformers in current technologies face three major bottlenecks in vision tasks:
[0302] Computational redundancy—the global attention complexity ($O(H^2W^2)$) is difficult to meet real-time requirements;
[0303] Feature distribution shift—cross-window feature fusion leads to boundary response breakage;
[0304] Poor robustness to shading – fixed structures are sensitive to shading failure.
[0305] The above three steps constitute a collaborative solution mechanism for the aforementioned technical problems.
[0306] Local window attention (efficiency and focus):
[0307] Performing multi-head self-attention (e.g., 7×7) within a fixed window reduces the computational complexity to O(M^2HW), thus cracking the code. Real-time bottlenecks are addressed, and local geometric relationships are strengthened through relative position encoding $B$.
[0308] Normalization and residual link (distribution stability):
[0309] After attention, the feature distribution shift is suppressed by LayerNorm, and the boundary response breaks are repaired by MLP residual connections. Ensure the continuity of features across windows.
[0310] Secondary residual enhancement (disturbance immunity and generalization):
[0311] The quadratic LayerNorm + DropPath residual provides double protection: LayerNorm resists illumination perturbations, and DropPath follows... The machine shielding path simulates occlusion scenarios, improving cross-scenario robustness.
[0312] Therefore, the three steps described above form the following cooperative relationship:
[0313] Local window attention (step 1) efficiently captures features but introduces boundary noise → first residual connection (step 2) The residual noise is further repaired and anti-noise is injected through LayerNorm correction of the distribution, MLP compensation of details → secondary residual (step 3). Interference capability, forming a cascaded repair link of a three-level pipeline of "computation-correction-reinforcement".
[0314] In addition, DropPath randomly discards sub-paths during training (e.g., with a 15% probability), forcing the network to build redundant representations. When actual occlusion occurs, this mechanism can autonomously switch feature propagation paths to avoid system crashes caused by local failures, thus achieving... A dynamic disturbance rejection closed loop was established.
[0315] Furthermore, positional encoding $B$ (step 1) establishes geometric priors → LayerNorm (steps 2 / 3) maintains semantic distribution stability. The final output retains structural edge consistency (e.g., vehicle contour IoU is improved by 27%), thus achieving geometric-semantic coordination. same.
[0316] In summary, the three steps are structured around local attention as the framework, residual normalization as the core, and random perturbation resistance as the avoidance mechanism. The system transforms the general architecture of Transformer into a dedicated module for visual tasks, balancing efficiency, accuracy, and robustness. Rod-like.
[0317] 13. The method according to Embodiment 11 is characterized in that the skip attention module in steps 2) and 6) introduces a random depth drop-through strategy, and for each residual branch, the attention output or multilayer perceptron output is randomly masked with a given probability p, so as to improve the robustness of the model in different scenarios.
[0318] 14. The method according to Embodiment 11 is characterized in that, in step 2), when performing channel mapping and normalization on the multi-scale feature map, the 1×1 convolution mapping and GroupNorm both adopt shared parameter configuration to ensure the consistency of statistical distribution of features at different scales during cross-stage fusion.
[0319] 15. The method according to Embodiment 11, characterized in that step 8) pre-setting the non-uniform depth candidate value sequence is generated by the following formula:
[0320]
[0321] Where, d min ,d max These represent the minimum and maximum depths, respectively, and N is the number of depth bins.
[0322] Optionally, in some embodiments, step S2) further includes:
[0323] The steps for calculating the basic depth interval parameters are as follows: Determine the basic interval parameters based on the preset minimum depth value, maximum depth value, and total number of depth bins;
[0324] The steps for generating a non-uniform depth candidate sequence are as follows: Based on the basic interval parameter, the minimum depth value, and the current bin index, calculate the candidate depth value bit by bit according to the quadratic function rule.
[0325] The basic parameters output from step 1 serve as the core input to drive the calculation of candidate values in step 2, forming a tightly coupled "global configuration → local generation" link. The denominator design of the basic parameters (containing N(N+1) terms) avoids the amplification of errors due to excessively large bin spacing over long distances, reducing the relative depth error of targets 70 meters away from 12.7% to 7.3%.
[0326] The quadratic function pattern of the candidate value sequence conforms to the geometric constraints of perspective projection (depth is inversely proportional to pixel size), providing prior knowledge guidance for depth regression and thus forming physical-data consistency.
[0327] The technical solution, achieved through the synergy of non-uniform depth modeling and explicit mathematical control, improves accuracy, efficiency, and robustness in monocular depth prediction tasks.
[0328] I. Technical Closed Loop of Depth Distribution Adaptive Modeling
[0329] Physical Law Adaptability: Step 1's basic interval parameter calculation transforms the scene depth range (minimum to maximum) and binning requirements (total N) into core parameters, ensuring that depth binning is strictly bound to scene physical characteristics (e.g., dense targets at close range in urban roads require smaller intervals). Step 2's quadratic function generation forces candidate values to exhibit a "near-dense, far-sparse" distribution: near-field binning intervals are refined to 0.5 meters to capture vehicle details, while far-field intervals are expanded to 5 meters to suppress sky redundancy errors.
[0330] Quantization error suppression: Compared with traditional uniform binning, this strategy reduces the absolute depth error of targets within 50 meters by 28% on the KITTI dataset, and significantly improves the depth continuity of occlusion boundaries (gradient variance is reduced by 42%).
[0331] II. Coordinated Optimization of Computational Efficiency and Real-Time Performance
[0332] Low-complexity explicit computation: Step 1 requires only one multiplication and division operation to generate the basic parameters, with a constant complexity (O(1)), avoiding the iteration overhead of the dynamic prediction network. The candidate sequence generation in Step 2 is implemented through parallelization, with a GPU single-frame processing latency of <0.1ms.
[0333] Resource-accuracy balance: The total number of bins can be dynamically configured (accuracy saturation when N=80), and the computational load does not increase linearly with the depth range, meeting the 30FPS real-time requirement of autonomous driving.
[0334] III. Enhanced Training Stability and Generalization
[0335] Gradient propagation optimization: The derivative property of the quadratic function in step 2 makes the gradient large at nearby candidate values and small at distant values, consistent with the true depth distribution, which alleviates the gradient saturation problem of uniform binning and improves the model convergence speed by 35%.
[0336] Scene adaptation capability: Basic parameters are automatically adapted to different datasets (e.g., parameters are adjusted synchronously when the maximum depth of a high-speed scene increases to 120 meters), and the fluctuation of AP3D in cross-domain testing (city → rural) is only ±1.2%.
[0337] 16. The method according to Embodiment 11, characterized in that the linear interpolation in step 9) is calculated using the following formula:
[0338]
[0339] Where z represents the continuous depth value at the corresponding pixel. E is the depth location encoding embedding table.
[0340] 17. The method according to Embodiment 11, characterized in that, in step 10), when constructing the Transformer encoder input sequence, the following three parts are concatenated along the channel dimension and then fed in:
[0341] 1) The second-stage fusion characteristics after flattening and transposing;
[0342] 2) Flattened depth prediction mask, used to indicate occluded or invalid areas;
[0343] 3) The original spatial location encoding of the flattened data;
[0344] After the encoder outputs, it is first reduced in dimension by 1×1 convolution, and then restored to the [H,W] spatial dimension by bilinear interpolation.
[0345] 18. The method according to embodiment 11 is characterized in that the window sizes used in the first stage and the second stage jump attention module can be configured as w1×w1 and w2×w2, respectively, to adapt to the receptive field requirements of different scale features, and w1 and w2 can be determined during training through hyperparameter search or learning.
[0346] 19. The method according to Embodiment 11, characterized in that the processing of feature maps of different sizes by the skip attention module in steps 4) and 6) is as follows:
[0347]
[0348] 20. The method according to Example 11, characterized in that, in step 8), a Softmax operation is performed on the depth logits to obtain the probability of each discrete interval:
[0349]
[0350] in This is the output for the i-th depth interval. Its preset non-uniform depth candidate value sequence is generated by the following formula:
[0351]
[0352] Where, d min ,d max These represent the minimum and maximum depths, respectively, and N is the number of depth bins.
[0353] 21. According to the method described in Embodiment 11, the expression for the depth position encoding in step 9) is:
[0354]
[0355] The linear interpolation is calculated using the following formula:
[0356] Lerp(x,y,δ)=(1-δ)x+δy
[0357] Where z represents the continuous depth value at the corresponding pixel. is the fractional part of the depth value, and E is the depth position encoding embedding matrix.
[0358] 22. The method according to claim 11, wherein step 11) comprises:
[0359] 1) Perform dimension permutation on the serialized feature tensor output by the Transformer encoder, converting it from sequence-first format [L,B,C] to batch-first format [B,C,L], where L is the feature sequence length, B is the batch size, and C is the number of feature channels;
[0360] 2) Reshape the feature tensor after dimension permutation into a spatial image format [B,C,H,W], where H and W are the height and width of the feature map, respectively, satisfying L=H×W;
[0361] 3) After performing depth position encoding interpolation on the predicted weighted depth map, a dynamic position encoding tensor [B,C,H,W] with the same dimensions as the spatial feature map is generated;
[0362] 4) The reshaped context-enhanced features are fused with the dynamic positional encoding element-wise, satisfying the following conditions:
[0363] F final [b,c,i,j]=F transformer [b,c,i,j]+E pos (b,D[b,i,j],c)
[0364] Where b is the batch index, c is the channel index, (i,j) is the spatial location coordinate, and D is the predicted depth value;
[0365] 5) Channel-weighted adjustments are applied to the fused features, and geometric perception is enhanced using learnable scaling parameters γ and bias parameters β:
[0366] F out =γ⊙F final +β
[0367] in These are channel-level learnable parameters;
[0368] 6) Output the final depth feature tensor [B,C,H,W] for downstream 3D perception tasks, including but not limited to 3D object detection, scene depth completion and stereo vision matching.
[0369] 23. The method according to claim 11, wherein when performing channel mapping and normalization on the multi-scale feature map in steps 2) and 5), the 1×1 convolution mapping and GroupNorm both adopt shared parameter configuration to ensure the consistency of statistical distribution of features at different scales during cross-stage fusion.
[0370] The SAM skip attention module (from the image depth estimation domain) in the above embodiments represents a significant improvement over existing technologies. The preferred method for fusing these three-scale features is as follows: features are fused through two SAM modules.
[0371] In addition, these embodiments also make some improvements to depth probability distribution prediction, continuous depth value estimation and dynamic position encoding: the prior art is indiscriminate global encoding, while in the embodiments of this application, depth features are dynamically encoded based on the predicted depth map.
[0372] [Alternative Implementation Method 2]:
[0373] like Figure 1 As shown in Example 1: A monocular depth prediction method based on two-stage skip attention and dynamic position coding, characterized by the following steps:
[0374] S1. By using two cascaded skip attention modules, shallow layer 1 / 8-1 / 16 features and mid-layer 1 / 32 global features are fused respectively to generate multi-scale fused features.
[0375] S2. Perform depth classification probability prediction on the multi-scale fusion features, and combine the non-uniform depth candidate values with weighted summation to output a continuously weighted depth map;
[0376] S3. Based on the weighted depth map interpolation, a dynamic position code is generated, which is added to the Transformer-encoded features to output the final depth features of geometry perception.
[0377] Optionally, step S1 further includes:
[0378] S1.1 Weighted aggregation of deep confidence map-guided feature alignment operation dynamically fuses conflicting regions between shallow textures and mid-level semantics;
[0379] S1.2 Inject an attention mask constrained by the optical flow motion trajectory to block erroneous feature associations in dynamically occluded regions; step S2 further includes:
[0380] S2.1 Generate an adaptive temperature coefficient based on the depth confidence map to sharpen the probability distribution of the static high confidence region;
[0381] S2.2 The output of the optical flow motion trajectory constraint module is integrated to enhance the depth continuity of dynamic targets;
[0382] Step S3 further includes:
[0383] S3.1 Backpropagate the depth residual gradient to fine-tune the parameter distribution of the position encoding table in the motion-blurred region;
[0384] S3.2 The depth confidence map is reused to construct a gating mechanism to filter out noise coding injection in low confidence regions.
[0385] The above six steps work together to solve the technical problem of spatiotemporal mismatch of multi-scale features in dynamic scenes, specifically manifested as: depth fracture of moving targets, dynamic occlusion boundary jumps, and distortion of motion-blurred regions.
[0386] Specifically, steps S1.1→S1.2 establish a spatiotemporal reference: S1.1 uses deep confidence weighted fusion to generate a high-confidence feature base, identifying statically reliable regions (such as road planes); S1.2 uses optical flow motion constraint masks to block dynamic interference (such as pedestrian-vehicle occlusion boundaries); thus, outputting clean features with spatiotemporal separation.
[0387] Steps S2.1 to S2.2 involve joint dynamic and static optimization: S2.1 reuses the confidence map sharpening probability to enhance the depth continuity of the static region (compression of the vehicle body planar distribution); S2.2 fuses optical flow signals to constrain the moving target, forcing the wheel depth to synchronize with the physical trajectory; thus, complementary static stability and dynamic consistency are achieved.
[0388] Steps S3.1→S3.2 perform closed-loop self-calibration: S3.1 fine-tunes the encoding table with residual gradient to specifically correct motion ambiguity areas (such as rotating wheels) identified in S1.2; S3.2 uses confidence gating to filter noise and suppress low-confidence encoding interference such as rain and fog; thus, the system's self-consistency is driven by error feedback.
[0389] The depth confidence map in step S1.1 is reused for probabilistic sharpening in S2.1 and gated filtering in S3.2, resulting in triple efficiency enhancement of a single data set. The optical flow signal in step S1.2 drives the motion constraints in S2.2 and guides the precise fine-tuning in S3.1, creating a closed loop for motion modeling.
[0390] The residual gradient in step S3.1 is fed back to the confidence map generation threshold in S1.1 (e.g., to enhance the weight of moving edges) and the spatiotemporal reference evolves dynamically; the gating signal in S3.2 is used to reverse-calibrate the optical flow mask sensitivity in S1.2 and iteratively improve the occlusion blocking accuracy.
[0391] Through the coordinated operation of the above steps, the three technical elements of static feature optimization (S2.1), dynamic motion modeling (S2.2), and closed-loop correction (S3) are linked together by the depth confidence map and optical flow signal, upgrading the traditional isolated "motion processing module" into a spatiotemporally adaptive organic system. The depth confidence map simultaneously serves probability distribution, noise filtering, and feedback calibration; the optical flow signal synchronously ensures motion constraints, fine-tuning positioning, and mask optimization. This resolves the two technical contradictions of dynamic occlusion depth jumps and moving target fragmentation.
[0392] Optionally, step S1 further includes:
[0393] S1.1 dynamically executes a feature-weighted fusion operation guided by a depth confidence map, adaptively balancing shallow and mid-layer textures. Semantic conflict response;
[0394] S1.2 Injects a spatiotemporal mask generated by the optical flow motion trajectory to block cross-object feature association in dynamically occluded regions. Disturbance;
[0395] S1.3 dynamically shrinks the size of the local attention window based on scene motion complexity, enhancing the edge detection of high-speed moving targets. Capturing the details of the relationship;
[0396] Step S2 further includes:
[0397] S2.1 Reuse the depth confidence map to generate the probability distribution temperature coefficient, and sharpen the depth distribution of the static high-confidence region. Class boundaries;
[0398] S2.2 Integrate the optical flow motion trajectory data to constrain the dynamic target depth value, forcing its change to be consistent with the physical displacement trajectory. Track synchronization;
[0399] Step S3 further includes:
[0400] S3.1 Backpropagation of the depth residual gradient of the motion-blurred region, fine-tuning the parameters of the corresponding coordinates in the position encoding table. cloth;
[0401] S3.2 Reuse the depth confidence map to construct a dual-channel gated network, selectively enhancing the geometric encoding of high-confidence regions. Code strength.
[0402] Specifically, firstly, step S1.1 identifies statically reliable regions using a depth confidence map, establishing a reliable benchmark for feature fusion; secondly, step S1.2 utilizes optical flow masks to block dynamic occlusion interference and isolate the boundaries of moving objects; and thirdly, step S1.3 shrinks the attention window based on the motion speed to lock onto the edge details of high-speed targets. These three steps work together to output spatiotemporally decoupled clean features, directly solving the problem of dynamic occlusion boundary transitions and laying the foundation for subsequent steps.
[0403] Secondly, step S2.1 reuses the aforementioned depth confidence map to sharpen the probability distribution of static regions, enhancing depth continuity; step S2.2 fuses optical flow trajectory data to constrain the depth changes of moving targets, forcing them to synchronize with physical displacement. Both steps are jointly optimized based on the same spatiotemporal reference, simultaneously tackling the problem of depth fragmentation in moving targets and further reducing residual errors from dynamic occlusion.
[0404] Finally, step S3.1 uses the depth residual gradient to fine-tune the position encoding table parameters to specifically correct high-speed motion blur regions; step S3.2 reuses the depth confidence map to construct a gating network to suppress noise in low-confidence regions. This layer accurately eliminates high-speed blur distortion, and at the same time, it feeds back the residual gradient to step S1.3 to dynamically optimize the window shrinkage threshold (e.g., shrinking the high-speed region window to 3×3), iteratively improving the motion edge capture accuracy.
[0405] In summary, the above seven steps form a tight closed loop through spatiotemporal benchmark construction → dynamic and static joint optimization → closed-loop calibration → feedback reinforcement.
[0406] The multi-step reuse rate of depth confidence maps and optical flow signals is improved, achieving triple efficiency enhancement of elements with near-zero new cost; the residual feedback mechanism drives the adaptive evolution of dynamic windows, reducing the depth error of high-speed rotating targets; moreover, the fourth-order technology chain suppresses three types of mismatch problems layer by layer (e.g., in some embodiments, motion breakage reduction > 60%, occlusion jump > 55%, and blur distortion > 40%). Thus, this solution solves the technical problem of spatiotemporal collaborative mismatch of multi-scale features in dynamic scenes through data closure and iterative optimization. In some application scenarios, this technical problem specifically manifests as: depth breakage of moving targets, dynamic occlusion boundary jump, and high-speed blur region distortion.
[0407] Optionally, step S1) further includes:
[0408] 1) Extract features from the input monocular image using the ResNet50 backbone network, and generate the first, second, and third feature maps at scales of 1 / 8, 1 / 16, and 1 / 32 respectively;
[0409] 2) The first, second, and third feature maps are mapped to the hidden dimension by 1×1 convolution, and then normalized by GroupNorm;
[0410] 3) The first feature map is downsampled by 3×3 convolution and processed by GroupNorm to align with the spatial resolution of the second feature map;
[0411] 4) Input the downsampled first feature map and the normalized second feature map into the skip attention module (SAM), and perform multi-head self-attention and MLP transformation within a fixed w×w window to obtain the first stage fusion feature;
[0412] 5) Perform bilinear interpolation on the third feature map, upsample it to the spatial size of the first-stage fused features, and process it with 1×1 convolution and GroupNorm;
[0413] 6) Input the first-stage fused features and the upsampled third feature map back into the SAM module to obtain the second-stage fused features;
[0414] Optionally, step S2) further includes:
[0415] 7) The fused features of the second stage are sequentially passed through a depth prediction head and a 1×1 convolutional classifier to generate depth logits;
[0416] 8) Perform Softmax operation on depth logits to obtain the probability distribution of each depth interval, and sum the weighted values according to the preset non-uniform depth candidate value sequence to output the weighted depth map;
[0417] Step S3) further includes:
[0418] 9) Using the weighted depth map as an index, perform linear interpolation in the depth position encoding embedding table to generate a dynamic position encoding of the same size as the feature map;
[0419] 10) Flatten and transpose the second-stage fusion features, and input them together with the flattened preprocessed mask and position encoding into a single-layer Transformer encoder to obtain context-enhanced features;
[0420] 11) Add the context enhancement features to the dynamic position encoding, and reshape them back to the [B,C,H,W] format to output the final depth features for subsequent tasks.
[0421] 2. The method according to Embodiment 1 is characterized in that, when performing channel mapping and normalization on the multi-scale feature map in steps 2) and 5), the 1×1 convolution mapping and GroupNorm both adopt shared parameter configuration to ensure the consistency of statistical distribution of features at different scales during cross-stage fusion.
[0422] 3. The method according to Embodiment 1, characterized in that the jump attention module (SAM) comprises:
[0423] 1) Within each local window of fixed size w×w, a multi-head self-attention mechanism is executed, and its calculation formula is as follows:
[0424]
[0425] Where Q, K, and V are the query, key, and value matrices, respectively, d is the dimension per head, and B is the relative position bias matrix;
[0426] 2) After the attention output, it is sequentially connected to the DropPath residual through LayerNorm, MLP, and the MLP includes two fully connected layers + GELU + Dropout;
[0427] 3) After the MLP output, LayerNorm and DropPath residual connections are applied again to form cross-window feature expression enhancement.
[0428] In Example 3, the Skip Attention Module (SAM) achieves efficient and robust feature fusion through a three-layer cascaded structure, specifically:
[0429] 1. Local window attention:
[0430]
[0431] Multi-head attention is computed within a fixed window (e.g., 7×7), and local geometric associations are enhanced by relative position encoding B.
[0432] 2. Normalization and Residual Linkage:
[0433] The attention output is connected via LayerNorm+MLP (GELU activation) residuals to correct feature distribution shifts.
[0434] 3. Enhanced secondary interference immunity:
[0435] The residual of the second-order LayerNorm+DropPath is used to simulate occlusion failure by randomly masking the path.
[0436] Thus, the three layers form a defense chain of "capture → correction → immunity":
[0437] Local attention captures features but introduces noise.
[0438] - Initial residual (LayerNorm+MLP) corrects distribution and compensates for details →
[0439] - The second-order residual (DropPath) injection provides anti-interference capabilities, forming a closed loop:
[0440] Noise characteristics → Distribution correction → Disturbance immunity enhancement → Robust output
[0441] Ultimately, it achieves a "precision-efficiency-robustness triangle balance" for multi-scale fusion in complex scenarios, which is particularly suitable for dynamic occlusion and lighting changes in autonomous driving.
[0442] Specifically, good technical results have been achieved in the following aspects:
[0443] 1. Edge depth continuity optimization:
[0444] LayerNorm suppresses feature breaks across windows and, combined with residual connections, repairs depth jumps in long-distance objects (such as telephone poles), improving boundary IoU to 0.79 (+27%).
[0445] example: Figure 2Vehicle profile depth error ↓32%
[0446] 2. Real-time guarantee:
[0447] Window attention reduces the complexity to O(M). 2 HW), the lightweight MLP design results in an additional computational load of <8%, and an inference speed of 25 FPS at 1080p input (60% faster than the global Transformer).
[0448] 3. Robust breakthrough through blocking:
[0449] DropPath randomly discards sub-paths with probability p, forcing the network to establish redundant paths. In the KITTI scene test with 30% occlusion, the depth prediction error was reduced by 31%. Figure 3 Hard scene AP3D increased by 17%.
[0450] 4. The method according to Embodiment 1, characterized in that the processing of feature maps of different sizes by the jump attention module in steps 4) and 6) is as follows:
[0451]
[0452] In Example 4, the Skip Attention (SAM) module processes multi-scale feature maps through a two-stage formula:
[0453] 1. First-stage fusion (local detail optimization):
[0454]
[0455] High-resolution shallow features (1 / 8 scale, including texture details) and mid-level features (1 / 16 scale, including contour semantics) are fused using local attention within a fixed window. By using a windowed design (e.g., 7×7), computational complexity is reduced while preserving edge details of near-field objects (e.g., vehicle tire texture), and semantic conflicts between shallow and mid-level features are avoided.
[0456] 2. Second-stage fusion (global context integration):
[0457]
[0458] The F1 score output from the first stage is fused with deep global features (1 / 32 scale, including distant scene layout). This stage employs a cross-scale receptive field expansion strategy (such as dilatation sampling) to ensure that intermediate features inherit shallow details while incorporating deep semantics (such as road extension structures), thus resolving the ambiguity problem in depth prediction for distant targets.
[0459] The first and second phases of processing form a synergistic mechanism, and the two-phase formula constitutes a chain optimization of "local foundation → global expansion":
[0460] 1. SAM1 provides "intermediate features for enhanced detail" for subsequent fusion, preventing deep features from directly overshadowing shallow information;
[0461] 2. SAM2 uses F1 as a medium to gradually inject deep semantics rather than brute-force overlay, ensuring that the detail continuity of far-field depth prediction is not lost.
[0462] Ultimately, lossless fusion of multi-scale features is achieved, significantly improving the consistency of depth estimation in complex scenarios (such as near vehicles and distant road signs in traffic congestion).
[0463] As a result, good technical results were achieved in the following three aspects:
[0464] Semantic conflict resolution: The phased fusion strategy isolates the interference between details and semantics. The first phase focuses on local consistency (such as nearby vehicles), while the second phase enhances global coherence (such as distant buildings), reducing the occlusion boundary depth error by 27% on the KITTI dataset (compared to traditional single-stage fusion).
[0465] Computational efficiency optimization: Window attention reduces complexity, and combined with two-stage cascading, the inference speed reaches 25 FPS (1080p input), which is 60% faster than the global Transformer.
[0466] Cross-scale adaptability: Through two feature recombinations, the network adaptively balances the receptive field requirements at different scales. For example... Figure 2-3 As shown, AP3D improves to 17.3% in Hard scenarios (compared to 16.38% for the original model), demonstrating its robustness in depth prediction for targets of varying sizes.
[0467] 5. The method according to Embodiment 1, characterized in that, in step 8), a Softmax operation is performed on the depth logits to obtain the probability of each discrete interval:
[0468]
[0469] in This is the output for the i-th depth interval. Its preset non-uniform depth candidate value sequence is generated by the following formula:
[0470]
[0471] Where, d min ,d max These represent the minimum and maximum depths, respectively, and N is the number of depth bins.
[0472] 6. The method according to Embodiment 1, characterized in that the expression for the depth location encoding in step 9) is:
[0473]
[0474] The linear interpolation is calculated using the following formula:
[0475] Lerp(x,y,δ)=(1-δ)x+δy
[0476] Where z represents the continuous depth value at the corresponding pixel. is the fractional part of the depth value, and E is the depth position encoding embedding matrix.
[0477] In Example 6, the refinement scheme in step 9 achieves continuous generation of dynamic position codes through a linear interpolation formula:
[0478]
[0479] Where z is the predicted continuous depth value, This represents the decimal part of the depth.
[0480] This approach, to some extent, creates a physics-driven design: z is decomposed into integer and fractional parts, explicitly modeling depth continuity and avoiding quantization errors from static binning. It also promotes dynamic adaptation: the interpolation weight δ adjusts adaptively with the prediction depth, making position encoding more sensitive in near-field high-variability regions (where δ fluctuates greatly) and more stable in far-field smooth regions.
[0481] Ultimately, a closed-loop optimization of "predicted depth → continuous encoding → geometric perception" is achieved, especially improving the robustness of depth estimation at occlusion boundaries (such as the boundary between vehicles and the background).
[0482] This improves the technical effectiveness of the solution in the following three aspects:
[0483] 1. Eliminate depth boundary jumps:
[0484] Traditional methods of rounding down depth values and looking up tables can lead to abrupt changes in the encoding of adjacent pixels (e.g., depths of 10.1 and 10.9 map to different indices). This scheme transforms the discrete encoding embedding table into a continuous function through linear interpolation, enabling smooth transitions in positional encoding when depth values change slightly. In KITTI data testing, the depth map edge breakage error was reduced by 42%.
[0485] 2. Enhanced geometric consistency:
[0486] The decimal part δ in the formula precisely reflects sub-pixel-level depth changes (e.g., δ = 0.3 in 10.3m), ensuring strict alignment between the positional encoding and the geometry of the real scene. Figure 3As shown, the depth continuity of the vehicle outline is significantly improved, and the IoU of the 3D object detection box is increased to 0.79 (+27%).
[0487] 3. Zero-overhead computation optimization:
[0488] Interpolation requires only two multiply-add operations ((1-δ)·A+δ·B), with a single-point GPU processing latency of <0.01ms, saving 90% of computation compared to traditional dynamic network predictive coding.
[0489] 7. The method according to Embodiment 1, characterized in that, in step 10), when constructing the Transformer encoder input sequence, the following three parts are concatenated along the channel dimension and then fed in:
[0490] 1) The second-stage fusion characteristics after flattening and transposing;
[0491] 2) Flattened depth prediction mask, used to indicate occluded or invalid areas;
[0492] 3) The original spatial location encoding of the flattened data;
[0493] After the encoder outputs, it is first reduced in dimension by 1×1 convolution, and then restored to the [H,W] spatial dimension by bilinear interpolation.
[0494] 8. The method according to Embodiment 1, characterized in that step 11) includes:
[0495] 1) Perform dimension permutation on the serialized feature tensor output by the Transformer encoder, converting it from sequence-first format [L,B,C] to batch-first format [B,C,L], where L is the feature sequence length, B is the batch size, and C is the number of feature channels;
[0496] 2) Reshape the feature tensor after dimension permutation into a spatial image format [B,C,H,W], where H and W are the height and width of the feature map, respectively, satisfying L=H×W;
[0497] 3) After performing depth position encoding interpolation on the predicted weighted depth map, a dynamic position encoding tensor [B,C,H,W] with the same dimensions as the spatial feature map is generated;
[0498] 4) The reshaped context-enhanced features are fused with the dynamic positional encoding element-wise, satisfying the following conditions:
[0499] F final [b,c,i,j]=F transformer [b,c,i,j]+E pos (b,D[b,i,j],c)
[0500] Where b is the batch index, c is the channel index, (i,j) is the spatial location coordinate, and D is the predicted depth value;
[0501] 5) Channel-weighted adjustments are applied to the fused features, and geometric perception is enhanced using learnable scaling parameters γ and bias parameters β:
[0502] F out =γ⊙F final +β
[0503] in These are channel-level learnable parameters;
[0504] 6) Output the final depth feature tensor [B,C,H,W] for downstream 3D perception tasks, including but not limited to 3D object detection, scene depth completion and stereo vision matching.
[0505] In Example 8, the refinement scheme in step 11 achieves geometric perception enhancement through a channel adaptive fusion mechanism: feature alignment:
[0506] The sequence features output by the Transformer are reshaped into the spatial format [B,C,H,W], satisfying:
[0507]
[0508] This ensures compatibility with dynamic position coding E pos Dimensions are consistent.
[0509] Deeply guided point-by-point injection:
[0510] Dynamic location encoding is generated based on the predicted depth value D and fused by element-wise addition:
[0511] F final [b,c,i,j]=F trans former [b,c,i,j]+E pos (b,D[b,i,j],c)
[0512] Where (i,j) are spatial coordinates, enabling precise injection of pixel-level geometric information.
[0513] Channel-level adaptive enhancement:
[0514] Introducing learnable parameters γ,β∈R C Perform channel weighting adjustment:
[0515] F out =γ☉F final +β
[0516] Enables the network to autonomously strengthen key geometric channels (such as edges and surfaces).
[0517] Thus, through formula F final =F transformer +E pos A low-level alignment between geometry and semantics is established, while γ and β perform high-level semantic filtering in the channel dimension, resulting in:
[0518] Geometric embedding: E pos Convert depth values into physical space coordinates;
[0519] Semantic fusion: Transformer features carry contextual relationships;
[0520] Channel filtering: γ suppresses conflicting signals (such as erroneous geometric correlations caused by occlusion).
[0521] A three-step collaborative approach enables structural fidelity in depth prediction under occluded scenarios (e.g., improving the depth continuity of an occluded wheel by 41%).
[0522] As a result, technical effects were achieved in the following aspects:
[0523] Geometry-semantic collaborative optimization:
[0524] Depth Position Encoding E pos Carrying subpixel-level geometric information (such as the curvature of an object's surface), and the semantic features F of the Transformer transformer By adding points one by one, the vehicle profile depth error was reduced by 32% on the KITTI data.
[0525] Channel adaptive enhancement: Dynamic calibration of the geometric weights of different channels using γ and β (e.g., strengthening edge channels and weakening channels in flat areas) improves the depth continuity of complex structures (e.g., wheels, building corners), increasing 3D detection box accuracy (AP3D) by 3.5%. Figure 2 ).
[0526] Zero computational redundancy:
[0527] The fusion only requires element-wise addition and channel scaling, reducing computation by 70% compared to the feature concatenation + convolution scheme, while maintaining a real-time performance of 25 FPS.
[0528] 9. The method according to Embodiment 1 is characterized in that the window sizes used in the first stage and the second stage jump attention module can be configured as w1×w1 and w2×w2, respectively, to adapt to the receptive field requirements of different scale features, and w1 and w2 can be determined during training through hyperparameter search or learning.
[0529] In Example 9, the window properties of the two-stage skip attention module were adaptively defined in the following two aspects:
[0530] Window size is configurable:
[0531] The first stage window size w1×w1 is for shallow high-resolution features (1 / 8, 1 / 16 scale), and the second stage w2×w2 is adapted to deep low-resolution features (1 / 32 scale), meeting the receptive field requirements of different scales.
[0532] Dynamic optimization mechanism:
[0533] The window parameters w1 and w2 are dynamically determined during training through hyperparameter search or gradient learning (e.g., w1 focuses on small windows of 3×3 to 7×7, and w2 expands to large windows of 7×7 to 11×11).
[0534] In this way, the two-stage window forms a synergistic mechanism and a complementary chain of "local focus → global expansion":
[0535] The first stage (with a smaller w1) involves intensive computation on high-resolution features, preserving details such as tire texture (e.g.) Figure 1 (Vehicle area). The second stage (w2w2 is larger): expands the receptive field based on downsampling features, associating distant traffic lights with road topology (e.g., Figure 1 (Vision)
[0536] In this way, the two windows work together to form a dynamic adjustment mechanism (such as hyperparameter search) to ensure that the window size always matches the scale distribution of the current input scene, thus solving the scale mismatch problem of fixed windows in complex scenes.
[0537] This window setting improves multi-scale adaptability:
[0538] Shallow features (such as vehicle textures) require small windows (w1=5) to capture details, while deep features (such as road layouts) require large windows (w2=9) to capture the global context. This design reduces the edge depth error of near-field objects by 28% and increases the continuity of distant structures by 35%. Figure 2-3 ).
[0539] In addition, computational efficiency has been optimized:
[0540] Dynamic windows limit complexity to It saves 18% of computation compared to the fixed window scheme (KITTI test results) while maintaining 25 FPS real-time performance.
[0541] Furthermore, the aforementioned window settings also improve cross-scenario robustness:
[0542] The window size is learned autonomously through training data (e.g., w1=5, w2=7 for urban scenes, w1=7, w2=9 for high-speed scenes), which compresses the model generalization fluctuation to ±0.8% (Table 2).
[0543] Optionally, in some embodiments, step S1 further includes:
[0544] -S1.1 Dynamically performs depth gradient-aware convolutional downsampling operations, prioritizing the preservation of fine edges in high-gradient regions. Section characteristics;
[0545] -S1.2 reuses the object boundary map generated by the semantic segmentation task to suppress window attention associations across occluded regions;
[0546] -Step S2 further includes:
[0547] -S2.1 Adaptive scaling of the softmax temperature coefficient of the depth probability distribution compresses the distribution width of the high-confidence region. Spend;
[0548] -S2.2 Introduces the edge map extracted by the depth gradient perception module, and constrains the gradient pair between the depth map and the RGB image. together;
[0549] -Step S3 further includes:
[0550] -S3.1 Reverse fine-tuning of the position encoding embedding table parameters to correct geometric errors identified by the depth gradient perception module. True region;
[0551] -S3.2 Generate gate weights based on the semantic segmentation boundary map to filter invalid position codes in occluded regions. enter.
[0552] The above six sub-steps work together functionally, as follows:
[0553] 1. Source suppression (S1.1→S1.2)
[0554] -S1.1 Preserves key edges (such as vehicle outlines) through deep gradient-aware downsampling, avoiding initial feature fusion. Geometric loss during time.
[0555] -S1.2 Reuse semantic segmentation boundary graph to block erroneous associations in occluded areas (such as isolating vehicles from the background), resulting in a cleaner output. feature.
[0556] 2. Process optimization (S2.1→S2.2)
[0557] -S2.1 Adaptive sharpening probability distribution enhances depth continuity in the high confidence region of the vehicle body and suppresses leaf occlusion in the leaf-covered area. noise.
[0558] -S2.2 reuses the depth gradient map of S1.1, forcing depth jumps to coincide with RGB edges to ensure geometric consistency.
[0559] 3. Closed-loop correction (S3.1→S3.2)
[0560] -S3.1 Fine-tune the position encoding parameters to correct the geometric distortion areas identified by S1.1 (such as the curvature of the foreground road).
[0561] -S3.2 reuses the semantic boundary graph of S1.2 to generate gating weights and filter out occlusion errors.
[0562] This constitutes a three-tiered chain of defense:
[0563] Source (S1 edge preservation + interference blocking) → Optimization (S2 probabilistic sharpening + gradient constraint) → Correction (S3 micro-encoding) (Adjust + gated filtering)
[0564] Form a semantic-geometric cross-domain alignment closed loop.
[0565] -Reusing resources reduces costs:
[0566] The depth gradient graph (S1.1→S2.2) and semantic boundary graph (S1.2→S3.2) are reused across steps with zero additional computational burden. load.
[0567] In summary, the depth gradient graph is passed from step S1 to S2.2 for reuse, and the semantic boundary graph is passed from step S2 to S3.2 for reuse. The error gradient of S3.1 is then fed back to S1.1 to optimize the downsampling region. Through this six-step technical solution, the overall... Above, the error feedback mechanism enables location coding to have scene self-evolution capabilities, and reduces depth error fluctuations in cross-domain testing (city → highway). <±1.5%。
[0568] The technical problem thus solved is the semantic-geometric cross-domain mismatch in multi-scale feature fusion. This problem manifests as... For: occlusion boundary depth jumps (semantic and geometric misalignment), loss of detail in high-texture areas (edge gradients not being utilized), static encoding The code is not adaptable enough to dynamic scenarios.
Claims
1. A monocular depth prediction method based on two-stage skip attention and dynamic position encoding, characterized in that, Includes the following steps: S1. By using two cascaded skip attention modules, shallow layer 1 / 8-1 / 16 features and mid-layer 1 / 32 global features are fused respectively to generate multi-scale fused features. S2. Perform depth classification probability prediction on the multi-scale fusion features, and combine the non-uniform depth candidate values with weighted summation to output a continuously weighted depth map; S3. Based on the weighted depth map interpolation, a dynamic position code is generated, which is added to the Transformer-encoded features to output the final depth features of geometry perception.
2. The monocular depth prediction method based on two-stage skip attention and dynamic position encoding as described in claim 1, wherein: Step S1 further includes: S11) Obtain a multi-scale feature map from a monocular image, wherein the multi-scale feature map includes a first feature map, a second feature map, and a third feature map obtained by downsampling at scales of 1 / 8, 1 / 16, and 1 / 32; S12) Input the first feature map and the second feature map into the jump attention module, and perform multi-head self-attention fusion and multilayer perceptron transformation respectively within a local fixed window to generate the first stage fusion feature; S13) The first-stage fusion features and the third feature map are input again into the jump attention module, and the second-stage fusion features are generated through multi-head self-attention and multilayer perceptron with the same or adjustable window size.
3. The monocular depth prediction method based on two-stage skip attention and dynamic position encoding as described in claim 2, wherein, Step S2 further includes: S24) The second-stage fusion features are sequentially processed by the depth prediction head and classifier to obtain depth classification logits, and the probability distribution of each depth interval is obtained through Softmax operation; S25) The weighted depth map is obtained by weighting and summing the probability distribution with the preset non-uniform depth candidate value sequence.
4. The monocular depth prediction method based on two-stage skip attention and dynamic position encoding as described in claim 3, wherein, Step S3 further includes: S36) Using the weighted depth map as a coordinate index, linear interpolation is performed in the depth position code embedding table to generate a dynamic position code; S37) Flatten the second-stage fused features and input them into the Transformer encoder to obtain context-enhanced features. Add the features to the dynamic position encoding to output the final depth features.
5. The method according to claim 4, characterized in that, The jump attention module includes: A local windowing multi-head self-attention layer with a fixed window size of w×w; a residual connection combining a normalization layer and a multilayer perceptron to enhance cross-window feature representation; Its expression is: Where Q is the query vector, K and V are key vectors, and B is the relative position encoding matrix.
6. The method according to claim 4, characterized in that, The generation of the first stage fusion feature in step S12) further includes performing convolutional downsampling and 1×1 convolutional projection on the first feature map and the second feature map respectively, so that the spatial resolution of the two is consistent before inputting them into the jump attention module.
7. The method according to claim 4, characterized in that, The generation of the second-stage fusion feature in step S13) further includes bilinear interpolation of the third feature map to the resolution of the first-stage fusion feature before inputting it into the skip attention module for fusion.
8. The method according to claim 4, characterized in that, Step S25) The preset non-uniform depth candidate value sequence is generated by the following formula: Where, d min ,d max These represent the minimum and maximum depths, respectively, and N is the number of depth bins. The linear interpolation is calculated using the following formula: Where z represents the continuous depth value at the corresponding pixel. E is the depth location encoding embedding table.
9. The method according to claim 4, characterized in that, The Transformer encoder contains only a single-layer encoder structure, which is used to enhance the context of flattened features to reduce computation and meet the requirements of real-time inference.
10. A monocular depth prediction device based on two-stage skip attention and dynamic position coding, comprising: The processor module is operable to execute the monocular depth method based on two-stage skip attention and dynamic position encoding according to any one of claims 1 to 9.
Citation Information
Cited By
Three-dimensional target detection model generation method and device, three-dimensional target detection model detection method and device, equipment and medium
CN121121083A
Document image correction method and device based on depth guidance, equipment and medium
CN121767245A
Document image rectification method and device based on deep guidance, equipment and medium
CN121767245B
Mine water defluorination and dosing intelligent control method adapting to water quality fluctuation
CN121913575A