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_face_2d_keypoints.py 1.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.outputs import OutputKeys
  4. from modelscope.pipelines import pipeline
  5. from modelscope.utils.constant import Tasks
  6. from modelscope.utils.cv.image_utils import draw_106face_keypoints
  7. from modelscope.utils.test_utils import test_level
  8. class EasyCVFace2DKeypointsPipelineTest(unittest.TestCase):
  9. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  10. def test_face_2d_keypoints(self):
  11. img_path = 'data/test/images/face_detection.png'
  12. model_id = 'damo/cv_mobilenet_face-2d-keypoints_alignment'
  13. face_2d_keypoints_align = pipeline(
  14. task=Tasks.face_2d_keypoints, model=model_id)
  15. output = face_2d_keypoints_align(img_path)
  16. output_keypoints = output[OutputKeys.KEYPOINTS]
  17. output_poses = output[OutputKeys.POSES]
  18. output_boxes = output[OutputKeys.BOXES]
  19. draw_106face_keypoints(
  20. img_path,
  21. output_keypoints,
  22. output_boxes,
  23. scale=2,
  24. save_path='face_keypoints.jpg')
  25. for idx in range(len(output_keypoints)):
  26. self.assertEqual(output_keypoints[idx].shape[0], 106)
  27. self.assertEqual(output_keypoints[idx].shape[1], 2)
  28. self.assertEqual(output_poses[idx].shape[0], 3)
  29. self.assertEqual(output_boxes[idx].shape[0], 4)
  30. if __name__ == '__main__':
  31. unittest.main()