instance_seg.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 InstanceSegPostProcess(BaseComponent):
  18. """Save Result Transform"""
  19. INPUT_KEYS = ["boxes", "masks"]
  20. OUTPUT_KEYS = ["img_path", "boxes", "masks", "labels"]
  21. DEAULT_INPUTS = {"boxes": "boxes", "masks": "masks"}
  22. DEAULT_OUTPUTS = {
  23. "boxes": "boxes",
  24. "masks": "masks",
  25. "labels": "labels",
  26. }
  27. def __init__(self, threshold=0.5, labels=None):
  28. super().__init__()
  29. self.threshold = threshold
  30. self.labels = labels
  31. def apply(self, boxes, masks):
  32. """apply"""
  33. expect_boxes = (boxes[:, 1] > self.threshold) & (boxes[:, 0] > -1)
  34. boxes = boxes[expect_boxes, :]
  35. masks = masks[expect_boxes, :, :]
  36. result = {
  37. "boxes": boxes,
  38. "masks": masks,
  39. "labels": self.labels,
  40. }
  41. return result