dformerv2
dformerv2
¶
DFormerv2: Geometry-aware RGB+Depth encoder for imitation learning.
Based on: "DFormerv2: Geometry Self-Attention for RGBD Semantic Segmentation" https://github.com/VCIP-RGBD/DFormer
DFormerVariant
¶
Bases: StrEnum
Available DFormerv2 model variants.
DFormerPretrainedWeights
¶
Bases: StrEnum
Pretrained checkpoint families on the HuggingFace mirror.
DFormerStage
¶
DFormerStage(embedding_dimension, number_of_heads, num_blocks, decomposition_mode, drop_path_rate=0.0, use_layer_scale=False, layer_scale_init_value=1e-05, initial_decay=2.0, decay_range=4.0, ffn_expansion_factor=4, downsample=None, use_raster_positions=False, use_feedforward_convolution=False)
Bases: Module
Single DFormer stage with multiple geometric attention blocks and optional downsampling.
Initialize DFormer stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Feature dimension for this stage |
required |
number_of_heads
|
int
|
Number of attention heads |
required |
num_blocks
|
int
|
Number of geometric attention blocks in this stage |
required |
decomposition_mode
|
AttentionDecompositionMode
|
Attention computation strategy (full or separable) |
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
|
ffn_expansion_factor
|
int
|
Expansion factor for FFN hidden dimension |
4
|
downsample
|
Module | None
|
Optional downsampling module for next stage |
None
|
use_raster_positions
|
bool
|
Whether rotary encoding uses flattened raster grid positions (the DFormerv2 reference convention). |
False
|
use_feedforward_convolution
|
bool
|
Whether blocks use the DFormerv2 FFN with an inner depthwise convolution instead of a plain MLP. |
False
|
Source code in src/versatil/models/encoding/encoders/cross_modal/rgbd/dformerv2.py
forward
¶
Forward pass through the stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rgb_features
|
Tensor
|
RGB features of shape (B, H, W, C) |
required |
depth_map
|
Tensor
|
Depth map of shape (B, 1, H, W) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
output_features |
Tensor
|
Normalized features for this stage output (B, H, W, C) |
next_features |
Tensor
|
Downsampled features for next stage (B, H', W', C') or same as output if no downsample |
depth_map |
Tensor
|
Resized depth map for next stage (B, 1, H', W') or same as input if no downsample |
Source code in src/versatil/models/encoding/encoders/cross_modal/rgbd/dformerv2.py
DFormerEncoder
¶
DFormerEncoder(input_keys, variant=value, decomposition_mode=value, drop_path_rate=0.1, layer_scale_init_value=1e-06, initial_decay=2.0, pretrained=False, frozen=False, pretrained_weights=value, pooling_method=value, model_dtype=None, lora_config=None)
Bases: RGBDEncoderMixin, Encoder
DFormerv2 encoder for RGB+Depth fusion using geometric self-attention.
Hierarchical encoder with multi-scale feature extraction and depth-conditioned attention.
Initialize DFormer encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_keys
|
str | list[str]
|
Input keys for RGB and depth |
required |
variant
|
str
|
Model variant (S/B/L) |
value
|
decomposition_mode
|
str
|
Attention computation strategy |
value
|
pooling_method
|
str
|
Feature pooling method (spatial_softmax or global_average) |
value
|
drop_path_rate
|
float
|
Stochastic depth rate |
0.1
|
layer_scale_init_value
|
float
|
Initial value for layer scale |
1e-06
|
initial_decay
|
float
|
Initial decay rate for spatial biases |
2.0
|
pretrained
|
bool
|
Whether to use pretrained weights |
False
|
frozen
|
bool
|
Whether to freeze encoder weights |
False
|
pretrained_weights
|
str
|
Which checkpoint family to download from
https://huggingface.co/bbynku/DFormerv2 when |
value
|
model_dtype
|
str | None
|
Precision string from experiment config (e.g. |
None
|
lora_config
|
LoRAAdaptation | None
|
Optional LoRA adapter configuration applied to the stage linears. |
None
|
Source code in src/versatil/models/encoding/encoders/cross_modal/rgbd/dformerv2.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 | |
encode
¶
Encode RGB + depth through DFormer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
dict[str, Tensor]
|
Dict with RGB as (B, C, H, W) and depth as (B, 1, H, W). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dict with RGBD features. |
Source code in src/versatil/models/encoding/encoders/cross_modal/rgbd/dformerv2.py
set_image_size
¶
Compute feature map dimensions and create pooling head.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_height
|
int
|
Target image height. |
required |
image_width
|
int
|
Target image width. |
required |
Source code in src/versatil/models/encoding/encoders/cross_modal/rgbd/dformerv2.py
get_explainability_targets
¶
Return the final DFormer stage for spatial attribution maps.
DFormer stages return a tuple; output_index=0 selects the stage
output before downsampling. The output is NHWC and is converted by the
explainability package before feature-grid map computation.
Returns:
| Type | Description |
|---|---|
list[VisionExplanationTarget]
|
One NHWC spatial feature-map target for the final DFormer stage. |
Source code in src/versatil/models/encoding/encoders/cross_modal/rgbd/dformerv2.py
get_output_specification
¶
Return the output feature names and dimensions for this encoder.
Returns:
| Type | Description |
|---|---|
list[FeatureMetadata]
|
List of FeatureMetadata with RGBD feature name and its pooled dimension. |