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_body_2d_keypoints.py 1.7 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import cv2
  4. from PIL import Image
  5. from modelscope.pipelines import pipeline
  6. from modelscope.pipelines.base import Pipeline
  7. from modelscope.utils.constant import Tasks
  8. from modelscope.utils.cv.image_utils import draw_keypoints
  9. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  10. from modelscope.utils.test_utils import test_level
  11. class Body2DKeypointsTest(unittest.TestCase, DemoCompatibilityCheck):
  12. def setUp(self) -> None:
  13. self.task = Tasks.body_2d_keypoints
  14. self.model_id = 'damo/cv_hrnetv2w32_body-2d-keypoints_image'
  15. self.test_image = 'data/test/images/keypoints_detect/000000438862.jpg'
  16. def pipeline_inference(self, pipeline: Pipeline, pipeline_input):
  17. output = pipeline(pipeline_input)
  18. image = draw_keypoints(output, self.test_image)
  19. cv2.imwrite('pose_keypoint.jpg', image)
  20. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  21. def test_run_modelhub_with_image_file(self):
  22. body_2d_keypoints = pipeline(self.task, model=self.model_id)
  23. self.pipeline_inference(body_2d_keypoints, self.test_image)
  24. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  25. def test_run_modelhub_with_image_input(self):
  26. body_2d_keypoints = pipeline(self.task, model=self.model_id)
  27. self.pipeline_inference(body_2d_keypoints, Image.open(self.test_image))
  28. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  29. def test_demo_compatibility(self):
  30. self.compatibility_check()
  31. if __name__ == '__main__':
  32. unittest.main()