det.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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. import os
  15. from ....utils import logging
  16. from ..base import BaseComponent
  17. class DetPostProcess(BaseComponent):
  18. """Save Result Transform"""
  19. INPUT_KEYS = ["img_path", "boxes"]
  20. OUTPUT_KEYS = ["boxes", "labels"]
  21. DEAULT_INPUTS = {"boxes": "boxes"}
  22. DEAULT_OUTPUTS = {
  23. "boxes": "boxes",
  24. "labels": "labels",
  25. }
  26. def __init__(self, threshold=0.5, labels=None):
  27. super().__init__()
  28. self.threshold = threshold
  29. self.labels = labels
  30. def apply(self, boxes):
  31. """apply"""
  32. expect_boxes = (boxes[:, 1] > self.threshold) & (boxes[:, 0] > -1)
  33. boxes = boxes[expect_boxes, :]
  34. result = {"boxes": boxes, "labels": self.labels}
  35. return result