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_virtual_try_on.py 1.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import cv2
  4. from PIL import Image
  5. from modelscope.outputs import OutputKeys
  6. from modelscope.pipelines import pipeline
  7. from modelscope.utils.constant import Tasks
  8. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  9. from modelscope.utils.test_utils import test_level
  10. class VirtualTryonTest(unittest.TestCase, DemoCompatibilityCheck):
  11. def setUp(self) -> None:
  12. self.task = Tasks.virtual_try_on
  13. self.model_id = 'damo/cv_daflow_virtual-try-on_base'
  14. masked_model = Image.open('data/test/images/virtual_tryon_model.jpg')
  15. pose = Image.open('data/test/images/virtual_tryon_pose.jpg')
  16. cloth = Image.open('data/test/images/virtual_tryon_cloth.jpg')
  17. input_imgs = (masked_model, pose, cloth)
  18. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  19. def test_run_with_model_name(self):
  20. pipeline_virtual_try_on = pipeline(
  21. task=Tasks.virtual_try_on, model=self.model_id)
  22. img = pipeline_virtual_try_on(self.input_imgs)[OutputKeys.OUTPUT_IMG]
  23. cv2.imwrite('demo.jpg', img[:, :, ::-1])
  24. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  25. def test_run_with_model_name_default_model(self):
  26. pipeline_virtual_tryon = pipeline(task=Tasks.virtual_try_on)
  27. img = pipeline_virtual_tryon(self.input_imgs)[OutputKeys.OUTPUT_IMG]
  28. cv2.imwrite('demo.jpg', img[:, :, ::-1])
  29. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  30. def test_demo_compatibility(self):
  31. self.compatibility_check()
  32. if __name__ == '__main__':
  33. unittest.main()