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_segmentation_pipeline.py 1.2 kB

1234567891011121314151617181920212223242526272829303132333435
  1. # Copyright (c) Alibaba, Inc. and its affiliates.
  2. import unittest
  3. import numpy as np
  4. from PIL import Image
  5. from modelscope.metainfo import Pipelines
  6. from modelscope.pipelines import pipeline
  7. from modelscope.utils.constant import Tasks
  8. from modelscope.utils.test_utils import test_level
  9. class EasyCVSegmentationPipelineTest(unittest.TestCase):
  10. @unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
  11. def test_segformer_b0(self):
  12. img_path = 'data/test/images/image_segmentation.jpg'
  13. model_id = 'EasyCV/EasyCV-Segformer-b0'
  14. img = np.asarray(Image.open(img_path))
  15. object_detect = pipeline(task=Tasks.image_segmentation, model=model_id)
  16. outputs = object_detect(img_path)
  17. self.assertEqual(len(outputs), 1)
  18. results = outputs[0]
  19. self.assertListEqual(
  20. list(img.shape)[:2], list(results['seg_pred'][0].shape))
  21. self.assertListEqual(results['seg_pred'][0][1, :10].tolist(),
  22. [161 for i in range(10)])
  23. self.assertListEqual(results['seg_pred'][0][-1, -10:].tolist(),
  24. [133 for i in range(10)])
  25. if __name__ == '__main__':
  26. unittest.main()