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_text_to_image_synthesis.py 2.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import numpy as np
  4. from modelscope.models import Model
  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 TextToImageSynthesisTest(unittest.TestCase, DemoCompatibilityCheck):
  11. def setUp(self) -> None:
  12. self.task = Tasks.text_to_image_synthesis
  13. self.model_id = 'damo/cv_diffusion_text-to-image-synthesis_tiny'
  14. test_text = {
  15. 'text': '宇航员',
  16. 'generator_ddim_timesteps': 2,
  17. 'upsampler_256_ddim_timesteps': 2,
  18. 'upsampler_1024_ddim_timesteps': 2,
  19. 'debug': True
  20. }
  21. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  22. def test_run_with_model_from_modelhub(self):
  23. model = Model.from_pretrained(self.model_id)
  24. pipe_line_text_to_image_synthesis = pipeline(
  25. task=Tasks.text_to_image_synthesis, model=model)
  26. img = pipe_line_text_to_image_synthesis(
  27. self.test_text)[OutputKeys.OUTPUT_IMG]
  28. print(np.sum(np.abs(img)))
  29. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  30. def test_run_with_model_name(self):
  31. pipe_line_text_to_image_synthesis = pipeline(
  32. task=Tasks.text_to_image_synthesis, model=self.model_id)
  33. img = pipe_line_text_to_image_synthesis(
  34. self.test_text)[OutputKeys.OUTPUT_IMG]
  35. print(np.sum(np.abs(img)))
  36. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  37. def test_run_with_default_model(self):
  38. pipe_line_text_to_image_synthesis = pipeline(
  39. task=Tasks.text_to_image_synthesis)
  40. img = pipe_line_text_to_image_synthesis(
  41. self.test_text)[OutputKeys.OUTPUT_IMG]
  42. print(np.sum(np.abs(img)))
  43. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  44. def test_demo_compatibility(self):
  45. self.compatibility_check()
  46. if __name__ == '__main__':
  47. unittest.main()