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. |
insample_prediction |
In-sample model prediction: labelable-but-unlabeled points (Tier-2). |
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
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 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
__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
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 | |
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
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 | |
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). |
use_chirality |
Literal['auto'] | bool
|
Whether to compute the whole-instance left/right mirror-flip (chirality) feature. If "auto", enables when the skeleton has symmetry pairs (defined or inferred by name). Reliable detector, default-ON. |
use_split_detection |
bool
|
Whether to compute the pose-split (chimera) feature that flags a single instance spanning two animals. Reliable detector, default-ON. |
use_duplicate_score |
bool
|
Whether to fold the complementary split-duplicate signal into frame-level duplicate detection. Reliable detector, default-ON. |
use_chain_ordering |
Literal['auto'] | bool
|
Whether to compute the keypoint chain-ordering feature (wrong order along an ordered chain). If "auto", enables when the longest chain has >= 4 nodes. Experimental, default-OFF. |
use_missing_node_check |
bool
|
Whether to run the missing-node check (a node a instance's peers usually keep is absent). Experimental, default-OFF. |
use_appearance |
bool
|
Whether to run the appearance-outlier channel (a node
placed on visually-wrong pixels, e.g. on bedding instead of fur).
Needs decoded image frames; scored outside the GMM as the
|
appearance_patch_size |
int
|
Side length (pixels) of the square image patch cut around each node for the appearance descriptor. |
appearance_min_samples |
int
|
Minimum number of patch samples a node needs at fit time before the appearance model has an opinion on it. |
use_insample_prediction |
bool
|
Whether to run the in-sample model-prediction
channel (Tier-2 missing-node): run a trained sleap-nn model on the
labeled frames and flag unlabeled nodes the model confidently
localizes. Scored outside the GMM as the |
insample_model_path |
str
|
Path to a trained sleap-nn model directory for the in-sample prediction channel. Empty disables the channel (no-op). |
insample_peak_threshold |
float
|
Peak-finding confidence threshold passed to the in-sample model inference (lower = more candidate peaks). |
insample_min_confidence |
float
|
Confidence at/above which a model prediction at an unlabeled node counts as a disagreement (gates the channel score). |
insample_device |
str
|
Torch device for the in-sample inference
( |
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. |
chirality_flip_threshold |
float
|
|
duplicate_score_threshold |
float
|
Combined duplicate-score at/above which a pair is flagged as a duplicate at the frame level. |
chain_turn_angle_deg |
float
|
Per-interior-node turning angle (degrees) above which a chain node counts as an ordering inversion. |
order_inversion_threshold |
float
|
|
missing_node_prob_threshold |
float
|
Minimum expected-visibility probability for a missing node to be flagged as suspicious. |
ordered_chains |
list
|
User-defined ordered chains as lists of node names (ground truth ordering for the chain-ordering detector). Empty = fall back to auto-detected skeleton chains. |
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_chain_ordering |
Determine if the chain-ordering feature should be used. |
should_use_chirality |
Determine if the chirality (L/R mirror-flip) feature should be used. |
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
9 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 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 | |
should_use_chain_ordering(max_chain_length)
¶
Determine if the chain-ordering feature should be used.
Source code in sleap/qc/config.py
should_use_chirality(has_symmetry)
¶
Determine if the chirality (L/R mirror-flip) feature should be used.
Source code in sleap/qc/config.py
should_use_curvature(max_chain_length)
¶
Determine if curvature features should be used.
Source code in sleap/qc/config.py
should_use_symmetry(has_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. |
forced_issues |
dict[InstanceKey, str]
|
Mapping from instance key to a forced top-issue label set
by a detector hard rule (e.g. "Whole-instance L/R flip"). Takes
precedence over inferred/channel issues in |
channel_scores |
dict[str, dict[InstanceKey, float]]
|
Mapping from channel name (e.g. "missing_node") to a
|
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
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 | |
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.
Merges the GMM-based instance_scores with any per-channel scores
(e.g. the missing-node channel) scored outside the GMM: the final score
for an instance is the max of its GMM score and its best channel score.
An instance can therefore be flagged purely on a channel even if it had
no GMM score (its feature_contributions may be absent, in which case
an empty dict is used safely).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
threshold
|
float
|
Score threshold (0-1). Instances with a final score
|
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. |