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.

54 lines
1.8 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.utils.category_util."""
  16. import os
  17. import tensorflow as tf
  18. from object_detection.utils import category_util
  19. class EvalUtilTest(tf.test.TestCase):
  20. def test_load_categories_from_csv_file(self):
  21. csv_data = """
  22. 0,"cat"
  23. 1,"dog"
  24. 2,"bird"
  25. """.strip(' ')
  26. csv_path = os.path.join(self.get_temp_dir(), 'test.csv')
  27. with tf.gfile.Open(csv_path, 'wb') as f:
  28. f.write(csv_data)
  29. categories = category_util.load_categories_from_csv_file(csv_path)
  30. self.assertTrue({'id': 0, 'name': 'cat'} in categories)
  31. self.assertTrue({'id': 1, 'name': 'dog'} in categories)
  32. self.assertTrue({'id': 2, 'name': 'bird'} in categories)
  33. def test_save_categories_to_csv_file(self):
  34. categories = [
  35. {'id': 0, 'name': 'cat'},
  36. {'id': 1, 'name': 'dog'},
  37. {'id': 2, 'name': 'bird'},
  38. ]
  39. csv_path = os.path.join(self.get_temp_dir(), 'test.csv')
  40. category_util.save_categories_to_csv_file(categories, csv_path)
  41. saved_categories = category_util.load_categories_from_csv_file(csv_path)
  42. self.assertEqual(saved_categories, categories)
  43. if __name__ == '__main__':
  44. tf.test.main()