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_salient_detection.py 2.2 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. from modelscope.outputs import OutputKeys
  4. from modelscope.pipelines import pipeline
  5. from modelscope.utils.constant import Tasks
  6. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  7. from modelscope.utils.test_utils import test_level
  8. class SalientDetectionTest(unittest.TestCase, DemoCompatibilityCheck):
  9. def setUp(self) -> None:
  10. self.task = Tasks.semantic_segmentation
  11. self.model_id = 'damo/cv_u2net_salient-detection'
  12. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  13. def test_salient_detection(self):
  14. input_location = 'data/test/images/image_salient_detection.jpg'
  15. model_id = 'damo/cv_u2net_salient-detection'
  16. salient_detect = pipeline(Tasks.semantic_segmentation, model=model_id)
  17. result = salient_detect(input_location)
  18. import cv2
  19. cv2.imwrite(input_location + '_salient.jpg', result[OutputKeys.MASKS])
  20. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  21. def test_salient_boudary_detection(self):
  22. input_location = 'data/test/images/image_salient_detection.jpg'
  23. model_id = 'damo/cv_res2net_salient-detection'
  24. salient_detect = pipeline(Tasks.semantic_segmentation, model=model_id)
  25. result = salient_detect(input_location)
  26. import cv2
  27. cv2.imwrite(input_location + '_boudary_salient.jpg',
  28. result[OutputKeys.MASKS])
  29. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  30. def test_camouflag_detection(self):
  31. input_location = 'data/test/images/image_camouflag_detection.jpg'
  32. model_id = 'damo/cv_res2net_camouflaged-detection'
  33. camouflag_detect = pipeline(
  34. Tasks.semantic_segmentation, model=model_id)
  35. result = camouflag_detect(input_location)
  36. import cv2
  37. cv2.imwrite(input_location + '_camouflag.jpg',
  38. result[OutputKeys.MASKS])
  39. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  40. def test_demo_compatibility(self):
  41. self.compatibility_check()
  42. if __name__ == '__main__':
  43. unittest.main()