talmolab / sleap

A deep learning framework for multi-animal pose tracking.
https://sleap.ai
Other
435 stars 97 forks source link

Allow max tracking args for Kalman filter #1986

Open eberrigan opened 1 month ago

eberrigan commented 1 month ago

Description

Replicating the Error

Software versions:
SLEAP: 1.4.1a2
TensorFlow: 2.9.2
Numpy: 1.22.4
Python: 3.9.20
OS: macOS-14.5-arm64-arm-64bit
.
.
.
Using already trained model for centroid: /Users/elizabethberrigan/repos/sleap/tests/data/models/minimal_instance.UNet.centroid/training_config.json
Using already trained model for centered_instance: /Users/elizabethberrigan/repos/sleap/tests/data/models/minimal_instance.UNet.centered_instance/training_config.json
Command line call:
sleap-track /Users/elizabethberrigan/repos/sleap/tests/data/tracks/clip.2node.slp --only-labeled-frames -m /Users/elizabethberrigan/repos/sleap/tests/data/models/minimal_instance.UNet.centroid/training_config.json -m /Users/elizabethberrigan/repos/sleap/tests/data/models/minimal_instance.UNet.centered_instance/training_config.json --batch_size 4 --tracking.tracker flow --tracking.similarity instance --tracking.match greedy --tracking.track_window 5 --tracking.kf_init_frame_count 10 --tracking.kf_node_indices 0,1,2 --tracking.post_connect_single_breaks 1 --controller_port 9000 --publish_port 9001 -o /Users/elizabethberrigan/repos/sleap/tests/data/tracks/predictions/clip.2node.slp.241003_221743.predictions.slp --verbosity json --no-empty-frames

Started inference at: 2024-10-03 22:17:47.149775
Args:
{
│   'data_path': '/Users/elizabethberrigan/repos/sleap/tests/data/tracks/clip.2node.slp',
│   'models': [
│   │   '/Users/elizabethberrigan/repos/sleap/tests/data/models/minimal_instance.UNet.centroid/training_config.json',
│   │   '/Users/elizabethberrigan/repos/sleap/tests/data/models/minimal_instance.UNet.centered_instance/training_config.json'
│   ],
│   'frames': '',
│   'only_labeled_frames': True,
│   'only_suggested_frames': False,
Traceback (most recent call last):
  File "/Users/elizabethberrigan/miniforge3/envs/sleap_v1.4.1a2/bin/sleap-track", line 33, in <module>
    sys.exit(load_entry_point('sleap==1.4.1a2', 'console_scripts', 'sleap-track')())
  File "/Users/elizabethberrigan/miniforge3/envs/sleap_v1.4.1a2/lib/python3.9/site-packages/sleap/nn/inference.py", line 5467, in main
    tracker = _make_tracker_from_cli(args)
  File "/Users/elizabethberrigan/miniforge3/envs/sleap_v1.4.1a2/lib/python3.9/site-packages/sleap/nn/inference.py", line 5401, in _make_tracker_from_cli
    tracker = Tracker.make_tracker_by_name(**policy_args["tracking"])
  File "/Users/elizabethberrigan/miniforge3/envs/sleap_v1.4.1a2/lib/python3.9/site-packages/sleap/nn/tracking.py", line 916, in make_tracker_by_name
    raise ValueError("Kalman filter requires target instance count.")
ValueError: Kalman filter requires target instance count.
│   'output': '/Users/elizabethberrigan/repos/sleap/tests/data/tracks/predictions/clip.2node.slp.241003_221743.predictions.slp',
│   'no_empty_frames': True,
│   'verbosity': 'json',
│   'video.dataset': None,
│   'video.input_format': 'channels_last',
│   'video.index': '',
│   'cpu': False,
Process return code: 1

Tracing the Error

Started inference at: 2024-10-07 20:55:35.535014 Args: { 'data_path': 'C:/repos/sleap/tests/data/tracks/clip.2node.slp', 'models': [ 'C:/repos/sleap/tests/data/tracks\models\241007_145636.centroid.n=1500\training_config.json', 'C:/repos/sleap/tests/data/tracks\models\241007_154651.centered_instance.n=1500\training_config.json' ], 'frames': '627,-682', 'only_labeled_frames': False, 'only_suggested_frames': False, 'output': 'C:/repos/sleap/tests/data/tracks\predictions\clip.2node.slp.241007_205530.predictions.slp', 'no_empty_frames': True, 'verbosity': 'json', 'video.dataset': None, 'video.input_format': 'channels_last', 'video.index': '0', 'cpu': False, 'first_gpu': False, 'last_gpu': False, 'gpu': 'auto', 'max_edge_length_ratio': 0.25, 'dist_penalty_weight': 1.0, 'batch_size': 4, 'open_in_gui': False, 'peak_threshold': 0.2, 'max_instances': None, 'tracking.tracker': 'flowmaxtracks', 'tracking.max_tracking': True, 'tracking.max_tracks': 2, 'tracking.target_instance_count': None, 'tracking.pre_cull_to_target': None, 'tracking.pre_cull_iou_threshold': None, 2024-10-07 20:55:37.291379: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 'tracking.post_connect_single_breaks': 1, 'tracking.clean_instance_count': None, 'tracking.clean_iou_threshold': None, 'tracking.similarity': 'instance', 'tracking.match': 'hungarian', 'tracking.robust': None, 'tracking.track_window': 5, 'tracking.min_new_track_points': None, 'tracking.min_match_points': None, 2024-10-07 20:55:37.799106: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1525] Created device /job:localhost/replica:0/task:0/device:GPU:0 with 5957 MB memory: -> device: 0, name: NVIDIA GeForce RTX 2070 SUPER, pci bus id: 0000:01:00.0, compute capability: 7.5 'tracking.img_scale': None, 'tracking.of_window_size': None, 'tracking.of_max_levels': None, 'tracking.save_shifted_instances': None, 'tracking.kf_node_indices': [0, 1], 'tracking.kf_init_frame_count': 10, 'tracking.oks_errors': None, 'tracking.oks_score_weighting': 0, 'tracking.oks_normalization': None }

INFO:sleap.nn.inference:Auto-selected GPU 0 with 6744 MiB of free memory. 2024-10-07 20:55:43.684523: I tensorflow/stream_executor/cuda/cuda_dnn.cc:366] Loaded cuDNN version 8201 Versions: Exception in thread Thread-3: Traceback (most recent call last): File "C:\Users\eb\Miniforge3\envs\sleap_dev\lib\threading.py", line 926, in _bootstrap_inner self.run() File "C:\Users\eb\Miniforge3\envs\sleap_dev\lib\threading.py", line 870, in run self._target(*self._args, **self._kwargs) File "c:\repos\sleap\sleap\nn\inference.py", line 2627, in _object_builder t=frame_ind, File "c:\repos\sleap\sleap\nn\tracking.py", line 1433, in track tracked_instances = self.init_tracker.track(untracked_instances, img, t) File "c:\repos\sleap\sleap\nn\tracking.py", line 714, in track img=img, File "c:\repos\sleap\sleap\nn\tracking.py", line 434, in get_candidates ref_instances, ref_img, ref_t, img, t File "c:\repos\sleap\sleap\nn\tracking.py", line 191, in get_shifted_instances max_levels=self.of_max_levels, File "c:\repos\sleap\sleap\nn\tracking.py", line 330, in flow_shift_instances 0.01, cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) in function 'calcOpticalFlowPyrLK'

Overload resolution failed:

  • prevImg is not a numpy array, neither a scalar
  • Expected Ptr for argument 'prevImg'

Types of changes

Does this address any currently open issues?

https://github.com/talmolab/sleap/pull/1447

1583, #1980

Outside contributors checklist

Thank you for contributing to SLEAP!

:heart:

Summary by CodeRabbit

coderabbitai[bot] commented 1 month ago

Walkthrough

The changes in this pull request primarily affect the sleap/nn/tracking.py file, focusing on the Tracker and FlowMaxTracksCandidateMaker classes. A new property max_tracking has been added to the Tracker class, facilitating maximum tracking functionality. The target_instance_count attribute is marked for deprecation, with adjustments made to various methods to accommodate the new max_tracks attribute. Logic for limiting track processing based on max_tracks has been implemented, enhancing the overall tracking capabilities and preparing the codebase for future updates.

Changes

File Path Change Summary
sleap/nn/tracking.py - Added max_tracking property to Tracker class.
- Deprecated target_instance_count attribute with adjusted usage.
- Updated FlowMaxTracksCandidateMaker to limit tracks based on max_tracks.
- Enhanced track method in Tracker to handle max_tracking.
- Modified final_pass method for flexible connection logic.
- Updated make_tracker_by_name method to reflect changes in parameters.

Poem

🐇 In the meadow where tracks align,
A new path opens, oh so fine!
With max_tracking guiding the way,
We hop and skip, come what may.
Old counts fade, new limits rise,
In our world, the future lies! 🌼


📜 Recent review details **Configuration used: CodeRabbit UI** **Review profile: CHILL**
📥 Commits Files that changed from the base of the PR and between 4a8db983fd161f1d9d49973bcbba0aad39bb7094 and 2db959d99f1738af560cf9f61a9b0bc54f592e45.
📒 Files selected for processing (1) * sleap/nn/tracking.py (9 hunks)
🚧 Files skipped from review as they are similar to previous changes (1) * sleap/nn/tracking.py
--- Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
❤️ Share - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)
🪧 Tips ### Chat There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai): - Review comments: Directly reply to a review comment made by CodeRabbit. Example: - `I pushed a fix in commit , please review it.` - `Generate unit testing code for this file.` - `Open a follow-up GitHub issue for this discussion.` - Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples: - `@coderabbitai generate unit testing code for this file.` - `@coderabbitai modularize this function.` - PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples: - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.` - `@coderabbitai read src/utils.ts and generate unit testing code.` - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.` - `@coderabbitai help me debug CodeRabbit configuration file.` Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. ### CodeRabbit Commands (Invoked using PR comments) - `@coderabbitai pause` to pause the reviews on a PR. - `@coderabbitai resume` to resume the paused reviews. - `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository. - `@coderabbitai full review` to do a full review from scratch and review all the files again. - `@coderabbitai summary` to regenerate the summary of the PR. - `@coderabbitai resolve` resolve all the CodeRabbit review comments. - `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository. - `@coderabbitai help` to get help. ### Other keywords and placeholders - Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed. - Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description. - Add `@coderabbitai` anywhere in the PR title to generate the title automatically. ### CodeRabbit Configuration File (`.coderabbit.yaml`) - You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository. - Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information. - If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json` ### Documentation and Community - Visit our [Documentation](https://coderabbit.ai/docs) for detailed information on how to use CodeRabbit. - Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback. - Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.
codecov[bot] commented 1 month ago

Codecov Report

Attention: Patch coverage is 33.33333% with 8 lines in your changes missing coverage. Please review.

Project coverage is 75.46%. Comparing base (7ed1229) to head (2db959d). Report is 56 commits behind head on develop.

Files with missing lines Patch % Lines
sleap/nn/tracking.py 33.33% 8 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #1986 +/- ## =========================================== + Coverage 73.30% 75.46% +2.15% =========================================== Files 134 133 -1 Lines 24087 24642 +555 =========================================== + Hits 17658 18596 +938 + Misses 6429 6046 -383 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.