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_image_super_resolution.py 1.2 kB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os
  3. import os.path as osp
  4. import unittest
  5. import cv2
  6. from modelscope.msdatasets import MsDataset
  7. from modelscope.outputs import OutputKeys
  8. from modelscope.pipelines import pipeline
  9. from modelscope.pipelines.base import Pipeline
  10. from modelscope.utils.constant import Tasks
  11. from modelscope.utils.test_utils import test_level
  12. class ImageSuperResolutionTest(unittest.TestCase):
  13. def setUp(self) -> None:
  14. self.model_id = 'damo/cv_rrdb_image-super-resolution'
  15. self.img = 'data/test/images/dogs.jpg'
  16. def pipeline_inference(self, pipeline: Pipeline, img: str):
  17. result = pipeline(img)
  18. if result is not None:
  19. cv2.imwrite('result.png', result[OutputKeys.OUTPUT_IMG])
  20. print(f'Output written to {osp.abspath("result.png")}')
  21. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  22. def test_run_modelhub(self):
  23. super_resolution = pipeline(
  24. Tasks.image_restoration, model=self.model_id)
  25. self.pipeline_inference(super_resolution, self.img)
  26. if __name__ == '__main__':
  27. unittest.main()