unet_input_builder
unet_input_builder
¶
torch.nn.Module to construct an input feature vector to use as conditioner for a U-Net.
UNetInputBuilder
¶
Bases: Module
Builds a flattened conditioning vector for U-Net decoders from multi-modal features.
This module takes a dictionary of encoded features (from various encoders like RGB, depth, proprioceptive, etc.), projects them to a common embedding dimension, and concatenates them into a single conditioning vector suitable for U-Net input.
Features are processed based on their dimensionality
- 2D (B, Emb): Used directly (pooled/single token features)
- 3D (B, Seq, Emb): Flattened to (B, Seq*Emb)
- 4D with time (B, T, Seq, Emb): Flattened to (B, TSeqEmb)
- 4D spatial or 5D: Not supported (must be pooled first)
Class tokens (if present) are appended at the end of the feature vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Target dimension for projecting all features. |
required |
Example
builder = UNetInputBuilder(embedding_dimension=256) features = {"rgb_pooled": torch.randn(4, 512), "proprio": torch.randn(4, 64)} conditioning = builder(features) # Shape: (4, 256 + 256)
Source code in src/versatil/models/decoding/unet_input_builder.py
forward
¶
Project and concatenate features into a single conditioning vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
dict[str, Tensor]
|
Dictionary mapping feature names to tensors. Padding masks and pad action keys are automatically filtered out. |
required |
Returns:
| Type | Description |
|---|---|
Tensor | None
|
Concatenated feature tensor of shape (B, total_features * embedding_dimension), |
Tensor | None
|
or None if no valid features are provided. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a feature has an unsupported shape (4D spatial or 5D). |