You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test_object_detection.py 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.pipelines import pipeline
  4. from modelscope.utils.constant import Tasks
  5. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  6. from modelscope.utils.test_utils import test_level
  7. class ObjectDetectionTest(unittest.TestCase, DemoCompatibilityCheck):
  8. def setUp(self) -> None:
  9. self.task = Tasks.human_detection
  10. self.model_id = 'damo/cv_resnet18_human-detection'
  11. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  12. def test_object_detection(self):
  13. input_location = 'data/test/images/image_detection.jpg'
  14. model_id = 'damo/cv_vit_object-detection_coco'
  15. object_detect = pipeline(Tasks.image_object_detection, model=model_id)
  16. result = object_detect(input_location)
  17. if result:
  18. print(result)
  19. else:
  20. raise ValueError('process error')
  21. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  22. def test_object_detection_with_default_task(self):
  23. input_location = 'data/test/images/image_detection.jpg'
  24. object_detect = pipeline(Tasks.image_object_detection)
  25. result = object_detect(input_location)
  26. if result:
  27. print(result)
  28. else:
  29. raise ValueError('process error')
  30. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  31. def test_human_detection(self):
  32. input_location = 'data/test/images/image_detection.jpg'
  33. model_id = 'damo/cv_resnet18_human-detection'
  34. human_detect = pipeline(Tasks.human_detection, model=model_id)
  35. result = human_detect(input_location)
  36. if result:
  37. print(result)
  38. else:
  39. raise ValueError('process error')
  40. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  41. def test_human_detection_with_default_task(self):
  42. input_location = 'data/test/images/image_detection.jpg'
  43. human_detect = pipeline(Tasks.human_detection)
  44. result = human_detect(input_location)
  45. if result:
  46. print(result)
  47. else:
  48. raise ValueError('process error')
  49. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  50. def test_demo_compatibility(self):
  51. self.compatibility_check()
  52. if __name__ == '__main__':
  53. unittest.main()