feature_projection
feature_projection
¶
Feature projection torch.nn.Module.
Across the module, the following abbreviations are used: - B: Batch size - T: Temporal length (if applicable) - C: Channels/ Original Feature dimension - H: Height (for spatial features) - W: Width (for spatial features) - Emb: Embedding dimension
FeatureProjection
¶
Bases: ModuleAttrMixin
Projects features to a common embedding dimension.
It supports algorithm-context features (B, C), temporal vectors (B, T, C), token sequences (B, T, S, C), and spatial features (B, T, C, H, W). Only 5D tensors are treated as spatial; every other rank is projected with a linear layer over the final dimension.
This module uses lazy initialization - projection layers are created on first forward pass. To support loading checkpoints, it overrides _load_from_state_dict to create layers dynamically from the state dict.
Example
Initialize feature projection module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
embedding_dimension
|
int
|
Target embedding dimension for all features |
required |
Source code in src/versatil/models/layers/feature_projection.py
forward
¶
Project features to common embedding dimension.
The caller controls which features to project by filtering the dictionary before passing it to this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
dict[str, Tensor]
|
Dictionary of features to project |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dictionary of projected features. Spatial inputs come back as |
dict[str, Tensor]
|
(B, T, Emb, H, W); all other ranks keep their shape with the final |
dict[str, Tensor]
|
dimension projected to Emb. |
Source code in src/versatil/models/layers/feature_projection.py
project_and_concatenate
¶
Project features and concatenate them.
The caller controls which features to include by filtering the dictionary before passing it to this method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
features
|
dict[str, Tensor]
|
Dictionary of features to project and concatenate |
required |
concatenation_dimension
|
int
|
Dimension to concatenate along (default: -1) |
-1
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Concatenated projected features |