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

COCO format support #102

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

COCO format support #102

wants to merge 5 commits into from

Conversation

talmo
Copy link
Contributor

@talmo talmo commented Jul 3, 2024

Summary by CodeRabbit

  • New Features

    • Introduced functionality for reading and writing COCO-formatted datasets.
    • Added support for loading COCO datasets through a new load_coco function.
    • Enhanced from_filename method to include backend-specific metadata.
  • Improvements

    • Updated video frame reading to conditionally use cv2.imread or iio.imread based on module availability.
  • Bug Fixes

    • Modified load_file function to handle COCO file format appropriately.

Copy link
Contributor

coderabbitai bot commented Jul 3, 2024

Walkthrough

An update to the SLEAP IO module enhanced functionality for handling COCO datasets, including reading, writing, and generating labels. Additionally, new methods for video handling and metadata integration were introduced, with improvements made to frame reading logic.

Changes

File Change Summary
sleap_io/io/coco.py Added functions for reading annotations, creating skeletons, generating labels, and saving them in COCO format.
sleap_io/io/main.py Introduced load_coco function to load COCO datasets and modified load_file to handle COCO files.
sleap_io/io/video.py Enhanced _read_frame function to conditionally use cv2.imread or fallback to iio.imread.
sleap_io/model/video.py Updated from_filename method to include backend_metadata parameter for storing backend-specific metadata.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SLEAP as SLEAP IO
    participant COCOParser as COCO Parser
    participant Video

    User->>SLEAP: Request to load COCO dataset
    SLEAP->>COCOParser: Call load_coco with filename and paths
    COCOParser->>Video: Generate video instances
    COCOParser->>User: Return parsed Labels
Loading

Poem

In the lines of code, a change we see,
COCO datasets handled with glee.
With videos parsed and labels clear,
SLEAP's enhancements bring us cheer.
Metadata kept where it should be,
A brighter, better SLEAP for you and me!

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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.
    • @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 as 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.

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.

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: 5

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 95b9c81 and c9947b6.

Files selected for processing (4)
  • sleap_io/io/coco.py (1 hunks)
  • sleap_io/io/main.py (5 hunks)
  • sleap_io/io/video.py (1 hunks)
  • sleap_io/model/video.py (3 hunks)
Additional context used
Ruff
sleap_io/io/coco.py

20-23: Use contextlib.suppress(ImportError) instead of try-except-pass

Replace with contextlib.suppress(ImportError)

(SIM105)


35-35: Unnecessary open mode parameters

Remove open mode parameters

(UP015)


82-82: Use is and is not for type comparisons, or isinstance() for isinstance checks

(E721)


152-152: Use ann.get("info") instead of ann.get("info", None)

Replace ann.get("info", None) with ann.get("info")

(SIM910)


223-223: Undefined name video

(F821)

sleap_io/model/video.py

63-63: Use X | Y for type annotations

Convert to X | Y

(UP007)


65-65: Use X | Y for type annotations

Convert to X | Y

(UP007)


66-66: Use X | Y for type annotations

Convert to X | Y

(UP007)

Additional comments not posted (8)
sleap_io/io/main.py (2)

134-168: LGTM!

The code changes for loading COCO datasets are approved.


228-229: LGTM!

The code changes for handling COCO files in load_file are approved.

sleap_io/io/coco.py (4)

40-58: LGTM!

The code changes for parsing skeleton metadata are approved.


157-178: LGTM!

The code changes for reading and parsing COCO annotations are approved.


129-129: Use isinstance for type comparison.

Use isinstance instead of type for type comparisons.

-  pts[pts[:, 3] != 2] = np.nan
+  pts[pts[:, 2] != 2] = np.nan

Likely invalid or redundant comment.


92-92: Verify the usage of ann["id"].

Ensure that ann["id"] is correctly defined and used.

Verification successful

ann["id"] is correctly defined and used.

The key ann["id"] is assigned a value from inst_id and is used appropriately within the codebase.

  • sleap_io/io/coco.py: ann["id"] = inst_id
  • sleap_io/io/coco.py: video_id_map[ann["id"]] = (
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `ann["id"]`.

# Test: Search for the definition and usage of `ann["id"]`. Expect: Proper definition and usage.
rg --type python $'ann["id"]'

Length of output: 61



Script:

#!/bin/bash
# Description: Verify the usage of `ann["id"]`.

# Test: Search for the definition and usage of `ann["id"]` in Python files.
rg --type py $'ann["id"]'

Length of output: 26



Script:

#!/bin/bash
# Description: Verify the usage of `ann`.

# Test: Search for the definition and usage of `ann` in Python files.
rg --type py '\bann\b'

Length of output: 2263

sleap_io/model/video.py (1)

Line range hint 66-88: LGTM!

The code changes for adding backend_metadata to from_filename are approved.

sleap_io/io/video.py (1)

740-743: LGTM!

The code changes for conditionally using cv2.imread in _read_frame are approved.

@@ -131,6 +131,43 @@ def save_jabs(labels: Labels, pose_version: int, root_folder: Optional[str] = No
jabs.write_labels(labels, pose_version, root_folder)


def load_coco(
Copy link
Contributor

Choose a reason for hiding this comment

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

Reminder: Address the TODO.

The TODO comment indicates that handling multiple annotations is not yet implemented.

Do you want me to implement the recursive call for handling multiple annotations or open a GitHub issue to track this task?

This function will group images that have the same shape together into a single
logical video.
"""
if type(imgs_prefix) == str:
Copy link
Contributor

Choose a reason for hiding this comment

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

Use isinstance for type comparison.

Use isinstance instead of type for type comparisons.

-  if type(imgs_prefix) == str:
+  if isinstance(imgs_prefix, str):
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if type(imgs_prefix) == str:
if isinstance(imgs_prefix, str):
Tools
Ruff

82-82: Use is and is not for type comparisons, or isinstance() for isinstance checks

(E721)


Use isinstance for type comparison.

Use isinstance instead of type for type comparisons.

-  if type(imgs_prefix) == str:
+  if isinstance(imgs_prefix, str):
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if type(imgs_prefix) == str:
if isinstance(imgs_prefix, str):
Tools
Ruff

82-82: Use is and is not for type comparisons, or isinstance() for isinstance checks

(E721)

img_filename_map = {}
for img_id, lf in enumerate(lfs):
img_filename = f"{img_id}.{img_format}"
img_shape = video.shape[[1, 2]]
Copy link
Contributor

Choose a reason for hiding this comment

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

Fix the undefined variable video.

The variable video is undefined.

-  img_shape = video.shape[[1, 2]]
+  img_shape = lf.video.shape[[1, 2]]
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
img_shape = video.shape[[1, 2]]
img_shape = lf.video.shape[[1, 2]]
Tools
Ruff

223-223: Undefined name video

(F821)

Returns:
A dictionary with the parsed data.
"""
with open(ann_json_path, "r") as f:
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove unnecessary open mode parameter.

The open mode parameter "r" is unnecessary.

-  with open(ann_json_path, "r") as f:
+  with open(ann_json_path) as f:
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. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
with open(ann_json_path, "r") as f:
with open(ann_json_path) as f:
Tools
Ruff

35-35: Unnecessary open mode parameters

Remove open mode parameters

(UP015)

@talmo talmo linked an issue Jul 3, 2024 that may be closed by this pull request
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.

Coco format support
1 participant