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

Aadi/sleap-anchors #21

Merged
merged 14 commits into from
Apr 22, 2024
Merged

Aadi/sleap-anchors #21

merged 14 commits into from
Apr 22, 2024

Conversation

aaprasad
Copy link
Contributor

@aaprasad aaprasad commented Nov 10, 2023

Fix SleapDataset to allow user-defined anchor for which crop will be centered around. Default to midpoint if the anchor isnt in the skeleton.

Summary by CodeRabbit

  • New Features

    • Introduced data classes for better tracking of video frame instances.
    • Added a new EvalDataset class for merging datasets.
    • Enhanced tracking inference capabilities with the GTR Model.
    • Implemented a queue system for sliding window tracking.
  • Enhancements

    • Improved model loading and data handling in various components.
    • Updated visualization functions for more detailed video annotations.
    • Upgraded dependency versions for better performance and compatibility.
  • Bug Fixes

    • Adjusted input parameters and logic in dataset handling to improve accuracy and efficiency.
  • Documentation

    • Enhanced docstrings across various methods for clearer code documentation.
  • Refactor

    • Refactored methods to operate on new data structures, improving code clarity and efficiency.

@aaprasad aaprasad changed the base branch from main to aadi-pymotmetrics November 10, 2023 06:26
Co-authored-by: aaprasad <aaprasad.ucsd.edu>
Copy link
Contributor

coderabbitai bot commented Apr 22, 2024

Important

Auto Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The project update primarily enhances the biogtr package, focusing on improving data handling with new structures like Frame and Instance, refining model inference, and expanding dataset functionalities. Changes include better memory management, clearer documentation, and updated methods across various modules to support new data classes, ensuring smoother operations and clearer codebase management.

Changes

Files Change Summary
.gitignore Excluded notebooks/ directory from version control.
biogtr/config.py Enhanced methods for model loading, data handling, and logging.
biogtr/data_structures.py, .../datasets/... Introduced Frame and Instance classes; updated dataset handling.
biogtr/inference/... Refactored to use new data structures and improved tracking logic.
biogtr/models/... Updated model methods to integrate Frame objects and enhanced features.
biogtr/training/..., .../visualize.py Adjusted training and visualization to utilize new structures.
environment.yml, environment_cpu.yml Updated dependency versions.
tests/... Updated tests to align with new data structures and functionalities.

🐰✨
In the land of code where the data hops around,
A rabbit worked hard without any bound.
Frames and Instances, now neatly align,
With models and metrics, all so divine.
Cheers to the changes, big and small,
Hop hop hurray, we've managed them all!
🎉🐇


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
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@aaprasad aaprasad marked this pull request as ready for review April 22, 2024 19:50
@aaprasad
Copy link
Contributor Author

aaprasad commented Apr 22, 2024

@coderabbitai review

Copy link
Contributor

coderabbitai bot commented Apr 22, 2024

@aaprasad, I've reviewed the changes made to biogtr/datasets/sleap_dataset.py as part of the PR. Here are some key observations and suggestions:

Key Changes:

  1. Verbose Mode: A verbose boolean parameter has been added to the SleapDataset class to control the verbosity of output, which is a useful feature for debugging.
  2. Anchor Handling: The anchor parameter now explicitly converts input to lowercase to ensure case insensitivity. This is a good practice for robustness.
  3. Error Handling: Enhanced error handling for frame reading with more informative error messages, which improves the usability and debuggability of the dataset loader.
  4. Data Structure Changes: The method now uses updated data structures like Frame and Instance to organize data, which likely helps in maintaining cleaner code and better separation of concerns.

Suggestions:

  1. Documentation: Consider updating the method and parameter documentation to reflect the new changes, especially the new verbose parameter and the behavior when the anchor is not found.
  2. Error Handling: While the error messages have been improved, it might be beneficial to also consider what happens after an error is printed. For instance, should the function continue processing other frames, or should it stop execution? This depends on the expected behavior in case of errors.
  3. Verbose Warnings: The use of warnings.warn in verbose mode is appropriate, but ensure that it does not clutter the output excessively, especially in long-running processes.

Overall, the modifications align well with the stated goal of the PR to allow user-defined anchors for cropping, with sensible defaults and improved error handling. If you have specific areas in these changes or other parts of the PR you'd like me to look deeper into, please let me know!

Analysis chain
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# List the files changed in the PR
git diff --name-only HEAD~1..HEAD

Length of output: 1129



Script:

#!/bin/bash
# Display the changes made to sleap_dataset.py
git diff HEAD~1..HEAD -- biogtr/datasets/sleap_dataset.py

Length of output: 10805

Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Actionable comments outside the diff hunks (1)
biogtr/datasets/data_utils.py (1)

Line range hint 342-342: Avoid using bare except statements.

Using a bare except statement can catch unexpected exceptions and make debugging more difficult. Specify the exception type to improve error handling and maintainability.


if not self.persistent_tracking:
if self.verbose:
warnings.warn(f"Clearing Queue after tracking")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use of f-string without placeholders.

- warnings.warn(f"Clearing Queue after tracking")
+ warnings.warn("Clearing Queue after tracking")

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
warnings.warn(f"Clearing Queue after tracking")
warnings.warn("Clearing Queue after tracking")

Comment on lines +118 to +133
def to(self, map_location):
"""Move instance to different device or change dtype. (See `torch.to` for more info).

Args:
map_location: Either the device or dtype for the instance to be moved.

Returns:
self: reference to the instance moved to correct device/dtype.
"""
self._gt_track_id = self._gt_track_id.to(map_location)
self._pred_track_id = self._pred_track_id.to(map_location)
self._bbox = self._bbox.to(map_location)
self._crop = self._crop.to(map_location)
self._features = self._features.to(map_location)
self.device = map_location
return self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method to should handle cases where map_location is None to avoid potential errors when no device or dtype is specified.

+ if map_location is not None:

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
def to(self, map_location):
"""Move instance to different device or change dtype. (See `torch.to` for more info).
Args:
map_location: Either the device or dtype for the instance to be moved.
Returns:
self: reference to the instance moved to correct device/dtype.
"""
self._gt_track_id = self._gt_track_id.to(map_location)
self._pred_track_id = self._pred_track_id.to(map_location)
self._bbox = self._bbox.to(map_location)
self._crop = self._crop.to(map_location)
self._features = self._features.to(map_location)
self.device = map_location
return self
def to(self, map_location):
"""Move instance to different device or change dtype. (See `torch.to` for more info).
Args:
map_location: Either the device or dtype for the instance to be moved.
Returns:
self: reference to the instance moved to correct device/dtype.
"""
if map_location is not None:
self._gt_track_id = self._gt_track_id.to(map_location)
self._pred_track_id = self._pred_track_id.to(map_location)
self._bbox = self._bbox.to(map_location)
self._crop = self._crop.to(map_location)
self._features = self._features.to(map_location)
self.device = map_location
return self


import seaborn as sns
import imageio
import hydra
import pandas as pd
import numpy as np
import cv2
import imageio
from matplotlib import pyplot
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unused import matplotlib.pyplot.

- from matplotlib import pyplot

Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation.

Suggested change
from matplotlib import pyplot

biogtr/visualize.py Outdated Show resolved Hide resolved
biogtr/datasets/sleap_dataset.py Outdated Show resolved Hide resolved
biogtr/config.py Outdated Show resolved Hide resolved
@@ -80,7 +81,7 @@ def main(cfg: DictConfig):
if cfg.view_batch.no_train:
return

model = train_cfg.get_gtr_runner()
model = train_cfg.get_gtr_runner() # TODO see if we can use torch.compile()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A TODO comment has been added regarding the use of torch.compile(). This should be addressed or tracked in the project's issue tracking system to ensure it does not get overlooked.

Would you like me to open a GitHub issue to track the investigation into the use of torch.compile() in this context?

biogtr/models/gtr_runner.py Show resolved Hide resolved
biogtr/inference/track_queue.py Show resolved Hide resolved
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@aaprasad aaprasad merged commit 4e0da7c into aadi-pymotmetrics Apr 22, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant