-
Notifications
You must be signed in to change notification settings - Fork 154
Add polygons and mask fields #1868
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
Conversation
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
4d78d51 to
94d177e
Compare
Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
94d177e to
fb3f606
Compare
Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
src/datumaro/experimental/fields.py
Outdated
| [6 7 8 9] | ||
| ] | ||
| """ | ||
| if data.dtype == "O": |
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.
Please define a variable for this magic string and also reuse it throughout this PR
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.
I have replaced it with object to avoid the string. It’s equivalent and more explicit.
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.
Pull Request Overview
This PR introduces comprehensive polygon and mask annotation support to the experimental dataset framework, enabling conversion between polygon, mask, and legacy annotation formats. It refactors the converter registration system to use classes instead of instances for better flexibility and category-based instantiation.
Key changes:
- Added
PolygonFieldandMaskFieldclasses with their factory functions for representing polygon coordinates and segmentation masks - Enhanced
LabelFieldto support list semantics viais_listparameter for better multi-label handling - Implemented
PolygonToMaskConverterfor converting polygon annotations to rasterized masks using OpenCV - Refactored annotation converter registry to store converter classes and instantiate them based on dataset categories
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/datumaro/experimental/fields.py | Added PolygonField, MaskField, and enhanced LabelField with is_list support |
| src/datumaro/experimental/converters.py | Added PolygonToMaskConverter for polygon-to-mask conversion |
| src/datumaro/experimental/legacy.py | Refactored converter registry and added ForwardPolygonAnnotationConverter/BackwardPolygonAnnotationConverter |
| src/datumaro/experimental/type_registry.py | Added polars_to_numpy_dtype utility function and improved dtype conversion |
| tests/unit/experimental/test_schema.py | Added comprehensive tests for PolygonField functionality |
| tests/unit/experimental/test_legacy.py | Updated tests for new converter pattern and added polygon conversion tests |
| tests/unit/experimental/test_converters.py | Added tests for PolygonToMaskConverter |
| CHANGELOG.md | Updated to reference this PR |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
|
|
||
| # When using np.array, there is a corner case for the case where len(polygons) == 1 where | ||
| # Numpy creates a 2D array of objects instead of a 1D array of objects. | ||
| # We may be able to solve this in the upcoming version of Numpy with the argument ndmax. |
Copilot
AI
Sep 9, 2025
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.
The comment mentions 'ndmax' which should be 'ndmin' (minimum number of dimensions).
| # We may be able to solve this in the upcoming version of Numpy with the argument ndmax. | |
| # We may be able to solve this in the upcoming version of Numpy with the argument ndmin (minimum number of dimensions). |
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.
Not correct, I am indeed referring to ndmax, not ndmin, since we would like to limit the number of dimensions to 1. See https://numpy.org/devdocs//reference/generated/numpy.array.html
Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
Signed-off-by: Grégoire Payen de La Garanderie <[email protected]>
This pull request introduces polygon and mask annotations. It also extends the label annotation to allow list of labels which can be used alongside polygons or bounding boxes. The PR adds conversion between polygons and masks, as well as conversion between legacy polygon datasets and new dataset class; however, I haven’t implemented this conversion yet for masks.
Polygon and Mask Annotation Support
PolygonFieldandMaskFieldclasses tofields.py, enabling robust representation and conversion of polygon and mask data, including normalization, format specification, and efficient serialization to Polars dataframes.PolygonToMaskConverterinconverters.py, allowing conversion of polygon annotations to rasterized masks using OpenCV.Label Handling Improvements
LabelFieldto support both multi-label and list semantics via newis_listproperty, and updated serialization logic to accommodate these cases. Thelabel_fieldfactory now acceptsis_listas a parameter. [1] [2] [3]Converter Registration and Instantiation Refactor
legacy.pyto store converter classes instead of instances, and introduced logic to instantiate converters based on dataset categories using a newcreate_from_categoriesclass method. [1] [2] [3]ForwardBboxAnnotationConverterto use the new instantiation pattern, including conditional support for label categories and improved schema attribute handling.Legacy Compatibility and Imports
Polygonto legacy annotation imports and updated usage to reflect new field and converter types for seamless integration with legacy datasets. [1] [2]Checklist