geometric_attention_encoder
geometric_attention_encoder
¶
Taken from DFormerV2 paper: https://arxiv.org/pdf/2504.04701
GeometricFeedForwardNetwork
¶
Bases: Module
DFormerv2-style feed-forward network with an inner depthwise convolution.
Mirrors the reference FeedForwardNetwork: fc1 -> GELU -> 3x3 depthwise convolution with an inner residual -> fc2. The convolution injects local spatial mixing that a plain MLP lacks, and pretrained DFormerv2 checkpoints carry its weights.
Initialize the feed-forward network.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Input and output feature dimension. |
required |
ffn_dimension
|
int
|
Hidden dimension between the two linears. |
required |
Source code in src/versatil/models/layers/geometric_attention/geometric_attention_encoder.py
forward
¶
Apply the feed-forward network to (B, H, W, C) features.
Source code in src/versatil/models/layers/geometric_attention/geometric_attention_encoder.py
GeometricAttentionEncoderBlock
¶
GeometricAttentionEncoderBlock(decomposition_mode, embedding_dimension, number_of_heads, ffn_dimension, drop_path_rate=0.0, use_layer_scale=False, layer_scale_init_value=1e-05, initial_decay=2.0, decay_range=4.0, value_dimension_factor=1, depthwise_kernel_size=5, depthwise_padding=2, input_positional_kernel_size=3, input_positional_padding=1, use_raster_positions=False, use_feedforward_convolution=False)
Bases: Module
Geometric attention encoder block for conditioning with depth maps on RGB images.
Integrates depth-conditioned attention, feed-forward network, and optional layer scaling for residual connections.
Initializes the geometric attention encoder block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decomposition_mode
|
AttentionDecompositionMode
|
Attention mode (full or separable). |
required |
embedding_dimension
|
int
|
Feature dimension. |
required |
number_of_heads
|
int
|
Number of attention heads. |
required |
ffn_dimension
|
int
|
Hidden dimension for the fully-connected layer that follows the self-attention layer. |
required |
drop_path_rate
|
float
|
Stochastic depth rate. |
0.0
|
use_layer_scale
|
bool
|
Whether to use layer scaling. |
False
|
layer_scale_init_value
|
float
|
Initial value for layer scale parameters. |
1e-05
|
initial_decay
|
float
|
Initial decay rate for spatial biases. |
2.0
|
decay_range
|
float
|
Range of decay rates across heads. |
4.0
|
value_dimension_factor
|
int
|
Expansion factor for value dimension. |
1
|
depthwise_kernel_size
|
int
|
Kernel size for value positional encoding. |
5
|
depthwise_padding
|
int
|
Padding for value positional encoding. |
2
|
input_positional_kernel_size
|
int
|
Kernel size for input positional encoding. |
3
|
input_positional_padding
|
int
|
Padding for input positional encoding. |
1
|
use_raster_positions
|
bool
|
Whether rotary encoding uses flattened raster grid positions (the DFormerv2 reference convention). |
False
|
use_feedforward_convolution
|
bool
|
Whether the feed-forward network uses the DFormerv2 inner depthwise convolution instead of a plain MLP. Required for pretrained DFormerv2 checkpoints. |
False
|
Source code in src/versatil/models/layers/geometric_attention/geometric_attention_encoder.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | |
forward
¶
Applies the geometric attention encoder block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb_tensor
|
Tensor
|
Input images of shape (B, H, W, C). |
required |
depth_map
|
Tensor
|
Depth map of shape (B, 1, H, W). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Updated features of shape (B, H, W, C). |