-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Refactor filtering mask, fix attribute error #8673
base: dev
Are you sure you want to change the base?
Conversation
a18a2c6
to
45d2a0a
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## dev #8673 +/- ##
==========================================
- Coverage 64.08% 64.06% -0.03%
==========================================
Files 361 361
Lines 29525 29533 +8
Branches 5020 5021 +1
==========================================
- Hits 18922 18921 -1
- Misses 9589 9592 +3
- Partials 1014 1020 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@jbwang1997 Do you know why the CUDA build could be failing? Locally I made the changes for this commit with a non CUDA torch and mmcv version. But when the tests are run here, this shouldn't be affected correct? |
Seem the CI failed when installing the dependence. I have restarted the CI. Let's wait for the results. |
Ok great, thank you for the restart! |
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.
LGTM
mmdet/datasets/pipelines/loading.py
Outdated
@@ -603,30 +603,26 @@ def __call__(self, results): | |||
assert 'gt_bboxes' in results | |||
gt_bboxes = results['gt_bboxes'] | |||
instance_num = gt_bboxes.shape[0] | |||
keep = np.ones(gt_bboxes.shape[0], dtype=bool) |
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.
gt_bboxes.shape[0] -> instance_num
@@ -603,30 +603,26 @@ def __call__(self, results): | |||
assert 'gt_bboxes' in results | |||
gt_bboxes = results['gt_bboxes'] | |||
instance_num = gt_bboxes.shape[0] | |||
keep = np.ones(gt_bboxes.shape[0], dtype=bool) | |||
if self.by_mask: | |||
assert 'gt_masks' in results | |||
gt_masks = results['gt_masks'] | |||
instance_num = len(gt_masks) |
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.
Is the mask instance_num equal to the box instance_num?
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.
Yes, I think it should be. And the test cases with both mask instances and gt_bbox instances passes.
mmdet/datasets/pipelines/loading.py
Outdated
if self.by_mask: | ||
assert 'gt_masks' in results | ||
gt_masks = results['gt_masks'] | ||
instance_num = len(gt_masks) | ||
keep = np.ones(len(gt_masks), dtype=bool) |
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.
Seems that instance_num
and keep
will over-write if self.by_box and self.by_mask is True.
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.
len(gt_masks) -> instance_num
@christian-hiebl Thanks for your contribution. if self.by_box:
assert 'gt_bboxes' in results
gt_bboxes = results['gt_bboxes']
instance_num = gt_bboxes.shape[0]
if self.by_mask:
assert 'gt_masks' in results
gt_masks = results['gt_masks']
instance_num = len(gt_masks)
keep = np.ones(instance_num, dtype=bool) Not sure if there is a more elegant way to fix the over-write problem. |
Thank you for the suggestion! In the init of the FilterAnnotations class there is an assertion, that the filtering is done by either mask or box, so the instance_num won't be over-written. |
if by_box and by_mask all set True, it also works. |
@BIGWangYuDong You are right, 'or' is inclusive so it should also work when both if statements are true. Currently it passes in the test case that a mask and box is given. Also, the instance_num for both is the same, so it will not be a problem. |
@@ -607,26 +607,20 @@ def __call__(self, results): | |||
assert 'gt_masks' in results | |||
gt_masks = results['gt_masks'] | |||
instance_num = len(gt_masks) | |||
|
|||
keep = np.ones(instance_num, dtype=bool) |
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 adding an assert before to avoid some potential error?
Such as:
instance_num = None
if self.by_box:
if instance_num is not None:
assert instance_num == box_num
if self.by_mask:
if instance_num is not None:
assert instance_num == mask_num
Motivation
Filtering annotations for a dataset is great (besides the gt_bboxes_ignore option) I changed the implementation of the keep mask and added the attribute error fix in repr as also discussed here #8214 but not included in #8136
Modification
Change of filter annotation masking from appending boolean mask to a list and iterating, to now a bumpy array. Additionally small fix discussed but not included from #8214
BC-breaking (Optional)
I don't think it will break BC.
Use cases (Optional)
Checklist