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_text_driven_segmentation.py 1.0 kB

12345678910111213141516171819202122232425262728
  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.test_utils import test_level
  7. class TextDrivenSegmentationTest(unittest.TestCase):
  8. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  9. def test_text_driven_segmentation(self):
  10. input_location = 'data/test/images/text_driven_segmentation.jpg'
  11. test_input = {
  12. 'image': input_location,
  13. 'text': 'bear',
  14. }
  15. model_id = 'damo/cv_vitl16_segmentation_text-driven-seg'
  16. shop_seg = pipeline(Tasks.text_driven_segmentation, model=model_id)
  17. result = shop_seg(test_input)
  18. import cv2
  19. # result[OutputKeys.MASKS] is segment map result,other keys are not used
  20. cv2.imwrite(input_location + '_lseg.jpg', result[OutputKeys.MASKS])
  21. if __name__ == '__main__':
  22. unittest.main()