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_retina_face_detection.py 1.1 kB

123456789101112131415161718192021222324252627282930313233
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os.path as osp
  3. import unittest
  4. import cv2
  5. from modelscope.pipelines import pipeline
  6. from modelscope.utils.constant import Tasks
  7. from modelscope.utils.cv.image_utils import draw_face_detection_result
  8. from modelscope.utils.test_utils import test_level
  9. class RetinaFaceDetectionTest(unittest.TestCase):
  10. def setUp(self) -> None:
  11. self.model_id = 'damo/cv_resnet50_face-detection_retinaface'
  12. def show_result(self, img_path, detection_result):
  13. img = draw_face_detection_result(img_path, detection_result)
  14. cv2.imwrite('result.png', img)
  15. print(f'output written to {osp.abspath("result.png")}')
  16. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  17. def test_run_modelhub(self):
  18. face_detection = pipeline(Tasks.face_detection, model=self.model_id)
  19. img_path = 'data/test/images/retina_face_detection.jpg'
  20. result = face_detection(img_path)
  21. self.show_result(img_path, result)
  22. if __name__ == '__main__':
  23. unittest.main()