test_coco.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. # Copyright (c) OpenMMLab. All rights reserved.
  2. import unittest
  3. from mmdet.datasets import CocoDataset
  4. class TestCocoDataset(unittest.TestCase):
  5. def test_coco_dataset(self):
  6. # test CocoDataset
  7. metainfo = dict(classes=('bus', 'car'), task_name='new_task')
  8. dataset = CocoDataset(
  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. def test_coco_dataset_without_filter_cfg(self):
  20. # test CocoDataset without filter_cfg
  21. dataset = CocoDataset(
  22. data_prefix=dict(img='imgs'),
  23. ann_file='tests/data/coco_sample.json',
  24. pipeline=[])
  25. self.assertEqual(len(dataset), 4)
  26. # test with test_mode = True
  27. dataset = CocoDataset(
  28. data_prefix=dict(img='imgs'),
  29. ann_file='tests/data/coco_sample.json',
  30. test_mode=True,
  31. pipeline=[])
  32. self.assertEqual(len(dataset), 4)
  33. def test_coco_annotation_ids_unique(self):
  34. # test annotation ids not unique error
  35. metainfo = dict(classes=('car', ), task_name='new_task')
  36. with self.assertRaisesRegex(AssertionError, 'are not unique!'):
  37. CocoDataset(
  38. data_prefix=dict(img='imgs'),
  39. ann_file='tests/data/coco_wrong_format_sample.json',
  40. metainfo=metainfo,
  41. pipeline=[])