base
base
¶
Base classes for encoder input/output specifications.
EncodingMixin
¶
Bases: ModuleAttrMixin, ABC
Base interface for all encoders, conditional and non-conditional.
Initialize base encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_specification
|
EncoderInput
|
Structured input specification for this encoder |
required |
pretrained
|
bool
|
Whether to use pretrained weights |
False
|
frozen
|
bool
|
Whether to freeze encoder weights |
False
|
device
|
str | None
|
Device to place the encoder on (will use "cuda" if available, else "cpu" if None) |
None
|
model_dtype
|
str | None
|
Precision string from experiment config (e.g. |
None
|
Source code in src/versatil/models/encoding/encoders/base.py
train
¶
Set train/eval mode while keeping fully frozen encoders eval-locked.
Source code in src/versatil/models/encoding/encoders/base.py
get_output_specification
abstractmethod
¶
get_vocab_size
¶
validate_input_metadata
¶
Check that observation metadata is compatible with this encoder.
Note
Called by the encoding pipeline per input key during setup. Subclasses override to check type, channels, dimensions, etc.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
str
|
Observation key being validated. |
required |
metadata
|
BaseMetadata
|
Metadata from the observation space for this key. |
required |
Returns:
| Type | Description |
|---|---|
str | None
|
Error message if incompatible, None if valid. |
Source code in src/versatil/models/encoding/encoders/base.py
set_image_size
¶
Set the target image size for this encoder.
Called by the encoding pipeline after Hydra instantiation, with per-camera image dimensions from the observation space. Image encoders override this to configure their backbone (ViT img_size) or pooling head (CNN spatial dims).
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/base.py
get_explainability_targets
¶
Return target layers and layout metadata for visual explanations.
Encoders that do not process images return an empty list. Vision encoders override this to expose the exact module whose activations should be captured, plus enough layout metadata for the explainability package to reshape gradients back to image space.
Returns:
| Type | Description |
|---|---|
list[VisionExplanationTarget]
|
Explainability targets supported by this encoder. |
Source code in src/versatil/models/encoding/encoders/base.py
is_vision_encoder
¶
Return whether this encoder exposes visual explanation targets.
Returns:
| Type | Description |
|---|---|
bool
|
True when at least one explainability target is available. |