2022-07-28 19:16:35 +08:00
|
|
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
|
|
from modelscope.pipelines import pipeline
|
2022-08-06 12:22:17 +08:00
|
|
|
from modelscope.utils.constant import Tasks
|
2022-07-28 19:16:35 +08:00
|
|
|
from modelscope.utils.test_utils import test_level
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Image2ImageTranslationTest(unittest.TestCase):
|
|
|
|
|
|
2022-08-31 12:57:14 +08:00
|
|
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
2022-07-28 19:16:35 +08:00
|
|
|
def test_run_modelhub(self):
|
|
|
|
|
r"""We provide three translation modes, i.e., uncropping, colorization and combination.
|
|
|
|
|
You can pass the following parameters for different mode.
|
|
|
|
|
1. Uncropping Mode:
|
|
|
|
|
result = img2img_gen_pipeline(('data/test/images/img2img_input.jpg', 'left', 0, 'result.jpg'))
|
|
|
|
|
2. Colorization Mode:
|
|
|
|
|
result = img2img_gen_pipeline(('data/test/images/img2img_input.jpg', 1, 'result.jpg'))
|
|
|
|
|
3. Combination Mode:
|
|
|
|
|
just like the following code.
|
|
|
|
|
"""
|
|
|
|
|
img2img_gen_pipeline = pipeline(
|
2022-08-02 20:21:05 +08:00
|
|
|
Tasks.image_to_image_translation,
|
2022-07-28 19:16:35 +08:00
|
|
|
model='damo/cv_latent_diffusion_image2image_translation')
|
|
|
|
|
result = img2img_gen_pipeline(
|
|
|
|
|
('data/test/images/img2img_input_mask.png',
|
|
|
|
|
'data/test/images/img2img_input_masked_img.png', 2,
|
|
|
|
|
'result.jpg')) # combination mode
|
|
|
|
|
|
|
|
|
|
print(f'output: {result}.')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
unittest.main()
|