tracker
sleap_nn.tracking.tracker
¶
Module for tracking.
Classes:
Name | Description |
---|---|
FlowShiftTracker |
Module for tracking using optical flow shift matching. |
Tracker |
Simple Pose Tracker. |
Functions:
Name | Description |
---|---|
connect_single_breaks |
Merge single-frame breaks in tracks by connecting single lost track with single new track. |
run_tracker |
Run tracking on a given set of frames. |
FlowShiftTracker
¶
Bases: Tracker
Module for tracking using optical flow shift matching.
This module handles tracking instances across frames by creating new track IDs (or)
assigning track IDs to each instance when the .track()
is called using optical flow
based track matching. This is a sub-class of the Tracker
module, which configures
the update_candidates()
method specific to optical flow shift matching. This class is
initialized in the Tracker.from_config()
method.
Attributes:
Name | Type | Description |
---|---|---|
candidates |
Either |
|
min_match_points |
int
|
Minimum non-NaN points for match candidates. Default: 0. |
features |
str
|
One of [ |
scoring_method |
str
|
Method to compute association score between features from the
current frame and the previous tracks. One of [ |
scoring_reduction |
str
|
Method to aggregate and reduce multiple scores if there are
several detections associated with the same track. One of [ |
robust_best_instance |
float
|
If the value is between 0 and 1 (excluded), use a robust quantile similarity score for the track. If the value is 1, use the max similarity (non-robust). For selecting a robust score, 0.95 is a good value. |
track_matching_method |
str
|
track matching algorithm. One of |
use_flow |
bool
|
If True, |
is_local_queue |
bool
|
|
img_scale |
float
|
Factor to scale the images by when computing optical flow. Decrease this to increase performance at the cost of finer accuracy. Sometimes decreasing the image scale can improve performance with fast movements. Default: 1.0. |
of_window_size |
int
|
Optical flow window size to consider at each pyramid scale level. Default: 21. |
of_max_levels |
int
|
Number of pyramid scale levels to consider. This is different from the scale parameter, which determines the initial image scaling. Default: 3 |
Methods:
Name | Description |
---|---|
get_shifted_instances_from_prv_frames |
Generate shifted instances onto the new frame by applying optical flow. |
update_candidates |
Return dictionary with the features of tracked instances. |
Source code in sleap_nn/tracking/tracker.py
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 |
|
get_shifted_instances_from_prv_frames(candidates_list, new_img, feature_method)
¶
Generate shifted instances onto the new frame by applying optical flow.
Source code in sleap_nn/tracking/tracker.py
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 |
|
update_candidates(candidates_list, image)
¶
Return dictionary with the features of tracked instances.
In this method, the tracked instances in the tracker queue are shifted on to the current frame using optical flow. The features are then computed from the shifted instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
candidates_list
|
Union[Deque, DefaultDict[int, Deque]]
|
Tracker queue from the candidate class. |
required |
image
|
ndarray
|
Image of the current untracked frame. (used for flow shift tracker) |
required |
Returns:
Type | Description |
---|---|
Dict[int, TrackedInstanceFeature]
|
Dictionary with keys as track IDs and values as the list of |
Source code in sleap_nn/tracking/tracker.py
Tracker
¶
Simple Pose Tracker.
This is the base class for all Trackers. This module handles tracking instances
across frames by creating new track IDs (or) assigning track IDs to each predicted
instance when the .track()
is called. This class is initialized in the Predictor
classes.
Attributes:
Name | Type | Description |
---|---|---|
candidate |
Union[FixedWindowCandidates, LocalQueueCandidates]
|
Instance of either |
min_match_points |
int
|
Minimum non-NaN points for match candidates. Default: 0. |
features |
str
|
Feature representation for the candidates to update current detections.
One of [ |
scoring_method |
str
|
Method to compute association score between features from the
current frame and the previous tracks. One of [ |
scoring_reduction |
str
|
Method to aggregate and reduce multiple scores if there are
several detections associated with the same track. One of [ |
track_matching_method |
str
|
Track matching algorithm. One of |
robust_best_instance |
float
|
If the value is between 0 and 1 (excluded), use a robust quantile similarity score for the track. If the value is 1, use the max similarity (non-robust). For selecting a robust score, 0.95 is a good value. |
use_flow |
bool
|
If True, |
is_local_queue |
bool
|
|
Methods:
Name | Description |
---|---|
assign_tracks |
Assign track IDs using Hungarian method. |
from_config |
Create |
generate_candidates |
Get the tracked instances from tracker queue. |
get_features |
Get features for the current untracked instances. |
get_scores |
Compute association score between untracked and tracked instances. |
scores_to_cost_matrix |
Converts |
track |
Assign track IDs to the untracked list of |
update_candidates |
Return dictionary with the features of tracked instances. |
Source code in sleap_nn/tracking/tracker.py
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 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 |
|
assign_tracks(current_instances, cost_matrix)
¶
Assign track IDs using Hungarian method.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_instances
|
Union[TrackInstances, List[TrackInstanceLocalQueue]]
|
|
required |
cost_matrix
|
ndarray
|
Cost matrix of shape (num_new_instances, num_existing_tracks). |
required |
Returns:
Type | Description |
---|---|
Union[TrackInstances, List[TrackInstanceLocalQueue]]
|
|
Source code in sleap_nn/tracking/tracker.py
from_config(window_size=5, min_new_track_points=0, candidates_method='fixed_window', min_match_points=0, features='keypoints', scoring_method='oks', scoring_reduction='mean', robust_best_instance=1.0, track_matching_method='hungarian', max_tracks=None, use_flow=False, of_img_scale=1.0, of_window_size=21, of_max_levels=3)
classmethod
¶
Create Tracker
from config.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
window_size
|
int
|
Number of frames to look for in the candidate instances to match with the current detections. Default: 5. |
5
|
min_new_track_points
|
int
|
We won't spawn a new track for an instance with fewer than this many non-nan points. Default: 0. |
0
|
candidates_method
|
str
|
Either of |
'fixed_window'
|
min_match_points
|
int
|
Minimum non-NaN points for match candidates. Default: 0. |
0
|
features
|
str
|
Feature representation for the candidates to update current detections.
One of [ |
'keypoints'
|
scoring_method
|
str
|
Method to compute association score between features from the
current frame and the previous tracks. One of [ |
'oks'
|
scoring_reduction
|
str
|
Method to aggregate and reduce multiple scores if there are
several detections associated with the same track. One of [ |
'mean'
|
robust_best_instance
|
float
|
If the value is between 0 and 1 (excluded), use a robust quantile similarity score for the track. If the value is 1, use the max similarity (non-robust). For selecting a robust score, 0.95 is a good value. |
1.0
|
track_matching_method
|
str
|
Track matching algorithm. One of |
'hungarian'
|
max_tracks
|
Optional[int]
|
Meaximum number of new tracks to be created to avoid redundant tracks. (only for local queues candidate) Default: None. |
None
|
use_flow
|
bool
|
If True, |
False
|
optical flow shifts. Default
|
|
required | |
of_img_scale
|
float
|
Factor to scale the images by when computing optical flow. Decrease
this to increase performance at the cost of finer accuracy. Sometimes
decreasing the image scale can improve performance with fast movements.
Default: 1.0. (only if |
1.0
|
of_window_size
|
int
|
Optical flow window size to consider at each pyramid scale
level. Default: 21. (only if |
21
|
of_max_levels
|
int
|
Number of pyramid scale levels to consider. This is different
from the scale parameter, which determines the initial image scaling.
Default: 3. (only if |
3
|
Source code in sleap_nn/tracking/tracker.py
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 |
|
generate_candidates()
¶
get_features(untracked_instances, frame_idx, image=None)
¶
Get features for the current untracked instances.
The feature can either be an embedding of cropped image around each instance (visual feature), the bounding box coordinates, or centroids, or the poses as a feature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
untracked_instances
|
List[PredictedInstance]
|
List of untracked |
required |
frame_idx
|
int
|
Frame index of the current untracked instances. |
required |
image
|
ndarray
|
Image of the current frame if visual features are to be used. |
None
|
Returns:
Type | Description |
---|---|
Union[TrackInstances, List[TrackInstanceLocalQueue]]
|
|
Source code in sleap_nn/tracking/tracker.py
get_scores(current_instances, candidates_feature_dict)
¶
Compute association score between untracked and tracked instances.
For visual feature vectors, this can be cosine_sim
, for bounding boxes
it could be iou
, for centroids it could be euclidean_dist
, and for poses it
could be oks
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
current_instances
|
Union[TrackInstances, List[TrackInstanceLocalQueue]]
|
|
required |
candidates_feature_dict
|
Dict[int, TrackedInstanceFeature]
|
Dictionary with keys as track IDs and values as the
list of |
required |
Returns:
Name | Type | Description |
---|---|---|
scores |
Score matrix of shape (num_new_instances, num_existing_tracks) |
Source code in sleap_nn/tracking/tracker.py
scores_to_cost_matrix(scores)
¶
Converts scores
matrix to cost matrix for track assignments.
track(untracked_instances, frame_idx, image=None)
¶
Assign track IDs to the untracked list of sio.PredictedInstance
objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
untracked_instances
|
List[PredictedInstance]
|
List of untracked |
required |
frame_idx
|
int
|
Frame index of the predicted instances. |
required |
image
|
ndarray
|
Source image if visual features are to be used (also when using flow). |
None
|
Returns:
Type | Description |
---|---|
List[PredictedInstance]
|
List of |
Source code in sleap_nn/tracking/tracker.py
update_candidates(candidates_list, image)
¶
Return dictionary with the features of tracked instances.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
candidates_list
|
Union[Deque, DefaultDict[int, Deque]]
|
List of tracked instances from tracker queue to consider. |
required |
image
|
ndarray
|
Image of the current untracked frame. (used for flow shift tracker) |
required |
Returns:
Type | Description |
---|---|
Dict[int, TrackedInstanceFeature]
|
Dictionary with keys as track IDs and values as the list of |
Source code in sleap_nn/tracking/tracker.py
connect_single_breaks(lfs, max_instances)
¶
Merge single-frame breaks in tracks by connecting single lost track with single new track.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
lfs
|
List[LabeledFrame]
|
List of |
required |
max_instances
|
int
|
The maximum number of instances we want per frame. |
required |
Returns:
Type | Description |
---|---|
List[LabeledFrame]
|
Updated list of labeled frames with modified track IDs. |
Source code in sleap_nn/tracking/tracker.py
run_tracker(untracked_frames, window_size=5, min_new_track_points=0, candidates_method='fixed_window', min_match_points=0, features='keypoints', scoring_method='oks', scoring_reduction='mean', robust_best_instance=1.0, track_matching_method='hungarian', max_tracks=None, use_flow=False, of_img_scale=1.0, of_window_size=21, of_max_levels=3, post_connect_single_breaks=False)
¶
Run tracking on a given set of frames.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
untracked_frames
|
List[LabeledFrame]
|
List of labeled frames with predicted instances to be tracked. |
required |
window_size
|
int
|
Number of frames to look for in the candidate instances to match with the current detections. Default: 5. |
5
|
min_new_track_points
|
int
|
We won't spawn a new track for an instance with fewer than this many points. Default: 0. |
0
|
candidates_method
|
str
|
Either of |
'fixed_window'
|
min_match_points
|
int
|
Minimum non-NaN points for match candidates. Default: 0. |
0
|
features
|
str
|
Feature representation for the candidates to update current detections.
One of [ |
'keypoints'
|
scoring_method
|
str
|
Method to compute association score between features from the
current frame and the previous tracks. One of [ |
'oks'
|
scoring_reduction
|
str
|
Method to aggregate and reduce multiple scores if there are
several detections associated with the same track. One of [ |
'mean'
|
robust_best_instance
|
float
|
If the value is between 0 and 1 (excluded), use a robust quantile similarity score for the track. If the value is 1, use the max similarity (non-robust). For selecting a robust score, 0.95 is a good value. |
1.0
|
track_matching_method
|
str
|
Track matching algorithm. One of |
'hungarian'
|
max_tracks
|
Optional[int]
|
Meaximum number of new tracks to be created to avoid redundant tracks. (only for local queues candidate) Default: None. |
None
|
use_flow
|
bool
|
If True, |
False
|
optical flow shifts. Default
|
|
required | |
of_img_scale
|
float
|
Factor to scale the images by when computing optical flow. Decrease
this to increase performance at the cost of finer accuracy. Sometimes
decreasing the image scale can improve performance with fast movements.
Default: 1.0. (only if |
1.0
|
of_window_size
|
int
|
Optical flow window size to consider at each pyramid scale
level. Default: 21. (only if |
21
|
of_max_levels
|
int
|
Number of pyramid scale levels to consider. This is different
from the scale parameter, which determines the initial image scaling.
Default: 3. (only if |
3
|
post_connect_single_breaks
|
bool
|
If True and |
False
|
Returns:
Type | Description |
---|---|
List[LabeledFrame]
|
|
Source code in sleap_nn/tracking/tracker.py
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 |
|