features
sleap.qc.features
¶
Feature extraction for Label QC.
Modules:
| Name | Description |
|---|---|
appearance |
Appearance-outlier detection: points placed on occluders / the wrong object. |
baseline |
Baseline feature extraction (v2 features). |
chirality |
Chirality (left/right mirror flip) features. |
duplicate_split |
Split/duplicate instance features for frame-level QC. |
missing_node |
Missing-node detection: labelable points left unlabeled. |
ordering |
Keypoint ordering features: turning angles along chains. |
pose_split |
Pose-split (chimera) features. |
reference |
Reference-based features: nearest neighbor distance. |
skeleton |
Skeleton graph analysis utilities. |
structural |
Structural features: curvature, convex hull. |
visibility |
Visibility pattern features. |
Classes:
| Name | Description |
|---|---|
BaselineFeatureExtractor |
Extract baseline (v2) features from pose instances. |
NearestNeighborScorer |
Score instances by distance to nearest neighbor in reference set. |
SkeletonAnalyzer |
Analyze skeleton topology to determine feature applicability. |
VisibilityModel |
Learn and score visibility patterns. |
Functions:
| Name | Description |
|---|---|
compute_convex_hull |
Compute convex hull metrics for pose compactness. |
compute_curvature |
Compute curvature along a chain of nodes (e.g., spine). |
normalize_pose |
Normalize pose to unit scale and center. |
BaselineFeatureExtractor
¶
Extract baseline (v2) features from pose instances.
Features include: - Edge length z-scores - Joint angle z-scores - Pairwise distance z-scores - Bounding box area z-score - Node isolation (centroid distance) - Symmetry consistency - Visibility features
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize extractor. |
extract |
Extract feature vector from a single instance. |
fit |
Compute statistics from reference instances. |
Source code in sleap/qc/features/baseline.py
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 184 185 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 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 | |
__init__(edges, n_nodes, symmetry_pairs=None)
¶
Initialize extractor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edges
|
list[tuple[int, int]]
|
List of edge tuples (src_idx, dst_idx). |
required |
n_nodes
|
int
|
Number of nodes in skeleton. |
required |
symmetry_pairs
|
Optional[list[tuple[int, int]]]
|
Optional list of symmetric node pairs. |
None
|
Source code in sleap/qc/features/baseline.py
extract(points)
¶
Extract feature vector from a single instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
(n_nodes, 2) array of pose coordinates. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(n_features,) feature vector. |
Source code in sleap/qc/features/baseline.py
182 183 184 185 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 | |
fit(instances)
¶
Compute statistics from reference instances.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instances
|
list[ndarray]
|
List of (n_nodes, 2) arrays of pose coordinates. NaN values indicate invisible nodes. |
required |
Returns:
| Type | Description |
|---|---|
'BaselineFeatureExtractor'
|
Self for chaining. |
Source code in sleap/qc/features/baseline.py
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 | |
NearestNeighborScorer
¶
Score instances by distance to nearest neighbor in reference set.
Uses KD-tree for efficient O(log n) nearest neighbor queries.
Attributes:
| Name | Type | Description |
|---|---|---|
normalize |
Whether to normalize poses before comparison. |
|
method |
Distance method ("euclidean" or "procrustes"). |
|
reference_poses |
Optional[ndarray]
|
Stored reference poses after fitting. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize scorer. |
fit |
Store reference poses and build KD-tree for fast queries. |
score |
Score a pose by distance to nearest neighbor. |
score_batch |
Score multiple poses efficiently using KD-tree. |
Source code in sleap/qc/features/reference.py
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 184 185 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 | |
__init__(normalize=True, method='euclidean')
¶
Initialize scorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
normalize
|
bool
|
Whether to normalize poses before comparison. |
True
|
method
|
str
|
Distance method. |
'euclidean'
|
Source code in sleap/qc/features/reference.py
fit(poses)
¶
Store reference poses and build KD-tree for fast queries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poses
|
ndarray
|
(N_instances, N_nodes, 2) array of reference poses. |
required |
Returns:
| Type | Description |
|---|---|
'NearestNeighborScorer'
|
Self for chaining. |
Source code in sleap/qc/features/reference.py
score(pose)
¶
Score a pose by distance to nearest neighbor.
Uses KD-tree for fast O(log n) queries when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pose
|
ndarray
|
(N_nodes, 2) array. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: - nn_distance: distance to nearest neighbor - nn_index: index of nearest neighbor - mean_distance: mean distance to all references (only for non-KD-tree) |
Source code in sleap/qc/features/reference.py
score_batch(poses)
¶
Score multiple poses efficiently using KD-tree.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
poses
|
ndarray
|
(N_instances, N_nodes, 2) array of poses to score. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N_instances,) array of nearest neighbor distances. |
Source code in sleap/qc/features/reference.py
SkeletonAnalyzer
¶
Analyze skeleton topology to determine feature applicability.
This class extracts structural properties from a skeleton graph that determine which QC features are applicable (e.g., curvature requires chains of 5+ nodes, symmetry requires defined pairs).
Attributes:
| Name | Type | Description |
|---|---|---|
n_nodes |
Number of nodes in the skeleton. |
|
n_edges |
Number of edges. |
|
edges |
list[tuple[int, int]]
|
List of edge tuples (src, dst). |
node_names |
List of node names. |
|
symmetry_pairs |
list[tuple[int, int]]
|
List of symmetric node pairs as (left_idx, right_idx). |
spine |
list[tuple[int, int]]
|
Longest path through the skeleton (main chain). |
all_chains |
list[tuple[int, int]]
|
All simple chains of length >= 3. |
endpoints |
list[tuple[int, int]]
|
Node indices with degree 1. |
branch_points |
list[tuple[int, int]]
|
Node indices with degree > 2. |
max_chain_length |
list[tuple[int, int]]
|
Length of the longest chain. |
n_triplets |
list[tuple[int, int]]
|
Number of joint triplets (for angle features). |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize from a sleap-io Skeleton. |
get_adjacency |
Get adjacency list representation. |
get_curvature_chains |
Get chains suitable for curvature computation. |
Source code in sleap/qc/features/skeleton.py
13 14 15 16 17 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 184 185 186 187 188 189 190 191 192 193 194 | |
has_symmetry
property
¶
Whether skeleton has symmetry pairs defined.
__init__(skeleton)
¶
Initialize from a sleap-io Skeleton.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
skeleton
|
'sio.Skeleton'
|
The skeleton to analyze. |
required |
Source code in sleap/qc/features/skeleton.py
get_adjacency()
¶
Get adjacency list representation.
Source code in sleap/qc/features/skeleton.py
get_curvature_chains(min_length=3)
¶
Get chains suitable for curvature computation.
Returns:
| Type | Description |
|---|---|
list[list[int]]
|
List of chains sorted by length (longest first). |
Source code in sleap/qc/features/skeleton.py
VisibilityModel
¶
Learn and score visibility patterns.
Learns which nodes tend to be visible together, then flags instances where the visibility pattern is unusual (e.g., hip visible but knee invisible when they're usually both visible or both invisible).
Attributes:
| Name | Type | Description |
|---|---|---|
n_nodes |
int
|
Number of nodes in skeleton. |
co_visibility_matrix |
Optional[ndarray]
|
P(node_j visible | node_i visible). |
visibility_rates |
Optional[ndarray]
|
Per-node visibility rates. |
n_instances |
int
|
Number of instances used for fitting. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the visibility model. |
fit |
Learn co-visibility patterns from data. |
get_expected_visibility |
Given some visible nodes, predict expected visibility of others. |
score |
Score how unusual a visibility pattern is. |
Source code in sleap/qc/features/visibility.py
10 11 12 13 14 15 16 17 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 | |
__init__()
¶
Initialize the visibility model.
fit(visibility_masks)
¶
Learn co-visibility patterns from data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visibility_masks
|
ndarray
|
(N_instances, N_nodes) boolean array. True = visible, False = invisible. |
required |
Returns:
| Type | Description |
|---|---|
'VisibilityModel'
|
Self for chaining. |
Source code in sleap/qc/features/visibility.py
get_expected_visibility(partial_mask)
¶
Given some visible nodes, predict expected visibility of others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
partial_mask
|
ndarray
|
(N_nodes,) boolean array with some nodes marked visible. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
(N_nodes,) array of expected visibility probabilities. |
Source code in sleap/qc/features/visibility.py
score(visibility_mask)
¶
Score how unusual a visibility pattern is.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
visibility_mask
|
ndarray
|
(N_nodes,) boolean array. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: - pattern_score: overall unusualness (0 = normal, 1 = very unusual) - n_violations: count of strong violations |
Source code in sleap/qc/features/visibility.py
compute_convex_hull(points)
¶
Compute convex hull metrics for pose compactness.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
(N, 2) array of node coordinates (NaN for invisible). |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: - hull_area: area of convex hull - hull_perimeter: perimeter of convex hull - hull_aspect_ratio: width/height of hull bounding box - compactness: 4*pi*area / perimeter^2 (1 = circle) - n_hull_points: number of points on hull |
Source code in sleap/qc/features/structural.py
compute_curvature(points, chain)
¶
Compute curvature along a chain of nodes (e.g., spine).
Curvature at each interior node is computed from the angle formed by adjacent edges. High curvature = sharp bend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
(N, 2) array of node coordinates. |
required |
chain
|
list[int]
|
Ordered list of node indices forming a chain. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Dictionary with: - curvatures: array of curvature values at each interior node - max_curvature: maximum absolute curvature - mean_curvature: mean absolute curvature - curvature_std: standard deviation of curvature - sign_changes: number of curvature sign changes (wiggliness) |
Source code in sleap/qc/features/structural.py
normalize_pose(points)
¶
Normalize pose to unit scale and center.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points
|
ndarray
|
(N_nodes, 2) array of coordinates (may contain NaN). |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Normalized points array (NaN preserved). |