Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit max tracks via track-local queues #1447

Merged
merged 31 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
8d88668
Initial commit
shrivaths16 Aug 10, 2023
acbb444
Merge remote-tracking branch 'origin/develop' into shrivaths/fix-maxi…
shrivaths16 Aug 11, 2023
3b23e1e
format files
shrivaths16 Aug 14, 2023
e32b8e3
[wip] adding local deque for tracks
shrivaths16 Aug 15, 2023
fe5aeef
format files
shrivaths16 Aug 15, 2023
f494cad
[wip] adding local deque for tracks
shrivaths16 Aug 15, 2023
c8328e1
Merge remote-tracking branch 'origin/develop' into shrivaths/fix-maxi…
shrivaths16 Aug 15, 2023
82ae620
Merge branch 'develop' into shrivaths/fix-maximum-tracking
shrivaths16 Aug 17, 2023
6352e2a
[wip] Add max tracking for simpletracker
shrivaths16 Aug 22, 2023
bef1548
Merge branch 'shrivaths/fix-maximum-tracking' of https://github.com/t…
shrivaths16 Aug 22, 2023
4ddcbc9
[wip] Add max tracking for simple tracker
shrivaths16 Aug 22, 2023
6ff43c6
[wip] add missing argument
shrivaths16 Aug 22, 2023
216f3a3
[wip] Add and modify test functions
shrivaths16 Aug 23, 2023
d897170
[wip] Add and modify test functions
shrivaths16 Aug 24, 2023
9c5579f
Bug fix and refactoring code
shrivaths16 Aug 25, 2023
380038f
[wip] Add max tracking for flow tracker.
shrivaths16 Aug 28, 2023
9413bfd
[wip] Including suggested changes
shrivaths16 Aug 31, 2023
1969d2b
[wip] refactor code
shrivaths16 Sep 1, 2023
c927090
Add test function to check max tracks
shrivaths16 Sep 1, 2023
2e4fece
Added suggestions and feedback
shrivaths16 Sep 2, 2023
bff3333
Prevent the creation of more than max tracks when we have unmatched d…
talmo Sep 6, 2023
0492ff7
Add tests
talmo Sep 6, 2023
89b04af
Use maximum tracking by default when loading model via high level API
talmo Sep 6, 2023
e62db0f
Lint
talmo Sep 8, 2023
3a72e1a
Fix integration test
talmo Sep 8, 2023
74ea980
Refactor max tracker tests
talmo Sep 8, 2023
f8254a4
Add integration test for CLI
talmo Sep 8, 2023
e1e7285
typo
talmo Sep 8, 2023
ee26e2e
Merge branch 'develop' into shrivaths/fix-maximum-tracking
talmo Sep 8, 2023
91ad0b6
Add max tracks to the tracking GUI
talmo Sep 8, 2023
0b2fdd9
Update CLI docs and add examples
talmo Sep 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 59 additions & 37 deletions sleap/config/pipeline_form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -376,28 +376,39 @@ inference:
none:

flow:
- type: text
text: '<b>Pre-tracker data cleaning</b>:'
- name: tracking.target_instance_count
label: Target Number of Instances Per Frame
type: optional_int
none_label: No target
default_disabled: true
range: 1,100
default: 1
- name: tracking.pre_cull_to_target
label: Cull to Target Instance Count
type: bool
default: false
- name: tracking.pre_cull_iou_threshold
label: Cull using IoU Threshold
type: double
default: 0.8
# - type: text
# text: '<b>Pre-tracker data cleaning</b>:'
# - name: tracking.target_instance_count
# label: Target Number of Instances Per Frame
# type: optional_int
# none_label: No target
# default_disabled: true
# range: 1,100
# default: 1
# - name: tracking.pre_cull_to_target
# label: Cull to Target Instance Count
# type: bool
# default: false
# - name: tracking.pre_cull_iou_threshold
# label: Cull using IoU Threshold
# type: double
# default: 0.8
- type: text
text: '<b>Tracking with optical flow</b>:<br />
This tracker "shifts" instances from previous frames using optical flow
before matching instances in each frame to the <i>shifted</i> instances from
prior frames.'
# - name: tracking.max_tracking
# label: Limit max number of tracks
# type: bool
default: false
- name: tracking.max_tracks
label: Max number of tracks
type: optional_int
none_label: No limit
default_disabled: true
range: 1,100
default: 1
- name: tracking.similarity
label: Similarity Method
type: list
Expand All @@ -422,10 +433,10 @@ inference:
none_label: Use max (non-robust)
range: 0,1
default: 0.95
- name: tracking.save_shifted_instances
label: Save shifted instances
type: bool
default: false
# - name: tracking.save_shifted_instances
# label: Save shifted instances
# type: bool
# default: false
- type: text
text: '<b>Kalman filter-based tracking</b>:<br />
Uses the above tracking options to track instances for an initial
Expand All @@ -449,27 +460,38 @@ inference:
default: false

simple:
# - type: text
# text: '<b>Pre-tracker data cleaning</b>:'
# - name: tracking.target_instance_count
# label: Target Number of Instances Per Frame
# type: optional_int
# none_label: No target
# default_disabled: true
# range: 1,100
# default: 1
# - name: tracking.pre_cull_to_target
# label: Cull to Target Instance Count
# type: bool
# default: false
# - name: tracking.pre_cull_iou_threshold
# label: Cull using IoU Threshold
# type: double
# default: 0.8
- type: text
text: '<b>Pre-tracker data cleaning</b>:'
- name: tracking.target_instance_count
label: Target Number of Instances Per Frame
text: '<b>Tracking</b>:<br />
This tracker assigns track identities by matching instances from prior
frames to instances on subsequent frames.'
# - name: tracking.max_tracking
# label: Limit max number of tracks
# type: bool
# default: false
- name: tracking.max_tracks
label: Max number of tracks
type: optional_int
none_label: No target
none_label: No limit
default_disabled: true
range: 1,100
default: 1
- name: tracking.pre_cull_to_target
label: Cull to Target Instance Count
type: bool
default: false
- name: tracking.pre_cull_iou_threshold
label: Cull using IoU Threshold
type: double
default: 0.8
- type: text
text: '<b>Tracking</b>:<br />
This tracker assigns track identities by matching instances from prior
frames to instances on subsequent frames.'
- name: tracking.similarity
label: Similarity Method
type: list
Expand Down
12 changes: 12 additions & 0 deletions sleap/gui/learning/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ def make_predict_cli_call(

optional_items_as_nones = (
"tracking.target_instance_count",
"tracking.max_tracks",
"tracking.kf_init_frame_count",
"tracking.robust",
"max_instances",
Expand All @@ -233,6 +234,16 @@ def make_predict_cli_call(
if key in self.inference_params and self.inference_params[key] is None:
del self.inference_params[key]

# Setting max_tracks to True means we want to use the max_tracking mode.
if "tracking.max_tracks" in self.inference_params:
self.inference_params["tracking.max_tracking"] = True

# Hacky: Update the tracker name to include "maxtracks" suffix.
if self.inference_params["tracking.tracker"] in ("simple", "flow"):
self.inference_params["tracking.tracker"] = (
self.inference_params["tracking.tracker"] + "maxtracks"
)

# --tracking.kf_init_frame_count enables the kalman filter tracking
# so if not set, then remove other (unused) args
if "tracking.kf_init_frame_count" not in self.inference_params:
Expand All @@ -241,6 +252,7 @@ def make_predict_cli_call(

bool_items_as_ints = (
"tracking.pre_cull_to_target",
"tracking.max_tracking",
"tracking.post_connect_single_breaks",
"tracking.save_shifted_instances",
)
Expand Down
16 changes: 11 additions & 5 deletions sleap/nn/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
)
from sleap.nn.utils import reset_input_layer
from sleap.io.dataset import Labels
from sleap.util import frame_list
from sleap.util import frame_list, make_scoped_dictionary
from sleap.instance import PredictedInstance, LabeledFrame

from tensorflow.python.framework.convert_to_constants import (
Expand Down Expand Up @@ -4773,8 +4773,7 @@ def load_model(
be performed.
tracker_window: Number of frames of history to use when tracking. No effect when
`tracker` is `None`.
tracker_max_instances: If not `None`, discard instances beyond this count when
tracking. No effect when `tracker` is `None`.
tracker_max_instances: If not `None`, create at most this many tracks.
disable_gpu_preallocation: If `True` (the default), initialize the GPU and
disable preallocation of memory. This is necessary to prevent freezing on
some systems with low GPU memory and has negligible impact on performance.
Expand Down Expand Up @@ -4863,11 +4862,18 @@ def unpack_sleap_model(model_path):
)
predictor.verbosity = progress_reporting
if tracker is not None:
use_max_tracker = tracker_max_instances is not None
if use_max_tracker and not tracker.endswith("maxtracks"):
# Append maxtracks to the tracker name to use the right tracker variants.
tracker += "maxtracks"
talmo marked this conversation as resolved.
Show resolved Hide resolved

predictor.tracker = Tracker.make_tracker_by_name(
tracker=tracker,
track_window=tracker_window,
post_connect_single_breaks=True,
clean_instance_count=tracker_max_instances,
max_tracking=use_max_tracker,
max_tracks=tracker_max_instances,
# clean_instance_count=tracker_max_instances,
)

# Remove temp dirs.
Expand Down Expand Up @@ -5335,7 +5341,7 @@ def _make_tracker_from_cli(args: argparse.Namespace) -> Optional[Tracker]:
Returns:
An instance of `Tracker` or `None` if tracking method was not specified.
"""
policy_args = sleap.util.make_scoped_dictionary(vars(args), exclude_nones=True)
policy_args = make_scoped_dictionary(vars(args), exclude_nones=True)
if "tracking" in policy_args:
tracker = Tracker.make_tracker_by_name(**policy_args["tracking"])
return tracker
Expand Down
Loading
Loading