You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/inference.md
+10Lines changed: 10 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -107,6 +107,8 @@ sleap-nn track \
107
107
|`--video_dataset`| The dataset for HDF5 videos |`None`|
108
108
|`--video_input_format`| The input_format for HDF5 videos |`channels_last`|
109
109
|`--frames`| List of frames indices. If `None`, all frames in the video are used | All frames |
110
+
|`--no_empty_frames`| If `True`, removes frames with no predicted instances from the output labels |`False`|
111
+
110
112
111
113
#### Performance
112
114
@@ -177,6 +179,14 @@ When using the `sleap-nn track` CLI command with both `--model_paths` and `--tra
177
179
|`--of_max_levels`| Number of pyramid scale levels to consider. This is different from the scale parameter, which determines the initial image scaling (only if `use_flow` is True) |`3`|
178
180
|`--post_connect_single_breaks`| If True and `max_tracks` is not None with local queues candidate method, connects track breaks when exactly one track is lost and exactly one new track is spawned in the frame |`False`|
179
181
182
+
!!! warning "Tracking cleaning and pre-cull parameters"
183
+
184
+
The parameters `--tracking_pre_cull_to_target`, `--tracking_target_instance_count`, `tracking_pre_cull_iou_threshold`, `tracking_clean_iou_threshold` and `--tracking_clean_instance_count` are provided for backwards compatibility with legacy SLEAP workflows and **may be deprecated in future releases**.
185
+
186
+
- To restrict the number of instances per frame, use the `--max_instances` parameter, which selects the top instances with the highest prediction scores.
187
+
188
+
We recommend using `--max_instances` for controlling the number of predicted instances per frame in new projects.
189
+
180
190
#### Fixed Window Tracking
181
191
182
192
This method maintains a fixed-size queue with the last N frames and uses all instances from those frames as candidates for matching.
help="Only run inference on unlabeled suggested frames when running on labels dataset. This is useful for generating predictions for initialization during labeling.",
211
211
)
212
+
@click.option(
213
+
"--no_empty_frames",
214
+
is_flag=True,
215
+
default=False,
216
+
help=("Clear empty frames that did not have predictions before saving to output."),
help="If True and `max_tracks` is not None with local queues candidate method, connects track breaks when exactly one track is lost and exactly one new track is spawned in the frame.",
382
388
)
389
+
@click.option(
390
+
"--tracking_target_instance_count",
391
+
type=int,
392
+
default=0,
393
+
help="Target number of instances to track per frame. (default: 0)",
394
+
)
395
+
@click.option(
396
+
"--tracking_pre_cull_to_target",
397
+
type=int,
398
+
default=0,
399
+
help=(
400
+
"If non-zero and target_instance_count is also non-zero, then cull instances "
401
+
"over target count per frame *before* tracking. (default: 0)"
402
+
),
403
+
)
404
+
@click.option(
405
+
"--tracking_pre_cull_iou_threshold",
406
+
type=float,
407
+
default=0,
408
+
help=(
409
+
"If non-zero and pre_cull_to_target also set, then use IOU threshold to remove "
410
+
"overlapping instances over count *before* tracking. (default: 0)"
411
+
),
412
+
)
413
+
@click.option(
414
+
"--tracking_clean_instance_count",
415
+
type=int,
416
+
default=0,
417
+
help="Target number of instances to clean *after* tracking. (default: 0)",
418
+
)
419
+
@click.option(
420
+
"--tracking_clean_iou_threshold",
421
+
type=float,
422
+
default=0,
423
+
help="IOU to use when culling instances *after* tracking. (default: 0)",
"""Entry point to run inference on trained SLEAP-NN models.
97
108
@@ -125,6 +136,7 @@ def run_inference(
125
136
provided, the anchor part in the `training_config.yaml` is used. Default: `None`.
126
137
only_labeled_frames: (bool) `True` if inference should be run only on user-labeled frames. Default: `False`.
127
138
only_suggested_frames: (bool) `True` if inference should be run only on unlabeled suggested frames. Default: `False`.
139
+
no_empty_frames: (bool) `True` if empty frames that did not have predictions should be cleared before saving to output. Default: `False`.
128
140
batch_size: (int) Number of samples per batch. Default: 4.
129
141
queue_maxsize: (int) Maximum size of the frame buffer queue. Default: 8.
130
142
video_index: (int) Integer index of video in .slp file to predict on. To be used with
@@ -224,6 +236,11 @@ def run_inference(
224
236
Default: 3. (only if `use_flow` is True).
225
237
post_connect_single_breaks: If True and `max_tracks` is not None with local queues candidate method,
226
238
connects track breaks when exactly one track is lost and exactly one new track is spawned in the frame.
239
+
tracking_target_instance_count: Target number of instances to track per frame. (default: 0)
240
+
tracking_pre_cull_to_target: If non-zero and target_instance_count is also non-zero, then cull instances over target count per frame *before* tracking. (default: 0)
241
+
tracking_pre_cull_iou_threshold: If non-zero and pre_cull_to_target also set, then use IOU threshold to remove overlapping instances over count *before* tracking. (default: 0)
242
+
tracking_clean_instance_count: Target number of instances to clean *after* tracking. (default: 0)
243
+
tracking_clean_iou_threshold: IOU to use when culling instances *after* tracking. (default: 0)
227
244
228
245
Returns:
229
246
Returns `sio.Labels` object if `make_labels` is True. Else this function returns
Copy file name to clipboardExpand all lines: sleap_nn/tracking/tracker.py
+53-3Lines changed: 53 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -28,6 +28,8 @@
28
28
compute_euclidean_distance,
29
29
compute_iou,
30
30
compute_cosine_sim,
31
+
cull_instances,
32
+
cull_frame_instances,
31
33
)
32
34
33
35
@@ -74,6 +76,9 @@ class Tracker:
74
76
robust_best_instance: float=1.0
75
77
use_flow: bool=False
76
78
is_local_queue: bool=False
79
+
tracking_target_instance_count: int=0
80
+
tracking_pre_cull_to_target: int=0
81
+
tracking_pre_cull_iou_threshold: float=0
77
82
_scoring_functions: Dict[str, Any] = {
78
83
"oks": compute_oks,
79
84
"iou": compute_iou,
@@ -114,6 +119,9 @@ def from_config(
114
119
of_img_scale: float=1.0,
115
120
of_window_size: int=21,
116
121
of_max_levels: int=3,
122
+
tracking_target_instance_count: int=0,
123
+
tracking_pre_cull_to_target: int=0,
124
+
tracking_pre_cull_iou_threshold: float=0,
117
125
):
118
126
"""Create `Tracker` from config.
119
127
@@ -154,6 +162,9 @@ def from_config(
154
162
of_max_levels: Number of pyramid scale levels to consider. This is different
155
163
from the scale parameter, which determines the initial image scaling.
156
164
Default: 3. (only if `use_flow` is True)
165
+
tracking_target_instance_count: Target number of instances to track per frame. (default: 0)
166
+
tracking_pre_cull_to_target: If non-zero and target_instance_count is also non-zero, then cull instances over target count per frame *before* tracking. (default: 0)
167
+
tracking_pre_cull_iou_threshold: If non-zero and pre_cull_to_target also set, then use IOU threshold to remove overlapping instances over count *before* tracking. (default: 0)
@@ -469,6 +492,9 @@ class FlowShiftTracker(Tracker):
469
492
of_max_levels: Number of pyramid scale levels to consider. This is different
470
493
from the scale parameter, which determines the initial image scaling.
471
494
Default: 3
495
+
tracking_target_instance_count: Target number of instances to track per frame. (default: 0)
496
+
tracking_pre_cull_to_target: If non-zero and target_instance_count is also non-zero, then cull instances over target count per frame *before* tracking. (default: 0)
497
+
tracking_pre_cull_iou_threshold: If non-zero and pre_cull_to_target also set, then use IOU threshold to remove overlapping instances over count *before* tracking. (default: 0)
472
498
473
499
"""
474
500
@@ -703,6 +729,11 @@ def run_tracker(
703
729
of_window_size: int=21,
704
730
of_max_levels: int=3,
705
731
post_connect_single_breaks: bool=False,
732
+
tracking_target_instance_count: int=0,
733
+
tracking_pre_cull_to_target: int=0,
734
+
tracking_pre_cull_iou_threshold: float=0,
735
+
tracking_clean_instance_count: int=0,
736
+
tracking_clean_iou_threshold: float=0,
706
737
) ->List[sio.LabeledFrame]:
707
738
"""Run tracking on a given set of frames.
708
739
@@ -746,6 +777,11 @@ def run_tracker(
746
777
Default: 3. (only if `use_flow` is True).
747
778
post_connect_single_breaks: If True and `max_tracks` is not None with local queues candidate method,
748
779
connects track breaks when exactly one track is lost and exactly one new track is spawned in the frame.
780
+
tracking_target_instance_count: Target number of instances to track per frame. (default: 0)
781
+
tracking_pre_cull_to_target: If non-zero and target_instance_count is also non-zero, then cull instances over target count per frame *before* tracking. (default: 0)
782
+
tracking_pre_cull_iou_threshold: If non-zero and pre_cull_to_target also set, then use IOU threshold to remove overlapping instances over count *before* tracking. (default: 0)
783
+
tracking_clean_instance_count: Target number of instances to clean *after* tracking. (default: 0)
784
+
tracking_clean_iou_threshold: IOU to use when culling instances *after* tracking. (default: 0)
0 commit comments