max_iou_assigner.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from __future__ import absolute_import
  15. from __future__ import division
  16. from __future__ import print_function
  17. from ppdet.core.workspace import register
  18. from ppdet.modeling.proposal_generator.target import label_box
  19. __all__ = ['MaxIoUAssigner']
  20. @register
  21. class MaxIoUAssigner(object):
  22. """a standard bbox assigner based on max IoU, use ppdet's label_box
  23. as backend.
  24. Args:
  25. positive_overlap (float): threshold for defining positive samples
  26. negative_overlap (float): threshold for denining negative samples
  27. allow_low_quality (bool): whether to lower IoU thr if a GT poorly
  28. overlaps with candidate bboxes
  29. """
  30. def __init__(self,
  31. positive_overlap,
  32. negative_overlap,
  33. allow_low_quality=True):
  34. self.positive_overlap = positive_overlap
  35. self.negative_overlap = negative_overlap
  36. self.allow_low_quality = allow_low_quality
  37. def __call__(self, bboxes, gt_bboxes):
  38. matches, match_labels = label_box(
  39. bboxes,
  40. gt_bboxes,
  41. positive_overlap=self.positive_overlap,
  42. negative_overlap=self.negative_overlap,
  43. allow_low_quality=self.allow_low_quality,
  44. ignore_thresh=-1,
  45. is_crowd=None,
  46. assign_on_cpu=False)
  47. return matches, match_labels