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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_denoising, 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(
  35. task=Tasks.image_denoising, model=self.model_id)
  36. denoise_img = pipeline_ins(
  37. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG]
  38. denoise_img = Image.fromarray(denoise_img)
  39. w, h = denoise_img.size
  40. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  41. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  42. def test_run_with_default_model(self):
  43. pipeline_ins = pipeline(task=Tasks.image_denoising)
  44. denoise_img = pipeline_ins(
  45. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG]
  46. denoise_img = Image.fromarray(denoise_img)
  47. w, h = denoise_img.size
  48. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  49. if __name__ == '__main__':
  50. unittest.main()