test_objects365.py 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import unittest
  3. from mmdet.datasets import Objects365V1Dataset, Objects365V2Dataset
  4. class TestObjects365V1Dataset(unittest.TestCase):
  5. def test_obj365v1_dataset(self):
  6. # test Objects365V1Dataset
  7. metainfo = dict(classes=('bus', 'car'), task_name='new_task')
  8. dataset = Objects365V1Dataset(
  9. data_prefix=dict(img='imgs'),
  10. ann_file='tests/data/coco_sample.json',
  11. metainfo=metainfo,
  12. filter_cfg=dict(filter_empty_gt=True, min_size=32),
  13. pipeline=[],
  14. serialize_data=False,
  15. lazy_init=False)
  16. self.assertEqual(dataset.metainfo['classes'], ('bus', 'car'))
  17. self.assertEqual(dataset.metainfo['task_name'], 'new_task')
  18. self.assertListEqual(dataset.get_cat_ids(0), [0, 1])
  19. self.assertEqual(dataset.cat_ids, [1, 2])
  20. def test_obj365v1_with_unsorted_annotation(self):
  21. # test Objects365V1Dataset with unsorted annotations
  22. metainfo = dict(classes=('bus', 'car'), task_name='new_task')
  23. dataset = Objects365V1Dataset(
  24. data_prefix=dict(img='imgs'),
  25. ann_file='tests/data/Objects365/unsorted_obj365_sample.json',
  26. metainfo=metainfo,
  27. filter_cfg=dict(filter_empty_gt=True, min_size=32),
  28. pipeline=[],
  29. serialize_data=False,
  30. lazy_init=False)
  31. self.assertEqual(dataset.metainfo['classes'], ('bus', 'car'))
  32. self.assertEqual(dataset.metainfo['task_name'], 'new_task')
  33. # sort the unsorted annotations
  34. self.assertListEqual(dataset.get_cat_ids(0), [0, 1])
  35. self.assertEqual(dataset.cat_ids, [1, 2])
  36. def test_obj365v1_annotation_ids_unique(self):
  37. # test annotation ids not unique error
  38. metainfo = dict(classes=('car', ), task_name='new_task')
  39. with self.assertRaisesRegex(AssertionError, 'are not unique!'):
  40. Objects365V1Dataset(
  41. data_prefix=dict(img='imgs'),
  42. ann_file='tests/data/coco_wrong_format_sample.json',
  43. metainfo=metainfo,
  44. pipeline=[])
  45. class TestObjects365V2Dataset(unittest.TestCase):
  46. def test_obj365v2_dataset(self):
  47. # test Objects365V2Dataset
  48. metainfo = dict(classes=('bus', 'car'), task_name='new_task')
  49. dataset = Objects365V2Dataset(
  50. data_prefix=dict(img='imgs'),
  51. ann_file='tests/data/coco_sample.json',
  52. metainfo=metainfo,
  53. filter_cfg=dict(filter_empty_gt=True, min_size=32),
  54. pipeline=[],
  55. serialize_data=False,
  56. lazy_init=False)
  57. self.assertEqual(dataset.metainfo['classes'], ('bus', 'car'))
  58. self.assertEqual(dataset.metainfo['task_name'], 'new_task')
  59. self.assertListEqual(dataset.get_cat_ids(0), [0, 1])
  60. self.assertEqual(dataset.cat_ids, [1, 2])
  61. def test_obj365v1_annotation_ids_unique(self):
  62. # test annotation ids not unique error
  63. metainfo = dict(classes=('car', ), task_name='new_task')
  64. with self.assertRaisesRegex(AssertionError, 'are not unique!'):
  65. Objects365V2Dataset(
  66. data_prefix=dict(img='imgs'),
  67. ann_file='tests/data/coco_wrong_format_sample.json',
  68. metainfo=metainfo,
  69. pipeline=[])