2022-07-25 13:07:20 +08:00
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
import cv2
|
2022-07-29 12:51:36 +08:00
|
|
|
from PIL import Image
|
2022-07-25 13:07:20 +08:00
|
|
|
|
|
|
|
|
from modelscope.outputs import OutputKeys
|
|
|
|
|
from modelscope.pipelines import pipeline
|
|
|
|
|
from modelscope.utils.constant import Tasks
|
|
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class VirtualTryonTest(unittest.TestCase):
|
2022-08-02 14:36:44 +08:00
|
|
|
model_id = 'damo/cv_daflow_virtual-try-on_base'
|
2022-07-29 12:51:36 +08:00
|
|
|
masked_model = Image.open('data/test/images/virtual_tryon_model.jpg')
|
|
|
|
|
pose = Image.open('data/test/images/virtual_tryon_pose.jpg')
|
|
|
|
|
cloth = Image.open('data/test/images/virtual_tryon_cloth.jpg')
|
|
|
|
|
input_imgs = (masked_model, pose, cloth)
|
2022-07-25 13:07:20 +08:00
|
|
|
|
2022-08-06 12:22:17 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
2022-07-25 13:07:20 +08:00
|
|
|
def test_run_with_model_name(self):
|
2022-08-02 14:36:44 +08:00
|
|
|
pipeline_virtual_try_on = pipeline(
|
|
|
|
|
task=Tasks.virtual_try_on, model=self.model_id)
|
|
|
|
|
img = pipeline_virtual_try_on(self.input_imgs)[OutputKeys.OUTPUT_IMG]
|
2022-07-25 13:07:20 +08:00
|
|
|
cv2.imwrite('demo.jpg', img[:, :, ::-1])
|
|
|
|
|
|
|
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
|
|
|
|
def test_run_with_model_name_default_model(self):
|
2022-08-02 14:36:44 +08:00
|
|
|
pipeline_virtual_tryon = pipeline(task=Tasks.virtual_try_on)
|
2022-07-25 13:07:20 +08:00
|
|
|
img = pipeline_virtual_tryon(self.input_imgs)[OutputKeys.OUTPUT_IMG]
|
|
|
|
|
cv2.imwrite('demo.jpg', img[:, :, ::-1])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|