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_body_reshaping.py 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import os.path as osp
  3. import unittest
  4. import cv2
  5. from modelscope.hub.snapshot_download import snapshot_download
  6. from modelscope.outputs import OutputKeys
  7. from modelscope.pipelines import pipeline
  8. from modelscope.pipelines.base import Pipeline
  9. from modelscope.utils.constant import Tasks
  10. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  11. from modelscope.utils.test_utils import test_level
  12. class ImageBodyReshapingTest(unittest.TestCase, DemoCompatibilityCheck):
  13. def setUp(self) -> None:
  14. self.task = Tasks.image_body_reshaping
  15. self.model_id = 'damo/cv_flow-based-body-reshaping_damo'
  16. self.test_image = 'data/test/images/image_body_reshaping.jpg'
  17. def pipeline_inference(self, pipeline: Pipeline, input_location: str):
  18. result = pipeline(input_location)
  19. if result is not None:
  20. cv2.imwrite('result_bodyreshaping.png',
  21. result[OutputKeys.OUTPUT_IMG])
  22. print(
  23. f'Output written to {osp.abspath("result_body_reshaping.png")}'
  24. )
  25. else:
  26. raise Exception('Testing failed: invalid output')
  27. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  28. def test_run_by_direct_model_download(self):
  29. model_dir = snapshot_download(self.model_id)
  30. image_body_reshaping = pipeline(
  31. Tasks.image_body_reshaping, model=model_dir)
  32. self.pipeline_inference(image_body_reshaping, self.test_image)
  33. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  34. def test_run_modelhub(self):
  35. image_body_reshaping = pipeline(
  36. Tasks.image_body_reshaping, model=self.model_id)
  37. self.pipeline_inference(image_body_reshaping, self.test_image)
  38. @unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
  39. def test_run_modelhub_default_model(self):
  40. image_body_reshaping = pipeline(Tasks.image_body_reshaping)
  41. self.pipeline_inference(image_body_reshaping, self.test_image)
  42. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  43. def test_demo_compatibility(self):
  44. self.compatibility_check()
  45. if __name__ == '__main__':
  46. unittest.main()