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_3d_keypoints.py 2.0 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import cv2
  4. import numpy as np
  5. from modelscope.outputs import OutputKeys
  6. from modelscope.pipelines import pipeline
  7. from modelscope.pipelines.base import Pipeline
  8. from modelscope.utils.constant import Tasks
  9. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  10. from modelscope.utils.test_utils import test_level
  11. class Body3DKeypointsTest(unittest.TestCase, DemoCompatibilityCheck):
  12. def setUp(self) -> None:
  13. self.model_id = 'damo/cv_canonical_body-3d-keypoints_video'
  14. self.test_video = 'data/test/videos/Walking.54138969.mp4'
  15. self.task = Tasks.body_3d_keypoints
  16. def pipeline_inference(self, pipeline: Pipeline, pipeline_input):
  17. output = pipeline(pipeline_input, output_video='./result.mp4')
  18. poses = np.array(output[OutputKeys.KEYPOINTS])
  19. print(f'result 3d points shape {poses.shape}')
  20. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  21. def test_run_modelhub_with_video_file(self):
  22. body_3d_keypoints = pipeline(
  23. Tasks.body_3d_keypoints, model=self.model_id)
  24. pipeline_input = self.test_video
  25. self.pipeline_inference(
  26. body_3d_keypoints, pipeline_input=pipeline_input)
  27. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  28. def test_run_modelhub_with_video_stream(self):
  29. body_3d_keypoints = pipeline(Tasks.body_3d_keypoints)
  30. cap = cv2.VideoCapture(self.test_video)
  31. if not cap.isOpened():
  32. raise Exception('modelscope error: %s cannot be decoded by OpenCV.'
  33. % (self.test_video))
  34. pipeline_input = self.test_video
  35. self.pipeline_inference(
  36. body_3d_keypoints, pipeline_input=pipeline_input)
  37. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  38. def test_demo_compatibility(self):
  39. self.compatibility_check()
  40. if __name__ == '__main__':
  41. unittest.main()