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/refactor-tracker #23

Merged
merged 6 commits into from
Apr 22, 2024
Merged

Conversation

aaprasad
Copy link
Contributor

@aaprasad aaprasad commented Nov 10, 2023

*Add better variable names for model and tracker

  • Implement persistent tracking (ie tracking across chunks)

Summary by CodeRabbit

  • New Features

    • Introduced data classes for better representation of video tracking instances and metadata.
    • Added new dataset classes and methods to enhance data handling and tracking.
    • Enhanced model functionality for improved tracking and inference capabilities.
    • Introduced new visualization techniques for video processing.
  • Enhancements

    • Updated various modules to improve memory management and error handling.
    • Enhanced documentation and type annotations across several modules for clarity.
  • Bug Fixes

    • Adjusted logic in dataset and model methods to fix data handling issues.
  • Documentation

    • Improved clarity and consistency in docstrings and method descriptions.
  • Tests

    • Added and updated tests to cover new data structures and functionalities.

Copy link

codecov bot commented Nov 10, 2023

Codecov Report

Attention: Patch coverage is 89.10891% with 11 lines in your changes are missing coverage. Please review.

Project coverage is 75.79%. Comparing base (e7ca49f) to head (41f45da).

❗ Current head 41f45da differs from pull request most recent head fc9c16e. Consider uploading reports for the commit fc9c16e to get more accurate results

Files Patch % Lines
biogtr/config.py 0.00% 4 Missing ⚠️
biogtr/inference/tracker.py 95.38% 3 Missing ⚠️
biogtr/models/gtr_runner.py 77.77% 2 Missing ⚠️
biogtr/visualize.py 0.00% 2 Missing ⚠️
Additional details and impacted files
@@                    Coverage Diff                     @@
##           aadi-sample-efficiency      #23      +/-   ##
==========================================================
+ Coverage                   75.65%   75.79%   +0.14%     
==========================================================
  Files                          24       24              
  Lines                        1532     1541       +9     
==========================================================
+ Hits                         1159     1168       +9     
  Misses                        373      373              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@aaprasad aaprasad changed the base branch from main to aadi-sample-efficiency November 10, 2023 06:28
Co-authored-by: aaprasad <aaprasad.ucsd.edu>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
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 update enhances the BioGTR framework, focusing on improved data handling, model inference, and configuration management. New data structures and datasets are introduced, and significant enhancements in tracking and visualization capabilities are implemented. The changes also include better error handling, memory management, and documentation to streamline the development and training processes.

Changes

Files Change Summary
.gitignore Added notebooks/ to ignore the notebooks directory.
biogtr/config.py, biogtr/models/... Enhanced model loading, logging, and configuration handling.
biogtr/data_structures.py, biogtr/datasets/... Introduced new data structures and significant dataset handling improvements.
biogtr/inference/... Expanded inference capabilities with new classes and refined tracking logic.
biogtr/training/..., biogtr/models/... Updated training and model architecture for better performance and clarity.
environment.yml, environment_cpu.yml Updated dependencies to support new functionalities.
tests/... Enhanced testing suite with new tests and updated configurations.

Poem

🐰✨
In the code burrows deep and wide,
Where data streams and models hide,
Changes spring like flowers bright,
Tracking, learning in the light.
Cheers to code, forever spry! 🎉
🐰✨


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 22:03
@aaprasad
Copy link
Contributor Author

@coderabbitai review

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 174-175: Avoid using bare except statements.

- except Exception as e:
-     print(e)
-     pass
+ except IndexError as e:
+     print(f"Error accessing data: {e}")

Using a bare except can catch unexpected exceptions and make debugging difficult. It's better to catch specific exceptions that you expect might occur during normal operation. In this case, an IndexError might be more appropriate if the error is related to accessing list indices.


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.

The warning message uses an f-string without placeholders. Consider using a regular string if no formatting is needed.

- 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")

anchor = self.anchor
else:
if self.verbose:
warnings.warn(
Copy link
Contributor

Choose a reason for hiding this comment

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

The warnings module is used but not imported, which will cause a runtime error.

+ import warnings

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(
import warnings
warnings.warn(

for i, instance in enumerate(frames[batch_idx].instances):
if instance.pred_track_id == -1:
instance.pred_track_id = curr_track_id
curr_track += 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Undefined variable curr_track used. It seems there is a typo or missing initialization.

- curr_track += 1
+ curr_track_id += 1

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
curr_track += 1
curr_track_id += 1

Comment on lines 174 to 175
except Exception as e:
print(f"Unable to end track due to {e}")
Copy link
Contributor

Choose a reason for hiding this comment

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

Handle exceptions more gracefully in the end_tracks method.

- except Exception as e:
-     print(f"Unable to end track due to {e}")
-     return False
+ except KeyError:
+     if self.verbose:
+         print(f"Track ID {track_id} not found in the queue.")
+     return False

Using a generic Exception is not recommended as it can mask other unexpected issues. It's better to catch specific exceptions (like KeyError for missing track IDs) to make the error handling clearer and more predictable.


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
except Exception as e:
print(f"Unable to end track due to {e}")
except KeyError:
if self.verbose:
print(f"Track ID {track_id} not found in the queue.")
return False

biogtr/inference/track_queue.py Show resolved Hide resolved
biogtr/inference/track_queue.py Show resolved Hide resolved
Comment on lines +183 to +184
print([[f.device for f in frame.get_features()] for frame in frames])
raise (e)
Copy link
Contributor

Choose a reason for hiding this comment

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

Improve error handling in the forward method.

- except Exception as e:
-     print([[f.device for f in frame.get_features()] for frame in frames])
-     raise (e)
+ except RuntimeError as e:
+     print("Error during feature concatenation:", e)
+     raise

Catching a general Exception is too broad and can obscure the source of errors. It's better to catch more specific exceptions like RuntimeError, which could occur during tensor operations. Additionally, improve the error message to provide more context about the error.


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
print([[f.device for f in frame.get_features()] for frame in frames])
raise (e)
print("Error during feature concatenation:", e)
raise

biogtr/models/global_tracking_transformer.py Show resolved Hide resolved
Comment on lines +10 to +24
def get_boxes_times(frames: List[Frame]) -> Tuple[torch.Tensor, torch.Tensor]:
"""Extract the bounding boxes and frame indices from the input list of instances.

Args:
instances (List[Dict]): List of instance dictionaries
frames (List[Frame]): List of frame objects containing metadata and instances.

Returns:
Tuple[torch.Tensor, torch.Tensor]: A tuple of two tensors containing the
bounding boxes and corresponding frame
indices, respectively.
"""
boxes, times = [], []
_, h, w = instances[0]["img_shape"].flatten()
_, h, w = frames[0].img_shape.flatten()

for fidx, instance in enumerate(instances):
bbox = deepcopy(instance["bboxes"])
for fidx, frame in enumerate(frames):
Copy link
Contributor

Choose a reason for hiding this comment

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

Refactor the get_boxes_times function to efficiently handle Frame objects.

10  def get_boxes_times(frames: List[Frame]) -> Tuple[torch.Tensor, torch.Tensor]:
11      """Extract the bounding boxes and frame indices from the input list of instances.
12  
13      Args:
14          frames (List[Frame]): List of frame objects containing metadata and instances.
15  
16      Returns:
17          Tuple[torch.Tensor, torch.Tensor]: A tuple of two tensors containing the
18                                            bounding boxes and corresponding frame
19                                            indices, respectively.
20      """
21      boxes, times = [], []
22      _, h, w = frames[0].img_shape.flatten()
23  
24      for fidx, frame in enumerate(frames):
25          bbox = deepcopy(frame.get_bboxes())
26          bbox[:, [0, 2]] /= w
27          bbox[:, [1, 3]] /= h
28  
29          boxes.append(bbox)
30          times.append(torch.full((bbox.shape[0],), fidx))
31  
32      boxes = torch.cat(boxes, dim=0)  # N x 4
33      times = torch.cat(times, dim=0).to(boxes.device)  # N
34      return boxes, times

Ensure that the function efficiently processes the Frame objects to extract bounding boxes and frame indices, optimizing for performance and memory usage.


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 get_boxes_times(frames: List[Frame]) -> Tuple[torch.Tensor, torch.Tensor]:
"""Extract the bounding boxes and frame indices from the input list of instances.
Args:
instances (List[Dict]): List of instance dictionaries
frames (List[Frame]): List of frame objects containing metadata and instances.
Returns:
Tuple[torch.Tensor, torch.Tensor]: A tuple of two tensors containing the
bounding boxes and corresponding frame
indices, respectively.
"""
boxes, times = [], []
_, h, w = instances[0]["img_shape"].flatten()
_, h, w = frames[0].img_shape.flatten()
for fidx, instance in enumerate(instances):
bbox = deepcopy(instance["bboxes"])
for fidx, frame in enumerate(frames):
def get_boxes_times(frames: List[Frame]) -> Tuple[torch.Tensor, torch.Tensor]:
"""Extract the bounding boxes and frame indices from the input list of instances.
Args:
frames (List[Frame]): List of frame objects containing metadata and instances.
Returns:
Tuple[torch.Tensor, torch.Tensor]: A tuple of two tensors containing the
bounding boxes and corresponding frame
indices, respectively.
"""
boxes, times = [], []
_, h, w = frames[0].img_shape.flatten()
for fidx, frame in enumerate(frames):
bbox = deepcopy(frame.get_bboxes())
bbox[:, [0, 2]] /= w
bbox[:, [1, 3]] /= h
boxes.append(bbox)
times.append(torch.full((bbox.shape[0],), fidx))
boxes = torch.cat(boxes, dim=0) # N x 4
times = torch.cat(times, dim=0).to(boxes.device) # N
return boxes, times

@aaprasad aaprasad merged commit dd51119 into aadi-sample-efficiency 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