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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os.path as osp
  3. import unittest
  4. import cv2
  5. from modelscope.hub.snapshot_download import snapshot_download
  6. from modelscope.outputs import OutputKeys
  7. from modelscope.pipelines import pipeline
  8. from modelscope.pipelines.base import Pipeline
  9. from modelscope.utils.constant import Tasks
  10. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  11. from modelscope.utils.test_utils import test_level
  12. class SkinRetouchingTest(unittest.TestCase, DemoCompatibilityCheck):
  13. def setUp(self) -> None:
  14. self.task = Tasks.skin_retouching
  15. self.model_id = 'damo/cv_unet_skin-retouching'
  16. self.test_image = 'data/test/images/skin_retouching.png'
  17. def pipeline_inference(self, pipeline: Pipeline, input_location: str):
  18. result = pipeline(input_location)
  19. cv2.imwrite('result_skinretouching.png', result[OutputKeys.OUTPUT_IMG])
  20. print(f'Output written to {osp.abspath("result_skinretouching.png")}')
  21. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  22. def test_run_by_direct_model_download(self):
  23. model_dir = snapshot_download(self.model_id)
  24. skin_retouching = pipeline(Tasks.skin_retouching, model=model_dir)
  25. self.pipeline_inference(skin_retouching, self.test_image)
  26. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  27. def test_run_modelhub(self):
  28. skin_retouching = pipeline(Tasks.skin_retouching, model=self.model_id)
  29. self.pipeline_inference(skin_retouching, self.test_image)
  30. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  31. def test_run_modelhub_default_model(self):
  32. skin_retouching = pipeline(Tasks.skin_retouching)
  33. self.pipeline_inference(skin_retouching, self.test_image)
  34. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  35. def test_demo_compatibility(self):
  36. self.compatibility_check()
  37. if __name__ == '__main__':
  38. unittest.main()