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_panoptic_segmentation.py 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import cv2
  4. import PIL
  5. from modelscope.outputs import OutputKeys
  6. from modelscope.pipelines import pipeline
  7. from modelscope.utils.constant import Tasks
  8. from modelscope.utils.cv.image_utils import panoptic_seg_masks_to_image
  9. from modelscope.utils.demo_utils import DemoCompatibilityCheck
  10. from modelscope.utils.test_utils import test_level
  11. class ImagePanopticSegmentationTest(unittest.TestCase, DemoCompatibilityCheck):
  12. def setUp(self) -> None:
  13. self.task = Tasks.image_segmentation
  14. self.model_id = 'damo/cv_swinL_panoptic-segmentation_cocopan'
  15. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  16. def test_image_panoptic_segmentation(self):
  17. input_location = 'data/test/images/image_panoptic_segmentation.jpg'
  18. pan_segmentor = pipeline(Tasks.image_segmentation, model=self.model_id)
  19. result = pan_segmentor(input_location)
  20. draw_img = panoptic_seg_masks_to_image(result[OutputKeys.MASKS])
  21. cv2.imwrite('result.jpg', draw_img)
  22. print('print test_image_panoptic_segmentation return success')
  23. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  24. def test_image_panoptic_segmentation_from_PIL(self):
  25. input_location = 'data/test/images/image_panoptic_segmentation.jpg'
  26. pan_segmentor = pipeline(Tasks.image_segmentation, model=self.model_id)
  27. PIL_array = PIL.Image.open(input_location)
  28. result = pan_segmentor(PIL_array)
  29. draw_img = panoptic_seg_masks_to_image(result[OutputKeys.MASKS])
  30. cv2.imwrite('result.jpg', draw_img)
  31. print('print test_image_panoptic_segmentation from PIL return success')
  32. @unittest.skip('demo compatibility test is only enabled on a needed-basis')
  33. def test_demo_compatibility(self):
  34. self.compatibility_check()
  35. if __name__ == '__main__':
  36. unittest.main()