flat
flat
¶
Flat RGB encoder producing (B, S, D) token sequences via timm forward_features.
FlatRGBEncoder
¶
FlatRGBEncoder(input_keys, pretrained, frozen, pooling_method=value, backbone=value, image_size=None, intermediate_layer_index=None, model_dtype=None, lora_config=None)
Bases: RGBEncoderMixin, Encoder
RGB encoder for backbones that output flat token sequences.
Initialize flat RGB encoder with timm backbone.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_keys
|
str | list[str]
|
Camera observation keys. |
required |
pretrained
|
bool
|
Whether to load pretrained weights. |
required |
frozen
|
bool
|
Whether to freeze all parameters. |
required |
pooling_method
|
str
|
Feature pooling strategy for patch tokens. Defaults to CLS token selection. |
value
|
backbone
|
str
|
timm model name for the backbone. |
value
|
image_size
|
int | tuple[int, int] | None
|
Optional image size passed to timm during backbone construction. |
None
|
intermediate_layer_index
|
int | None
|
Optional intermediate layer index for feature extraction. Negative values index from the end. |
None
|
model_dtype
|
str | None
|
Precision string from experiment config (e.g. |
None
|
lora_config
|
LoRAAdaptation | None
|
Optional PEFT LoRA adapter configuration. |
None
|
Source code in src/versatil/models/encoding/encoders/rgb/flat.py
encode
¶
Encode images into features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
dict[str, Tensor]
|
Dict mapping camera keys to image tensors (B*T, C, H, W);
|
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
Dict with RGB features. Single camera: key is |
dict[str, Tensor]
|
Multiple cameras: keys are |
Source code in src/versatil/models/encoding/encoders/rgb/flat.py
set_image_size
¶
Rebuild the backbone with the target image size.
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/rgb/flat.py
validate_input_metadata
¶
Validate that input metadata is camera metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Observation key being validated. |
required |
metadata
|
BaseMetadata
|
Metadata from the observation space. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Error message if incompatible, None if valid. |
Source code in src/versatil/models/encoding/encoders/rgb/flat.py
get_explainability_targets
¶
Return a transformer block for patch-token attribution maps.
Returns:
| Type | Description |
|---|---|
list[VisionExplanationTarget]
|
One token-sequence target with NLC layout, prefix-token count, and |
list[VisionExplanationTarget]
|
patch-grid metadata when available. Returns an empty list for |
list[VisionExplanationTarget]
|
backbones that do not expose a ViT |
Note
Standard CLS-token ViTs often read only the CLS token in the final head, so final patch-token outputs can be uninformative. When the backbone exposes at least two blocks, this selects the block before the last block.
Source code in src/versatil/models/encoding/encoders/rgb/flat.py
get_output_specification
¶
Get structured output specification with feature names and dimensions.
Returns:
| Type | Description |
|---|---|
list[FeatureMetadata]
|
List of FeatureMetadata with per-camera feature names and pooled dimensions. |