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_denoise.py 2.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from PIL import Image
  4. from modelscope.hub.snapshot_download import snapshot_download
  5. from modelscope.models import Model
  6. from modelscope.outputs import OutputKeys
  7. from modelscope.pipelines import pipeline
  8. from modelscope.pipelines.cv import ImageDenoisePipeline
  9. from modelscope.utils.constant import Tasks
  10. from modelscope.utils.test_utils import test_level
  11. class ImageDenoiseTest(unittest.TestCase):
  12. model_id = 'damo/cv_nafnet_image-denoise_sidd'
  13. demo_image_path = 'data/test/images/noisy-demo-1.png'
  14. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  15. def test_run_by_direct_model_download(self):
  16. cache_path = snapshot_download(self.model_id)
  17. pipeline = ImageDenoisePipeline(cache_path)
  18. denoise_img = pipeline(
  19. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG]
  20. denoise_img = Image.fromarray(denoise_img)
  21. w, h = denoise_img.size
  22. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  23. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  24. def test_run_with_model_from_modelhub(self):
  25. model = Model.from_pretrained(self.model_id)
  26. pipeline_ins = pipeline(task=Tasks.image_denoise, model=model)
  27. denoise_img = pipeline_ins(
  28. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG]
  29. denoise_img = Image.fromarray(denoise_img)
  30. w, h = denoise_img.size
  31. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  32. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  33. def test_run_with_model_name(self):
  34. pipeline_ins = pipeline(task=Tasks.image_denoise, model=self.model_id)
  35. denoise_img = pipeline_ins(
  36. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG]
  37. denoise_img = Image.fromarray(denoise_img)
  38. w, h = denoise_img.size
  39. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  40. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  41. def test_run_with_default_model(self):
  42. pipeline_ins = pipeline(task=Tasks.image_denoise)
  43. denoise_img = pipeline_ins(
  44. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG]
  45. denoise_img = Image.fromarray(denoise_img)
  46. w, h = denoise_img.size
  47. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  48. if __name__ == '__main__':
  49. unittest.main()