test_coco_api_wrapper.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import os.path as osp
  2. import tempfile
  3. import unittest
  4. from mmengine.fileio import dump
  5. from mmdet.datasets.api_wrappers import COCOPanoptic
  6. class TestCOCOPanoptic(unittest.TestCase):
  7. def setUp(self):
  8. self.tmp_dir = tempfile.TemporaryDirectory()
  9. def tearDown(self):
  10. self.tmp_dir.cleanup()
  11. def test_create_index(self):
  12. ann_json = {'test': ['test', 'createIndex']}
  13. annotation_file = osp.join(self.tmp_dir.name, 'createIndex.json')
  14. dump(ann_json, annotation_file)
  15. COCOPanoptic(annotation_file)
  16. def test_load_anns(self):
  17. categories = [{
  18. 'id': 0,
  19. 'name': 'person',
  20. 'supercategory': 'person',
  21. 'isthing': 1
  22. }]
  23. images = [{
  24. 'id': 0,
  25. 'width': 80,
  26. 'height': 60,
  27. 'file_name': 'fake_name1.jpg',
  28. }]
  29. annotations = [{
  30. 'segments_info': [
  31. {
  32. 'id': 1,
  33. 'category_id': 0,
  34. 'area': 400,
  35. 'bbox': [10, 10, 10, 40],
  36. 'iscrowd': 0
  37. },
  38. ],
  39. 'file_name':
  40. 'fake_name1.png',
  41. 'image_id':
  42. 0
  43. }]
  44. ann_json = {
  45. 'images': images,
  46. 'annotations': annotations,
  47. 'categories': categories,
  48. }
  49. annotation_file = osp.join(self.tmp_dir.name, 'load_anns.json')
  50. dump(ann_json, annotation_file)
  51. api = COCOPanoptic(annotation_file)
  52. api.load_anns(1)
  53. self.assertIsNone(api.load_anns(0.1))