-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
base: develop
Are you sure you want to change the base?
Add option to SDK allowing upload of annotation as masks instead of polygon. #8823
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughA new optional parameter, Changes
Poem
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 theconv_mask_to_poly
parameter toimport_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
📒 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
:
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.
cvat-sdk/cvat_sdk/core/uploading.py
Outdated
if conv_mask_top_poly is not None: | ||
value = "true" if conv_mask_to_poly else "false" | ||
params["conv_mask_to_poly"] = value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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 |
### 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>) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update the changelog entry to include all affected methods and fix PR reference.
The changelog entry needs the following improvements:
- Include all affected methods that received the new parameter:
import_dataset
create_from_dataset
upload_file_and_wait
- 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.
### 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)) |
Hi, could you add at least 1 test for this? |
There was a problem hiding this 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.
Yes, I can add a test. I looked how the method At the moment, I just added dummy test that sets the value to |
|
||
assert project.get_tasks()[0].size == 1 | ||
assert "100%" in pbar_out.getvalue().strip("\r").split("\r")[-1] | ||
assert self.stdout.getvalue() == "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assert self.stdout.getvalue() == "" | |
assert self.stdout.getvalue() == "" | |
task = project.get_tasks()[0] | |
imported_annotations = task.get_annotations() | |
assert all([s.type.value == "polygon" if convert else "mask" for s in imported_annotations.shapes]) |
Consider doing something like this to check if it works as intended. You will need to upload a COCO dataset with an RLE-encoded annotation, the current one has just one bbox inside.
Thank you for your suggestions! I incorporated them into the tests and pushed. |
|
I am suprised that I would have to implement support for polygons in COCO format. In the use case I presented I use camvid, that already supports that,doesn't it. Why do I have to implement it on a different dataset format? Would it be ok, to just use camvid in the test? I presume that the test parameter |
No, you don't. You pushed a test using COCO taking from the existing example, so I thought you want to continue using it. If you want to use a test CamVid dataset, there are no problems with this. |
Quality Gate passedIssues Measures |
Good. So I replaced the coco format with camvid. There was an issue with the absence of camvid dataset fixture so I tried to add some. However, the code seems to be rather messy compared to the other fixtures because it creates the data itself without using other fixtures of helpers. None the less I decided to continue favouring the conciseness of this solution compared to creating fixtures and utilities that would not be used anywhere else. Let me know if I should change anything. Also, I was not able to run the test myself as I am having troubles with setting up all the test dependencies with the cross-referenced guides so I rely on the testing pipeline ATM. |
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:
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 tocreate_from_dataset
method aboveThis 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
develop
branch- [ ] I have updated the documentation accordinglyI looked around the code and there were no docsstrings/comments to update- [ ] I have linked related issues (see GitHub docs)(cvat-canvas,
cvat-core,
cvat-data and
cvat-ui)
License
Feel free to contact the maintainers if that's a concern.
Summary by CodeRabbit
New Features
Bug Fixes