feat(detection): add transform method to remap and filter detections #1846
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces a new
transform
method to theDetections
class insupervision/detection/core.py
, allowing remapping and filtering of detections to match a target dataset's class set. It also includes corresponding unit tests to validate the functionality.New
transform
method inDetections
:transform
method to theDetections
class, enabling remapping of class names using an optionalclass_mapping
dictionary and filtering detections to match the classes in a target dataset. The method raises an error if the requiredclass_name
field is missing from the.data
attribute.Type of change
Please delete options that are not relevant.
How has this change been tested, please provide a testcase or example of how you tested the change?
Unit tests for
transform
(intest_transform.py
)test_transform_remap_and_filter
to verify that the method correctly remaps class names, filters out invalid detections, and updatesclass_id
to match the target dataset's class indices.test_transform_no_class_mapping
to ensure the method works correctly when noclass_mapping
is provided, retaining only the classes present in the target dataset.test_transform_raises_without_class_name
to confirm that the method raises aValueError
if theclass_name
field is missing in the.data
attribute.