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_person_image_cartoon.py 1.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os
  3. import os.path as osp
  4. import unittest
  5. import cv2
  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.test_utils import test_level
  11. class ImageCartoonTest(unittest.TestCase):
  12. def setUp(self) -> None:
  13. self.model_id = 'damo/cv_unet_person-image-cartoon_compound-models'
  14. self.test_image = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_cartoon.png'
  15. def pipeline_inference(self, pipeline: Pipeline, input_location: str):
  16. result = pipeline(input_location)
  17. if result is not None:
  18. cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
  19. print(f'Output written to {osp.abspath("result.png")}')
  20. @unittest.skip('deprecated, download model from model hub instead')
  21. def test_run_by_direct_model_download(self):
  22. model_dir = './assets'
  23. if not os.path.exists(model_dir):
  24. os.system(
  25. 'wget https://invi-label.oss-cn-shanghai.aliyuncs.com/label/model/cartoon/assets.zip'
  26. )
  27. os.system('unzip assets.zip')
  28. img_cartoon = pipeline(Tasks.image_generation, model=model_dir)
  29. self.pipeline_inference(img_cartoon, self.test_image)
  30. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  31. def test_run_modelhub(self):
  32. img_cartoon = pipeline(Tasks.image_generation, model=self.model_id)
  33. self.pipeline_inference(img_cartoon, self.test_image)
  34. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  35. def test_run_modelhub_default_model(self):
  36. img_cartoon = pipeline(Tasks.image_generation)
  37. self.pipeline_inference(img_cartoon, self.test_image)
  38. if __name__ == '__main__':
  39. unittest.main()