explainability
explainability
¶
Explainability contracts exposed by encoding modules.
ExplanationTargetKind
¶
Bases: StrEnum
Kinds of encoder activations that can be converted into visual maps.
ActivationLayout
¶
Bases: StrEnum
Tensor layouts produced by explainability target layers.
VisionExplanationTarget
dataclass
¶
VisionExplanationTarget(layer, target_kind, activation_layout, output_index=None, prefix_token_count=0, patch_grid=None)
Target-layer metadata needed to convert activations into image maps.
Attributes:
| Name | Type | Description |
|---|---|---|
layer |
Module
|
Module whose forward activation should be captured. |
target_kind |
str
|
Target category from :class: |
activation_layout |
str
|
Layout of the captured activation from
:class: |
output_index |
int | None
|
Optional index when |
prefix_token_count |
int
|
Number of prefix tokens to discard before reshaping ViT patch-token attributions. |
patch_grid |
tuple[int, int] | None
|
Optional |
__post_init__
¶
Validate target metadata.
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
Source code in src/versatil/models/encoding/explainability.py
resolve_timm_feature_info_layer
¶
Resolve a timm feature extractor module from feature_info metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backbone
|
Module
|
timm feature extractor module. |
required |
layer_index
|
int
|
Feature-info output index selected by the encoder. |
required |
Returns:
| Type | Description |
|---|---|
Module | None
|
Module that produces the selected feature output, or |
Module | None
|
backbone has no resolvable feature-info module for that index. |