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.6 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. print(result)
  18. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  19. def test_object_detection_with_default_task(self):
  20. input_location = 'data/test/images/image_detection.jpg'
  21. object_detect = pipeline(Tasks.image_object_detection)
  22. result = object_detect(input_location)
  23. print(result)
  24. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  25. def test_human_detection(self):
  26. input_location = 'data/test/images/image_detection.jpg'
  27. model_id = 'damo/cv_resnet18_human-detection'
  28. human_detect = pipeline(Tasks.human_detection, model=model_id)
  29. result = human_detect(input_location)
  30. print(result)
  31. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  32. def test_human_detection_with_default_task(self):
  33. input_location = 'data/test/images/image_detection.jpg'
  34. human_detect = pipeline(Tasks.human_detection)
  35. result = human_detect(input_location)
  36. print(result)
  37. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  38. def test_demo_compatibility(self):
  39. self.compatibility_check()
  40. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  41. def test_image_object_detection_auto_pipeline(self):
  42. model_id = 'damo/cv_yolox_image-object-detection-auto'
  43. test_image = 'data/test/images/auto_demo.jpg'
  44. image_object_detection_auto = pipeline(
  45. Tasks.image_object_detection, model=model_id)
  46. result = image_object_detection_auto(test_image)[0]
  47. image_object_detection_auto.show_result(test_image, result,
  48. 'auto_demo_ret.jpg')
  49. if __name__ == '__main__':
  50. unittest.main()