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_image2image_translation.py 1.5 kB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os.path as osp
  3. import shutil
  4. import unittest
  5. from modelscope.fileio import File
  6. from modelscope.msdatasets import MsDataset
  7. from modelscope.pipelines import pipeline
  8. from modelscope.utils.constant import ModelFile, Tasks
  9. from modelscope.utils.test_utils import test_level
  10. class Image2ImageTranslationTest(unittest.TestCase):
  11. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  12. def test_run_modelhub(self):
  13. r"""We provide three translation modes, i.e., uncropping, colorization and combination.
  14. You can pass the following parameters for different mode.
  15. 1. Uncropping Mode:
  16. result = img2img_gen_pipeline(('data/test/images/img2img_input.jpg', 'left', 0, 'result.jpg'))
  17. 2. Colorization Mode:
  18. result = img2img_gen_pipeline(('data/test/images/img2img_input.jpg', 1, 'result.jpg'))
  19. 3. Combination Mode:
  20. just like the following code.
  21. """
  22. img2img_gen_pipeline = pipeline(
  23. Tasks.image_generation,
  24. model='damo/cv_latent_diffusion_image2image_translation')
  25. result = img2img_gen_pipeline(
  26. ('data/test/images/img2img_input_mask.png',
  27. 'data/test/images/img2img_input_masked_img.png', 2,
  28. 'result.jpg')) # combination mode
  29. print(f'output: {result}.')
  30. if __name__ == '__main__':
  31. unittest.main()