centroid_convert
sleap_nn.inference.centroid_convert
¶
Conversion helpers for centroid-only output representation.
Single place that owns the mapping between sleap-nn's centroid predictions
and sleap_io objects, so the representation (single-node PredictedInstance
vs sio.PredictedCentroid) and the source tag stay consistent across
outputs.py / predictor.py / writer.py.
#586 consistency. The centroid's meaning is defined by
sleap_nn/data/instance_centroids.py::generate_centroids (shared by training
target generation AND GT-centroid inference), and is selected by the head
config's centroid_method / centroid_fallback (resolved by
resolve_centroid_method). The source tag we record mirrors that, in the
sio.Centroid.from_instance(method=...) vocabulary:
- an explicit, configured anchor node ->
"anchor:<node>" - no anchor configured -> the reduce method itself,
"center_of_mass"(the default),"bbox_center"or"geometric_median"
so the recorded metadata never contradicts the trained target. Keep this in
lockstep with generate_centroids: whatever resolve_centroid_method
returns for a config is what a model trained on it predicts.
Functions:
| Name | Description |
|---|---|
build_predicted_centroid |
Construct a |
centroid_source_for_anchor |
Return the |
build_predicted_centroid(x, y, score, *, track=None, tracking_score=None, source=CENTER_OF_MASS)
¶
Construct a sio.PredictedCentroid from a predicted centroid peak.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
Centroid x-coordinate in original-image pixels. |
required |
y
|
float
|
Centroid y-coordinate in original-image pixels. |
required |
score
|
float
|
Per-instance confidence (the centroid peak value). |
required |
track
|
Optional['sio.Track']
|
Optional |
None
|
tracking_score
|
Optional[float]
|
Optional per-instance tracking score. |
None
|
source
|
str
|
The |
CENTER_OF_MASS
|
Returns:
| Type | Description |
|---|---|
'sio.PredictedCentroid'
|
A |
Source code in sleap_nn/inference/centroid_convert.py
centroid_source_for_anchor(anchor_ind, node_names=None, centroid_method=None)
¶
Return the sio.Centroid.source tag for a centroid model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
anchor_ind
|
Optional[int]
|
The configured anchor-node index ( |
required |
node_names
|
Optional[List[str]]
|
The training skeleton's node names, used to resolve a
human-readable |
None
|
centroid_method
|
Optional[str]
|
The resolved method the model was trained with, one of
|
None
|
Returns:
| Type | Description |
|---|---|
str
|
|
Note
This is a MODEL-level descriptor, not per-instance: a trained centroid
model with an anchor will have learned to predict that anchor when
visible and (per #586) its fallback otherwise, but we cannot recover
per-instance visibility from a bare centroid peak. anchor:* is the
closest faithful model-level tag.