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

Add option to SDK allowing upload of annotation as masks instead of polygon. #8823

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

jaroslavknotek
Copy link

@jaroslavknotek jaroslavknotek commented Dec 12, 2024

Motivation and context

I am using SDK to create project with pre-annotations. Having data in Camvid 1.0 format, I create a project and upload annotations using the following code:

project_request = ProjectWriteRequest(
    name="Project",
    labels= [
        PatchedLabelRequest(
            name="FG",
            attributes=[],
            type="mask",
            color="#1dff1d",
        )
    ],
    target_storage=PatchedProjectWriteRequestTargetStorage(),
    source_storage=PatchedProjectWriteRequestTargetStorage(),
)
project_response = client.projects.create_from_dataset(
    project_request,
    dataset_path = dataset_path,
    dataset_format=annotations_format,
)

After that I noticed that the mask-type annotations are represented as polygons which is the problem I wanted to overcome by implementing conv_mask_to_poly parameter to create_from_dataset method above

This change corresponds to the UI toggle Convert Masks to Polygons. Which does exactly the same.

How has this been tested?

Given the impact of this change, no extensive tests were done appart of running the code.

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
    - [ ] I have updated the documentation accordingly I looked around the code and there were no docsstrings/comments to update
  • I have added tests to cover my changes
    - [ ] I have linked related issues (see GitHub docs)
  • I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features

    • Introduced a new parameter for converting masks to polygon format during dataset export and import.
    • Enhanced the uploading process to support mask conversion options.
  • Bug Fixes

    • Corrected a reference error in the upload method related to mask conversion.

Copy link
Contributor

coderabbitai bot commented Dec 12, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

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

A new optional parameter, conv_mask_to_poly, has been introduced across multiple methods in the SDK to facilitate the conversion of masks to polygon format during dataset export and import. This parameter has been added to the export_dataset, import_dataset, and create_from_dataset methods. Additionally, the upload_file_and_wait method in the DatasetUploader class has been updated to include this parameter, which affects how datasets are uploaded. Minor corrections were also made to ensure proper referencing of the parameter.

Changes

File Path Change Summary
changelog.d/20241212_185016_knotekjaroslav_add_mask_poly_conv_param.md Added conv_mask_to_poly parameter to project.export_dataset method.
cvat-sdk/cvat_sdk/core/proxies/projects.py Updated import_dataset and create_from_dataset methods to include conv_mask_to_poly parameter.
cvat-sdk/cvat_sdk/core/uploading.py Added conv_mask_to_poly parameter to upload_file_and_wait method and corrected a reference typo.

Poem

In the land of code where rabbits play,
A new parameter has come our way! 🐇
Masks to polygons, oh what a sight,
Export and import, all done just right.
With each little change, our hearts do leap,
In the world of datasets, joy we keep! 🌟


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>, 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 generate docstrings to generate docstrings for this PR. (Experiment)
  • @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 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: 2

🧹 Outside diff range and nitpick comments (1)
cvat-sdk/cvat_sdk/core/proxies/projects.py (1)

Line range hint 115-131: Pass the conv_mask_to_poly parameter to import_dataset.

The parameter is added to the method signature but not passed through to the import_dataset call.

Apply this diff to fix the issue:

             project.import_dataset(
                 format_name=dataset_format,
                 filename=dataset_path,
                 pbar=pbar,
                 status_check_period=status_check_period,
+                conv_mask_to_poly=conv_mask_to_poly,
             )
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 289ad43 and fcf4ac1.

📒 Files selected for processing (3)
  • changelog.d/20241212_185016_knotekjaroslav_add_mask_poly_conv_param.md (1 hunks)
  • cvat-sdk/cvat_sdk/core/proxies/projects.py (3 hunks)
  • cvat-sdk/cvat_sdk/core/uploading.py (1 hunks)
🔇 Additional comments (1)
cvat-sdk/cvat_sdk/core/proxies/projects.py (1)

67-67: ⚠️ Potential issue

Fix indentation and parameter usage.

The conv_mask_to_poly parameter is incorrectly indented and defined as a parameter but not passed in the method call.

Apply this diff to fix the issues:

-            conv_mask_to_poly: Optional[bool] = None,
             pbar=pbar,
             status_check_period=status_check_period,
+            conv_mask_to_poly=conv_mask_to_poly,

Likely invalid or redundant comment.

Comment on lines 291 to 293
if conv_mask_top_poly is not None:
value = "true" if conv_mask_to_poly else "false"
params["conv_mask_to_poly"] = value
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix typo in variable name.

There's a typo in the variable name that would cause the feature to fail.

Apply this diff to fix the typo:

-        if conv_mask_top_poly is not None:
+        if conv_mask_to_poly is not None:
             value = "true" if conv_mask_to_poly else "false"
             params["conv_mask_to_poly"] = value
📝 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 conv_mask_top_poly is not None:
value = "true" if conv_mask_to_poly else "false"
params["conv_mask_to_poly"] = value
if conv_mask_to_poly is not None:
value = "true" if conv_mask_to_poly else "false"
params["conv_mask_to_poly"] = value

Comment on lines 1 to 4
### Added <!-- pick one -->

- Added parameter `conv_mask_to_poly` to SDK's `project.export_dataset` method to allow conversion upon adding annotations.
(<https://github.com/cvat-ai/cvat/pull/feature/add_mask_poly_conv_param>)
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Update the changelog entry to include all affected methods and fix PR reference.

The changelog entry needs the following improvements:

  1. Include all affected methods that received the new parameter:
    • import_dataset
    • create_from_dataset
    • upload_file_and_wait
  2. Fix the PR reference format

Apply this diff to update the changelog:

 ### Added <!-- pick one -->

-Added parameter `conv_mask_to_poly` to SDK's `project.export_dataset` method to allow conversion upon adding annotations.
-(<https://github.com/cvat-ai/cvat/pull/feature/add_mask_poly_conv_param>)
+Added parameter `conv_mask_to_poly` to the following SDK methods to control mask-to-polygon conversion:
+- `project.export_dataset`
+- `project.import_dataset`
+- `project.create_from_dataset`
+- `DatasetUploader.upload_file_and_wait`
+([#8823](https://github.com/cvat-ai/cvat/pull/8823))
📝 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
### Added <!-- pick one -->
- Added parameter `conv_mask_to_poly` to SDK's `project.export_dataset` method to allow conversion upon adding annotations.
(<https://github.com/cvat-ai/cvat/pull/feature/add_mask_poly_conv_param>)
### Added <!-- pick one -->
Added parameter `conv_mask_to_poly` to the following SDK methods to control mask-to-polygon conversion:
- `project.export_dataset`
- `project.import_dataset`
- `project.create_from_dataset`
- `DatasetUploader.upload_file_and_wait`
([#8823](https://github.com/cvat-ai/cvat/pull/8823))

@zhiltsov-max
Copy link
Contributor

Hi, could you add at least 1 test for this?

Copy link
Contributor

@zhiltsov-max zhiltsov-max left a comment

Choose a reason for hiding this comment

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

Probably, it makes sense to support this in jobs and tasks, and in CLI as well.

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.

2 participants