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.8 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.hub.snapshot_download import snapshot_download
  4. from modelscope.models import Model
  5. from modelscope.outputs import OutputKeys
  6. from modelscope.pipelines import pipeline
  7. from modelscope.pipelines.cv import ImageDenoisePipeline
  8. from modelscope.utils.constant import Tasks
  9. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  10. from modelscope.utils.test_utils import test_level
  11. class ImageDenoiseTest(unittest.TestCase, DemoCompatibilityCheck):
  12. def setUp(self) -> None:
  13. self.task = Tasks.image_denoising
  14. self.model_id = 'damo/cv_nafnet_image-denoise_sidd'
  15. demo_image_path = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/noisy-demo-0.png'
  16. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  17. def test_run_by_direct_model_download(self):
  18. cache_path = snapshot_download(self.model_id)
  19. pipeline = ImageDenoisePipeline(cache_path)
  20. pipeline.group_key = self.task
  21. denoise_img = pipeline(
  22. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG] # BGR
  23. h, w = denoise_img.shape[:2]
  24. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  25. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  26. def test_run_with_model_from_modelhub(self):
  27. model = Model.from_pretrained(self.model_id)
  28. pipeline_ins = pipeline(task=Tasks.image_denoising, model=model)
  29. denoise_img = pipeline_ins(
  30. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG] # BGR
  31. h, w = denoise_img.shape[:2]
  32. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  33. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  34. def test_run_with_model_name(self):
  35. pipeline_ins = pipeline(
  36. task=Tasks.image_denoising, model=self.model_id)
  37. denoise_img = pipeline_ins(
  38. input=self.demo_image_path)[OutputKeys.OUTPUT_IMG] # BGR
  39. h, w = denoise_img.shape[:2]
  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] # BGR
  46. h, w = denoise_img.shape[:2]
  47. print('pipeline: the shape of output_img is {}x{}'.format(h, w))
  48. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  49. def test_demo_compatibility(self):
  50. self.compatibility_check()
  51. if __name__ == '__main__':
  52. unittest.main()