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.6 kB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 panoptic_seg_masks_to_image
  8. from modelscope.utils.test_utils import test_level
  9. class ImagePanopticSegmentationTest(unittest.TestCase):
  10. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  11. def test_image_panoptic_segmentation(self):
  12. input_location = 'data/test/images/image_panoptic_segmentation.jpg'
  13. model_id = 'damo/cv_swinL_panoptic-segmentation_cocopan'
  14. pan_segmentor = pipeline(Tasks.image_segmentation, model=model_id)
  15. result = pan_segmentor(input_location)
  16. draw_img = panoptic_seg_masks_to_image(result[OutputKeys.MASKS])
  17. cv2.imwrite('result.jpg', draw_img)
  18. print('print test_image_panoptic_segmentation return success')
  19. @unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
  20. def test_image_panoptic_segmentation_from_PIL(self):
  21. input_location = 'data/test/images/image_panoptic_segmentation.jpg'
  22. model_id = 'damo/cv_swinL_panoptic-segmentation_cocopan'
  23. pan_segmentor = pipeline(Tasks.image_segmentation, model=model_id)
  24. PIL_array = PIL.Image.open(input_location)
  25. result = pan_segmentor(PIL_array)
  26. draw_img = panoptic_seg_masks_to_image(result[OutputKeys.MASKS])
  27. cv2.imwrite('result.jpg', draw_img)
  28. print('print test_image_panoptic_segmentation from PIL return success')
  29. if __name__ == '__main__':
  30. unittest.main()