qc
sleap.qc
¶
Label Quality Control module for SLEAP.
This module provides tools to detect annotation errors in pose labeling data.
Example usage
import sleap_io as sio from sleap.qc import LabelQCDetector, QCConfig
Load labels¶
labels = sio.load_file("labels.slp")
Create detector with default config¶
detector = LabelQCDetector()
Fit on labels (uses all instances for training)¶
detector.fit(labels)
Get results¶
results = detector.score(labels)
Get flagged instances above threshold¶
flagged = results.get_flagged(threshold=0.7)
Modules:
| Name | Description |
|---|---|
config |
Configuration for Label QC detector. |
detector |
Main Label QC Detector class. |
features |
Feature extraction for Label QC. |
frame_level |
Frame-level quality checks: instance count, duplicate detection. |
gmm |
Gaussian Mixture Model for anomaly detection. |
results |
Result classes for Label QC. |
Classes:
| Name | Description |
|---|---|
LabelQCDetector |
Main detection interface for Label QC. |
QCConfig |
Configuration for QC detector. |
QCFlag |
Single flagged instance with explanation. |
QCResults |
Container for all QC results. |
LabelQCDetector
¶
Main detection interface for Label QC.
This class provides the primary API for detecting annotation errors in pose labeling data.
Example
detector = LabelQCDetector() detector.fit(labels) results = detector.score(labels) flagged = results.get_flagged(threshold=0.7)
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Configuration for the detector. |
|
skeleton_analyzer |
Optional[SkeletonAnalyzer]
|
Analyzer for skeleton properties. |
baseline_extractor |
Optional[BaselineFeatureExtractor]
|
Baseline feature extractor. |
gmm_detector |
Optional[GMMDetector]
|
GMM-based anomaly detector. |
zscore_detector |
Optional[ZScoreDetector]
|
Fallback z-score detector. |
visibility_model |
Optional[VisibilityModel]
|
Visibility pattern model. |
nn_scorer |
Optional[NearestNeighborScorer]
|
Nearest neighbor scorer. |
instance_count_checker |
Optional[InstanceCountChecker]
|
Frame-level instance count checker. |
use_gmm |
bool
|
Whether GMM is being used (vs fallback). |
feature_names |
list[str]
|
Combined list of feature names. |
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize detector with optional config. |
fit |
Fit detector on labels (uses user-labeled instances). |
flag |
Return list of flagged instances above threshold. |
score |
Score all instances and return results. |
Source code in sleap/qc/detector.py
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 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 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 | |
__init__(config=None)
¶
Initialize detector with optional config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Optional[QCConfig]
|
Configuration for the detector. If None, uses defaults. |
None
|
Source code in sleap/qc/detector.py
fit(labels, progress_callback=None)
¶
Fit detector on labels (uses user-labeled instances).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
'sio.Labels'
|
Labels object containing annotated instances. |
required |
progress_callback
|
Optional[ProgressCallback]
|
Optional callback for progress updates. Called with (step_name, progress_fraction, detail_message). |
None
|
Returns:
| Type | Description |
|---|---|
'LabelQCDetector'
|
Self for chaining. |
Source code in sleap/qc/detector.py
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 | |
flag(labels, threshold=None)
¶
Return list of flagged instances above threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
'sio.Labels'
|
Labels object to check. |
required |
threshold
|
Optional[float]
|
Score threshold. If None, uses config default. |
None
|
Returns:
| Type | Description |
|---|---|
list
|
List of QCFlag objects. |
Source code in sleap/qc/detector.py
score(labels, progress_callback=None)
¶
Score all instances and return results.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
labels
|
'sio.Labels'
|
Labels object to score. |
required |
progress_callback
|
Optional[ProgressCallback]
|
Optional callback for progress updates. Called with (step_name, progress_fraction, detail_message). |
None
|
Returns:
| Type | Description |
|---|---|
QCResults
|
QCResults containing instance scores, frame results, and feature contributions. |
Source code in sleap/qc/detector.py
QCConfig
dataclass
¶
Configuration for QC detector.
Attributes:
| Name | Type | Description |
|---|---|---|
use_gmm |
bool
|
Whether to use GMM-based anomaly detection. |
use_curvature |
Literal['auto'] | bool
|
Whether to compute curvature features. If "auto", enables when skeleton has chains >= 5 nodes. |
use_symmetry |
Literal['auto'] | bool
|
Whether to compute symmetry features. If "auto", enables when skeleton has symmetry pairs defined. |
use_anatomical |
bool
|
Whether to compute anatomical features (signed angles). |
instance_threshold |
float
|
Threshold for flagging instances (0-1). Higher = fewer flags, lower = more flags. |
frame_threshold |
float
|
Threshold for frame-level checks. |
duplicate_iou_threshold |
float
|
IOU threshold for duplicate detection. |
duplicate_node_overlap_ratio |
float
|
Node overlap ratio for partial duplicates. |
gmm_n_components |
int
|
Number of GMM components. |
gmm_min_samples |
int
|
Minimum samples required for GMM fitting. Below this, falls back to z-score thresholding. |
gmm_percentile_threshold |
float
|
Percentile below which instances are anomalies. |
auto_calibrate |
bool
|
Whether to auto-calibrate threshold from data. |
calibration_percentile |
float
|
Percentile for auto-calibration. |
Methods:
| Name | Description |
|---|---|
should_use_curvature |
Determine if curvature features should be used. |
should_use_symmetry |
Determine if symmetry features should be used. |
Source code in sleap/qc/config.py
QCFlag
dataclass
¶
Single flagged instance with explanation.
Attributes:
| Name | Type | Description |
|---|---|---|
frame_idx |
int
|
Frame index. |
instance_idx |
int
|
Instance index within the frame. |
video_idx |
int
|
Video index. |
Source code in sleap/qc/results.py
QCResults
dataclass
¶
Container for all QC results.
Attributes:
| Name | Type | Description |
|---|---|---|
instance_scores |
dict[InstanceKey, float]
|
Mapping from instance key to anomaly score (0-1). |
frame_results |
dict[FrameKey, FrameQC]
|
Mapping from frame key to frame-level QC results. |
feature_contributions |
dict[InstanceKey, dict[str, float]]
|
Mapping from instance key to per-feature scores. |
feature_names |
list[str]
|
List of feature names used. |
Methods:
| Name | Description |
|---|---|
get_explanation |
Get human-readable explanation for instance. |
get_flagged |
Get instances flagged above threshold. |
get_frame_issues |
Get frames with issues (incomplete, duplicates, or bad negatives). |
to_dataframe |
Export results as DataFrame. |
Source code in sleap/qc/results.py
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 | |
get_explanation(instance_key)
¶
Get human-readable explanation for instance.
Source code in sleap/qc/results.py
get_flagged(threshold=0.7)
¶
Get instances flagged above threshold.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Score threshold (0-1). Instances with scores >= threshold are flagged. |
0.7
|
Returns:
| Type | Description |
|---|---|
list[QCFlag]
|
List of QCFlag objects, sorted by score descending. |
Source code in sleap/qc/results.py
get_frame_issues()
¶
Get frames with issues (incomplete, duplicates, or bad negatives).
Source code in sleap/qc/results.py
to_dataframe()
¶
Export results as DataFrame.
Returns:
| Type | Description |
|---|---|
'pd.DataFrame'
|
DataFrame with columns: video_idx, frame_idx, instance_idx, score, confidence, top_issue, and one column per feature. |