-
Notifications
You must be signed in to change notification settings - Fork 588
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
Adding Non-Maximum Suppression (NMS) utility to fiftyone.utils.labels through perform_nms() #4160
Conversation
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.
@rohis06 overall the method looks great, just have a few suggestions on implementation that would clean things up a bit if you're open to them! 😄
fiftyone/utils/labels.py
Outdated
sample_collection: a | ||
:class:`fiftyone.core.collections.SampleCollection` | ||
in_field: the name of the :class:`fiftyone.core.labels.Detections` field | ||
out_field: the name of the :class:`fiftyone.core.labels.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.
How about making this optional: if not specified, the input field is updated in-place?
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.
Sure, that sounds like a good idea to me.
I'll make it optional.
fiftyone/utils/labels.py
Outdated
|
||
with fou.ProgressBar(progress=progress) as pb: | ||
for sample in pb(samples): | ||
detections_data_json_str = sample[in_field].to_json() |
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.
Can you implement this by processing sample[in_field].detections
as a list of Detection
objects rather than serializing to JSON? We generally try to avoid converting to other formats if not necessary.
Note that you can call sample[in_field].copy()
to get a copy of the detections so that the existing detections aren't modified in-place
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.
Oh, definitely! I will check out the .copy()
method.
fiftyone/utils/labels.py
Outdated
# Compare with other detections for NMS | ||
for d in detections: | ||
if d["label"] == selected_detection["label"]: | ||
iou = _calculate_iou( |
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.
Can you use the existing fiftyone.utils.iou.compute_ious()
utility here to avoid re-implementing this calculation?
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.
Sure, I'll incorporate this. It's much better always to use an existing utility! 😄
Thanks a lot for reviewing this, @brimoor. I really appreciate your feedback! 😄 |
@brimoor, I have addressed the review comments. |
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.
@rohis06 thanks for your contribution! 🎉
Anytime! 😄 |
What changes are proposed in this pull request?
Adds Non-Maximum Suppression (NMS) utility to fiftyone.utils.labels through
perform_nms()
! 🎉It can be loaded as follows:
How is this patch tested? If it is not, please explain why.
It has been thoroughly tested, as seen in this nms_test.pdf
Release Notes
Is this a user-facing change that should be mentioned in the release notes?
notes for FiftyOne users.
Addition of perform_nms() utility to fiftyone.utils.labels
What areas of FiftyOne does this PR affect?
fiftyone
Python library changes