You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.4 KiB

6 years ago
  1. # Copyright 2017 The TensorFlow 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. # ==============================================================================
  15. """Tests for object_detection.np_box_ops."""
  16. import numpy as np
  17. import tensorflow as tf
  18. from object_detection.utils import np_box_ops
  19. class BoxOpsTests(tf.test.TestCase):
  20. def setUp(self):
  21. boxes1 = np.array([[4.0, 3.0, 7.0, 5.0], [5.0, 6.0, 10.0, 7.0]],
  22. dtype=float)
  23. boxes2 = np.array([[3.0, 4.0, 6.0, 8.0], [14.0, 14.0, 15.0, 15.0],
  24. [0.0, 0.0, 20.0, 20.0]],
  25. dtype=float)
  26. self.boxes1 = boxes1
  27. self.boxes2 = boxes2
  28. def testArea(self):
  29. areas = np_box_ops.area(self.boxes1)
  30. expected_areas = np.array([6.0, 5.0], dtype=float)
  31. self.assertAllClose(expected_areas, areas)
  32. def testIntersection(self):
  33. intersection = np_box_ops.intersection(self.boxes1, self.boxes2)
  34. expected_intersection = np.array([[2.0, 0.0, 6.0], [1.0, 0.0, 5.0]],
  35. dtype=float)
  36. self.assertAllClose(intersection, expected_intersection)
  37. def testIOU(self):
  38. iou = np_box_ops.iou(self.boxes1, self.boxes2)
  39. expected_iou = np.array([[2.0 / 16.0, 0.0, 6.0 / 400.0],
  40. [1.0 / 16.0, 0.0, 5.0 / 400.0]],
  41. dtype=float)
  42. self.assertAllClose(iou, expected_iou)
  43. def testIOA(self):
  44. boxes1 = np.array([[0.25, 0.25, 0.75, 0.75],
  45. [0.0, 0.0, 0.5, 0.75]],
  46. dtype=np.float32)
  47. boxes2 = np.array([[0.5, 0.25, 1.0, 1.0],
  48. [0.0, 0.0, 1.0, 1.0]],
  49. dtype=np.float32)
  50. ioa21 = np_box_ops.ioa(boxes2, boxes1)
  51. expected_ioa21 = np.array([[0.5, 0.0],
  52. [1.0, 1.0]],
  53. dtype=np.float32)
  54. self.assertAllClose(ioa21, expected_ioa21)
  55. if __name__ == '__main__':
  56. tf.test.main()