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

fix: coco category ids can now be not sequential - avoiding memory leak #4309

Merged
merged 3 commits into from
May 6, 2024

Conversation

patrontheo
Copy link
Contributor

@patrontheo patrontheo commented Apr 25, 2024

Closes #4293.

What changes are proposed in this pull request?

parse_coco_categories returns classes_map instead of classes. It is a dict mapping class IDs to class labels. In areas where the list of classes are needed, it it obtained through list(classes_map.values()).

The caveat I see here is that the public facing add_coco_labels function takes classes as an argument (the list of class labels). To avoid changing the public interface, I did not modify that and built classes_mapusing classes_map = {i: label for i, label in enumerate(classes)}. This should work but requires that in labels_or_path files, the category IDs are sequential (starting from zero). This was already the case before this change.
If we want to allow non-sequential category IDs here also, we need to change the public interface and require classes_mapinstead of classes. Or do you see another solution ? Should we change the public interface or leave it like that ?

How is this patch tested? If it is not, please explain why.

Not thoroughly. I am opening a draft PR to run the tests, as explained in Contributing.

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

Summary by CodeRabbit

  • New Features
    • Enhanced label handling in COCO dataset utilities by introducing a mapping of class IDs to labels for improved accuracy and flexibility.

Copy link
Contributor

coderabbitai bot commented Apr 25, 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 in the fiftyone/utils/coco.py file introduces a classes_map to efficiently map class IDs to their corresponding labels. This mapping replaces direct references to classes across various functions, enhancing the handling and flexibility of class identification in COCO dataset operations.

Changes

File Path Change Summary
.../utils/coco.py Introduced classes_map for mapping class IDs to labels, replacing direct references to classes in multiple functions. Adjustments made to handle classes based on classes_map presence.

🐰✨📜
In the land of code, where the rabbits hop,
A new map was drawn, and old paths do stop.
classes_map now leads the way,
Through COCO fields, where data play.
Cheers to changes, both big and small,
Hop along, coders, one and 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.

Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

@patrontheo thanks for taking this on! I'll defer to @swheaton for functional review.

With respect to your comment about add_coco_labels(), perhaps you could update so that its classes argument can be either a list (current) or a dict (new format)?

fiftyone/utils/coco.py Outdated Show resolved Hide resolved
@brimoor brimoor requested a review from swheaton April 25, 2024 14:51
@patrontheo
Copy link
Contributor Author

With respect to your comment about add_coco_labels(), perhaps you could update so that its classes argument can be either a list (current) or a dict (new format)?

Yes, good idea, I did that.

For the Exporter, I haven't tried yet to use existing IDs as you suggested (in #4293), but I'll see if I get a bit of time to look at it.

@patrontheo
Copy link
Contributor Author

@swheaton any input ?

@brimoor brimoor changed the base branch from develop to fix_random_cat_id May 5, 2024 23:28
@brimoor brimoor marked this pull request as ready for review May 5, 2024 23:29
Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

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

LGTM, I'll handle my suggestion to retain class mappings when exporting in a follow-up commit 👍

@brimoor brimoor merged commit 3ca8ba4 into voxel51:fix_random_cat_id May 6, 2024
9 of 10 checks passed
@swheaton
Copy link
Contributor

swheaton commented May 6, 2024

@patrontheo sorry been very busy, prepping to go on leave.

Thank you for the contribution!!

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.

[BUG] Memory leak when importing CocoDetection Dataset with random category_id into FiftyOne
3 participants