-
Notifications
You must be signed in to change notification settings - Fork 3k
feat(detection): add transform method to remap and filter detections #1846
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
base: develop
Are you sure you want to change the base?
feat(detection): add transform method to remap and filter detections #1846
Conversation
soumik12345
left a comment
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.
Hi @AshAnand34, thanks for the PR!
I left some comments, it would be great if you address them.
|
|
||
| return Detections.merge(result) | ||
|
|
||
| def transform(self, dataset, class_mapping: Optional[dict] = None) -> Detections: |
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.
remap_class_indices would be a more appropriate name for this function.
| [class_mapping.get(name, name) for name in class_names] | ||
| ) | ||
| # Filter out detections whose class is not in dataset.classes | ||
| keep = np.isin(class_names, dataset.classes) |
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 think its better to remove the filtering functionality from the scope of this PR since the filter can be easily applied on the remapped sv.Detections object. Supervision should consist of atomic functionalities that can be chained together as per the developer's requirement.
| from supervision.detection.core import Detections | ||
|
|
||
|
|
||
| def test_transform_remap_and_filter(): |
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.
This testcase is failing, please make sure that tests are passing.
I am out of town at the moment. I will address them when I get back. |
Description
This pull request introduces a new
transformmethod to theDetectionsclass 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
transformmethod inDetections:transformmethod to theDetectionsclass, enabling remapping of class names using an optionalclass_mappingdictionary and filtering detections to match the classes in a target dataset. The method raises an error if the requiredclass_namefield is missing from the.dataattribute.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_filterto verify that the method correctly remaps class names, filters out invalid detections, and updatesclass_idto match the target dataset's class indices.test_transform_no_class_mappingto ensure the method works correctly when noclass_mappingis provided, retaining only the classes present in the target dataset.test_transform_raises_without_class_nameto confirm that the method raises aValueErrorif theclass_namefield is missing in the.dataattribute.