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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import unittest
  2. import cv2
  3. import PIL
  4. from modelscope.outputs import OutputKeys
  5. from modelscope.pipelines import pipeline
  6. from modelscope.utils.constant import Tasks
  7. from modelscope.utils.cv.image_utils import semantic_seg_masks_to_image
  8. from modelscope.utils.logger import get_logger
  9. from modelscope.utils.test_utils import test_level
  10. class ImageSemanticSegmentationTest(unittest.TestCase):
  11. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  12. def test_image_semantic_segmentation_panmerge(self):
  13. input_location = 'data/test/images/image_semantic_segmentation.jpg'
  14. model_id = 'damo/cv_swinL_semantic-segmentation_cocopanmerge'
  15. segmenter = pipeline(Tasks.image_segmentation, model=model_id)
  16. result = segmenter(input_location)
  17. draw_img = semantic_seg_masks_to_image(result[OutputKeys.MASKS])
  18. cv2.imwrite('result.jpg', draw_img)
  19. print('test_image_semantic_segmentation_panmerge DONE')
  20. PIL_array = PIL.Image.open(input_location)
  21. result = segmenter(PIL_array)
  22. draw_img = semantic_seg_masks_to_image(result[OutputKeys.MASKS])
  23. cv2.imwrite('result.jpg', draw_img)
  24. print('test_image_semantic_segmentation_panmerge_from_PIL DONE')
  25. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  26. def test_image_semantic_segmentation_vitadapter(self):
  27. input_location = 'data/test/images/image_semantic_segmentation.jpg'
  28. model_id = 'damo/cv_vitadapter_semantic-segmentation_cocostuff164k'
  29. segmenter = pipeline(Tasks.image_segmentation, model=model_id)
  30. result = segmenter(input_location)
  31. draw_img = semantic_seg_masks_to_image(result[OutputKeys.MASKS])
  32. cv2.imwrite('result.jpg', draw_img)
  33. print('test_image_semantic_segmentation_vitadapter DONE')
  34. PIL_array = PIL.Image.open(input_location)
  35. result = segmenter(PIL_array)
  36. draw_img = semantic_seg_masks_to_image(result[OutputKeys.MASKS])
  37. cv2.imwrite('result.jpg', draw_img)
  38. print('test_image_semantic_segmentation_vitadapter_from_PIL DONE')
  39. if __name__ == '__main__':
  40. unittest.main()