provenance
sleap_nn.inference.provenance
¶
Provenance metadata utilities for inference outputs.
This module provides utilities for building and managing provenance metadata that is stored in SLP files produced during inference. Provenance metadata helps track where predictions came from and how they were generated.
Functions:
| Name | Description |
|---|---|
build_inference_provenance |
Build provenance metadata dictionary for inference output. |
build_tracking_only_provenance |
Build provenance metadata for tracking-only pipeline. |
merge_provenance |
Merge additional provenance fields into base provenance. |
build_inference_provenance(model_paths=None, model_type=None, start_time=None, end_time=None, input_labels=None, input_path=None, frames_processed=None, frames_total=None, frame_selection_method=None, inference_params=None, tracking_params=None, device=None, cli_args=None, include_system_info=True)
¶
Build provenance metadata dictionary for inference output.
This function creates a comprehensive provenance dictionary that captures all relevant metadata about an inference run, enabling reproducibility and tracking of prediction origins.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_paths
|
Optional[list[str]]
|
List of paths to model checkpoints used for inference. |
None
|
model_type
|
Optional[str]
|
Type of model used (e.g., "top_down", "bottom_up", "single_instance"). |
None
|
start_time
|
Optional[datetime]
|
Datetime when inference started. |
None
|
end_time
|
Optional[datetime]
|
Datetime when inference finished. |
None
|
input_labels
|
Optional[Labels]
|
Input Labels object if inference was run on an SLP file. The provenance from this object will be preserved. |
None
|
input_path
|
Optional[Union[str, Path]]
|
Path to input file (SLP or video). |
None
|
frames_processed
|
Optional[int]
|
Number of frames that were processed. |
None
|
frames_total
|
Optional[int]
|
Total number of frames in the input. |
None
|
frame_selection_method
|
Optional[str]
|
Method used to select frames (e.g., "all", "labeled", "suggested", "range"). |
None
|
inference_params
|
Optional[dict[str, Any]]
|
Dictionary of inference parameters (peak_threshold, integral_refinement, batch_size, etc.). |
None
|
tracking_params
|
Optional[dict[str, Any]]
|
Dictionary of tracking parameters if tracking was run. |
None
|
device
|
Optional[str]
|
Device used for inference (e.g., "cuda:0", "cpu", "mps"). |
None
|
cli_args
|
Optional[dict[str, Any]]
|
Command-line arguments if available. |
None
|
include_system_info
|
bool
|
If True, include detailed system information. Set to False for lighter-weight provenance. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing provenance metadata suitable for storing in Labels.provenance. |
Example
from datetime import datetime provenance = build_inference_provenance( ... model_paths=["/path/to/model.ckpt"], ... model_type="top_down", ... start_time=datetime.now(), ... end_time=datetime.now(), ... device="cuda:0", ... ) labels.provenance = provenance labels.save("predictions.slp")
Source code in sleap_nn/inference/provenance.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
build_tracking_only_provenance(input_labels=None, input_path=None, start_time=None, end_time=None, tracking_params=None, frames_processed=None, include_system_info=True)
¶
Build provenance metadata for tracking-only pipeline.
This is a simplified version of build_inference_provenance for when only tracking is run without model inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_labels
|
Optional[Labels]
|
Input Labels object with existing predictions. |
None
|
input_path
|
Optional[Union[str, Path]]
|
Path to input SLP file. |
None
|
start_time
|
Optional[datetime]
|
Datetime when tracking started. |
None
|
end_time
|
Optional[datetime]
|
Datetime when tracking finished. |
None
|
tracking_params
|
Optional[dict[str, Any]]
|
Dictionary of tracking parameters. |
None
|
frames_processed
|
Optional[int]
|
Number of frames that were tracked. |
None
|
include_system_info
|
bool
|
If True, include system information. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing provenance metadata. |
Source code in sleap_nn/inference/provenance.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | |
merge_provenance(base_provenance, additional, overwrite=True)
¶
Merge additional provenance fields into base provenance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_provenance
|
dict[str, Any]
|
Base provenance dictionary. |
required |
additional
|
dict[str, Any]
|
Additional fields to merge. |
required |
overwrite
|
bool
|
If True, additional fields overwrite base fields. If False, base fields take precedence. |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Merged provenance dictionary. |