test_instaboost.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. import os.path as osp
  2. import unittest
  3. import numpy as np
  4. from mmdet.registry import TRANSFORMS
  5. from mmdet.utils import register_all_modules
  6. register_all_modules()
  7. class TestInstaboost(unittest.TestCase):
  8. def setUp(self):
  9. """Setup the model and optimizer which are used in every test method.
  10. TestCase calls functions in this order: setUp() -> testMethod() ->
  11. tearDown() -> cleanUp()
  12. """
  13. img_path = osp.join(osp.dirname(__file__), '../../data/gray.jpg')
  14. self.results = {
  15. 'img_path':
  16. img_path,
  17. 'img_shape': (300, 400),
  18. 'instances': [{
  19. 'bbox': [0, 0, 10, 20],
  20. 'bbox_label': 1,
  21. 'mask': [[0, 0, 0, 20, 10, 20, 10, 0]],
  22. 'ignore_flag': 0
  23. }, {
  24. 'bbox': [10, 10, 110, 120],
  25. 'bbox_label': 2,
  26. 'mask': [[10, 10, 110, 10, 110, 120, 110, 10]],
  27. 'ignore_flag': 0
  28. }, {
  29. 'bbox': [50, 50, 60, 80],
  30. 'bbox_label': 2,
  31. 'mask': [[50, 50, 60, 50, 60, 80, 50, 80]],
  32. 'ignore_flag': 1
  33. }]
  34. }
  35. def test_transform(self):
  36. load = TRANSFORMS.build(dict(type='LoadImageFromFile'))
  37. instaboost_transform = TRANSFORMS.build(dict(type='InstaBoost'))
  38. # Execute transforms
  39. results = load(self.results)
  40. results = instaboost_transform(results)
  41. self.assertEqual(results['img'].dtype, np.uint8)
  42. self.assertIn('instances', results)
  43. def test_repr(self):
  44. instaboost_transform = TRANSFORMS.build(dict(type='InstaBoost'))
  45. self.assertEqual(
  46. repr(instaboost_transform), 'InstaBoost(aug_ratio=0.5)')