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.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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.test_utils import test_level
  6. class ObjectDetectionTest(unittest.TestCase):
  7. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  8. def test_object_detection(self):
  9. input_location = 'data/test/images/image_detection.jpg'
  10. model_id = 'damo/cv_vit_object-detection_coco'
  11. object_detect = pipeline(Tasks.image_object_detection, model=model_id)
  12. result = object_detect(input_location)
  13. if result:
  14. print(result)
  15. else:
  16. raise ValueError('process error')
  17. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  18. def test_object_detection_with_default_task(self):
  19. input_location = 'data/test/images/image_detection.jpg'
  20. object_detect = pipeline(Tasks.image_object_detection)
  21. result = object_detect(input_location)
  22. if result:
  23. print(result)
  24. else:
  25. raise ValueError('process error')
  26. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  27. def test_human_detection(self):
  28. input_location = 'data/test/images/image_detection.jpg'
  29. model_id = 'damo/cv_resnet18_human-detection'
  30. human_detect = pipeline(Tasks.human_detection, model=model_id)
  31. result = human_detect(input_location)
  32. if result:
  33. print(result)
  34. else:
  35. raise ValueError('process error')
  36. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  37. def test_human_detection_with_default_task(self):
  38. input_location = 'data/test/images/image_detection.jpg'
  39. human_detect = pipeline(Tasks.human_detection)
  40. result = human_detect(input_location)
  41. if result:
  42. print(result)
  43. else:
  44. raise ValueError('process error')
  45. if __name__ == '__main__':
  46. unittest.main()