writer
writer
¶
Disk writer for explainability outputs.
ExplanationWriter
¶
Write raw heatmaps and image overlays to disk.
Initialize the writer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_directory
|
Path
|
Root directory where explanation files are written. |
required |
image_weight
|
float
|
Original-image blend weight used when saving overlay images. |
required |
overlay_image_format
|
str
|
Image file format for overlays. Values may
include a leading dot, such as |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/versatil/explainability/writer.py
save_raw_heatmaps
¶
Write heatmap tensors for one batch and method to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heatmaps
|
dict[str, Tensor]
|
Heatmaps keyed by camera name. |
required |
explanation_type
|
str
|
Explanation method that produced the maps. |
required |
metadata
|
dict
|
Source metadata for this batch. |
required |
batch_counter
|
int
|
Runner-local batch ordinal used in filenames. |
required |
Source code in src/versatil/explainability/writer.py
save_overlays
¶
Write image overlays for one batch and method to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heatmaps
|
dict[str, Tensor]
|
Heatmaps keyed by camera name. |
required |
explanation_type
|
str
|
Explanation method that produced the maps. |
required |
batch
|
ExplanationBatch
|
Source batch containing display images and metadata. |
required |
batch_counter
|
int
|
Runner-local batch ordinal used in fallback names. |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a heatmap has no matching display camera tensor. |
Source code in src/versatil/explainability/writer.py
normalize_image_extension
staticmethod
¶
Normalize and validate an overlay image extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_format
|
str
|
Image file format, with or without a leading dot. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Lowercase extension including the leading dot. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/versatil/explainability/writer.py
select_image_tensor
staticmethod
¶
Select one (C, H, W) image from a camera batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image_tensor
|
Tensor
|
Camera tensor with shape |
required |
batch_index
|
int
|
Batch row index. |
required |
temporal_index
|
int
|
Observation-window index. |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Single image tensor with shape |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/versatil/explainability/writer.py
image_tensor_to_numpy
staticmethod
¶
Convert one image tensor to normalized RGB numpy format.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
image
|
Tensor
|
Image tensor with shape |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
RGB image array in |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the channel count is not 1 or 3. |
Source code in src/versatil/explainability/writer.py
sanitize
staticmethod
¶
Convert metadata strings into filesystem-safe fragments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str
|
Raw value used in a path or filename. |
required |
Returns:
| Type | Description |
|---|---|
str
|
String containing only path-safe alphanumeric, underscore, dot, and |
str
|
dash characters. |
Source code in src/versatil/explainability/writer.py
source_directory
staticmethod
¶
Return the source-specific output subdirectory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict
|
Source metadata attached to the explanation batch. |
required |
Returns:
| Type | Description |
|---|---|
Path
|
|
Source code in src/versatil/explainability/writer.py
sample_label
¶
Build a stable filename prefix for one batch row.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
metadata
|
dict
|
Source metadata for the current batch. |
required |
batch_index
|
int
|
Row within the current batch. |
required |
batch_counter
|
int
|
Runner-local batch ordinal used as a fallback. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Filesystem-safe label. |